40 const double small=1e-28;
43 for(
int i=0;i<2;i++)
for(
int j=0;j<2;j++)
for(
int k=0;k<2;k++) shifts[i][j][k].clear();
47 for(
int l=-1;l<=1;l++)
for(
int m=-1;
m<=1;
m++)
for(
int n=-1;
n<=1;
n++){
50 int ishift[3]={l,
m,
n};
55 for(
int s=0;s<3;s++)
if(ishift[s]!=0) count++;
59 if(count==0 || count==3)
continue;
68 if(std::fabs(ref-dp*dp)<small)
continue;
71 for(
int i=0;i<2;i++)
for(
int j=0;j<2;j++)
for(
int k=0;k<2;k++){
73 int block[3]={2*i-1,2*j-1,2*k-1};
77 for(
int s=0;s<3;s++) if(ishift[s]*block[s]>0) skip=
true;
83 if(((1-ishift[s]*ishift[s])*block[s])*cosdir[s]<-small) skip=
false;
104 for(
int i=-smax;i<=smax;i++)
for(
int j=-smax;j<=smax;j++)
for(
int k=-smax;k<=smax;k++){
105 Vector trial=d+i*a0+j*a1+k*a2;
122 if(det*det<epsilon)
return;
127 if(
box(0,1)*
box(0,1)<epsilon &&
box(1,0)*
box(1,0)<epsilon) cxy=
true;
128 if(
box(0,2)*
box(0,2)<epsilon &&
box(2,0)*
box(2,0)<epsilon) cxz=
true;
129 if(
box(1,2)*
box(1,2)<epsilon &&
box(2,1)*
box(2,1)<epsilon) cyz=
true;
139 for(
unsigned i=0;i<3;i++){
155 else{
return (
delta(v1,v2) ).modulo(); }
168 }
else if(
type==
generic) {
180 if((std::fabs(s[0])+std::fabs(s[1])+std::fabs(s[2])>0.5)){
182 const std::vector<Vector> & myshifts(
shifts[(s[0]>0?1:0)][(s[1]>0?1:0)][(s[2]>0?1:0)]);
186 if(nshifts) *nshifts+=myshifts.size();
187 for(
int i=0;i<myshifts.size();i++){
188 Vector trial=d+myshifts[i];
198 }
else plumed_merror(
"unknown pbc type");
225 for(
int i=0;i<1000;i++){
228 for(
int j=0;j<3;j++)
for(
int k=0;k<3;k++)
if(r.
U01()>0.2){
229 box[j][k]=2.0*r.
U01()-1.0;
235 for(
int j=0;j<3;j++)
for(
int k=0;k<3;k++)
if(j!=k) box[j][k]=0.0;
236 for(
int j=1;j<3;j++) box[j][j]=box[0][0];
240 for(
int j=0;j<3;j++)
for(
int k=0;k<3;k++)
if(j!=k) box[j][k]=0.0;
245 int perm=r.
U01()*100;
247 a(0)=r.
U01()*2-2;
a(1)=0.0;
a(2)=0.0;
248 double d=r.
U01()*2-2;
250 Vector c(0.0,0.5*d,sqrt(3.0)*d*0.5);
259 int perm=r.
U01()*100;
260 double d=r.
U01()*2-2;
272 int perm=r.
U01()*100;
273 double d=r.
U01()*2-2;
289 std::cerr<<
"( "<<boxtype<<
" )\n";
291 for(
int j=0;j<3;j++)
for(
int k=0;k<3;k++) std::cerr<<
" "<<box[j][k];
293 std::cerr<<
"Determinant: "<<
determinant(box)<<
"\n";
294 std::cerr<<
"Shifts:";
295 for(
int j=0;j<2;j++)
for(
int k=0;k<2;k++)
for(
int l=0;l<2;l++) std::cerr<<
" "<<pbc.
shifts[j][k][l].size();
299 for(
int j=0;j<ntot;j++){
302 for(
int j=0;j<3;j++)
if(r.
U01()>0.2) v(j)=0.0;
310 std::cerr<<
"orig "<<v[0]<<
" "<<v[1]<<
" "<<v[2]<<
"\n";
311 std::cerr<<
"fast "<<fast[0]<<
" "<<fast[1]<<
" "<<fast[2]<<
"\n";
312 std::cerr<<
"full "<<full[0]<<
" "<<full[1]<<
" "<<full[2]<<
"\n";
317 std::cerr<<
"Average number of shifts: "<<double(nshifts)/double(ntot)<<
"\n";
Tensor invBox
Inverse box.
void zero()
set it to zero
double determinant(const TensorGeneric< 3, 3 > &t)
TensorGeneric< 3, 3 > inverse(const TensorGeneric< 3, 3 > &t)
double modulo() const
Compute the modulo.
TensorGeneric< m, n > transpose() const
return the transpose matrix
Class implementing fixed size matrices of doubles.
enum PLMD::Pbc::@6 type
Type of box.
TensorGeneric< n, l > matmul(const TensorGeneric< n, m > &a, const TensorGeneric< m, l > &b)
Class implementing fixed size vectors of doubles.
Vector scaledToReal(const Vector &) const
Transform a vector in scaled coordinates to a vector in real space.
Tensor reduced
Reduced box.
Vector diag
Alternative representation for orthorombic cells.
Tensor invReduced
Inverse of the reduced box.
void transpose(const Matrix< T > &A, Matrix< T > &AT)
Vector distance(const Vector &, const Vector &, int *nshifts) const
internal version of distance, also returns the number of attempted shifts (used in Pbc::test())...
double determinant() const
returns the determinant
std::vector< Vector > shifts[2][2][2]
List of shifts that should be attempted.
VectorGeneric< n > delta(const VectorGeneric< n > &v1, const VectorGeneric< n > &v2)
T dotProduct(const std::vector< T > &A, const std::vector< T > &B)
Calculate the dot product between two vectors.
const Tensor & getInvBox() const
Returns the inverse matrix of box.
double modulo2() const
compute the squared modulo
double modulo2(const VectorGeneric< n > &v)
static void test()
Perform some check. Useful for debugging.
void buildShifts(std::vector< Vector > shifts[2][2][2]) const
Build list of shifts.
void fullSearch(Vector &) const
Full search (for testing)
static void reduce(Vector &a, Vector &b)
Gaussian reduction.
bool isOrthorombic() const
Returns true if the box vectors are orthogonal.
TensorGeneric & setRow(unsigned i, const VectorGeneric< m > &r)
set i-th row
Vector3d Vector
Alias for three dimensional vectors.
Vector realToScaled(const Vector &) const
Transform a vector in real space to a vector in scaled coordinates.
VectorGeneric< m > getRow(unsigned i) const
get i-th row
TensorGeneric inverse() const
return the matrix inverse
const Tensor & getBox() const
Returns the box.
void setBox(const Tensor &b)
Set the lattice vectors.