8 #ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_AVERAGE_HPP_
9 #define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_AVERAGE_HPP_
13 #define CENTRAL_B_ONE_SIDE 1
17 #include "util/mathutil.hpp"
18 #include "Vector/map_vector.hpp"
19 #include "Grid/comb.hpp"
20 #include "FiniteDifference/util/common.hpp"
21 #include "util/util_num.hpp"
30 template<
unsigned int d,
typename Field,
typename Sys_eqs,
unsigned int impl=CENTRAL>
40 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" only CENTRAL, FORWARD, BACKWARD derivative are defined";
55 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" only CENTRAL, FORWARD, BACKWARD derivative are defined";
69 template<
unsigned int d,
typename arg,
typename Sys_eqs>
70 class Avg<d,arg,Sys_eqs,CENTRAL>
90 inline static void value(
const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition::extended_type>::type & 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)
99 long int old_val = kmap.
getKeyRef().get(d);
101 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
107 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
123 auto arg_pos = arg::position(pos,gs,s_pos);
126 if (arg_pos.get(d) == -1)
152 template<
unsigned int d,
typename arg,
typename Sys_eqs>
153 class Avg<d,arg,Sys_eqs,FORWARD>
173 inline static void value(
const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition::extended_type>::type & 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)
176 long int old_val = kmap.
getKeyRef().get(d);
178 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
182 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
198 return arg::position(pos,gs,s_pos);
212 template<
unsigned int d,
typename arg,
typename Sys_eqs>
213 class Avg<d,arg,Sys_eqs,BACKWARD>
233 inline static void value(
const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition::extended_type>::type & 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)
235 long int old_val = kmap.
getKeyRef().get(d);
237 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
241 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
257 return arg::position(pos,gs,s_pos);
grid_key_dx< dim > & getKeyRef()
Get the reference key.
static void value(const typename stub_or_real< Sys_eqs, Sys_eqs::dims, typename Sys_eqs::stype, typename Sys_eqs::b_grid::decomposition::extended_type >::type &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)
Calculate which colums of the Matrix are non zero.
static grid_key_dx< Sys_eqs::dims > position(grid_key_dx< Sys_eqs::dims > &pos, const grid_sm< Sys_eqs::dims, void > &gs, const openfpm::vector< comb< Sys_eqs::dims >> &s_pos=openfpm::vector< comb< Sys_eqs::dims >>())
Calculate the position where the derivative is calculated.
static void value(const typename stub_or_real< Sys_eqs, Sys_eqs::dims, typename Sys_eqs::stype, typename Sys_eqs::b_grid::decomposition::extended_type >::type &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)
Calculate which colums of the Matrix are non zero.
Grid key for a distributed grid.
static void value(const grid_key_dx< Sys_eqs::dims > &pos, const grid_sm< Sys_eqs::dims, void > &gs, std::unordered_map< long int, typename Sys_eqs::stype > &cols, typename Sys_eqs::stype coeff)
Create the row of the Matrix.
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])
Calculate the position in the cell where the average is calculated.
is_grid_staggered analyse T if it has a property grid_type defined and indicate that the grid is stag...
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])
Calculate the position where the average is calculated.
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])
Calculate the position in the cell where the average is calculated.
Implementation of 1-D std::vector like structure.
static void value(const typename stub_or_real< Sys_eqs, Sys_eqs::dims, typename Sys_eqs::stype, typename Sys_eqs::b_grid::decomposition::extended_type >::type &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)
Calculate which colums of the Matrix are non zero.