4#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_FD_SIMPLE_HPP
5#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_FD_SIMPLE_HPP
8#include "Grid/grid_dist_id.hpp"
20template <
size_t Field,
typename gr
idtype,
typename keytype>
21auto FD_forward(gridtype &
grid, keytype & key,
size_t d)
23 return (
grid.template get<Field> (key.move(d, 1)) -
grid.template get<Field> (key)) /
grid.getSpacing()[d];
35template <
size_t Field,
typename gr
idtype,
typename keytype>
36auto FD_backward(gridtype &
grid, keytype & key,
size_t d)
38 return (
grid.template get<Field> (key) -
grid.template get<Field> (key.move(d, -1))) /
grid.getSpacing()[d];
52template <
size_t Field,
typename gr
idtype,
typename keytype>
53auto FD_central(gridtype &
grid, keytype & key,
size_t d)
55 return (
grid.template get<Field>(key.move(d, 1))
56 -
grid.template get<Field>(key.move(d, -1)))
57 / (2 *
grid.getSpacing()[d]);
69template <
size_t Field,
size_t Gradient,
typename gr
idtype>
70void get_central_FD_grid(gridtype &
grid,
const bool one_sided_BC)
72 grid.template ghost_get<Field>(KEEP_PROPERTIES);
73 auto dom =
grid.getDomainIterator();
79 auto key_g =
grid.getGKey(key);
80 for(
size_t d = 0; d < gridtype::dims; d++)
83 if (key_g.get(d) > 0 && key_g.get(d) <
grid.size(d) - 1)
86 grid.template get<Gradient> (key) [d] = FD_central<Field>(
grid, key, d);
88 else if (key_g.get(d) == 0)
90 grid.template get<Gradient> (key) [d] = FD_forward<Field>(
grid, key, d);
92 else if (key_g.get(d) >=
grid.size(d) - 1)
94 grid.template get<Gradient> (key) [d] = FD_backward<Field>(
grid, key, d);
104 auto key = dom.get();
105 for(
size_t d = 0; d < gridtype::dims; d++)
107 grid.template get<Gradient> (key) [d] = FD_central<Field>(
grid, key, d);