Simpatico  v1.10
SpecialPotentialFacade.tpp
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 "SpecialPotentialFacade.h"
9 #include <mcMd/simulation/System.h>
10 
11 namespace McMd
12 {
13 
14  using namespace Util;
15 
19  template <class PotentialType, class FactoryType>
21  : SpecialPotential(false),
22  systemPtr_(&system),
23  potentialPtr_(0),
24  style_()
25  { setClassName("SpecialPotential"); }
26 
27  /*
28  * Destructor.
29  */
30  template <class PotentialType, class FactoryType>
32  {
33  if (potentialPtr_) {
34  delete potentialPtr_;
35  }
36  }
37 
38  /*
39  * Read parameters from file.
40  */
41  template <class PotentialType, class FactoryType>
42  void
44  {
45  read(in, "style", style_);
46 
47  // Create PotentialType child
48  FactoryType factory(*systemPtr_);
49  potentialPtr_ = factory.factory(style_);
50  UTIL_CHECK (potentialPtr_);
51 
52  // Read parameters for child
53  bool next = false;
54  addParamComposite(*potentialPtr_, next);
55  potentialPtr_->readParameters(in);
56  }
57 
58  /*
59  * Compute total eneryg.
60  */
61  template <class PotentialType, class FactoryType>
63  {
64  if (!energy_.isSet()) {
65  potentialPtr_->computeEnergy();
66  }
67  energy_.set(potentialPtr_->energy());
68  }
69 
70  /*
71  * Add forces from this potential to all atomic forces.
72  */
73  template <class PotentialType, class FactoryType>
75  { potentialPtr_->addForces(); }
76 
77 }
void set(const T &value)
Set the value and mark as set.
Definition: Setable.h:107
bool isSet() const
Is this object set (is the value known)?
Definition: Setable.h:124
void addForces()
Add forces from this potential to all atomic forces.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
void readParameters(std::istream &in)
Read parameters.
Specialized potential for an MD simulation.
SpecialPotentialFacade(System &system)
Constructor.
virtual ~SpecialPotentialFacade()
Destructor.
Utility classes for scientific computation.
Definition: accumulators.mod:1
void computeEnergy()
Compute total energy.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void addParamComposite(ParamComposite &child, bool next=true)
Add a child ParamComposite object to the format array.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
void setClassName(const char *className)
Set class name string.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.