| 1 |
tim |
1727 |
/* |
| 2 |
|
|
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
| 3 |
|
|
* |
| 4 |
|
|
* Contact: oopse@oopse.org |
| 5 |
|
|
* |
| 6 |
|
|
* This program is free software; you can redistribute it and/or |
| 7 |
|
|
* modify it under the terms of the GNU Lesser General Public License |
| 8 |
|
|
* as published by the Free Software Foundation; either version 2.1 |
| 9 |
|
|
* of the License, or (at your option) any later version. |
| 10 |
|
|
* All we ask is that proper credit is given for our work, which includes |
| 11 |
|
|
* - but is not limited to - adding the above copyright notice to the beginning |
| 12 |
|
|
* of your source code files, and to any copyright notice that you may distribute |
| 13 |
|
|
* with programs based on this work. |
| 14 |
|
|
* |
| 15 |
|
|
* This program is distributed in the hope that it will be useful, |
| 16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
|
|
* GNU Lesser General Public License for more details. |
| 19 |
|
|
* |
| 20 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
| 21 |
|
|
* along with this program; if not, write to the Free Software |
| 22 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 |
|
|
* |
| 24 |
|
|
*/ |
| 25 |
|
|
|
| 26 |
|
|
/** |
| 27 |
|
|
* @file Snapshot.cpp |
| 28 |
|
|
* @author tlin |
| 29 |
|
|
* @date 11/11/2004 |
| 30 |
|
|
* @time 10:56am |
| 31 |
|
|
* @version 1.0 |
| 32 |
|
|
*/ |
| 33 |
|
|
|
| 34 |
|
|
#include "brains/Snapshot.hpp" |
| 35 |
tim |
1869 |
#include "utils/NumericConstant.hpp" |
| 36 |
|
|
#include "utils/simError.h" |
| 37 |
tim |
1727 |
#include "utils/Utility.hpp" |
| 38 |
tim |
1804 |
namespace oopse { |
| 39 |
|
|
|
| 40 |
tim |
1869 |
void Snapshot::setHmat(const Mat3x3d& m) { |
| 41 |
|
|
const double orthoTolerance = NumericConstant::epsilon; |
| 42 |
|
|
hmat_ = m; |
| 43 |
|
|
invHmat_ = hmat_.inverse(); |
| 44 |
|
|
|
| 45 |
|
|
//prepare fortran Hmat |
| 46 |
|
|
double fortranHmat[9]; |
| 47 |
|
|
double fortranInvHmat[9]; |
| 48 |
|
|
hmat_.getArray(fortranHmat); |
| 49 |
|
|
invHmat_.getArray(fortranInvHmat); |
| 50 |
|
|
|
| 51 |
|
|
//determine whether the box is orthoTolerance or not |
| 52 |
|
|
int oldOrthoRhombic = orthoRhombic_; |
| 53 |
|
|
|
| 54 |
|
|
double smallDiag = fabs(hmat_(0, 0)); |
| 55 |
|
|
if(smallDiag > fabs(hmat_(1, 1))) smallDiag = fabs(hmat_(1, 1)); |
| 56 |
|
|
if(smallDiag > fabs(hmat_(2, 2))) smallDiag = fabs(hmat_(2, 2)); |
| 57 |
|
|
double tol = smallDiag * orthoTolerance; |
| 58 |
|
|
|
| 59 |
|
|
orthoRhombic_ = 1; |
| 60 |
|
|
|
| 61 |
|
|
for (int i = 0; i < 3; i++ ) { |
| 62 |
|
|
for (int j = 0 ; j < 3; j++) { |
| 63 |
|
|
if (i != j) { |
| 64 |
|
|
if (orthoRhombic_) { |
| 65 |
|
|
if ( fabs(hmat_(i, j)) >= tol) |
| 66 |
|
|
orthoRhombic_ = 0; |
| 67 |
|
|
} |
| 68 |
|
|
} |
| 69 |
|
|
} |
| 70 |
|
|
} |
| 71 |
|
|
|
| 72 |
|
|
if( oldOrthoRhombic != orthoRhombic_ ){ |
| 73 |
|
|
|
| 74 |
|
|
if( orthoRhombic_ ) { |
| 75 |
|
|
sprintf( painCave.errMsg, |
| 76 |
|
|
"OOPSE is switching from the default Non-Orthorhombic\n" |
| 77 |
|
|
"\tto the faster Orthorhombic periodic boundary computations.\n" |
| 78 |
|
|
"\tThis is usually a good thing, but if you wan't the\n" |
| 79 |
|
|
"\tNon-Orthorhombic computations, make the orthoBoxTolerance\n" |
| 80 |
|
|
"\tvariable ( currently set to %G ) smaller.\n", |
| 81 |
|
|
orthoTolerance); |
| 82 |
|
|
painCave.severity = OOPSE_INFO; |
| 83 |
|
|
simError(); |
| 84 |
|
|
} |
| 85 |
|
|
else { |
| 86 |
|
|
sprintf( painCave.errMsg, |
| 87 |
|
|
"OOPSE is switching from the faster Orthorhombic to the more\n" |
| 88 |
|
|
"\tflexible Non-Orthorhombic periodic boundary computations.\n" |
| 89 |
|
|
"\tThis is usually because the box has deformed under\n" |
| 90 |
|
|
"\tNPTf integration. If you wan't to live on the edge with\n" |
| 91 |
|
|
"\tthe Orthorhombic computations, make the orthoBoxTolerance\n" |
| 92 |
|
|
"\tvariable ( currently set to %G ) larger.\n", |
| 93 |
|
|
orthoTolerance); |
| 94 |
|
|
painCave.severity = OOPSE_WARNING; |
| 95 |
|
|
simError(); |
| 96 |
|
|
} |
| 97 |
|
|
} |
| 98 |
|
|
|
| 99 |
|
|
//notify fortran simulation box has changed |
| 100 |
|
|
setFortranBox(fortranHmat, fortranInvHmat, &orthoRhombic_); |
| 101 |
|
|
} |
| 102 |
|
|
|
| 103 |
|
|
|
| 104 |
tim |
1727 |
void Snapshot::wrapVector(Vector3d& pos) { |
| 105 |
|
|
|
| 106 |
|
|
int i; |
| 107 |
tim |
1765 |
Vector3d scaled; |
| 108 |
tim |
1727 |
|
| 109 |
|
|
if( !orthoRhombic_ ){ |
| 110 |
|
|
|
| 111 |
|
|
// calc the scaled coordinates. |
| 112 |
|
|
scaled = invHmat_* pos; |
| 113 |
|
|
|
| 114 |
|
|
// wrap the scaled coordinates |
| 115 |
|
|
for (i = 0; i < 3; ++i) { |
| 116 |
|
|
scaled[i] -= roundMe(scaled[i]); |
| 117 |
|
|
} |
| 118 |
|
|
|
| 119 |
|
|
// calc the wrapped real coordinates from the wrapped scaled coordinates |
| 120 |
|
|
pos = hmat_ * scaled; |
| 121 |
|
|
|
| 122 |
|
|
} else {//if it is orthoRhombic, we could improve efficiency by only caculating the diagonal element |
| 123 |
|
|
|
| 124 |
|
|
// calc the scaled coordinates. |
| 125 |
|
|
for (i=0; i<3; i++) { |
| 126 |
|
|
scaled[i] = pos[i] * invHmat_(i, i); |
| 127 |
|
|
} |
| 128 |
|
|
|
| 129 |
|
|
// wrap the scaled coordinates |
| 130 |
|
|
for (i = 0; i < 3; ++i) { |
| 131 |
|
|
scaled[i] -= roundMe(scaled[i]); |
| 132 |
|
|
} |
| 133 |
|
|
|
| 134 |
|
|
// calc the wrapped real coordinates from the wrapped scaled coordinates |
| 135 |
|
|
for (i=0; i<3; i++) { |
| 136 |
|
|
pos[i] = scaled[i] * hmat_(i, i); |
| 137 |
|
|
} |
| 138 |
|
|
|
| 139 |
|
|
} |
| 140 |
|
|
|
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
|
} |
| 144 |
|
|
|