Commit cdc8dd42 authored by incardon's avatar incardon

Continuing coding FD mul part

parent b4d8373a
...@@ -31,7 +31,7 @@ class D ...@@ -31,7 +31,7 @@ class D
* \tparam ord * \tparam ord
* *
*/ */
inline static std::unordered_map<long int,typename Sys_eqs::stype> value(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) inline 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)
{ {
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " only CENTRAL, FORWARD, BACKWARD derivative are defined"; std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " only CENTRAL, FORWARD, BACKWARD derivative are defined";
} }
......
...@@ -46,7 +46,7 @@ public: ...@@ -46,7 +46,7 @@ public:
// convert into global coordinate the position // convert into global coordinate the position
auto keyg = it.getGKey(key); auto keyg = it.getGKey(key);
// Convert local key into global key // Calculate the non-zero colums
T::value(keyg,gs,cols,1.0); T::value(keyg,gs,cols,1.0);
// create the triplet // create the triplet
......
...@@ -103,49 +103,6 @@ class minus ...@@ -103,49 +103,6 @@ class minus
} }
}; };
/*! \brief It model an expression expr1 * expr2
*
* \warning expr1 MUST be a constant expression
*
* \tparam expr1
* \tparam expr2
*
*/
template<typename expr1,typename expr2, typename Sys_eqs>
class mul
{
/*! \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<triplet<typename Sys_eqs::stype>> value_s(grid_key_dx<Sys_eqs::dims> & it)
{
return expr1::const_value(it) * expr2::value_s(it);
}
/*! \brief fill the row
*
*
*/
static void value_f(grid_key_dx<Sys_eqs::dims> & it)
{
return expr1::const_value(it) * expr2::value_s(it);
}
};
// spatial position + value // spatial position + value
template<unsigned int dim,typename T> template<unsigned int dim,typename T>
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "Laplacian.hpp" #include "Laplacian.hpp"
#include "FiniteDifference/eq.hpp" #include "FiniteDifference/eq.hpp"
#include "FiniteDifference/sum.hpp" #include "FiniteDifference/sum.hpp"
#include "FiniteDifference/mul.hpp"
#include "Grid/grid_dist_id.hpp" #include "Grid/grid_dist_id.hpp"
#include "data_type/scalar.hpp" #include "data_type/scalar.hpp"
#include "Decomposition/CartDecomposition.hpp" #include "Decomposition/CartDecomposition.hpp"
...@@ -41,12 +42,12 @@ struct lid_nn ...@@ -41,12 +42,12 @@ struct lid_nn
const bool lid_nn::boundary[] = {NON_PERIODIC,NON_PERIODIC}; const bool lid_nn::boundary[] = {NON_PERIODIC,NON_PERIODIC};
// Constant Field // Constant Field
struct eta struct eta
{ {
float val() {return 1.0;}
}; };
// Model the equation // Model the equations
constexpr unsigned int v[] = {0,1}; constexpr unsigned int v[] = {0,1};
constexpr unsigned int P = 2; constexpr unsigned int P = 2;
...@@ -73,6 +74,8 @@ typedef D<x,v_x,lid_nn> dx_vx; ...@@ -73,6 +74,8 @@ typedef D<x,v_x,lid_nn> dx_vx;
typedef D<y,v_y,lid_nn> dy_vy; typedef D<y,v_y,lid_nn> dy_vy;
typedef sum<dx_vx,dy_vy> incompressibility; typedef sum<dx_vx,dy_vy> incompressibility;
BOOST_AUTO_TEST_SUITE( eq_test_suite )
// Lid driven cavity, uncompressible fluid // Lid driven cavity, uncompressible fluid
BOOST_AUTO_TEST_CASE( lid_driven_cavity ) BOOST_AUTO_TEST_CASE( lid_driven_cavity )
...@@ -107,4 +110,6 @@ BOOST_AUTO_TEST_CASE( lid_driven_cavity ) ...@@ -107,4 +110,6 @@ BOOST_AUTO_TEST_CASE( lid_driven_cavity )
fd.impose(vy, g_dist.getGridInfo(), g_dist.getSubDomainIterator(bulk_start,bulk_end)); fd.impose(vy, g_dist.getGridInfo(), g_dist.getSubDomainIterator(bulk_start,bulk_end));
} }
BOOST_AUTO_TEST_SUITE_END()
#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_HPP_ */ #endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_EQ_UNIT_TEST_HPP_ */
...@@ -9,6 +9,46 @@ ...@@ -9,6 +9,46 @@
#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_SUM_HPP_ #define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_SUM_HPP_
#include <boost/mpl/vector.hpp> #include <boost/mpl/vector.hpp>
#include "config.h"
#include <unordered_map>
#include "util/for_each_ref.hpp"
template<typename v_expr>
struct sum_functor_value
{
//! Number of elements in the vector v_expr
typedef boost::mpl::size<v_expr> size;
//! Last element of sum
typedef typename boost::mpl::at<v_expr,boost::mpl::int_<size::value-1> >::type last;
//! sum functor
std::unordered_map<long int,typename last::stype> & cols;
const grid_sm<last::dims,void> & gs;
//! position
grid_key_dx<last::dims> & key;
//! coefficent
typename last::stype coeff;
/*! \brief constructor
*
*/
sum_functor_value(grid_key_dx<last::dims> & key, const grid_sm<last::dims,void> & gs, typename last::stype coeff)
:cols(cols),gs(gs),key(key),coeff(coeff)
{};
//! It call this function for every expression in the sum
template<typename T>
void operator()(T& t) const
{
boost::mpl::at<v_expr, boost::mpl::int_<T::value> >::type::value(key,gs,cols,coeff);
}
};
/*! \brief It model an expression expr1 + ... exprn /*! \brief It model an expression expr1 + ... exprn
* *
...@@ -32,9 +72,13 @@ struct sum ...@@ -32,9 +72,13 @@ struct sum
* \tparam ord * \tparam ord
* *
*/ */
inline static std::unordered_map<long int,typename Sys_eqs::stype> value(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) inline static void value(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)
{ {
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " only CENTRAL, FORWARD, BACKWARD derivative are defined"; // Sum functor
sum_functor_value<v_expr> sm(pos,gs,coeff);
// for each element in the expression calculate the non-zero Matrix elements
boost::mpl::for_each_ref< boost::mpl::range_c<int,0,v_sz::type::value - 1> >(sm);
} }
/*! \brief Calculate the position where the derivative is calculated /*! \brief Calculate the position where the derivative is calculated
......
...@@ -6,3 +6,4 @@ ...@@ -6,3 +6,4 @@
#include "FiniteDifference/FDScheme_unit_tests.hpp" #include "FiniteDifference/FDScheme_unit_tests.hpp"
#include "FiniteDifference/util/common_test.hpp" #include "FiniteDifference/util/common_test.hpp"
#include "FiniteDifference/eq_unit_test.hpp" #include "FiniteDifference/eq_unit_test.hpp"
#include "util/util_num_unit_tests.hpp"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment