Laplacian.hpp 2.86 KB
 incardon committed Oct 14, 2015 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ``````/* * Laplacian.hpp * * Created on: Oct 5, 2015 * Author: i-bird */ #ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_ #define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_ /*! \brief Laplacian second order on h (spacing) * * \tparam Field which field derive * \tparam impl which implementation * */ template class Lap { /*! \brief Create the row of the Matrix * * \tparam ord * */ `````` incardon committed Nov 11, 2015 26 `````` inline static void value(const typename stub_or_real::type & g_map, grid_dist_key_dx & kmap , const grid_sm & gs, std::unordered_map & cols, typename Sys_eqs::stype coeff) `````` incardon committed Oct 14, 2015 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 `````` { std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " only CENTRAL, FORWARD, BACKWARD derivative are defined"; } /*! \brief Calculate the position where the laplacian is calculated * * In case on non staggered case this function just return pos, in case of staggered, * it calculate where the operator is calculated on a staggered grid * */ inline static grid_key_dx position(grid_key_dx & pos, const grid_sm & gs) { std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " only CENTRAL, FORWARD, BACKWARD derivative are defined"; } }; /*! \brief Derivative on direction i * * */ template class Lap { public: /*! \brief fill the row * * */ `````` incardon committed Nov 11, 2015 56 `````` inline static void value(const typename stub_or_real::type & g_map, grid_dist_key_dx & kmap , const grid_sm & gs, std::unordered_map & cols, typename Sys_eqs::stype coeff) `````` incardon committed Oct 14, 2015 57 58 59 60 `````` { // for each dimension for (size_t i = 0 ; i < Sys_eqs::dims ; i++) { `````` incardon committed Oct 28, 2015 61 62 63 64 `````` long int old_val = kmap.getKeyRef().get(i); kmap.getKeyRef().set_d(i, kmap.getKeyRef().get(i) + 1); arg::value(g_map,kmap,gs,cols,coeff); kmap.getKeyRef().set_d(i,old_val); `````` incardon committed Oct 14, 2015 65 `````` `````` incardon committed Oct 28, 2015 66 67 68 69 `````` old_val = kmap.getKeyRef().get(i); kmap.getKeyRef().set_d(i, kmap.getKeyRef().get(i) - 1); arg::value(g_map,kmap,gs,cols,coeff); kmap.getKeyRef().set_d(i,old_val); `````` incardon committed Oct 14, 2015 70 71 `````` } `````` incardon committed Oct 28, 2015 72 `````` arg::value(g_map,kmap,gs,cols, - 2.0 * Sys_eqs::dims * coeff); `````` incardon committed Oct 14, 2015 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 `````` } /*! \brief Calculate the position where the derivative is calculated * * In case of non staggered case this function just return pos, in case of staggered, * it calculate where the operator is calculated on a staggered grid * */ inline static grid_key_dx position(grid_key_dx & pos, const openfpm::vector> & s_pos, long int & fld) { return pos; } }; #endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_ */``````