Simpatico  v1.10
ddMd/chemistry/Atom.h
1 #ifndef DDMD_ATOM_H
2 #define DDMD_ATOM_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 //#define UTIL_32BIT
12 
13 #include <util/space/Vector.h> // members
14 #include <ddMd/chemistry/Mask.h> // member
15 #include <ddMd/communicate/Plan.h> // member
16 #include "AtomArray.h" // inline methods
17 
18 namespace Util{ class Memory; }
19 
20 namespace DdMd
21 {
22 
23  class Buffer;
24  using namespace Util;
25 
64  class Atom
65  {
66 
67  public:
68 
69  // Static member functions
70 
76  static void setHasAtomContext(bool hasAtomContext);
77 
81  static bool hasAtomContext();
82 
83  #ifdef UTIL_MPI
84 
87  static int packedAtomSize();
88 
92  static int packedGhostSize();
93  #endif
94 
95  // Non-static member functions
96 
98 
99 
103  Atom& operator = (Atom const & other);
104 
108  void clear();
109 
118  void setId(int Id);
119 
125  void setTypeId(int Id);
126 
132  void setIsGhost(bool isGhost);
133 
135 
137 
141  Vector& position();
142 
146  Vector& velocity();
147 
151  Vector& force();
152 
156  Mask& mask();
157 
161  Plan& plan();
162 
173  AtomContext& context();
174 
186  unsigned int& groups();
187 
188  #if 0
189 
192  IntVector& shift();
193  #endif
194 
195 
197 
201  int id() const;
202 
206  int typeId() const;
207 
211  bool isGhost() const;
212 
216  const Vector& position() const;
217 
221  const Vector& velocity() const;
222 
226  const Vector& force() const;
227 
231  const Mask& mask() const;
232 
236  const Plan& plan() const;
237 
245  const AtomContext& context() const;
246 
252  unsigned int groups() const;
253 
254  #if 0
255 
258  const IntVector& shift() const;
259  #endif
260 
261 
263 
264 
265  #ifdef UTIL_MPI
266 
274  void packAtom(Buffer& buffer);
275 
281  void unpackAtom(Buffer& buffer);
282 
290  void packGhost(Buffer& buffer);
291 
299  void unpackGhost(Buffer& buffer);
300 
308  void packUpdate(Buffer& buffer);
309 
317  void unpackUpdate(Buffer& buffer);
318 
326  void packForce(Buffer& buffer);
327 
336  void unpackForce(Buffer& buffer);
337 
338  #endif // ifdef UTIL_MPI
339 
345  void copyLocalGhost(Atom const & sendAtom);
346 
352  void copyLocalUpdate(Atom const & sendAtom);
353 
355 
356  private:
357 
361  static bool hasAtomContext_;
362 
366  Vector position_;
367 
371  int typeId_;
372 
384  unsigned int localId_;
385 
389  Vector force_;
390 
394  AtomArray* arrayPtr_;
395 
396  #ifdef UTIL_32BIT
397 
400  int pad_;
401  #endif
402 
412  Atom();
413 
419  Atom(Atom const & other);
420 
421  // friends:
422 
423  friend class AtomArray;
424  friend class Util::Memory;
425 
426  };
427 
428  // Inline methods
429 
430  /*
431  * Set type Id for Atom.
432  */
433  inline void Atom::setTypeId(int typeId)
434  { typeId_ = typeId; }
435 
436  /*
437  * Set isGhost flag.
438  */
439  inline void Atom::setIsGhost(bool isGhost)
440  {
441  if (isGhost) {
442  // Set least significant bit of localId_ to 1
443  localId_ = localId_ | 1;
444  } else {
445  // Set least significant bit of localId_ to 0
446  localId_ = localId_ & ~1;
447  }
448  }
449 
450  /*
451  * Get atom type Id.
452  */
453  inline int Atom::typeId() const
454  { return typeId_; }
455 
456  /*
457  * Is this a ghost atom?
458  */
459  inline bool Atom::isGhost() const
460  {
461  // Return least significant bit of localId_
462  return bool(localId_ & 1);
463  }
464 
465  /*
466  * Get position by reference.
467  */
468  inline Vector& Atom::position()
469  { return position_; }
470 
471  /*
472  * Get position by const reference.
473  */
474  inline Vector const & Atom::position() const
475  { return position_; }
476 
477  /*
478  * Get force by reference.
479  */
480  inline Vector& Atom::force()
481  { return force_; }
482 
483  /*
484  * Get force by const reference.
485  */
486  inline Vector const & Atom::force() const
487  { return force_; }
488 
489  /*
490  * Accessors for pseudo-members stored in separate arrays.
491  *
492  * An atom can be constructed only as an element of a parent AtomArray
493  * (see documentation for private default constructor). Some data owned
494  * by an Atom is stored in a set of private array that are allocated by
495  * its AtomArray. In each such array, the element associated with this
496  * Atom is indexed by the localId_ of this atom, without the least
497  * signficant bit (see documentation of the localId_ member). The bit
498  * shift operation "localId_ >> 1" in each of the following functions
499  * strips off the least signficant bit, which is used to store the isGhost
500  * flag, and returns the relevant array index. Each arrays that stores
501  * pseudo-member data is a private member of the parent AtomArray (e.g.,
502  * AtomArray::velocities_, AtomArray::masks_, etc.) that is accessible
503  * because Atom is a friend class of AtomArray.
504  */
505 
506  /*
507  * Get reference to velocity.
508  */
509  inline Vector& Atom::velocity()
510  { return arrayPtr_->velocities_[localId_ >> 1]; }
511 
512  /*
513  * Get velocity by const reference.
514  */
515  inline Vector const & Atom::velocity() const
516  { return arrayPtr_->velocities_[localId_ >> 1]; }
517 
518  /*
519  * Get the Mask by reference.
520  */
521  inline Mask& Atom::mask()
522  { return arrayPtr_->masks_[localId_ >> 1]; }
523 
524  /*
525  * Get the Mask by const reference.
526  */
527  inline Mask const & Atom::mask() const
528  { return arrayPtr_->masks_[localId_ >> 1]; }
529 
530  /*
531  * Get the communication plan by reference.
532  */
533  inline Plan& Atom::plan()
534  { return arrayPtr_->plans_[localId_ >> 1]; }
535 
536  /*
537  * Get the communication plan by const reference.
538  */
539  inline Plan const & Atom::plan() const
540  { return arrayPtr_->plans_[localId_ >> 1]; }
541 
542  /*
543  * Get the global id for this Atom.
544  */
545  inline int Atom::id() const
546  { return arrayPtr_->ids_[localId_ >> 1]; }
547 
548  /*
549  * Set the global id for this Atom.
550  */
551  inline void Atom::setId(int id)
552  { arrayPtr_->ids_[localId_ >> 1] = id; }
553 
554  /*
555  * Get AtomContext by non-const reference.
556  */
557  inline AtomContext& Atom::context()
558  {
559  if (!hasAtomContext_) {
560  UTIL_THROW("Atom does not have AtomContext");
561  }
562  return arrayPtr_->contexts_[localId_ >> 1];
563  }
564 
565  /*
566  * Get AtomContext by const reference.
567  */
568  inline AtomContext const & Atom::context() const
569  {
570  if (!hasAtomContext_) {
571  UTIL_THROW("Atom does not have AtomContext");
572  }
573  return arrayPtr_->contexts_[localId_ >> 1];
574  }
575 
576  /*
577  * Get group bit map by non-const reference.
578  */
579  inline unsigned int& Atom::groups()
580  { return arrayPtr_->groups_[localId_ >> 1]; }
581 
582  /*
583  * Get groups bit map by value.
584  */
585  inline unsigned int Atom::groups() const
586  { return arrayPtr_->groups_[localId_ >> 1]; }
587 
588  /*
589  * Is AtomContext data enabled?
590  */
591  inline bool Atom::hasAtomContext()
592  { return hasAtomContext_; }
593 
594 }
595 #endif
Set of Atoms for which pair interactions with a parent Atom are "masked".
A Vector is a Cartesian vector.
Definition: Vector.h:75
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Descriptor for context of an Atom within a molecule and species.
Definition: AtomContext.h:21
An array of Atom objects.
Definition: AtomArray.h:40
Utility classes for scientific computation.
Definition: accumulators.mod:1
Provides method to allocate array.
Definition: Memory.h:28
Buffer for interprocessor communication.
Definition: Buffer.h:217
Communication plan.
Definition: Plan.h:45
An IntVector is an integer Cartesian vector.
Definition: IntVector.h:73