Commit 6c6b3e43 authored by Pietro Incardona's avatar Pietro Incardona

Finite differences it scale

parent 834b07c4
/*
* eq_unit_tests.hpp
*
* Created on: Sep 18, 2015
* Author: i-bird
*/
#ifndef OPENFPM_NUMERICS_SRC_EQUATIONS_EQ_UNIT_TESTS_HPP_
#define OPENFPM_NUMERICS_SRC_EQUATIONS_EQ_UNIT_TESTS_HPP_
#include "FiniteDifference/FDScheme.hpp"
BOOST_AUTO_TEST_SUITE( eq_test )
struct Sys_p
{
static const unsigned int dims = 3;
typedef float stype;
};
// define coordinates id
constexpr unsigned int x = 0;
constexpr unsigned int y = 1;
// define constants
constexpr unsigned int eta = 0;
constexpr unsigned int zeta = 1;
constexpr unsigned int gamma = 2;
constexpr unsigned int nu = 3;
constexpr unsigned int lambda = 4;
constexpr unsigned int dmu = 5;
constexpr unsigned int sigma[2][2] = {{6,7},{8,9}};
constexpr unsigned int p[] = {10,11};
constexpr unsigned int del_nu = 12;
constexpr unsigned int g_ext = 13;
// define variables fields
// velocity
constexpr unsigned int V[2] = {0,1};
// pressure
constexpr unsigned int P = 2;
// model Eq1 active Gel
//// First level expression
/*
*
* p_x^2
*
*/
//typedef mul<p[x],p[x],Sys_p> px2;
/*
*
* p_y^2
*
*/
//typedef mul<p[y],p[y],Sys_p> py2;
/*
* p_x * p_y
*
*/
//typedef mul<p[x],p[y],Sys_p> px_py;
BOOST_AUTO_TEST_CASE( eq_test_use)
{
// create an equation object
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* OPENFPM_NUMERICS_SRC_EQUATIONS_EQ_UNIT_TESTS_HPP_ */
...@@ -87,7 +87,7 @@ class Avg<d,arg,Sys_eqs,CENTRAL> ...@@ -87,7 +87,7 @@ class Avg<d,arg,Sys_eqs,CENTRAL>
* \snippet FDScheme_unit_tests.hpp Usage of stencil derivative * \snippet FDScheme_unit_tests.hpp Usage of stencil derivative
* *
*/ */
inline static void value(const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::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) 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)
{ {
// if the system is staggered the CENTRAL derivative is equivalent to a forward derivative // if the system is staggered the CENTRAL derivative is equivalent to a forward derivative
if (is_grid_staggered<Sys_eqs>::value()) if (is_grid_staggered<Sys_eqs>::value())
...@@ -170,7 +170,7 @@ class Avg<d,arg,Sys_eqs,FORWARD> ...@@ -170,7 +170,7 @@ class Avg<d,arg,Sys_eqs,FORWARD>
* \snippet FDScheme_unit_tests.hpp Usage of stencil derivative * \snippet FDScheme_unit_tests.hpp Usage of stencil derivative
* *
*/ */
inline static void value(const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::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) 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)
{ {
long int old_val = kmap.getKeyRef().get(d); long int old_val = kmap.getKeyRef().get(d);
...@@ -230,7 +230,7 @@ class Avg<d,arg,Sys_eqs,BACKWARD> ...@@ -230,7 +230,7 @@ class Avg<d,arg,Sys_eqs,BACKWARD>
* \snippet FDScheme_unit_tests.hpp Usage of stencil derivative * \snippet FDScheme_unit_tests.hpp Usage of stencil derivative
* *
*/ */
inline static void value(const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::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) 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)
{ {
long int old_val = kmap.getKeyRef().get(d); long int old_val = kmap.getKeyRef().get(d);
kmap.getKeyRef().set_d(d, kmap.getKeyRef().get(d) - 1); kmap.getKeyRef().set_d(d, kmap.getKeyRef().get(d) - 1);
......
...@@ -90,7 +90,7 @@ class D<d,arg,Sys_eqs,CENTRAL> ...@@ -90,7 +90,7 @@ class D<d,arg,Sys_eqs,CENTRAL>
* \snippet FDScheme_unit_tests.hpp Usage of stencil derivative * \snippet FDScheme_unit_tests.hpp Usage of stencil derivative
* *
*/ */
inline static void value(const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::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) 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)
{ {
// if the system is staggered the CENTRAL derivative is equivalent to a forward derivative // if the system is staggered the CENTRAL derivative is equivalent to a forward derivative
if (is_grid_staggered<Sys_eqs>::value()) if (is_grid_staggered<Sys_eqs>::value())
...@@ -205,7 +205,7 @@ public: ...@@ -205,7 +205,7 @@ public:
* \snippet FDScheme_unit_tests.hpp Usage of stencil derivative * \snippet FDScheme_unit_tests.hpp Usage of stencil derivative
* *
*/ */
static void value(const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::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) 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)
{ {
#ifdef SE_CLASS1 #ifdef SE_CLASS1
if (Sys_eqs::boundary[d] == PERIODIC) if (Sys_eqs::boundary[d] == PERIODIC)
...@@ -318,7 +318,7 @@ class D<d,arg,Sys_eqs,FORWARD> ...@@ -318,7 +318,7 @@ class D<d,arg,Sys_eqs,FORWARD>
* \snippet FDScheme_unit_tests.hpp Usage of stencil derivative * \snippet FDScheme_unit_tests.hpp Usage of stencil derivative
* *
*/ */
inline static void value(const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::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) 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)
{ {
long int old_val = kmap.getKeyRef().get(d); long int old_val = kmap.getKeyRef().get(d);
...@@ -374,7 +374,7 @@ class D<d,arg,Sys_eqs,BACKWARD> ...@@ -374,7 +374,7 @@ class D<d,arg,Sys_eqs,BACKWARD>
* \snippet FDScheme_unit_tests.hpp Usage of stencil derivative * \snippet FDScheme_unit_tests.hpp Usage of stencil derivative
* *
*/ */
inline static void value(const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::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) 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)
{ {
long int old_val = kmap.getKeyRef().get(d); long int old_val = kmap.getKeyRef().get(d);
......
...@@ -124,7 +124,7 @@ class FDScheme ...@@ -124,7 +124,7 @@ class FDScheme
public: public:
// Distributed grid map // Distributed grid map
typedef grid_dist_id<Sys_eqs::dims,typename Sys_eqs::stype,scalar<size_t>,typename Sys_eqs::b_grid::decomposition> g_map_type; typedef grid_dist_id<Sys_eqs::dims,typename Sys_eqs::stype,scalar<size_t>,typename Sys_eqs::b_grid::decomposition::extended_type> g_map_type;
typedef Sys_eqs Sys_eqs_typ; typedef Sys_eqs Sys_eqs_typ;
...@@ -135,7 +135,8 @@ private: ...@@ -135,7 +135,8 @@ private:
typedef typename Sys_eqs::SparseMatrix_type::triplet_type triplet; typedef typename Sys_eqs::SparseMatrix_type::triplet_type triplet;
openfpm::vector<typename Sys_eqs::stype> b; // Vector b
typename Sys_eqs::Vector_type b;
// Domain Grid informations // Domain Grid informations
const grid_sm<Sys_eqs::dims,void> & gs; const grid_sm<Sys_eqs::dims,void> & gs;
...@@ -325,13 +326,14 @@ public: ...@@ -325,13 +326,14 @@ public:
* \param pd Padding, how many points out of boundary are present * \param pd Padding, how many points out of boundary are present
* \param domain extension of the domain * \param domain extension of the domain
* \param gs grid infos where Finite differences work * \param gs grid infos where Finite differences work
* \param stencil maximum extension of the stencil on each directions
* \param dec Decomposition of the domain * \param dec Decomposition of the domain
* *
*/ */
FDScheme(Padding<Sys_eqs::dims> & pd, const Box<Sys_eqs::dims,typename Sys_eqs::stype> & domain, const grid_sm<Sys_eqs::dims,void> & gs, const typename Sys_eqs::b_grid::decomposition & dec) FDScheme(Padding<Sys_eqs::dims> & pd, const Ghost<Sys_eqs::dims,long int> & stencil, const Box<Sys_eqs::dims,typename Sys_eqs::stype> & domain, const grid_sm<Sys_eqs::dims,void> & gs, const typename Sys_eqs::b_grid & b_g)
:pd(pd),gs(gs),g_map(dec,padding(gs.getSize(),pd),domain,Ghost<Sys_eqs::dims,typename Sys_eqs::stype>(1)),row(0),row_b(0) :pd(pd),gs(gs),g_map(b_g,stencil,pd),row(0),row_b(0)
{ {
Vcluster & v_cl = dec.getVC(); Vcluster & v_cl = b_g.getDecomposition().getVC();
// Calculate the size of the local domain // Calculate the size of the local domain
size_t sz = g_map.getLocalDomainSize(); size_t sz = g_map.getLocalDomainSize();
...@@ -364,10 +366,7 @@ public: ...@@ -364,10 +366,7 @@ public:
} }
// sync the ghost // sync the ghost
g_map.write("g_map_before_ghost.vtk");
g_map.template ghost_get<0>(); g_map.template ghost_get<0>();
g_map.write("g_map_after_ghost.vtk");
// Create a CellDecomposer and calculate the spacing // Create a CellDecomposer and calculate the spacing
...@@ -399,8 +398,8 @@ public: ...@@ -399,8 +398,8 @@ public:
template<typename T> void impose(const T & op , typename Sys_eqs::stype num ,long int id ,const long int (& start)[Sys_eqs::dims], const long int (& stop)[Sys_eqs::dims], bool skip_first = false) template<typename T> void impose(const T & op , typename Sys_eqs::stype num ,long int id ,const long int (& start)[Sys_eqs::dims], const long int (& stop)[Sys_eqs::dims], bool skip_first = false)
{ {
// add padding to start and stop // add padding to start and stop
grid_key_dx<Sys_eqs::dims> start_k = grid_key_dx<Sys_eqs::dims>(start) + pd.getKP1(); grid_key_dx<Sys_eqs::dims> start_k = grid_key_dx<Sys_eqs::dims>(start);
grid_key_dx<Sys_eqs::dims> stop_k = grid_key_dx<Sys_eqs::dims>(stop) + pd.getKP1(); grid_key_dx<Sys_eqs::dims> stop_k = grid_key_dx<Sys_eqs::dims>(stop);
auto it = g_map.getSubDomainIterator(start_k,stop_k); auto it = g_map.getSubDomainIterator(start_k,stop_k);
...@@ -423,6 +422,8 @@ public: ...@@ -423,6 +422,8 @@ public:
*/ */
template<typename T> void impose(const T & op , typename Sys_eqs::stype num ,long int id ,grid_dist_iterator_sub<Sys_eqs::dims,typename g_map_type::d_grid> it_d, bool skip_first = false) template<typename T> void impose(const T & op , typename Sys_eqs::stype num ,long int id ,grid_dist_iterator_sub<Sys_eqs::dims,typename g_map_type::d_grid> it_d, bool skip_first = false)
{ {
Vcluster & v_cl = *global_v_cluster;
openfpm::vector<triplet> & trpl = A.getMatrixTriplets(); openfpm::vector<triplet> & trpl = A.getMatrixTriplets();
auto it = it_d; auto it = it_d;
...@@ -431,19 +432,21 @@ public: ...@@ -431,19 +432,21 @@ public:
std::unordered_map<long int,float> cols; std::unordered_map<long int,float> cols;
// resize b if needed // resize b if needed
b.resize(Sys_eqs::nvar * gs.size()); b.resize(Sys_eqs::nvar * g_map.size());
bool is_first = skip_first; bool is_first = skip_first;
// iterate all the grid points // iterate all the grid points
while (it.isNext()) while (it.isNext())
{ {
if (is_first == true) if (is_first == true && v_cl.getProcessUnitID() == 0)
{ {
++it; ++it;
is_first = false; is_first = false;
continue; continue;
} }
else
is_first = false;
// get the position // get the position
auto key = it.get(); auto key = it.get();
...@@ -463,7 +466,7 @@ public: ...@@ -463,7 +466,7 @@ public:
// std::cout << "(" << trpl.last().row() << "," << trpl.last().col() << "," << trpl.last().value() << ")" << "\n"; // std::cout << "(" << trpl.last().row() << "," << trpl.last().col() << "," << trpl.last().value() << ")" << "\n";
} }
b.get(g_map.template get<0>(key)*Sys_eqs::nvar + id) = num; b(g_map.template get<0>(key)*Sys_eqs::nvar + id) = num;
cols.clear(); cols.clear();
// std::cout << "\n"; // std::cout << "\n";
...@@ -491,14 +494,12 @@ public: ...@@ -491,14 +494,12 @@ public:
#ifdef SE_CLASS1 #ifdef SE_CLASS1
consistency(); consistency();
#endif #endif
A.resize(row,row); A.resize(g_map.size()*Sys_eqs::nvar,g_map.size()*Sys_eqs::nvar);
return A; return A;
} }
typename Sys_eqs::Vector_type B;
/*! \brief produce the B vector /*! \brief produce the B vector
* *
* \return the vector produced * \return the vector produced
...@@ -510,13 +511,7 @@ public: ...@@ -510,13 +511,7 @@ public:
consistency(); consistency();
#endif #endif
B.resize(row_b); return b;
// copy the vector
for (size_t i = 0; i < row_b; i++)
B.insert(i,b.get(i));
return B;
} }
}; };
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "util/grid_dist_testing.hpp" #include "util/grid_dist_testing.hpp"
#include "FiniteDifference/Average.hpp" #include "FiniteDifference/Average.hpp"
#include "FiniteDifference/sum.hpp" #include "FiniteDifference/sum.hpp"
#include "eq.hpp"
constexpr unsigned int x = 0; constexpr unsigned int x = 0;
constexpr unsigned int y = 1; constexpr unsigned int y = 1;
......
...@@ -33,7 +33,7 @@ class Lap ...@@ -33,7 +33,7 @@ class Lap
* \snippet FDScheme_unit_tests.hpp Laplacian usage * \snippet FDScheme_unit_tests.hpp Laplacian usage
* *
*/ */
inline static void value(const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::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) 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, 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";
} }
...@@ -88,7 +88,7 @@ public: ...@@ -88,7 +88,7 @@ public:
* \snippet FDScheme_unit_tests.hpp Laplacian usage * \snippet FDScheme_unit_tests.hpp Laplacian usage
* *
*/ */
inline static void value(const typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::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) 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)
{ {
// for each dimension // for each dimension
for (size_t i = 0 ; i < Sys_eqs::dims ; i++) for (size_t i = 0 ; i < Sys_eqs::dims ; i++)
......
...@@ -81,7 +81,7 @@ struct pos_val ...@@ -81,7 +81,7 @@ struct pos_val
template<unsigned int f, typename Sys_eqs> template<unsigned int f, typename Sys_eqs>
class Field class Field
{ {
typedef typename stub_or_real<Sys_eqs,Sys_eqs::dims,typename Sys_eqs::stype,typename Sys_eqs::b_grid::decomposition>::type map_grid; 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;
public: public:
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "Vector/Vector.hpp" #include "Vector/Vector.hpp"
#include "Solvers/umfpack_solver.hpp" #include "Solvers/umfpack_solver.hpp"
#include "data_type/aggregate.hpp" #include "data_type/aggregate.hpp"
#include "FiniteDifference/FDScheme.hpp"
BOOST_AUTO_TEST_SUITE( eq_test_suite ) BOOST_AUTO_TEST_SUITE( eq_test_suite )
...@@ -139,16 +140,18 @@ typedef Avg<y,v_x,lid_nn,FORWARD> avg_vx_f; ...@@ -139,16 +140,18 @@ typedef Avg<y,v_x,lid_nn,FORWARD> avg_vx_f;
BOOST_AUTO_TEST_CASE(lid_driven_cavity) BOOST_AUTO_TEST_CASE(lid_driven_cavity)
{ {
Vcluster & v_cl = *global_v_cluster;
//! [lid-driven cavity 2D] //! [lid-driven cavity 2D]
// Domain, a rectangle // Domain, a rectangle
Box<2,float> domain({0.0,0.0},{1.0,1.0}); Box<2,float> domain({0.0,0.0},{3.0,1.0});
// Ghost (Not important in this case but required) // Ghost (Not important in this case but required)
Ghost<2,float> g(0.01); Ghost<2,float> g(0.01);
// Grid points on x=256 and y=64 // Grid points on x=256 and y=64
long int sz[] = {8,8}; long int sz[] = {256,64};
size_t szu[2]; size_t szu[2];
szu[0] = (size_t)sz[0]; szu[0] = (size_t)sz[0];
szu[1] = (size_t)sz[1]; szu[1] = (size_t)sz[1];
...@@ -165,8 +168,11 @@ BOOST_AUTO_TEST_CASE(lid_driven_cavity) ...@@ -165,8 +168,11 @@ BOOST_AUTO_TEST_CASE(lid_driven_cavity)
// Distributed grid that store the solution // Distributed grid that store the solution
grid_dist_id<2,float,aggregate<float[2],float>,CartDecomposition<2,float>> g_dist(szu,domain,g); grid_dist_id<2,float,aggregate<float[2],float>,CartDecomposition<2,float>> g_dist(szu,domain,g);
// Ghost stencil
Ghost<2,long int> stencil_max(1);
// Finite difference scheme // Finite difference scheme
FDScheme<lid_nn> fd(pd,domain,g_dist.getGridInfo(),g_dist.getDecomposition()); FDScheme<lid_nn> fd(pd, stencil_max, domain, g_dist.getGridInfo(), g_dist);
// Here we impose the equation, we start from the incompressibility Eq imposed in the bulk with the // Here we impose the equation, we start from the incompressibility Eq imposed in the bulk with the
// exception of the first point {0,0} and than we set P = 0 in {0,0}, why we are doing this is again // exception of the first point {0,0} and than we set P = 0 in {0,0}, why we are doing this is again
...@@ -218,12 +224,35 @@ BOOST_AUTO_TEST_CASE(lid_driven_cavity) ...@@ -218,12 +224,35 @@ BOOST_AUTO_TEST_CASE(lid_driven_cavity)
//! [lid-driven cavity 2D] //! [lid-driven cavity 2D]
g_dist.write("lid_driven_cavity"); g_dist.write("lid_driven_cavity_p" + std::to_string(v_cl.getProcessingUnits()));
if (v_cl.getProcessUnitID() == 0)
// Check that match {
bool test = compare("lid_driven_cavity_grid_0_test.vtk","lid_driven_cavity_grid_0.vtk"); if (v_cl.getProcessingUnits() == 1)
BOOST_REQUIRE_EQUAL(test,true); {
// Check that match
bool test = compare("lid_driven_cavity_p1_grid_0_test.vtk","lid_driven_cavity_grid_0.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
else if (v_cl.getProcessingUnits() == 2)
{
// Check that match
bool test = compare("lid_driven_cavity_p2_grid_0_test.vtk","lid_driven_cavity_p2_grid_0.vtk");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("lid_driven_cavity_p2_grid_1_test.vtk","lid_driven_cavity_p2_grid_1.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
else if (v_cl.getProcessingUnits() == 3)
{
// Check that match
bool test = compare("lid_driven_cavity_p3_grid_0_test.vtk","lid_driven_cavity_p3_grid_0.vtk");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("lid_driven_cavity_p3_grid_1_test.vtk","lid_driven_cavity_p3_grid_1.vtk");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("lid_driven_cavity_p3_grid_2_test.vtk","lid_driven_cavity_p3_grid_2.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
}
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
......
...@@ -130,6 +130,8 @@ typedef Avg<x,v_z,lid_nn_3d,FORWARD> avg_x_vz_f; ...@@ -130,6 +130,8 @@ typedef Avg<x,v_z,lid_nn_3d,FORWARD> avg_x_vz_f;
BOOST_AUTO_TEST_CASE(lid_driven_cavity) BOOST_AUTO_TEST_CASE(lid_driven_cavity)
{ {
Vcluster & v_cl = *global_v_cluster;
// Domain // Domain
Box<3,float> domain({0.0,0.0,0.0},{3.0,1.0,1.0}); Box<3,float> domain({0.0,0.0,0.0},{3.0,1.0,1.0});
...@@ -154,8 +156,11 @@ BOOST_AUTO_TEST_CASE(lid_driven_cavity) ...@@ -154,8 +156,11 @@ BOOST_AUTO_TEST_CASE(lid_driven_cavity)
// Initialize openfpm // Initialize openfpm
grid_dist_id<3,float,aggregate<float[3],float>,CartDecomposition<3,float>> g_dist(szu,domain,g); grid_dist_id<3,float,aggregate<float[3],float>,CartDecomposition<3,float>> g_dist(szu,domain,g);
// Ghost stencil
Ghost<3,long int> stencil_max(1);
// Distributed grid // Distributed grid
FDScheme<lid_nn_3d> fd(pd,domain,g_dist.getGridInfo(),g_dist.getDecomposition()); FDScheme<lid_nn_3d> fd(pd,stencil_max,domain,g_dist.getGridInfo(),g_dist);
// start and end of the bulk // start and end of the bulk
...@@ -228,11 +233,35 @@ BOOST_AUTO_TEST_CASE(lid_driven_cavity) ...@@ -228,11 +233,35 @@ BOOST_AUTO_TEST_CASE(lid_driven_cavity)
// Bring the solution to grid // Bring the solution to grid
x.copy<FDScheme<lid_nn_3d>,decltype(g_dist),velocity,pressure>(fd,{0,0},{sz[0]-1,sz[1]-1,sz[2]-1},g_dist); x.copy<FDScheme<lid_nn_3d>,decltype(g_dist),velocity,pressure>(fd,{0,0},{sz[0]-1,sz[1]-1,sz[2]-1},g_dist);
g_dist.write("lid_driven_cavity_3d"); g_dist.write("lid_driven_cavity_3d_p" + std::to_string(v_cl.getProcessingUnits()));
// Check that match if (v_cl.getProcessUnitID() == 0)
bool test = compare("lid_driven_cavity_3d_grid_0.vtk","lid_driven_cavity_3d_grid_0_test.vtk"); {
BOOST_REQUIRE_EQUAL(test,true); if (v_cl.getProcessingUnits() == 1)
{
// Check that match
bool test = compare("lid_driven_cavity_3d_p1_grid_0_test.vtk","lid_driven_cavity_3d_p1_grid_0.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
else if (v_cl.getProcessingUnits() == 2)
{
// Check that match
bool test = compare("lid_driven_cavity_p2_grid_0_test.vtk","lid_driven_cavity_p2_grid_0.vtk");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("lid_driven_cavity_p2_grid_1_test.vtk","lid_driven_cavity_p2_grid_1.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
else if (v_cl.getProcessingUnits() == 3)
{
// Check that match
bool test = compare("lid_driven_cavity_p3_grid_0_test.vtk","lid_driven_cavity_p3_grid_0.vtk");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("lid_driven_cavity_p3_grid_1_test.vtk","lid_driven_cavity_p3_grid_1.vtk");
BOOST_REQUIRE_EQUAL(test,true);