Simpatico  v1.10
SpecialFactory.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 <mcMd/potentials/special/SpecialFactory.h>
9 
10 #include <mcMd/simulation/System.h>
11 #include <mcMd/mdSimulation/MdSystem.h>
12 #include <mcMd/potentials/special/SpecialPotential.h>
13 
14 #include <mcMd/potentials/special/SpecialExternal.h>
15 
16 
17 
18 namespace McMd
19 {
20 
21  using namespace Util;
22  using namespace Simp;
23 
28  {}
29 
30  /*
31  * Add a subfactory to the list of children, and set communicator (if any).
32  */
34  { subfactories_.push_back(&subfactory); }
35 
36  /*
37  * Return a pointer to a new SpecialPotential, if possible.
38  */
40  SpecialFactory::mdFactory(const std::string& name, System& system) const
41  {
42  SpecialPotential* ptr = 0;
43  MdSystem& mdsystem = dynamic_cast<MdSystem&>(system);
44 
45  // Try subfactories first
46  ptr = tryMdSubfactories(name, system);
47  if (ptr) return ptr;
48 
49  if (name == "SpecialExternal") {
50  ptr = new SpecialExternal(mdsystem);
51  }
52 
53  return ptr;
54  }
55 
56  /*
57  * Try all subfactories in sequence searching for a match.
58  */
60  SpecialFactory::tryMdSubfactories(const std::string& className, System& system) const
61  {
62  SpecialPotential* typePtr = 0;
63  int n = subfactories_.size();
64  for (int i = 0; i < n && typePtr == 0; ++i) {
65  typePtr = subfactories_[i]->mdFactory(className, system);
66  }
67  return typePtr;
68  }
69 
70 }
71 
Potential for testing purposes.
SpecialFactory()
Constructor.
SpecialPotential * tryMdSubfactories(const std::string &className, System &system) const
Search subfactories for match to SpecialPotential subclass name.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
Classes used by all simpatico molecular simulations.
Specialized potential for an MD simulation.
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual SpecialPotential * mdFactory(const std::string &subclass, System &system) const
Return a pointer to a new SpecialPotential, if possible.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
Factory for specialized subclasses of SpecialPotential.
void addSubfactory(SpecialFactory &subfactory)
Add a new subfactory to the list.
A System for Molecular Dynamics simulation.
Definition: MdSystem.h:68