Skip to content
Snippets Groups Projects
Commit 939a3710 authored by Niklaus Johner's avatar Niklaus Johner
Browse files

Added function to wrap Vec3 and Vec3List in a periodic box

parent 02b50500
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@ Real (*Mat3Minor)(const Mat3& m, unsigned int i, unsigned int j) = &Minor;
Vec3 (*Vec3Min)(const Vec3&, const Vec3&) = &Min;
Vec3 (*Vec3Max)(const Vec3&, const Vec3&) = &Max;
Real (*Vec3Distance2WithPBC)(const Vec3&, const Vec3&, const Vec3&) = &Distance2WithPBC;
Real (*Vec3DistanceWithPBC)(const Vec3&, const Vec3&, const Vec3&) = &DistanceWithPBC;
Real (*Vec3DistanceWithPBC)(const Vec3&, const Vec3&, const Vec3&) = &DistanceWithPBC;
void export_VecMat3_op()
{
......@@ -69,4 +69,6 @@ void export_VecMat3_op()
def("DistanceWithPBC",Vec3DistanceWithPBC);
def("MinDistance",MinDistance);
def("MinDistanceWithPBC",MinDistanceWithPBC);
def("WrapVec3",WrapVec3);
def("WrapVec3List",WrapVec3List);
}
......@@ -227,5 +227,26 @@ Real MinDistanceWithPBC(const Vec3List& l1, const Vec3List& l2, Vec3& basis_vec)
}
return std::sqrt(min);
}
Vec3 WrapVec3(const Vec3& v1,const Vec3& box_center,const Vec3& basis_vec){
Vec3 v;
Real r;
for (int i=0; i<3; i++) {
r=(v1[i]-box_center[i])/basis_vec[i];
r=(r > 0.0) ? std::floor(r + 0.5) : std::ceil(r - 0.5);
v[i]=v1[i]-basis_vec[i]*r;
}
return v;
}
Vec3List WrapVec3List(const Vec3List& vl, const Vec3& box_center,const Vec3& basis_vec){
Vec3List vl_out;
vl_out.reserve(vl_out.size());
for (Vec3List::const_iterator v1=vl.begin(),e=vl.end();v1!=e ; v1++) {
vl_out.push_back(WrapVec3(*v1,box_center,basis_vec));
}
return vl_out;
}
} // ns
......@@ -215,6 +215,13 @@ Real MinDistance(const Vec3List& l1, const Vec3List& l2);
//! returns the minimal distance between the points in two Vec3List
// with periodic boundaries in x,y,z given in basis_vec
Real MinDistanceWithPBC(const Vec3List& l1, const Vec3List& l2, Vec3& basis_vec);
//!wraps a vector in a box with periodic boundaries
Vec3 WrapVec3(const Vec3& v1,const Vec3& box_center,const Vec3& basis_vec);
//!wraps all the verctors in a Vec3List in a box with periodic boundaries
Vec3List WrapVec3List(const Vec3List& vl,const Vec3& box_center,const Vec3& basis_vec);
} // ns
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment