OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
Laplacian.hpp
1/*
2 * Laplacian.hpp
3 *
4 * Created on: Oct 5, 2015
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_
9#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_
10
11#include "FD_util_include.hpp"
12#include "util/util_num.hpp"
13#include "FiniteDifference/eq.hpp"
14
21template<typename arg, typename Sys_eqs, unsigned int impl=CENTRAL>
22class Lap
23{
44 std::unordered_map<long int,typename Sys_eqs::stype > & cols,
45 typename Sys_eqs::stype coeff)
46 {
47 std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " only CENTRAL, FORWARD, BACKWARD derivative are defined";
48 }
49};
50
67template<typename arg, typename Sys_eqs>
68class Lap<arg,Sys_eqs,CENTRAL>
69{
70public:
71
72
93 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims] ,
94 std::unordered_map<long int,typename Sys_eqs::stype > & cols,
95 typename Sys_eqs::stype coeff)
96 {
97 // for each dimension
98 for (size_t i = 0 ; i < Sys_eqs::dims ; i++)
99 {
100 long int old_val = kmap.getKeyRef().get(i);
101 kmap.getKeyRef().set_d(i, kmap.getKeyRef().get(i) + 1);
102 arg::value(g_map,kmap,gs,spacing,cols,coeff/spacing[i]/spacing[i]);
103 kmap.getKeyRef().set_d(i,old_val);
104
105 old_val = kmap.getKeyRef().get(i);
106 kmap.getKeyRef().set_d(i, kmap.getKeyRef().get(i) - 1);
107 arg::value(g_map,kmap,gs,spacing,cols,coeff/spacing[i]/spacing[i]);
108 kmap.getKeyRef().set_d(i,old_val);
109
110 arg::value(g_map,kmap,gs,spacing,cols, - 2.0 * coeff/spacing[i]/spacing[i]);
111 }
112 }
113};
114
115
132template<typename arg, typename Sys_eqs>
133class Lap<arg,Sys_eqs,CENTRAL_SYM>
134{
135public:
136
137
155 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)
156 {
157 // for each dimension
158 for (size_t i = 0 ; i < Sys_eqs::dims ; i++)
159 {
160 long int old_val = kmap.getKeyRef().get(i);
161 kmap.getKeyRef().set_d(i, kmap.getKeyRef().get(i) + 2);
162 arg::value(g_map,kmap,gs,spacing,cols,coeff/spacing[i]/spacing[i]/4.0);
163 kmap.getKeyRef().set_d(i,old_val);
164
165 old_val = kmap.getKeyRef().get(i);
166 kmap.getKeyRef().set_d(i, kmap.getKeyRef().get(i) - 2);
167 arg::value(g_map,kmap,gs,spacing,cols,coeff/spacing[i]/spacing[i]/4.0);
168 kmap.getKeyRef().set_d(i,old_val);
169
170 arg::value(g_map,kmap,gs,spacing,cols, - 2.0 * coeff/spacing[i]/spacing[i]/4.0);
171 }
172 }
173};
174
175#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_LAPLACIAN_HPP_ */
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.
Definition Laplacian.hpp:90
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.
Laplacian second order on h (spacing)
Definition Laplacian.hpp:23
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, std::unordered_map< long int, typename Sys_eqs::stype > &cols, typename Sys_eqs::stype coeff)
Calculate which colums of the Matrix are non zero.
Definition Laplacian.hpp:41
Grid key for a distributed grid.
base_key & getKeyRef()
Get the reference key.
Declaration grid_sm.
Definition grid_sm.hpp:167