9 #include "ReplicaMove.h" 11 #include <mcMd/perturb/Perturbation.h> 12 #include <mcMd/perturb/LinearPerturbation.h> 13 #include <mcMd/simulation/Simulation.h> 14 #include <mcMd/simulation/System.h> 15 #include <simp/boundary/OrthorhombicBoundary.h> 17 #include <util/archives/MemoryOArchive.h> 18 #include <util/archives/MemoryIArchive.h> 19 #include <util/archives/MemoryCounter.h> 20 #include <util/random/Random.h> 21 #include <util/misc/Observer.h> 53 UTIL_THROW(
"Parent System has no Perturbation");
58 myId_ = communicatorPtr_->Get_rank();
59 nProcs_ = communicatorPtr_->Get_size();
83 if (ptPositionPtr_)
delete [] ptPositionPtr_;
84 if (myPositionPtr_)
delete [] myPositionPtr_;
92 read<long>(in,
"interval", interval_);
94 UTIL_THROW(
"Invalid value input for interval_");
96 read<int>(in,
"nSampling", nSampling_);
97 if (nSampling_ <= 0) {
98 UTIL_THROW(
"Invalid value input for nSampling_");
103 ptPositionPtr_ =
new Vector[nAtom];
104 myPositionPtr_ =
new Vector[nAtom];
113 loadParameter<long>(ar,
"interval", interval_);
114 loadParameter<int>(ar,
"nSampling", nSampling_);
119 if (interval_ <= 0) {
120 UTIL_THROW(
"Invalid value input for interval_");
122 if (nSampling_ <= 0) {
123 UTIL_THROW(
"Invalid value input for nSampling_");
128 ptPositionPtr_ =
new Vector[nAtom];
129 myPositionPtr_ =
new Vector[nAtom];
143 ptPositionPtr_ =
new Vector[nAtom];
144 myPositionPtr_ =
new Vector[nAtom];
152 MPI::Request request[4];
164 myDerivatives.
allocate(nParameters_);
166 myParameters.
allocate(nParameters_);
168 for (
int i=0; i< nParameters_; i++) {
182 sendCurrent << myDerivatives;
183 sendCurrent << myParameters;
185 sendCurrent.
send(*communicatorPtr_, 0);
192 allDerivatives[0].
allocate(nParameters_);
193 allDerivatives[0] = myDerivatives;
194 allParameters[0].
allocate(nParameters_);
195 allParameters[0] = myParameters;
197 for (
int i = 1; i<nProcs_; i++) {
200 recvPartner.
recv(*communicatorPtr_, i);
201 allDerivatives[i].
allocate(nParameters_);
202 allParameters[i].
allocate(nParameters_);
203 recvPartner >> allDerivatives[i];
204 recvPartner >> allParameters[i];
211 for (
int i = 0; i < nProcs_; i++)
214 for (
int n =0; n < nSampling_; n++) {
223 for (
int k = 0; k < nParameters_; k++) {
224 double deltaDerivative = allDerivatives[i][k] - allDerivatives[j][k];
226 weight += (allParameters[permutation[j]][k] - allParameters[permutation[i]][k])*deltaDerivative;
228 double exponential = exp(-weight);
234 int tmp = permutation[i];
235 permutation[i] = permutation[j];
236 permutation[j] = tmp;
241 for (
int i = 0; i < nProcs_; i++) {
243 communicatorPtr_->Send(&permutation[i], 1, MPI::INT, i, 0);
245 sendPt = permutation[i];
247 if (permutation[i] != 0)
248 communicatorPtr_->Send(&i, 1, MPI::INT, permutation[i], 1);
257 communicatorPtr_->Recv(&sendPt, 1, MPI::INT, 0, 0);
259 communicatorPtr_->Recv(&recvPt, 1, MPI::INT, 0, 1);
262 if (recvPt == myId_ || sendPt == myId_) {
264 outputFile_ << sendPt << std::endl;
268 assert(recvPt != myId_ && sendPt != myId_);
276 request[0] = communicatorPtr_->Irecv(&ptBoundary, 1,
280 request[1] = communicatorPtr_->Isend(&myBoundary, 1,
292 for (molIter->begin(atomIter); atomIter.
notEnd(); ++atomIter) {
293 myPositionPtr_[iA] = atomIter->position();
300 request[2] = communicatorPtr_->Irecv(ptPositionPtr_, iA,
304 request[3] = communicatorPtr_->Isend(myPositionPtr_, iA,
314 for (molIter->begin(atomIter); atomIter.
notEnd(); ++atomIter){
315 atomIter->position() = ptPositionPtr_[iA];
324 partners[0] = sendPt;
325 partners[1] = recvPt;
329 outputFile_ << sendPt << std::endl;
336 #endif // ifdef UTIL_MPI void send(MPI::Intracomm &comm, int dest)
Send packed data via MPI.
virtual void readParameters(std::istream &in)
Read parameters.
A Vector is a Cartesian vector.
void notifyObservers(const Event &event)
Notify the list of observers about an Event.
int memorySize(T &data)
Function template to compute memory size of one object.
FileMaster & fileMaster() const
Get the associated FileMaster by reference.
void begin(int speciesId, MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this System.
virtual ~ReplicaMove()
Destructor.
bool notEnd() const
Is the current pointer not at the end of the array?
ReplicaMove(System &system)
Constructor.
void setOrthorhombic(const Vector &lengths)
Set unit cell dimensions for orthorhombic boundary.
const Vector & lengths() const
Get Vector of unit cell lengths by const reference.
int atomCapacity() const
Get the total number of Atoms allocated.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
A set of interacting Molecules enclosed by a Boundary.
bool hasPerturbation() const
Does this system have an associated Perturbation?
Classes used by all simpatico molecular simulations.
virtual bool move()
Attempt, and accept or reject a replica exchange move.
virtual double derivative(int i) const =0
Get derivative of the Boltzmann weight W(X,p) with respect to the perturbation parameter p[i] of inde...
Saving / output archive for binary ostream.
double parameter(int i, int id)
Get parameter i of system id.
void allocate(size_t capacity)
Allocate memory block.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Simulation & simulation() const
Get the parent Simulation by reference.
Save archive for packed heterogeneous binary data.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
int getNParameters() const
Gets the number of parameters per system.
long uniformInt(long range1, long range2)
Return random long int x uniformly distributed in range1 <= x < range2.
MPI::Intracomm & communicator()
Get the MPI communicator by reference.
Forward iterator for an Array or a C array.
Forward iterator for a PArray.
Boundary & boundary() const
Get the Boundary by reference.
Saving archive for binary istream.
Perturbation & perturbation() const
Get the associated Perturbation by reference.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
This file contains templates for global functions send<T>, recv<T> and bcast<T>.
void recv(MPI::Intracomm &comm, int source)
Receive packed data via MPI.
void setClassName(const char *className)
Set class name string.
virtual void allocate(size_t capacity)
Allocate memory.
void allocate(int capacity)
Allocate the underlying C array.
System & system()
Return the associated system by reference.
Input archive for packed heterogeneous binary data.
Random & random()
Get the random number generator by reference.