Commit 318e7496 authored by incardon's avatar incardon

Fixing running test with SE_CLASS3

parent 63e26b66
openfpm_numerics @ 4cbdaaa7
Subproject commit 9a13102746a2160146c84318e54832c4d1c8e30e
Subproject commit 4cbdaaa7e37d236b598c130187170559d07d94c3
......@@ -117,7 +117,7 @@ public:
if (extends< typename boost::mpl::at<typename T::type,boost::mpl::int_<p> >::type >::mul() != cmb.size())
std::cerr << __FILE__ << ":" << __LINE__ << " error properties has " << extends< typename boost::mpl::at<typename T::type,boost::mpl::int_<p> >::type >::mul() << " components, but " << cmb.size() << "has been defined \n";
#endif
c_prp.get(p) = cmb;
c_prp[p] = cmb;
}
/*! \brief It set all the properties defined to be staggered on the default location
......
......@@ -16,6 +16,7 @@
#define SE3_STATUS -2
#define SE3_TYPE -1
#define SE3_SIZE 2
enum statuses
{
......@@ -37,6 +38,67 @@ enum ptype
INSIDE
};
// is initialized
template<typename T>
struct is_initialized
{
static const int init = UNINITIALIZED;
};
// is initialized
template<typename T>
struct is_initialized<openfpm::vector<T>>
{
static const int init = CLEAN;
};
///////////////////////////////
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to initialize the properties
*
* \tparam encap source
* \tparam encap dst
*
*/
template<unsigned int Np, typename vector>
struct init_prop
{
//! vector for prop initializetion
size_t (& prp_init)[Np];
/*! \brief constructor
*
*
* \param src encapsulated object1
* \param dst encapsulated object2
*
*/
inline init_prop(size_t ( & prp_init)[Np])
:prp_init(prp_init)
{
};
/*! \brief It call the copy function for each property
*
* \param t each member
*
*/
template<typename T>
inline void operator()(T& t) const
{
typedef typename boost::mpl::at<vector,boost::mpl::int_<T::value>>::type tc;
prp_init[T::value] = is_initialized<tc>::init;
}
};
// Unknown type
template<typename tcheck, bool foundamental>
struct typeCheck
......@@ -147,7 +209,7 @@ template<typename vector>
struct propCheckNAN
{
//! Data to check
vector & data;
const vector & data;
//! Element to check
size_t id;
......@@ -157,7 +219,7 @@ struct propCheckNAN
* \param
*
*/
inline propCheckNAN(vector & data, size_t id)
inline propCheckNAN(const vector & data, size_t id)
:data(data),id(id)
{};
......@@ -196,7 +258,7 @@ template<typename vector>
struct propCheckINF
{
//! Data to check
vector & data;
const vector & data;
//! id
size_t id;
......@@ -207,7 +269,7 @@ struct propCheckINF
* \param
*
*/
inline propCheckINF(vector & data, size_t id)
inline propCheckINF(const vector & data, size_t id)
:data(data),id(id)
{};
......@@ -261,7 +323,7 @@ class se_class3_vector
int sync[2][Np];
//! number of real properties + POSITION
static const size_t Np_real = Np+SE3_STATUS+1;
static const size_t Np_real = Np+SE3_STATUS;
//! Domain decomposition object
Decomposition & dec;
......@@ -272,6 +334,9 @@ class se_class3_vector
//! temporal buffer
openfpm::vector<size_t> non_NP;
//! last write
size_t l_wrt;
bool isLocalHalo(const Point<dim,T> & p)
{
for (size_t i = 0; i < dec.getNLocalSub(); i++)
......@@ -335,7 +400,7 @@ class se_class3_vector
{
non_NP.clear();
for (size_t i = 0 ; i < Np_real-1 ; i++)
for (size_t i = 0 ; i < Np_real ; i++)
{
bool found = false;
for (size_t j = 0 ; j < sizeof...(prp) ; j++)
......@@ -355,7 +420,7 @@ class se_class3_vector
std::string getPrpName(size_t i) const
{
if (i == Np_real-1)
if (i == Np_real)
return std::string("POSITION");
return std::to_string(i);
......@@ -382,8 +447,9 @@ class se_class3_vector
{
auto p = it.get();
for (size_t i = 0 ; i < Np_real ; i++)
vd.template getPropNC<Np+SE3_STATUS>(p)[i] = UNINITIALIZED;
init_prop<Np_real+1,typename vector::value_type::type> np_r(vd.template getPropNC<Np+SE3_STATUS>(p));
boost::mpl::for_each_ref< boost::mpl::range_c<int,0,Np_real+1> >(np_r);
vd.template getPropNC<Np+SE3_TYPE>(p) = INSIDE;
......@@ -452,9 +518,12 @@ class se_class3_vector
for (size_t i = 0 ; i < sizeof...(prp) ; i++)
{
if (vd.template getPropNC<Np+SE3_STATUS>(p)[gg[i]] == DIRTY)
vd.template getPropNC<Np+SE3_STATUS>(p)[gg[i]] = CLEAN;
{vd.template getPropNC<Np+SE3_STATUS>(p)[gg[i]] = CLEAN;}
}
if (vd.template getPropNC<Np+SE3_STATUS>(p)[Np_real] == DIRTY)
{vd.template getPropNC<Np+SE3_STATUS>(p)[Np_real] = CLEAN;}
vd.template getPropNC<Np+SE3_TYPE>(p) = GHOST;
++it2;
......@@ -463,7 +532,7 @@ class se_class3_vector
if (!(opt & KEEP_PROPERTIES))
{
for (size_t i = 0 ; i < non_NP.size() ; i++)
sync[GHOST][gg[i]] = NOTSYNC;
sync[GHOST][non_NP.get(i)] = NOTSYNC;
auto it = vd.getGhostIterator_no_se3();
......@@ -484,7 +553,9 @@ class se_class3_vector
sync[GHOST][gg[i]] = SYNC;
if (!(opt & NO_POSITION))
{
sync[GHOST][Np_real] = SYNC;
}
if (!(opt & KEEP_PROPERTIES))
{
......@@ -549,52 +620,12 @@ class se_class3_vector
{
auto p = it.get();
for (size_t j = 0 ; j < Np ; j++)
for (size_t j = 0 ; j < Np_real + 1 ; j++)
{
if (vd.template getPropNC<Np+SE3_STATUS>(p)[j] == DIRTY)
vd.template getPropNC<Np+SE3_STATUS>(p)[j] = CLEAN;
}
#ifdef CHECK_FOR_POSINF
if ( std::isinf(vd.getPosNC(p)[0]) || std::isinf(vd.getPosNC(p)[1]) || std::isinf(vd.getPosNC(p)[2]) )
{
std::cerr << __FILE__ << ":" << __LINE__ << " error detected INF in position for particle p=" << p.getKey() << " of type=" << getParticleTypeString(vd.template getPropNC<Np+SE3_TYPE>(p)) << std::endl;
ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
}
#endif
#ifdef CHECKFOR_POSNAN
if ( std::isnan(vd.getPosNC(p)[0]) || std::isnan(vd.getPosNC(p)[1]) || std::isnan(vd.getPosNC(p)[2]) )
{
std::cerr << __FILE__ << ":" << __LINE__ << " error detected NAN in position for particle p=" << p.getKey() << " of type=" << getParticleTypeString(vd.template getPropNC<Np+SE3_TYPE>(p)) << std::endl;
ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
}
#endif
#ifdef CHECKFOR_PROPINF
{
propCheckINF<vector> checker(vd,p.getKey());
boost::mpl::for_each_ref< boost::mpl::range_c<int,0, Np_real-1 > > (checker);
}
#endif
#ifdef CHECKFOR_PROPNAN
{
propCheckNAN<vector> checker(vd,p.getKey());
boost::mpl::for_each_ref< boost::mpl::range_c<int,0, Np_real-1 > >(checker);
}
#endif
++it;
}
}
......@@ -607,7 +638,7 @@ class se_class3_vector
{
auto p = it.get();
for (size_t j = 0 ; j < Np ; j++)
for (size_t j = 0 ; j < Np_real + 1 ; j++)
{
if (vd.template getPropNC<Np+SE3_STATUS>(p)[j] == DIRTY)
{
......@@ -621,7 +652,7 @@ class se_class3_vector
void map_post()
{
for (size_t j = 0 ; j < Np ; j++)
for (size_t j = 0 ; j < Np_real + 1 ; j++)
{
sync[GHOST][j] = NOTSYNC;
......@@ -633,12 +664,9 @@ class se_class3_vector
{
auto p = it.get();
for (size_t j = 0 ; j < Np ; j++)
{
Point<vector::dims,typename vector::stype> xp = vd.getPosNC(p);
vd.template getPropNC<Np+SE3_TYPE>(p) = getParticleType(xp,p.getKey(),vd);
}
++it;
}
......@@ -657,20 +685,20 @@ class se_class3_vector
str << __FILE__ << ":" << __LINE__ << " Error you are reading from the particle " << p << " of type " << type_str << " the property=" << getPrpName(prp) << ". But it result to be uninitialized" << std::endl;
// It is an error read from an uninitialized property
std::cerr << str.str();
std::cerr << str.str() << std::endl;
ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
}
if (vd.template getPropNC<Np+SE3_STATUS>(p)[prp] == DIRTY)
if (vd.template getPropNC<Np+SE3_STATUS>(p)[prp] == DIRTY && p != l_wrt)
{
std::cerr << __FILE__ << ":" << __LINE__ << " Warning you are reading from an particle that has been changed already in the same cycle" << std::endl;
std::cerr << __FILE__ << ":" << __LINE__ << " Warning you are reading from a particle that has been changed already in the same cycle" << std::endl;
ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
}
if (vd.template getPropNC<Np+SE3_TYPE>(p) == GHOST || vd.template getPropNC<Np+SE3_TYPE>(p) == HALO)
if (vd.template getPropNC<Np+SE3_TYPE>(p) == GHOST)
{
// if we read from the ghost we have to ensure that the ghost is in
// sync in particular that the state of the halo is CLEAR
// sync in particular that the state of the halo is CLEAN
if (sync[vd.template getPropNC<Np+SE3_TYPE>(p)][prp] != SYNC)
{
......@@ -678,6 +706,47 @@ class se_class3_vector
ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
}
}
#ifdef CHECK_FOR_POSINF
if ( std::isinf(vd.getPosNC(p)[0]) || std::isinf(vd.getPosNC(p)[1]) || std::isinf(vd.getPosNC(p)[2]) )
{
std::cerr << __FILE__ << ":" << __LINE__ << " error detected INF in position for particle p=" << p << " of type=" << getParticleTypeString(vd.template getPropNC<Np+SE3_TYPE>(p)) << std::endl;
ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
}
#endif
#ifdef CHECKFOR_POSNAN
if ( std::isnan(vd.getPosNC(p)[0]) || std::isnan(vd.getPosNC(p)[1]) || std::isnan(vd.getPosNC(p)[2]) )
{
std::cerr << __FILE__ << ":" << __LINE__ << " error detected NAN in position for particle p=" << p << " of type=" << getParticleTypeString(vd.template getPropNC<Np+SE3_TYPE>(p)) << std::endl;
ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
}
#endif
#ifdef CHECKFOR_PROPINF
{
propCheckINF<vector> checker(vd,p);
boost::mpl::for_each_ref< boost::mpl::range_c<int,0, Np_real > > (checker);
}
#endif
#ifdef CHECKFOR_PROPNAN
{
propCheckNAN<vector> checker(vd,p);
boost::mpl::for_each_ref< boost::mpl::range_c<int,0, Np_real > >(checker);
}
#endif
}
template<unsigned int prp> void write(vector & vd, size_t p)
......@@ -691,32 +760,28 @@ class se_class3_vector
vd.get_se_class3().template setGhostOutSync<prp>();
}
l_wrt = p;
}
//! Copy operator
se_class3_vector<Np,dim,T,Decomposition,vector> & operator=(const se_class3_vector<Np,dim,T,Decomposition,vector> & se3)
{
for (size_t i = 0 ; i < Np ; i++)
for (size_t i = 0 ; i < Np_real + 1 ; i++)
{
sync[0][i] = se3.sync[0][i];
sync[1][i] = se3.sync[1][i];
}
dec = se3.dec;
vd = se3.vd;
return *this;
}
template<unsigned int prp> void setHaloOutSync()
{
for (size_t i = 0 ; i < Np ; i++)
sync[HALO][prp] = NOTSYNC;
}
template<unsigned int prp> void setGhostOutSync()
{
for (size_t i = 0 ; i < Np ; i++)
sync[GHOST][prp] = NOTSYNC;
}
......
......@@ -558,7 +558,7 @@ BOOST_AUTO_TEST_CASE( vector_dist_class3_check_nan_inf )
{
try
{
auto it = vd.getDomainIterator();
vd.getPosRead(0);
}
catch (std::exception & e)
{
......@@ -585,7 +585,7 @@ BOOST_AUTO_TEST_CASE( vector_dist_class3_check_nan_inf )
{
try
{
auto it = vd2.getDomainIterator();
vd2.getLastPosRead();
}
catch (std::exception & e)
{
......
......@@ -743,6 +743,8 @@ public:
#endif
}
#ifndef ONLY_READWRITE_GETTER
/*! \brief Get the position of the last element
*
* \return the position of the element in space
......@@ -765,6 +767,8 @@ public:
return v_prp.template get<id>(g_m - 1);
}
#endif
////////////////////////////// READ AND WRITE VERSION //////////
/*! \brief Get the position of the last element
......@@ -775,7 +779,7 @@ public:
inline auto getLastPosRead() -> decltype(v_pos.template get<0>(0))
{
#ifdef SE_CLASS3
se3.read<prop::max_prop_real>(*this,g_m-1);
se3.template read<prop::max_prop_real>(*this,g_m-1);
#endif
return v_pos.template get<0>(g_m - 1);
......@@ -806,7 +810,7 @@ public:
inline auto getLastPosWrite() -> decltype(v_pos.template get<0>(0))
{
#ifdef SE_CLASS3
se3.write<prop::max_prop_real>(*this,g_m-1);
se3.template write<prop::max_prop_real>(*this,g_m-1);
#endif
return v_pos.template get<0>(g_m - 1);
......@@ -822,7 +826,7 @@ public:
template<unsigned int id> inline auto getLastPropWrite() -> decltype(v_prp.template get<id>(0))
{
#ifdef SE_CLASS3
se3.write<id>(*this,g_m-1);
se3.template write<id>(*this,g_m-1);
#endif
return v_prp.template get<id>(g_m - 1);
......@@ -882,10 +886,11 @@ public:
* \return the Cell list
*
*/
template<typename CellL = CellList_gen<dim, St, Process_keys_lin, Mem_fast, shift<dim, St> > > CellL getCellList(St r_cut)
template<typename CellL = CellList_gen<dim, St, Process_keys_lin, Mem_fast, shift<dim, St> > > CellL getCellList(St r_cut, bool no_se3 = false)
{
#ifdef SE_CLASS3
se3.getNN();
if (no_se3 == false)
{se3.getNN();}
#endif
#ifdef SE_CLASS1
check_ghost_compatible_rcut(r_cut);
......@@ -895,7 +900,7 @@ public:
Ghost<dim,St> g = getDecomposition().getGhost();
g.magnify(1.013);
return getCellList<CellL>(r_cut, g);
return getCellList<CellL>(r_cut, g,no_se3);
}
/*! \brief Construct an hilbert cell list starting from the stored particles
......@@ -930,10 +935,11 @@ public:
* \param cell_list Cell list to update
*
*/
template<typename CellL> void updateCellList(CellL & cell_list)
template<typename CellL> void updateCellList(CellL & cell_list, bool no_se3 = false)
{
#ifdef SE_CLASS3
se3.getNN();
if (no_se3 == false)
{se3.getNN();}
#endif
// This function assume equal spacing in all directions
......@@ -1012,10 +1018,11 @@ public:
* \return the CellList
*
*/
template<typename CellL = CellList_gen<dim, St, Process_keys_lin, Mem_fast, shift<dim, St> > > CellL getCellList(St r_cut, const Ghost<dim, St> & enlarge)
template<typename CellL = CellList_gen<dim, St, Process_keys_lin, Mem_fast, shift<dim, St> > > CellL getCellList(St r_cut, const Ghost<dim, St> & enlarge, bool no_se3 = false)
{
#ifdef SE_CLASS3
se3.getNN();
if (no_se3 == false)
{se3.getNN();}
#endif
CellL cell_list;
......@@ -1032,7 +1039,7 @@ public:
cell_list.Initialize(pbox, div, g_m);
cell_list.set_ndec(getDecomposition().get_ndec());
updateCellList(cell_list);
updateCellList(cell_list,no_se3);
return cell_list;
}
......@@ -1987,6 +1994,10 @@ public:
*/
template<typename cli> ParticleItCRS_Cells<dim,cli> getParticleIteratorCRS_Cell(cli & NN)
{
#ifdef SE_CLASS3
se3.getIterator();
#endif
#ifdef SE_CLASS1
if (!(opt & BIND_DEC_TO_GHOST))
{
......
......@@ -119,6 +119,8 @@ BOOST_AUTO_TEST_CASE( vector_dist_hdf5_save_test )
BOOST_AUTO_TEST_CASE( vector_dist_hdf5_load_test )
{
#ifndef SE_CLASS3
Vcluster & v_cl = create_vcluster();
Box<dim,float> box;
......@@ -169,6 +171,8 @@ BOOST_AUTO_TEST_CASE( vector_dist_hdf5_load_test )
++it2;
}
#endif
}
BOOST_AUTO_TEST_SUITE_END()
......
......@@ -222,21 +222,21 @@ BOOST_AUTO_TEST_CASE( vector_dist_multiphase_cell_list_sym_test )
phases.get(2).add();
phases.get(3).add();
phases.get(0).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
phases.get(0).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
phases.get(0).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
phases.get(0).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
phases.get(0).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
phases.get(0).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
phases.get(1).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
phases.get(1).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
phases.get(1).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
phases.get(1).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
phases.get(1).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
phases.get(1).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
phases.get(2).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
phases.get(2).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
phases.get(2).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
phases.get(2).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
phases.get(2).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
phases.get(2).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
phases.get(3).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
phases.get(3).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
phases.get(3).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
phases.get(3).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
phases.get(3).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
phases.get(3).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
++g_it;
}
......@@ -289,8 +289,8 @@ BOOST_AUTO_TEST_CASE( vector_dist_multiphase_cell_list_sym_test )
// Neighborhood particle q
auto q = Np.get();
phases.get(0).getProp<0>(p)++;
phases.get(1).getProp<0>(q)++;
phases.get(0).getPropWrite<0>(p)++;
phases.get(1).getPropWrite<0>(q)++;
++Np;
}
......@@ -301,13 +301,19 @@ BOOST_AUTO_TEST_CASE( vector_dist_multiphase_cell_list_sym_test )
phases.get(0).ghost_put<add_,0>();
phases.get(1).ghost_put<add_,0>();
#ifdef SE_CLASS3
phases.get(1).getDomainIterator();
#endif
it = phases.get(0).getDomainIterator();
while (it.isNext())
{
auto p = it.get();
ret &= phases.get(0).getProp<0>(p) == 7;
ret &= phases.get(1).getProp<0>(p) == 7;
ret &= phases.get(0).getPropRead<0>(p) == 7;