8 #include "GeneralPeriodicExternal.h" 21 : externalParameter_(),
34 : externalParameter_(other.externalParameter_),
35 nWaveVectors_(other.nWaveVectors_),
36 periodicity_(other.periodicity_),
37 interfaceWidth_(other.interfaceWidth_),
38 boundaryPtr_(other.boundaryPtr_),
39 nAtomType_(other.nAtomType_),
40 isInitialized_(other.isInitialized_)
42 prefactor_.
allocate(nAtomType_ * nWaveVectors_);
43 for (
int i=0; i < nAtomType_ * nWaveVectors_; ++i) {
44 prefactor_[i] = other.prefactor_[i];
46 waveVectors_.allocate(nWaveVectors_);
48 for (
int i=0; i < nWaveVectors_; ++i) {
49 waveVectors_[i][j] = other.waveVectors_[i][j];
53 for (
int i=0; i < nWaveVectors_; ++i) {
54 phases_[i] = other.phases_[i];
56 prefactor_.
allocate(Dimension * nWaveVectors_);
57 for (
int i=0; i < Dimension * nWaveVectors_; ++i) {
58 shifts_[i] = other.shifts_[i];
67 externalParameter_ = other.externalParameter_;
68 nWaveVectors_ = other.nWaveVectors_;
69 periodicity_ = other.periodicity_;
70 interfaceWidth_ = other.interfaceWidth_;
71 boundaryPtr_ = other.boundaryPtr_;
72 nAtomType_ = other.nAtomType_;
73 isInitialized_ = other.isInitialized_;
74 for (
int i=0; i < nAtomType_ * nWaveVectors_; ++i) {
75 prefactor_[i] = other.prefactor_[i];
78 for (
int i=0; i < nWaveVectors_; ++i) {
79 waveVectors_[i][j] = other.waveVectors_[i][j];
82 for (
int i=0; i < nWaveVectors_; ++i) {
83 phases_[i] = other.phases_[i];
85 for (
int i=0; i < Dimension * nWaveVectors_; ++i) {
86 shifts_[i] = other.shifts_[i];
99 if (nAtomType > MaxAtomType) {
100 UTIL_THROW(
"nAtomType > GeneralPeriodicExternal::MaxAtomType");
102 nAtomType_ = nAtomType;
108 if (!isInitialized_) {
109 UTIL_THROW(
"GeneralPeriodicExternal potential is not initialized");
120 { boundaryPtr_ = &boundary; }
127 if (nAtomType_ == 0) {
128 UTIL_THROW(
"nAtomType must be set before readParam");
131 UTIL_THROW(
"Boundary must be set before readParam");
135 read<int>(in,
"nWaveVectors", nWaveVectors_);
137 prefactor_.
allocate(nAtomType_ * nWaveVectors_);
138 readDArray<double>(in,
"prefactor", prefactor_, nAtomType_ * nWaveVectors_);
140 waveVectors_.allocate(nWaveVectors_);
141 readDArray<Vector>(in,
"waveVectors", waveVectors_, nWaveVectors_);
144 readDArray<double>(in,
"phases", phases_, nWaveVectors_);
147 readDArray<double>(in,
"shifts", shifts_,
Dimension * nWaveVectors_);
149 read<double>(in,
"externalParameter", externalParameter_);
151 read<double>(in,
"interfaceWidth", interfaceWidth_);
153 read<int>(in,
"periodicity", periodicity_);
154 isInitialized_ =
true;
163 if (nAtomType_ <= 0) {
166 prefactor_.
allocate(nAtomType_ * nWaveVectors_);
167 loadDArray<double>(ar,
"prefactor", prefactor_, nAtomType_ * nWaveVectors_);
169 waveVectors_.allocate(nWaveVectors_);
170 loadDArray<Vector>(ar,
"waveVectors", waveVectors_, nWaveVectors_);
173 loadDArray<double>(ar,
"phases", phases_, nWaveVectors_);
176 loadDArray<double>(ar,
"shifts", shifts_,
Dimension * nWaveVectors_);
178 loadParameter<double>(ar,
"externalParameter", externalParameter_);
180 loadParameter<double>(ar,
"interfaceWidth", interfaceWidth_);
182 loadParameter<int>(ar,
"periodicity", periodicity_);
183 isInitialized_ =
true;
193 ar << externalParameter_;
197 ar << interfaceWidth_;
204 void GeneralPeriodicExternal::set(std::string name,
double value)
206 if (name ==
"externalParameter") {
207 externalParameter_ = value;
209 if (name ==
"interfaceWidth") {
210 interfaceWidth_ = value;
212 if (name ==
"periodicity") {
213 periodicity_ = value;
222 double GeneralPeriodicExternal::get(std::string name)
const 225 if (name ==
"externalParameter") {
226 value = externalParameter_;
228 if (name ==
"interfaceWidth") {
229 value = interfaceWidth_;
231 if (name ==
"periodicity") {
232 value = periodicity_;
241 return externalParameter_;
248 {
return std::string(
"GeneralPeriodicExternal"); }
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
const int Dimension
Dimensionality of space.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
void readParameters(std::istream &in)
Read potential parameters, and initialize other variables.
An orthorhombic periodic unit cell.
void setNAtomType(int nAtomType)
Set nAtomType value.
Classes used by all simpatico molecular simulations.
double externalParameter() const
Returns external parameter.
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.
std::string className() const
Return name string "GeneralPeriodicExternal".
GeneralPeriodicExternal()
Default constructor.
Saving archive for binary istream.
void setClassName(const char *className)
Set class name string.
A clipped cosine potential that induces ordering along directions specified by waveIntVectors, w_i.
void allocate(int capacity)
Allocate the underlying C array.
void setExternalParameter(double externalParameter)
Sets external parameter.
GeneralPeriodicExternal & operator=(const GeneralPeriodicExternal &other)
Assignment.
void setBoundary(Boundary &boundary)
Set pointer to Boundary.