eq.hpp 2.38 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * eq.hpp
 *
 *  Created on: Oct 5, 2015
 *      Author: i-bird
 */

#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_HPP_
#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_HPP_

#define EQS_FIELD 0
#define EQS_POS 1

14 15
//#define PERIODIC true
//#define NON_PERIODIC false
incardon's avatar
incardon committed
16

incardon's avatar
incardon committed
17
#include "util/util_num.hpp"
incardon's avatar
incardon committed
18
#include "Matrix/SparseMatrix.hpp"
19

incardon's avatar
incardon committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
/*! \brief Equation
 *
 * It model an equation like expr1 = expr2
 *
 * \tparam expr1
 * \tparam expr2
 *
 */
template<typename expr1,typename expr2,typename Sys_eqs>
class Eq
{
	/*! \brief Create the row of the Matrix
	 *
	 * \tparam ord
	 *
	 */
	template<unsigned int ord=EQS_FIELD> static void value(const grid_key_dx<Sys_eqs::dims> & pos)
	{
		if (EQS_FIELD)
			value_f(pos);
		else
			value_s(pos);
	}

	/*! \brief fill the row
	 *
	 *
	 */
	static openfpm::vector<cval<typename Sys_eqs::stype>> value_s(grid_key_dx<Sys_eqs::dims> & it)
	{
		return expr1::value_s(it) - expr2::value_s(it);
	}

	/*! \brief fill the row
	 *
	 *
	 */
	static void value_f(grid_key_dx<Sys_eqs::dims> & it)
	{
		return expr1::value_s(it) - expr2::value_s(it);
	}
};


// spatial position + value

template<unsigned int dim,typename T>
struct pos_val
{
	/*! \brief Initialize to zero the value
	 *
	 */
	pos_val()
	{
		value = 0.0;
	}

	grid_key_dx<dim> pos;
	T value;
};

template<unsigned int f, typename Sys_eqs>
class Field
{
84
	typedef typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition::extended_type::extended_type>::type map_grid;
incardon's avatar
incardon committed
85

incardon's avatar
incardon committed
86 87 88 89 90 91
public:

	/*! \brief fill the row
	 *
	 *
	 */
92
	static void value(const map_grid & 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)
incardon's avatar
incardon committed
93
	{
94 95 96 97 98 99 100 101 102 103
		cols[g_map.template get<0>(kmap)*Sys_eqs::nvar + f] += coeff;
	}

	/*! \brief
	 *
	 *
	 */
	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])
	{
			return grid_key_dx<Sys_eqs::dims>(s_pos[f]);
incardon's avatar
incardon committed
104 105 106 107 108 109 110 111 112 113
	}
};

class ConstField
{

};

inline size_t mat_factor(size_t nvar, size_t sz, const size_t ord)
{
114
	return nvar;
incardon's avatar
incardon committed
115 116
}

117 118 119 120 121 122
#include "mul.hpp"
#include "Average.hpp"
#include "Derivative.hpp"
#include "sum.hpp"
#include "Laplacian.hpp"

incardon's avatar
incardon committed
123
#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_HPP_ */