9 #include <util/space/Dimension.h> 47 intracommPtr_ = &intraCommunicator;
48 gridRank_ = intracommPtr_->Get_rank();
51 void Domain::setRank(
int rank)
59 { boundaryPtr_ = &boundary; }
68 if (intracommPtr_ == 0) {
69 UTIL_THROW(
"Intra-communicator not set before readParam");
73 UTIL_THROW(
"grid rank not set before readParam");
76 UTIL_THROW(
"Boundary not set before readParam");
83 read<IntVector>(in,
"gridDimensions", gridDimensions_);
93 if (intracommPtr_ == 0) {
94 UTIL_THROW(
"Intra-communicator not set before readParam");
98 UTIL_THROW(
"grid rank not set before readParam");
101 UTIL_THROW(
"Boundary not set before readParam");
103 if (isInitialized_) {
108 loadParameter<IntVector>(ar,
"gridDimensions", gridDimensions_);
116 { ar << gridDimensions_; }
121 void Domain::initialize()
126 if (gridDimensions_[i] <= 0) {
127 UTIL_THROW(
"Processor grid dimensions must be greater than 0");
129 nproc *= gridDimensions_[i];
133 commSize = intracommPtr_->Get_size();
135 if (nproc != commSize) {
136 UTIL_THROW(
"Grid dimensions inconsistent with communicator size");
144 gridIsPeriodic_[i] =
true;
148 gridCoordinates_ = grid_.
position(gridRank_);
157 for (j = 0; j < 2; ++j) {
160 k = (j == 0 ? 1 : -1);
163 jp = (j == 0 ? 1 : 0);
166 sourceCoordinates = gridCoordinates_;
167 sourceCoordinates[i] = gridCoordinates_[i] + k;
170 if (gridIsPeriodic_[i] ==
true) {
171 shift_(i, j) = grid_.
shift(sourceCoordinates[i], i);
172 sourceRanks_(i, j) = grid_.
rank(sourceCoordinates);
173 destRanks_(i, jp) = sourceRanks_(i, j);
176 if (!grid_.
isInGrid(sourceCoordinates[i], i)) {
177 destRanks_(i, j) = -1;
178 sourceRanks_(i, jp) = -1;
184 isInitialized_ =
true;
193 assert(isInitialized_);
194 assert(boundaryPtr_);
201 dL = 1.0 / double(gridDimensions_[i]);
202 return (gridCoordinates_[i] + j)*dL;
211 assert(isInitialized_);
212 assert(boundaryPtr_);
217 dL = 1.0 / double(gridDimensions_[i]);
218 r[i] = int(position[i] / dL);
219 if (r[i] < 0 || r[i] >= gridDimensions_[i]) {
220 Log::file() <<
"Cart i = " << i << std::endl;
221 Log::file() <<
"position = " << position[i] << std::endl;
222 Log::file() <<
"dL = " << dL << std::endl;
223 Log::file() <<
"r = " << r[i] << std::endl;
224 Log::file() <<
"gridDim = " << gridDimensions_[i] << std::endl;
228 return grid_.
rank(r);
237 assert(isInitialized_);
238 assert(boundaryPtr_);
243 dL = 1.0 / double(gridDimensions_[i]);
244 if (position[i] < gridCoordinates_[i]*dL) {
247 if (position[i] >= (gridCoordinates_[i] + 1)*dL) {
const int Dimension
Dimensionality of space.
virtual void readParameters(std::istream &in)
Read parameters and initialize.
A Vector is a Cartesian vector.
An orthorhombic periodic unit cell.
void setGridCommunicator(MPI::Intracomm &communicator)
Set the grid communicator.
int ownerRank(const Vector &position) const
Return rank of the processor whose domain contains a position.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
IntVector position(int rank) const
Get the position IntVector of a grid point with a specified rank.
Parallel domain decomposition (DD) MD simulation.
bool isInGrid(int coordinate, int i) const
Is this coordinate in range?
int shift(int &coordinate, int i) const
Shift a periodic coordinate into range.
virtual ~Domain()
Destructor.
Saving / output archive for binary ostream.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Utility classes for scientific computation.
int rank(const IntVector &position) const
Get the rank of a grid point with specified position.
void setBoundary(Boundary &boundary)
Set the associated Boundary object.
static std::ostream & file()
Get log ostream by reference.
bool isInDomain(const Vector &position) const
Is a position in the domain owned by this processor?
Saving archive for binary istream.
double domainBound(int i, int j) const
Get one boundary of the domain owned by this processor.
void setClassName(const char *className)
Set class name string.
An IntVector is an integer Cartesian vector.
void setDimensions(const IntVector &dimensions)
Set the grid dimensions in all directions.
bool hasBoundary() const
Has an associated Boundary been set?
An object that can read multiple parameters from file.