8 #include "SphericalTabulatedExternal.h" 36 rMaxSq_(other.rMaxSq_),
38 boundaryPtr_(other.boundaryPtr_),
40 nAtomType_(other.nAtomType_),
43 if (other.potentials_.isAllocated()) {
44 UTIL_CHECK(other.potentials_.capacity() == nAtomType_);
45 potentials_.allocate(nAtomType_);
47 for (i = 0; i < nAtomType_; ++i) {
48 UTIL_CHECK(other.potentials_[i].isAllocated());
49 UTIL_CHECK(other.potentials_[i].capacity() == nr_);
50 potentials_[i].allocate(nr_);
51 for (j = 0; j < nr_; ++j) {
52 potentials_[i][j] = other.potentials_[i][j];
56 isInitialized_ = other.isInitialized_;
66 rMaxSq_ = other.rMaxSq_;
68 boundaryPtr_ = other.boundaryPtr_;
69 boundaryPtr_ = other.boundaryPtr_;
71 nAtomType_ = other.nAtomType_;
72 if (other.potentials_.isAllocated()) {
73 UTIL_CHECK(other.potentials_.capacity() == nAtomType_);
74 if (!potentials_.isAllocated()) {
75 potentials_.allocate(nAtomType_);
77 UTIL_CHECK(potentials_.capacity() == nAtomType_);
79 for (i = 0; i < nAtomType_; ++i) {
80 UTIL_CHECK(other.potentials_[i].capacity() == nr_);
81 if (!potentials_[i].isAllocated()) {
82 potentials_[i].allocate(nr_);
85 for (j = 0; j < nr_; ++j) {
86 potentials_[i][j] = other.potentials_[i][j];
90 isInitialized_ = other.isInitialized_;
100 if (nAtomType <= 0) {
103 if (nAtomType > MaxAtomType) {
104 UTIL_THROW(
"nAtomType > SphericalTabulatedExternal::MaxAtomType");
106 nAtomType_ = nAtomType;
113 { boundaryPtr_ = &boundary; }
120 if (nAtomType_ == 0) {
121 UTIL_THROW(
"nAtomType must be set before readParam");
124 UTIL_THROW(
"Boundary must be set before readParam");
128 read<double>(in,
"rMax", rMax_);
129 read<int>(in,
"nr", nr_);
130 read<std::string>(in,
"filename", filename_);
132 rMaxSq_ = rMax_*rMax_;
133 dr_ = rMax_/double(nr_ - 1);
136 potentials_.allocate(nAtomType_);
137 for (
int i = 0; i < nAtomType_; ++i) {
138 potentials_[i].allocate(nr_);
140 std::cout <<
"Allocated potentials" << std::endl;
144 file.open(filename_.c_str());
147 for (j = 0; j < nr_; ++j) {
150 for (i = 0; i < nAtomType_; ++i) {
151 file >> potentials_[i][j];
157 std::cout << std::endl;
158 for (j = 0; j < nr_; ++j) {
159 std::cout <<
" " << j;
160 for (i = 0; i < nAtomType_; ++i) {
161 potentials_[i][j] -= potentials_[i][nr_ - 1];
162 std::cout <<
" " << potentials_[i][j];
164 std::cout << std::endl;
166 isInitialized_ =
true;
175 if (nAtomType_ <= 0) {
179 UTIL_THROW(
"Boundary must be set before loadParameters");
181 loadParameter<double> (ar,
"rMax", rMax_);
182 loadParameter<int> (ar,
"nr", nr_);
183 rMaxSq_ = rMax_*rMax_;
184 dr_ = rMax_/double(nr_ - 1);
187 if (!potentials_.isAllocated()) {
188 potentials_.allocate(nAtomType_);
190 UTIL_CHECK(potentials_.capacity() == nAtomType_);
192 for (i = 0; i < nAtomType_; ++i) {
193 if (!potentials_[i].isAllocated()) {
194 potentials_[i].allocate(nr_);
197 for (j = 0; j < nr_; ++j) {
198 ar >> potentials_[i][j];
202 isInitialized_ =
true;
215 for (i = 0; i < nAtomType_; ++i) {
217 for (j = 0; j < nr_; ++j) {
218 ar << potentials_[i][j];
226 void SphericalTabulatedExternal::set(std::string name,
double value)
228 if (name ==
"rMax") {
238 double SphericalTabulatedExternal::get(std::string name)
const 241 if (name ==
"rMax") {
256 {
return std::string(
"SphericalTabulatedExternal"); }
SphericalTabulatedExternal & operator=(const SphericalTabulatedExternal &other)
Assignment.
An orthorhombic periodic unit cell.
Classes used by all simpatico molecular simulations.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
std::string className() const
Return name string for this interaction class.
Saving / output archive for binary ostream.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.
SphericalTabulatedExternal()
Default constructor.
void readParameters(std::istream &in)
Read potential parameters, and initialize other variables.
Saving archive for binary istream.
The potential is independent on the type of atoms.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
void setClassName(const char *className)
Set class name string.
void setBoundary(Boundary &boundary)
Set pointer to Boundary.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
void setNAtomType(int nAtomType)
Set nAtomType value.