| 1 | /* |
| 2 | * eq.hpp |
| 3 | * |
| 4 | * Created on: Oct 5, 2015 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_HPP_ |
| 9 | #define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_HPP_ |
| 10 | |
| 11 | #define EQS_FIELD 0 |
| 12 | #define EQS_POS 1 |
| 13 | |
| 14 | //#define PERIODIC true |
| 15 | //#define NON_PERIODIC false |
| 16 | |
| 17 | #include "util/util_num.hpp" |
| 18 | #include "Matrix/SparseMatrix.hpp" |
| 19 | |
| 20 | /*! \brief Equation |
| 21 | * |
| 22 | * It model an equation like expr1 = expr2 |
| 23 | * |
| 24 | * \tparam expr1 |
| 25 | * \tparam expr2 |
| 26 | * |
| 27 | */ |
| 28 | template<typename expr1,typename expr2,typename Sys_eqs> |
| 29 | class Eq |
| 30 | { |
| 31 | /*! \brief Create the row of the Matrix |
| 32 | * |
| 33 | * \tparam ord |
| 34 | * |
| 35 | */ |
| 36 | template<unsigned int ord=EQS_FIELD> static void value(const grid_key_dx<Sys_eqs::dims> & pos) |
| 37 | { |
| 38 | if (EQS_FIELD) |
| 39 | value_f(pos); |
| 40 | else |
| 41 | value_s(pos); |
| 42 | } |
| 43 | |
| 44 | /*! \brief fill the row |
| 45 | * |
| 46 | * |
| 47 | */ |
| 48 | static openfpm::vector<cval<typename Sys_eqs::stype>> value_s(grid_key_dx<Sys_eqs::dims> & it) |
| 49 | { |
| 50 | return expr1::value_s(it) - expr2::value_s(it); |
| 51 | } |
| 52 | |
| 53 | /*! \brief fill the row |
| 54 | * |
| 55 | * |
| 56 | */ |
| 57 | static void value_f(grid_key_dx<Sys_eqs::dims> & it) |
| 58 | { |
| 59 | return expr1::value_s(it) - expr2::value_s(it); |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | // spatial position + value |
| 65 | |
| 66 | template<unsigned int dim,typename T> |
| 67 | struct pos_val |
| 68 | { |
| 69 | /*! \brief Initialize to zero the value |
| 70 | * |
| 71 | */ |
| 72 | pos_val() |
| 73 | { |
| 74 | value = 0.0; |
| 75 | } |
| 76 | |
| 77 | grid_key_dx<dim> pos; |
| 78 | T value; |
| 79 | }; |
| 80 | |
| 81 | template<unsigned int f, typename Sys_eqs> |
| 82 | class Field |
| 83 | { |
| 84 | typedef typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition::extended_type::extended_type>::type map_grid; |
| 85 | |
| 86 | public: |
| 87 | |
| 88 | /*! \brief fill the row |
| 89 | * |
| 90 | * |
| 91 | */ |
| 92 | static void value(const map_grid & g_map, grid_dist_key_dx<Sys_eqs::dims> & kmap, const grid_sm<Sys_eqs::dims,void> & gs, typename Sys_eqs::stype (& spacing )[Sys_eqs::dims] , std::unordered_map<long int,typename Sys_eqs::stype > & cols, typename Sys_eqs::stype coeff) |
| 93 | { |
| 94 | cols[g_map.template get<0>(kmap)*Sys_eqs::nvar + f] += coeff; |
| 95 | } |
| 96 | |
| 97 | /*! \brief |
| 98 | * |
| 99 | * |
| 100 | */ |
| 101 | static grid_key_dx<Sys_eqs::dims> position(grid_key_dx<Sys_eqs::dims> & pos, const grid_sm<Sys_eqs::dims,void> & gs, const comb<Sys_eqs::dims> (& s_pos)[Sys_eqs::nvar]) |
| 102 | { |
| 103 | return grid_key_dx<Sys_eqs::dims>(s_pos[f]); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | class ConstField |
| 108 | { |
| 109 | |
| 110 | }; |
| 111 | |
| 112 | inline size_t mat_factor(size_t nvar, size_t sz, const size_t ord) |
| 113 | { |
| 114 | return nvar; |
| 115 | } |
| 116 | |
| 117 | #include "mul.hpp" |
| 118 | #include "Average.hpp" |
| 119 | #include "Derivative.hpp" |
| 120 | #include "sum.hpp" |
| 121 | #include "Laplacian.hpp" |
| 122 | |
| 123 | #endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_HPP_ */ |
| 124 | |