Simpatico  v1.10
Domain.h
1 #ifndef DDMD_DOMAIN_H
2 #define DDMD_DOMAIN_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <simp/boundary/Boundary.h> // typedef used in interface
12 #include <util/param/ParamComposite.h> // base class
13 #include <util/containers/FMatrix.h> // member template
14 #include <util/containers/FArray.h> // member template
15 #include <util/space/IntVector.h> // member
16 #include <util/space/Grid.h> // member
17 #include <util/space/Dimension.h> // constant expression
18 #include <util/global.h>
19 
20 namespace DdMd
21 {
22 
23  using namespace Util;
24  using namespace Simp;
25 
31  class Domain : public ParamComposite
32  {
33 
34  public:
35 
39  Domain();
40 
44  virtual ~Domain();
45 
46  // Mutators
47 
48  #if UTIL_MPI
49 
55  void setGridCommunicator(MPI::Intracomm& communicator);
56 
57  #else
58 
59  void setRank(int Rank);
60 
61  #endif
62 
68  void setBoundary(Boundary& boundary);
69 
75  virtual void readParameters(std::istream& in);
76 
82  virtual void loadParameters(Serializable::IArchive &ar);
83 
89  virtual void save(Serializable::OArchive &ar);
90 
91  // Accessors
92 
96  const Grid& grid() const;
97 
103  int gridCoordinate(int i) const;
104 
110  int gridDimension(int i) const;
111 
117  bool gridIsPeriodic(int i) const;
118 
122  int gridRank() const;
123 
127  bool isMaster() const;
128 
135  int sourceRank(int i, int j) const;
136 
143  int destRank(int i, int j) const;
144 
156  int shift(int i, int j) const;
157 
158  #if UTIL_MPI
159 
162  MPI::Intracomm& communicator() const;
163  #endif
164 
176  double domainBound(int i, int j) const;
177 
184  int ownerRank(const Vector& position) const;
185 
192  bool isInDomain(const Vector& position) const;
193 
197  bool isInitialized() const;
198 
202  bool hasBoundary() const;
203 
204  private:
205 
206  // Ranks of sending (source) processor for each shift.
207  FMatrix<int, Dimension, 2> sourceRanks_;
208 
209  // Ranks of receiving (destination) processor for each shift.
210  FMatrix<int, Dimension, 2> destRanks_;
211 
212  // Shifts due to periodic boundary conditions in each send direction.
214 
215  // Grid object with dimensions given by gridDimensions_.
216  Grid grid_;
217 
218  // Number of processors in each direction.
219  IntVector gridDimensions_;
220 
221  // Coordinates of this domain in processor grid.
222  IntVector gridCoordinates_;
223 
224  // Rank of this processor in Cartesian communicator.
225  int gridRank_;
226 
227  // Is each direction periodic (1 = true, 0 = false).
228  FArray<bool, Dimension> gridIsPeriodic_;
229 
230  #if UTIL_MPI
231 
232  // Pointer to Intracommunicator.
233  MPI::Intracomm* intracommPtr_;
234 
235  #endif
236 
237  // Pointer to associated Boundary object.
238  Boundary* boundaryPtr_;
239 
240  // Is this object initialized (Has a grid been set?)
241  bool isInitialized_;
242 
243  /*
244  * Initialize after reading/loading gridDimensions.
245  *
246  * Used in implementation of readParameters and loadParameters.
247  */
248  void initialize();
249 
250  };
251 
252  #if UTIL_MPI
253 
257  inline MPI::Intracomm& Domain::communicator() const
258  {
259  assert(intracommPtr_);
260  return *intracommPtr_;
261  }
262 
263  #endif
264 
265  /*
266  * Return processor Grid by const reference.
267  */
268  inline const Grid& Domain::grid() const
269  {
270  assert(isInitialized_);
271  return grid_;
272  }
273 
274  /*
275  * Return a coordinate of this processor within grid.
276  */
277  inline int Domain::gridCoordinate(int i) const
278  {
279  assert(isInitialized_);
280  return gridCoordinates_[i];
281  }
282 
286  inline int Domain::gridDimension(int i) const
287  {
288  assert(isInitialized_);
289  return gridDimensions_[i];
290  }
291 
295  inline bool Domain::gridIsPeriodic(int i) const
296  {
297  assert(isInitialized_);
298  return gridIsPeriodic_[i];
299  }
300 
301  /*
302  * Rank of this processor in Cartesian communicator.
303  */
304  inline int Domain::gridRank() const
305  {
306  assert(isInitialized_);
307  return gridRank_;
308  }
309 
310  /*
311  * Is this the master processor (gridRank == 0)?
312  */
313  inline bool Domain::isMaster() const
314  {
315  assert(isInitialized_);
316  return bool(gridRank_ == 0);
317  }
318 
319  /*
320  * Rank of the processor from which to receive in transfer (i, j).
321  */
322  inline int Domain::sourceRank(int i, int j) const
323  {
324  assert(isInitialized_);
325  return sourceRanks_(i, j);
326  }
327 
328  /*
329  * Rank of the processor to which to send in transfer (i, j).
330  */
331  inline int Domain::destRank(int i, int j) const
332  {
333  assert(isInitialized_);
334  return destRanks_(i,j);
335  }
336 
337  /*
338  * Shift applied in direction i for transfer (i, j)
339  */
340  inline int Domain::shift(int i, int j) const
341  {
342  assert(isInitialized_);
343  return shift_(i, j);
344  }
345 
346  /*
347  * Has this Domain been initialized by calling readParam?
348  */
349  inline bool Domain::isInitialized() const
350  { return isInitialized_; }
351 
352  /*
353  * Has an associated Boundary been set ?
354  */
355  inline bool Domain::hasBoundary() const
356  { return (boundaryPtr_ != 0); }
357 
358 }
359 #endif
A Vector is a Cartesian vector.
Definition: Vector.h:75
bool isInitialized() const
Has this Domain been initialized by calling readParam?
Definition: Domain.h:349
int sourceRank(int i, int j) const
Rank of the processor from which to receive for transfer (i, j).
Definition: Domain.h:322
An orthorhombic periodic unit cell.
int shift(int i, int j) const
Shift to be applied to sent coordinates in transfer (i, j).
Definition: Domain.h:340
File containing preprocessor macros for error handling.
Parallel domain decomposition (DD) MD simulation.
Classes used by all simpatico molecular simulations.
bool gridIsPeriodic(int i) const
Is the grid periodic in the specified direction?
Definition: Domain.h:295
MPI::Intracomm & communicator() const
Return Cartesian communicator by reference.
Definition: Domain.h:257
Saving / output archive for binary ostream.
int gridRank() const
Get rank of this processor in the processor grid.
Definition: Domain.h:304
Utility classes for scientific computation.
Definition: accumulators.mod:1
int gridDimension(int i) const
Get dimension of processor grid in specified direction.
Definition: Domain.h:286
const Grid & grid() const
Return processor Grid by const reference.
Definition: Domain.h:268
bool isMaster() const
Is this the master processor (gridRank == 0) ?
Definition: Domain.h:313
Decomposition of the system into domains associated with processors.
Definition: Domain.h:31
Saving archive for binary istream.
An IntVector is an integer Cartesian vector.
Definition: IntVector.h:73
int gridCoordinate(int i) const
Get coordinate of processor within grid in specified direction.
Definition: Domain.h:277
int destRank(int i, int j) const
Rank of the processor to which to send for transfer (i, j).
Definition: Domain.h:331
A grid of points indexed by integer coordinates.
Definition: Grid.h:33
bool hasBoundary() const
Has an associated Boundary been set?
Definition: Domain.h:355
An object that can read multiple parameters from file.