OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
sum.hpp
1 /*
2 * sum.hpp
3 *
4 * Created on: Oct 13, 2015
5 * Author: i-bird
6 */
7
8 #ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_SUM_HPP_
9 #define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_SUM_HPP_
10
11 #include <boost/mpl/vector.hpp>
12 #include "config.h"
13 #include <unordered_map>
14 #include "util/for_each_ref.hpp"
15
21 template<typename v_expr>
23 {
25 typedef boost::mpl::size<v_expr> size;
26
28 typedef typename boost::mpl::at<v_expr,boost::mpl::int_<size::value-1> >::type last;
29
31 std::unordered_map<long int,typename last::stype> & cols;
32
35
38
41
43 typename last::stype coeff;
44
46 typename last::stype (& spacing)[last::dims];
47
48
62 typename last::stype (& spacing)[last::dims],
63 std::unordered_map<long int,typename last::stype> & cols,
64 typename last::stype coeff)
66 {};
67
73 template<typename T>
74 void operator()(T& t) const
75 {
76 boost::mpl::at<v_expr, boost::mpl::int_<T::value> >::type::value(g_map,kmap,gs,spacing,cols,coeff);
77 }
78
79};
80
91template<typename ... expr>
92struct sum
93{
95 typedef boost::mpl::vector<expr... > v_expr;
96
98 typedef typename boost::mpl::size<v_expr>::type v_sz;
99
101 typedef typename boost::mpl::at<v_expr, boost::mpl::int_<v_sz::type::value - 1> >::type Sys_eqs;
102
120 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims],
121 std::unordered_map<long int,typename Sys_eqs::stype > & cols,
122 typename Sys_eqs::stype coeff)
123 {
124 // Sum functor
125 sum_functor_value<v_expr> sm(g_map,kmap,gs,spacing,cols,coeff);
126
127 // for each element in the expression calculate the non-zero Matrix elements
128 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,v_sz::type::value - 1> >(sm);
129 }
130
131
132};
133
140template<typename arg, typename Sys_eqs>
141struct minus
142{
160 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims],
161 std::unordered_map<long int,typename Sys_eqs::stype > & cols,
162 typename Sys_eqs::stype coeff)
163 {
164 arg::value(g_map,kmap,gs,spacing,cols,-coeff);
165 }
166
167
168};
169
170#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_SUM_HPP_ */
Grid key for a distributed grid.
Declaration grid_sm.
Definition grid_sm.hpp:167
It ancapsulate the minus operation.
Definition sum.hpp:142
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)
Create the row of the Matrix.
Definition sum.hpp:157
sum functor value
Definition sum.hpp:23
grid_dist_key_dx< last::dims > & kmap
grid position
Definition sum.hpp:40
last::stype(& spacing)[last::dims]
spacing
Definition sum.hpp:46
boost::mpl::at< v_expr, boost::mpl::int_< size::value-1 > >::type last
Last element of sum.
Definition sum.hpp:28
void operator()(T &t) const
It call this function for every expression operand in the sum.
Definition sum.hpp:74
const stub_or_real< last, last::dims, typenamelast::stype, typenamelast::b_grid::decomposition::extended_type >::type & g_map
grid mapping
Definition sum.hpp:37
const grid_sm< last::dims, void > & gs
Grid info.
Definition sum.hpp:34
std::unordered_map< long int, typename last::stype > & cols
sum functor
Definition sum.hpp:31
boost::mpl::size< v_expr > size
Number of elements in the vector v_expr.
Definition sum.hpp:25
sum_functor_value(const typename stub_or_real< last, last::dims, typename last::stype, typename last::b_grid::decomposition::extended_type >::type &g_map, grid_dist_key_dx< last::dims > &kmap, const grid_sm< last::dims, void > &gs, typename last::stype(&spacing)[last::dims], std::unordered_map< long int, typename last::stype > &cols, typename last::stype coeff)
constructor
Definition sum.hpp:59
last::stype coeff
coefficent
Definition sum.hpp:43
It model an expression expr1 + ... exprn.
Definition sum.hpp:93
boost::mpl::at< v_expr, boost::mpl::int_< v_sz::type::value-1 > >::type Sys_eqs
struct that specify the syste, of equations
Definition sum.hpp:101
boost::mpl::size< v_expr >::type v_sz
size of v_expr
Definition sum.hpp:98
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 sum.hpp:117
boost::mpl::vector< expr... > v_expr
Transform from variadic template to boost mpl vector.
Definition sum.hpp:95