Commit 173b92ab authored by incardon's avatar incardon

Test working

parent 6a195bfe
......@@ -13,6 +13,11 @@
#include <unordered_map>
#include "util/for_each_ref.hpp"
/*! \brief sum functor value
*
* \param v_expr vector expression
*
*/
template<typename v_expr>
struct sum_functor_value
{
......@@ -28,10 +33,10 @@
//! Grid info
const grid_sm<last::dims,void> & gs;
// grid mapping
//! grid mapping
const typename stub_or_real<last,last::dims,typename last::stype,typename last::b_grid::decomposition::extended_type>::type & g_map;
// grid position
//! grid position
grid_dist_key_dx<last::dims> & kmap;
//! coefficent
......@@ -42,13 +47,29 @@
/*! \brief constructor
*
* \param g_map Grid mapping, it convert grid position into vector/Matrix row
* \param kmap grid position
* \param gs grid information
* \param spacing grid spacing
* \param cols unordered map contain the map colum -> value
* \param coeff it contain an additional actual coefficients in front of the values
*
*/
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)
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)
:cols(cols),gs(gs),g_map(g_map),kmap(kmap),coeff(coeff),spacing(spacing)
{};
//! It call this function for every expression in the sum
/*! \brief It call this function for every expression operand in the sum
*
* \param t expression operand id
*
*/
template<typename T>
void operator()(T& t) const
{
......@@ -70,27 +91,35 @@
template<typename ... expr>
struct sum
{
// Transform from variadic template to boost mpl vector
//! Transform from variadic template to boost mpl vector
typedef boost::mpl::vector<expr... > v_expr;
// size of v_expr
//! size of v_expr
typedef typename boost::mpl::size<v_expr>::type v_sz;
//! struct that specify the syste, of equations
typedef typename boost::mpl::at<v_expr, boost::mpl::int_<v_sz::type::value - 1> >::type Sys_eqs;
/*! \brief Calculate which colums of the Matrix are non zero
*
* \param pos position where the derivative is calculated
* \param gs Grid info
* \param cols non-zero colums calculated by the function
* \param coeff coefficent (constant in front of the derivative)
* \param g_map Grid mapping, it convert grid position into vector/Matrix row
* \param kmap grid position
* \param gs grid information
* \param spacing grid spacing
* \param cols unordered map contain the map colum -> value
* \param coeff it contain an additional actual coefficients in front of the values
*
* ### Example
*
* \snippet FDScheme_unit_tests.hpp sum example
*
*/
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)
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)
{
// Sum functor
sum_functor_value<v_expr> sm(g_map,kmap,gs,spacing,cols,coeff);
......@@ -99,23 +128,15 @@ struct sum
boost::mpl::for_each_ref< boost::mpl::range_c<int,0,v_sz::type::value - 1> >(sm);
}
/*! \brief Calculate the position in the cell where the sum operator is performed
*
* it is done for the first element, the others are supposed to be in the same position
* it just return the position of the staggered property in the first expression
*
* \param position where we are calculating the derivative
* \param gs Grid info
* \param s_pos staggered position of the properties
*
*/
inline 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 boost::mpl::at<v_expr, boost::mpl::int_<0> >::type::position(pos,gs,s_pos);
}
};
};
/*! \brief It ancapsulate the minus operation
*
* \tparam arg
* \tparam Sys_eqs system of equation
*
*/
template<typename arg, typename Sys_eqs>
struct minus
{
......@@ -123,23 +144,27 @@ struct minus
*
* \tparam ord
*
* \snipper FDScheme_unit_tests.hpp minus example
* \snippet FDScheme_unit_tests.hpp minus example
*
* \param g_map Grid mapping, it convert grid position into vector/Matrix row
* \param kmap grid position
* \param gs grid information
* \param spacing grid spacing
* \param cols unordered map contain the map colum -> value
* \param coeff it contain an additional actual coefficients in front of the values
*
*/
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)
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)
{
arg::value(g_map,kmap,gs,spacing,cols,-coeff);
}
/*! \brief Calculate the position where the minus is calculated
*
* it just return the position of the staggered property at first expression
*
*/
inline 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])
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " only CENTRAL, FORWARD, BACKWARD derivative are defined";
}
};
#endif /* OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_SUM_HPP_ */
......@@ -875,7 +875,15 @@ public:
*/
void setRelTol(PetscReal rtol_)
{
PetscOptionsSetValue("-ksp_rtol",std::to_string(rtol_).c_str());
PetscReal rtol;
PetscReal abstol;
PetscReal dtol;
PetscInt maxits;
PETSC_SAFE_CALL(KSPGetTolerances(ksp,&rtol,&abstol,&dtol,&maxits));
PETSC_SAFE_CALL(KSPSetTolerances(ksp,rtol_,abstol,dtol,maxits));
// PetscOptionsSetValue("-ksp_rtol",std::to_string(rtol_).c_str());
}
/*! \brief Set the absolute tolerance as stop criteria
......@@ -887,7 +895,15 @@ public:
*/
void setAbsTol(PetscReal abstol_)
{
PetscOptionsSetValue("-ksp_atol",std::to_string(abstol_).c_str());
PetscReal rtol;
PetscReal abstol;
PetscReal dtol;
PetscInt maxits;
PETSC_SAFE_CALL(KSPGetTolerances(ksp,&rtol,&abstol,&dtol,&maxits));
PETSC_SAFE_CALL(KSPSetTolerances(ksp,rtol,abstol_,dtol,maxits));
// PetscOptionsSetValue("-ksp_atol",std::to_string(abstol_).c_str());
}
/*! \brief Set the divergence tolerance
......@@ -899,7 +915,15 @@ public:
*/
void setDivTol(PetscReal dtol_)
{
PetscOptionsSetValue("-ksp_dtol",std::to_string(dtol_).c_str());
PetscReal rtol;
PetscReal abstol;
PetscReal dtol;
PetscInt maxits;
PETSC_SAFE_CALL(KSPGetTolerances(ksp,&rtol,&abstol,&dtol,&maxits));
PETSC_SAFE_CALL(KSPSetTolerances(ksp,rtol,abstol,dtol_,maxits));
// PetscOptionsSetValue("-ksp_dtol",std::to_string(dtol_).c_str());
}
/*! \brief Set the maximum number of iteration for Krylov solvers
......@@ -909,8 +933,16 @@ public:
*/
void setMaxIter(PetscInt n)
{
PetscOptionsSetValue("-ksp_max_it",std::to_string(n).c_str());
maxits = n;
PetscReal rtol;
PetscReal abstol;
PetscReal dtol;
PetscInt maxits;
PETSC_SAFE_CALL(KSPGetTolerances(ksp,&rtol,&abstol,&dtol,&maxits));
PETSC_SAFE_CALL(KSPSetTolerances(ksp,rtol,abstol,dtol,n));
// PetscOptionsSetValue("-ksp_max_it",std::to_string(n).c_str());
this->maxits = n;
}
/*! For the BiCGStab(L) it define the number of search directions
......
This diff is collapsed.
This diff is collapsed.
......@@ -83,7 +83,7 @@ template<typename vector, unsigned int mom_p> void momenta_vector(vector & vd,ty
}
BOOST_AUTO_TEST_CASE( interpolation_full_test )
BOOST_AUTO_TEST_CASE( interpolation_full_test_2D )
{
Box<2,float> domain({0.0,0.0},{1.0,1.0});
size_t sz[2] = {64,64};
......@@ -107,9 +107,8 @@ BOOST_AUTO_TEST_CASE( interpolation_full_test )
vd.getPos(p)[0] = (double)rand()/RAND_MAX;
vd.getPos(p)[1] = (double)rand()/RAND_MAX;
vd.getPos(p)[2] = (double)rand()/RAND_MAX;
vd.getProp<0>(p) = 5.0/*(double)rand()/RAND_MAX*/;
vd.getProp<0>(p) = 5.0;
++it;
}
......@@ -249,6 +248,186 @@ BOOST_AUTO_TEST_CASE( interpolation_full_test )
}
}
BOOST_AUTO_TEST_CASE( interpolation_full_test_3D )
{
Box<3,double> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
size_t sz[3] = {64,64,64};
Ghost<3,long int> gg(2);
Ghost<3,double> gv(0.01);
size_t bc_v[3] = {PERIODIC,PERIODIC,PERIODIC};
{
vector_dist<3,double,aggregate<double>> vd(65536,domain,bc_v,gv);
grid_dist_id<3,double,aggregate<double>> gd(vd.getDecomposition(),sz,gg);
// set one particle on vd
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto p = it.get();
vd.getPos(p)[0] = (double)rand()/RAND_MAX;
vd.getPos(p)[1] = (double)rand()/RAND_MAX;
vd.getPos(p)[2] = (double)rand()/RAND_MAX;
vd.getProp<0>(p) = 5.0;
++it;
}
vd.map();
// Reset the grid
auto it2 = gd.getDomainGhostIterator();
while (it2.isNext())
{
auto key = it2.get();
gd.template get<0>(key) = 0.0;
++it2;
}
interpolate<decltype(vd),decltype(gd),mp4_kernel<double>> inte(vd,gd);
inte.p2m<0,0>(vd,gd);
double mg[3];
double mv[3];
momenta_grid<decltype(gd),0>(gd,mg);
momenta_vector<decltype(vd),0>(vd,mv);
BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
momenta_grid<decltype(gd),1>(gd,mg);
momenta_vector<decltype(vd),1>(vd,mv);
BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
momenta_grid<decltype(gd),2>(gd,mg);
momenta_vector<decltype(vd),2>(vd,mv);
BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
auto & v_cl = create_vcluster();
// We have to do a ghost get before interpolating m2p
// Before doing mesh to particle particle must be arranged
// into a grid like
vd.clear();
auto it4 = vd.getGridIterator(sz);
while(it4.isNext())
{
auto key = it4.get();
vd.add();
vd.getLastPos()[0] = key.get(0) * it4.getSpacing(0) + domain.getLow(0) + 0.1*it4.getSpacing(0);
vd.getLastPos()[1] = key.get(1) * it4.getSpacing(1) + domain.getLow(1) + 0.1*it4.getSpacing(1);
vd.getLastPos()[2] = key.get(2) * it4.getSpacing(2) + domain.getLow(2) + 0.1*it4.getSpacing(2);
vd.getLastProp<0>() = 0.0;
++it4;
}
// Reset also the grid
auto it5 = gd.getDomainGhostIterator();
while(it5.isNext())
{
auto key = it5.get();
gd.get<0>(key) = 0.0;
++it5;
}
gd.ghost_get<0>();
grid_key_dx<3> start({3,3,3});
grid_key_dx<3> stop({(long int)gd.size(0) - 4,(long int)gd.size(1) - 4,(long int)gd.size(2) - 4});
auto it6 = gd.getSubDomainIterator(start,stop);
while(it6.isNext())
{
auto key = it6.get();
gd.get<0>(key) = 5.0;
++it6;
}
gd.ghost_get<0>();
vd.map();
gd.ghost_get<0>();
inte.m2p<0,0>(gd,vd);
momenta_grid_domain<decltype(gd),0>(gd,mg);
momenta_vector<decltype(vd),0>(vd,mv);
v_cl.sum(mg[0]);
v_cl.sum(mg[1]);
v_cl.sum(mg[2]);
v_cl.sum(mv[0]);
v_cl.sum(mv[1]);
v_cl.sum(mv[2]);
v_cl.execute();
BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
momenta_grid_domain<decltype(gd),1>(gd,mg);
momenta_vector<decltype(vd),1>(vd,mv);
v_cl.sum(mg[0]);
v_cl.sum(mg[1]);
v_cl.sum(mg[2]);
v_cl.sum(mv[0]);
v_cl.sum(mv[1]);
v_cl.sum(mv[2]);
v_cl.execute();
BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
momenta_grid_domain<decltype(gd),2>(gd,mg);
momenta_vector<decltype(vd),2>(vd,mv);
v_cl.sum(mg[0]);
v_cl.sum(mg[1]);
v_cl.sum(mg[2]);
v_cl.sum(mv[0]);
v_cl.sum(mv[1]);
v_cl.sum(mv[2]);
v_cl.execute();
BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
}
}
BOOST_AUTO_TEST_CASE( int_kernel_test )
{
mp4_kernel<float> mp4;
......
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