8#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_AVERAGE_HPP_
9#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_AVERAGE_HPP_
11#include "FiniteDifference/FD_util_include.hpp"
12#include "util/mathutil.hpp"
13#include "Vector/map_vector.hpp"
14#include "Grid/comb.hpp"
15#include "FiniteDifference/util/common.hpp"
16#include "util/util_num.hpp"
25template<
unsigned int d,
typename Field,
typename Sys_eqs,
unsigned int impl=CENTRAL>
35 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" only CENTRAL, FORWARD, BACKWARD derivative are defined";
50 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" only CENTRAL, FORWARD, BACKWARD derivative are defined";
64template<
unsigned int d,
typename arg,
typename Sys_eqs>
65class Avg<d,arg,Sys_eqs,CENTRAL>
85 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)
94 long int old_val = kmap.
getKeyRef().get(d);
96 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
102 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
118 auto arg_pos = arg::position(pos,gs,s_pos);
121 if (arg_pos.get(d) == -1)
147template<
unsigned int d,
typename arg,
typename Sys_eqs>
148class Avg<d,arg,Sys_eqs,FORWARD>
168 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)
171 long int old_val = kmap.
getKeyRef().get(d);
173 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
177 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
193 return arg::position(pos,gs,s_pos);
207template<
unsigned int d,
typename arg,
typename Sys_eqs>
208class Avg<d,arg,Sys_eqs,BACKWARD>
228 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)
230 long int old_val = kmap.
getKeyRef().get(d);
232 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
236 arg::value(g_map,kmap,gs,spacing,cols,coeff/2);
252 return arg::position(pos,gs,s_pos);
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 comb< Sys_eqs::dims >(&s_pos)[Sys_eqs::nvar])
Calculate the position in the cell where the average 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.
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.
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 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 openfpm::vector< comb< Sys_eqs::dims > > &s_pos=openfpm::vector< comb< Sys_eqs::dims > >())
Calculate the position where the derivative is calculated.
Grid key for a distributed grid.
base_key & getKeyRef()
Get the reference key.
grid_key_dx is the key to access any element in the grid
Implementation of 1-D std::vector like structure.
Position of the element of dimension d in the hyper-cube of dimension dim.
is_grid_staggered analyse T if it has a property grid_type defined and indicate that the grid is stag...