| 1 | /* |
| 2 | * util.hpp |
| 3 | * |
| 4 | * Created on: Feb 23, 2016 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef OPENFPM_IO_SRC_PLOT_UTIL_HPP_ |
| 9 | #define OPENFPM_IO_SRC_PLOT_UTIL_HPP_ |
| 10 | |
| 11 | /*! \brief It fill the vector x with function values |
| 12 | * |
| 13 | * ### Define a function |
| 14 | * \snippet Plot_unit_tests.hpp Definition of a function |
| 15 | * ### Example vector with points on a specified range |
| 16 | * \snippet Plot_unit_tests.hpp fill a vector with a function |
| 17 | * |
| 18 | */ |
| 19 | template<typename T> static inline void Fill1D(T start, T stop, size_t np, openfpm::vector<T> & x,T f(T x)) |
| 20 | { |
| 21 | x.resize(np); |
| 22 | |
| 23 | T spacing = (stop - start) / (np - 1); |
| 24 | |
| 25 | for (size_t i = 0 ; i < np ; i++) |
| 26 | x.get(i) = f(start + i*spacing); |
| 27 | } |
| 28 | |
| 29 | /*! \brief It fill the vector x with uniformly distributed set of points |
| 30 | * |
| 31 | * ### Example vector with points on a specified range |
| 32 | * \snippet Plot_unit_tests.hpp fill a vector |
| 33 | * |
| 34 | */ |
| 35 | template<typename T> static inline void Fill1D(T start, T stop, size_t np, openfpm::vector<T> & x) |
| 36 | { |
| 37 | x.resize(np); |
| 38 | |
| 39 | T spacing = (stop - start) / (np - 1); |
| 40 | |
| 41 | for (size_t i = 0 ; i < np ; i++) |
| 42 | x.get(i) = start + i*spacing; |
| 43 | } |
| 44 | |
| 45 | #endif /* OPENFPM_IO_SRC_PLOT_UTIL_HPP_ */ |
| 46 | |