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

Rename basis_vec to ucell_size in the geom functions using Periodic boundary conditions

in view of adding PBC for non-orthogonal cells
parent d419feee
Branches
Tags
No related merge requests found
......@@ -208,20 +208,20 @@ Real MinDistance(const Vec3List& l1, const Vec3List& l2)
return std::sqrt(min);
}
Real MinDistanceWithPBC(const Vec3List& l1, const Vec3List& l2, Vec3& basis_vec)
Real MinDistanceWithPBC(const Vec3List& l1, const Vec3List& l2, Vec3& ucell_size)
{
// returns the minimal distance between two sets of points (Vec3List)
// given the periodic boundary condition along x,y,z given in the basis_vec
// given the periodic boundary condition along x,y,z given in the ucell_size
if (l1.size()==0 || l2.size()==0){throw GeomException("cannot calculate minimal distance: empty Vec3List");}
Real min=Length2(*l1.begin()-*l2.begin());
Real d;
Vec3 v;
for (int i=0; i<3; i++) {
basis_vec[i]=std::fabs(basis_vec[i]);
ucell_size[i]=std::fabs(ucell_size[i]);
}
for (Vec3List::const_iterator p1=l1.begin(),e1=l1.end(); p1!=e1; p1++) {
for (Vec3List::const_iterator p2=l2.begin(),e2=l2.end(); p2!=e2; p2++) {
d=Distance2WithPBC(*p1, *p2, basis_vec);
d=Distance2WithPBC(*p1, *p2, ucell_size);
if (d<min) min=d;
}
}
......@@ -268,22 +268,22 @@ Vec3List CalculateUnitCellVectors(const Vec3& ucell_size, const Vec3& ucell_angl
return ucell_vec;
}
Vec3 WrapVec3(const Vec3& v1,const Vec3& box_center,const Vec3& basis_vec){
Vec3 WrapVec3(const Vec3& v1,const Vec3& box_center,const Vec3& ucell_size){
Vec3 v;
Real r;
for (int i=0; i<3; i++) {
r=(v1[i]-box_center[i])/basis_vec[i];
r=(v1[i]-box_center[i])/ucell_size[i];
r=(r > 0.0) ? std::floor(r + 0.5) : std::ceil(r - 0.5);
v[i]=v1[i]-basis_vec[i]*r;
v[i]=v1[i]-ucell_size[i]*r;
}
return v;
}
Vec3List WrapVec3List(const Vec3List& vl, const Vec3& box_center,const Vec3& basis_vec){
Vec3List WrapVec3List(const Vec3List& vl, const Vec3& box_center,const Vec3& ucell_size){
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));
vl_out.push_back(WrapVec3(*v1,box_center,ucell_size));
}
return vl_out;
}
......
......@@ -195,35 +195,35 @@ inline Real Distance(const Vec3& p1, const Vec3& p2)
}
//! return the squared distance between two points with periodic boundaries in x,y,z given in basis_vec
inline Real Distance2WithPBC(const Vec3& v1, const Vec3& v2, const Vec3& basis_vec){
//! return the squared distance between two points with periodic boundaries in x,y,z given in ucell_size
inline Real Distance2WithPBC(const Vec3& v1, const Vec3& v2, const Vec3& ucell_size){
Vec3 v;
v=v1-v2;
for (int i=0; i<3; i++) {
if (std::fabs(v[i])>basis_vec[i]/2.){
v[i]=std::fabs(v[i])-basis_vec[i]*int(std::fabs(v[i])/basis_vec[i]+0.5);
if (std::fabs(v[i])>ucell_size[i]/2.){
v[i]=std::fabs(v[i])-ucell_size[i]*int(std::fabs(v[i])/ucell_size[i]+0.5);
}
}
return Length2(v);
}
//! return the distance between two points with periodic boundaries in x,y,z given in basis_vec
inline Real DistanceWithPBC(const Vec3& v1, const Vec3& v2, const Vec3& basis_vec){
return sqrt(Distance2WithPBC(v1, v2, basis_vec));
//! return the distance between two points with periodic boundaries in x,y,z given in ucell_size
inline Real DistanceWithPBC(const Vec3& v1, const Vec3& v2, const Vec3& ucell_size){
return sqrt(Distance2WithPBC(v1, v2, ucell_size));
}
//! returns the minimal distance between the points in two Vec3List
Real DLLEXPORT_OST_GEOM 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 DLLEXPORT_OST_GEOM MinDistanceWithPBC(const Vec3List& l1, const Vec3List& l2, Vec3& basis_vec);
// with periodic boundaries in x,y,z given in ucell_size
Real DLLEXPORT_OST_GEOM MinDistanceWithPBC(const Vec3List& l1, const Vec3List& l2, Vec3& ucell_size);
//! returns the indices index1, index2 corresponding to the points in
//! the Vec3List l1 and l2 having the minimal distance.
std::vector<unsigned int> DLLEXPORT_OST_GEOM MinDistanceIndices(const Vec3List& l1, const Vec3List& l2);
//! Calculates the Unit Cell Vectors from their sizes and angles (given as Vec3(gamma,beta,alpha)).
Vec3List DLLEXPORT_OST_GEOM CalculateUnitCellVectors(const Vec3& ucell_size, const Vec3& ucell_angles);
//!wraps a vector in a box with periodic boundaries
Vec3 DLLEXPORT_OST_GEOM WrapVec3(const Vec3& v1,const Vec3& box_center,const Vec3& basis_vec);
Vec3 DLLEXPORT_OST_GEOM WrapVec3(const Vec3& v1,const Vec3& box_center,const Vec3& ucell_size);
//!wraps all the verctors in a Vec3List in a box with periodic boundaries
Vec3List DLLEXPORT_OST_GEOM WrapVec3List(const Vec3List& vl,const Vec3& box_center,const Vec3& basis_vec);
Vec3List DLLEXPORT_OST_GEOM WrapVec3List(const Vec3List& vl,const Vec3& box_center,const Vec3& ucell_size);
} // ns
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment