Simpatico  v1.10
Modifier.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 "Modifier.h"
9 
10 namespace DdMd
11 {
12 
13  using namespace Util;
14 
15  const Bit Modifier::Flags::Setup = 0;
27  const Bit Modifier::Flags::Exchange = 12;
28  const Bit Modifier::Flags::Update = 13;
30 
31  /*
32  * This static method exists to guarantee initialization of static
33  * constants that are defined in the same file. Call it somewhere
34  * in the program to guarantee that the contents of this file will
35  * be linked, rather than optimized away.
36  */
38  {
39  // This function can only be called once.
40  static int nCall = 0;
41  if (nCall == 0) {
42  ++nCall;
43  }
44  }
45 
46  /*
47  * Default constructor.
48  */
50  : ParamComposite(),
51  flags_(0),
52  interval_(1),
53  simulationPtr_(0)
54  {}
55 
56  /*
57  * Constructor.
58  */
60  : ParamComposite(),
61  flags_(0),
62  interval_(1),
63  simulationPtr_(&simulation)
64  {}
65 
66  /*
67  * Destructor.
68  */
70  {}
71 
72  /*
73  * Return true if a flag is set, false otherwise.
74  */
75  bool Modifier::isSet(Bit flag) const
76  { return flag.isSet(flags_); }
77 
78  /*
79  * Return unsigned int representation of all bit flags.
80  */
81  unsigned int Modifier::flags() const
82  { return flags_; }
83 
84  // Protected methods
85 
86  /*
87  * Return true if a flag is set, false otherwise.
88  */
89  void Modifier::set(Bit flag)
90  { flag.set(flags_); }
91 
92  /*
93  * Read the interval from parameter file, with error checking.
94  */
95  void Modifier::readInterval(std::istream &in)
96  {
97 
98  // Read interval value (inherited from Interval)
99  read<long>(in, "interval", interval_);
100 
101  // Check that interval has a nonzero, positive value
102  if (interval_ == 0) {
103  UTIL_THROW("interval_ == 0");
104  }
105  if (interval_ < 0) {
106  UTIL_THROW("interval_ < 0");
107  }
108 
109  }
110 
111  /*
112  * Load parameter interval from input archive.
113  */
115  {
116  loadParameter<long>(ar, "interval", interval_);
117 
118  // Check that interval has a nonzero, positive value
119  if (interval_ == 0) {
120  UTIL_THROW("interval_ == 0");
121  }
122  if (interval_ < 0) {
123  UTIL_THROW("interval_ < 0");
124  }
125  }
126 
127  /*
128  * Save interval parameter to an archive.
129  */
131  { ar << interval_; }
132 
133 }
static const Bit Update
Flag to activate pack/unpack update functions.
Definition: Modifier.h:289
void set(unsigned int &flags) const
Set this bit in the flags parameter.
Definition: Bit.h:80
static const Bit PostForce
Flag to activate postForce() function.
Definition: Modifier.h:280
static const Bit PreTransform
Flag to activate preTransform() function.
Definition: Modifier.h:259
Simulation & simulation()
Get the parent Simulation by reference.
Definition: Modifier.h:391
static const Bit PreExchange
Flag to activate preExchange() function.
Definition: Modifier.h:262
static const Bit Setup
Flag to activate setup() function.
Definition: Modifier.h:250
static const Bit ReverseUpdate
Flag to activate pack/unpack reverse update functions.
Definition: Modifier.h:292
static const Bit PreIntegrate1
Flag to activate preIntegrate() function.
Definition: Modifier.h:253
Parallel domain decomposition (DD) MD simulation.
void readInterval(std::istream &in)
Read parameter interval from file.
Definition: Modifier.cpp:95
Main object for a domain-decomposition MD simulation.
static const Bit PostIntegrate1
Flag to activate postIntegrate1() function.
Definition: Modifier.h:256
Saving / output archive for binary ostream.
static const Bit PreUpdate
Flag to activate preUpdate() function.
Definition: Modifier.h:271
bool isSet(unsigned int flags) const
Is this bit set in the flags integer?
Definition: Bit.h:92
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
bool isSet(Bit flag) const
Return true if a flag is set, false otherwise.
Definition: Modifier.cpp:75
void saveInterval(Serializable::OArchive &ar)
Save interval parameter to an archive.
Definition: Modifier.cpp:130
static const Bit PostExchange
Flag to activate postExchange() function.
Definition: Modifier.h:265
static const Bit PreForce
Flag to activate preForce() function.
Definition: Modifier.h:277
Utility classes for scientific computation.
Definition: accumulators.mod:1
static const Bit PostNeighbor
Flag to activate postNeighbor() function.
Definition: Modifier.h:268
static const Bit Exchange
Flag to activate pack/unpack exchange functions.
Definition: Modifier.h:286
static const Bit EndOfStep
Flag to activate endOfStep() function.
Definition: Modifier.h:283
unsigned int flags() const
Return the unsigned int representation of all bit flags.
Definition: Modifier.cpp:81
Saving archive for binary istream.
static void initStatic()
Call this to guarantee initialization of static variables.
Definition: Modifier.cpp:37
Modifier()
Default constructor (for unit testing)
Definition: Modifier.cpp:49
Represents a specific bit location within an unsigned int.
Definition: Bit.h:21
virtual ~Modifier()
Destructor.
Definition: Modifier.cpp:69
static const Bit PostUpdate
Flag to activate postUpdate() function.
Definition: Modifier.h:274
An object that can read multiple parameters from file.
void set(Bit flag)
Set the flag associated with a particular action.
Definition: Modifier.cpp:89
void loadInterval(Serializable::IArchive &ar)
Load parameter interval from input archive.
Definition: Modifier.cpp:114