Simpatico  v1.10
mcMd/chemistry/Atom.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "Atom.h"
9 #include <util/containers/RArray.h>
10 
11 namespace McMd
12 {
13 
14  using namespace Util;
15 
16  // Define and initialize static variables
17  Atom* Atom::atoms_ = 0;
18  Mask* Atom::masks_ = 0;
19  Molecule** Atom::moleculePtrs_ = 0;
20  Vector* Atom::velocities_ = 0;
21  Vector* Atom::forces_ = 0;
22  bool* Atom::isActives_ = 0;
23  #ifdef MCMD_SHIFT
24  IntVector* Atom::shifts_ = 0;
25  #endif
26  int Atom::capacity_ = 0;
27 
28  // Static functions
29 
30  /*
31  * Initialize static variables
32  *
33  * The only purpose of this function is to guarantee inclusion of file in static library.
34  */
36  {
37  atoms_ = 0;
38  masks_ = 0;
39  moleculePtrs_ = 0;
40  velocities_ = 0;
41  forces_ = 0;
42  isActives_ = 0;
43  #ifdef MCMD_SHIFT
44  shifts_ = 0;
45  #endif
46  capacity_ = 0;
47  }
48 
49  /*
50  * Allocate a static array of Atom objects.
51  */
52  void Atom::allocate(int capacity, RArray<Atom>& atoms)
53  {
54  if (capacity == 0) return;
55 
56  assert(atoms_ == 0);
57  assert(masks_ == 0);
58  assert(moleculePtrs_ == 0);
59  assert(velocities_ == 0);
60  assert(forces_ == 0);
61  assert(isActives_ == 0);
62  #ifdef MCMD_SHIFT
63  assert(shifts_ == 0);
64  #endif
65 
66  atoms_ = new Atom[capacity];
67  masks_ = new Mask[capacity];
68  moleculePtrs_ = new Molecule*[capacity];
69  capacity_ = capacity;
70  for (int i = 0; i < capacity_; ++i) {
71  atoms_[i].id_ = i;
72  moleculePtrs_[i] = 0;
73  }
74  atoms.associate(atoms_, capacity_);
75 
76  velocities_ = new Vector[capacity_];
77  for (int i = 0; i < capacity_; ++i) {
78  velocities_[i].zero();
79  }
80 
81  forces_ = new Vector[capacity_];
82  for (int i = 0; i < capacity_; ++i) {
83  forces_[i].zero();
84  }
85 
86  isActives_ = new bool[capacity_];
87  for (int i = 0; i < capacity_; ++i) {
88  isActives_[i] = true;
89  }
90 
91  #ifdef MCMD_SHIFT
92  shifts_ = new IntVector[capacity_];
93  for (int i = 0; i < capacity_; ++i) {
94  shifts_[i].zero();
95  }
96  #endif
97 
98  }
99 
100  /*
101  * Deallocate all atoms.
102  */
104  {
105  if (atoms_) {
106  delete [] atoms_;
107  atoms_ = 0;
108  }
109  if (masks_) {
110  delete [] masks_;
111  masks_ = 0;
112  }
113  if (moleculePtrs_) {
114  delete [] moleculePtrs_;
115  moleculePtrs_ = 0;
116  }
117  if (velocities_) {
118  delete [] velocities_;
119  velocities_ = 0;
120  }
121  if (forces_) {
122  delete [] forces_;
123  forces_ = 0;
124  }
125  if (isActives_) {
126  delete [] isActives_;
127  isActives_ = 0;
128  }
129  #ifdef MCMD_SHIFT
130  if (shifts_) {
131  delete [] shifts_;
132  shifts_ = 0;
133  }
134  #endif
135  capacity_ = 0;
136  }
137 
138  // Nonstatic member functions
139 
140  /*
141  * Constructor.
142  */
143  Atom::Atom() :
144  typeId_(NullIndex),
145  id_(NullIndex)
146  {}
147 
148  /*
149  * Set pointer to parent molecule.
150  */
151  void Atom::setMolecule(Molecule &molecule)
152  { moleculePtrs_[id_] = &molecule; }
153 
154 }
Vector & zero()
Set all elements of a 3D vector to zero.
Definition: Vector.h:514
A Vector is a Cartesian vector.
Definition: Vector.h:75
static void deallocate()
Delete all static arrays.
IntVector & zero()
Set all elements of a 3D vector to zero.
Definition: IntVector.h:140
void associate(Array< Data > &array)
Associate this RArray with an existing Array object.
Definition: RArray.h:83
Set of Atoms for which pair interactions with a target Atom are "masked".
void setMolecule(Molecule &molecule)
Set the parent molecule.
static void initStatic()
Method to guarantee initialization of static data.
static void allocate(int capacity, RArray< Atom > &atoms)
Allocate a static array of Atom objects.
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
An IntVector is an integer Cartesian vector.
Definition: IntVector.h:73
An Array that acts as a reference to another Array or C array.
Definition: RArray.h:46
A physical molecule (a set of covalently bonded Atoms).