Simpatico  v1.10
mcMd/potentials/pair/PairFactory.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2014, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include <mcMd/potentials/pair/PairFactory.h>
9 
10 #include <mcMd/simulation/System.h>
11 #include <mcMd/mdSimulation/MdSystem.h>
12 
13 // PairPotential interfaces and implementation classes
14 #include <mcMd/potentials/pair/MdPairPotential.h>
15 #include <mcMd/potentials/pair/MdPairPotentialImpl.h>
16 #include <mcMd/potentials/pair/McPairPotential.h>
17 #include <mcMd/potentials/pair/McPairPotentialImpl.h>
18 #ifdef SIMP_COULOMB
19 #include <mcMd/potentials/pair/MdEwaldPairPotentialImpl.h>
20 #endif
21 
22 // Pair Potential interaction classes
23 #include <simp/interaction/pair/LJPair.h>
24 #include <simp/interaction/pair/WcaPair.h>
25 #include <simp/interaction/pair/DpdPair.h>
26 
27 #ifdef SIMP_BOND
28 #include <simp/interaction/pair/CompensatedPair.h>
29 #include <simp/interaction/bond/FeneBond.h>
30 #endif
31 
32 
33 namespace McMd
34 {
35 
36  using namespace Util;
37  using namespace Simp;
38 
43  {}
44 
45  /*
46  * Add a subfactory to the list of children, and set communicator (if any).
47  */
49  { subfactories_.push_back(&subfactory); }
50 
51  /*
52  * Return a pointer to a new McPairInteration, if possible.
53  */
55  PairFactory::mcFactory(const std::string& name, System& system) const
56  {
57  McPairPotential* ptr = 0;
58 
59  // Try subfactories first
60  ptr = tryMcSubfactories(name, system);
61  if (ptr) return ptr;
62 
63  if (name == "LJPair") {
64  ptr = new McPairPotentialImpl<LJPair>(system);
65  } else
66  if (name == "WcaPair") {
67  ptr = new McPairPotentialImpl<WcaPair>(system);
68  } else
69  if (name == "DpdPair") {
70  ptr = new McPairPotentialImpl<DpdPair>(system);
71  }
72  #ifdef SIMP_BOND
73  else
74  if (name == "CompensatedPair<DpdPair,FeneBond>") {
76  }
77  #endif
78  return ptr;
79  }
80 
81  /*
82  * Return a pointer to a new MdPairPotential, if possible.
83  */
85  PairFactory::mdFactory(const std::string& name, System& system) const
86  {
87  MdPairPotential* ptr = 0;
88  MdSystem& mdsystem = dynamic_cast<MdSystem&>(system);
89 
90  // Try subfactories first
91  ptr = tryMdSubfactories(name, system);
92  if (ptr) return ptr;
93 
94  #ifdef SIMP_COULOMB
95  if (!mdsystem.simulation().hasCoulomb()) {
96  #endif
97 
98  // std::cout << "Attempting to instantiate MdPairPotentialImpl instance - neutral system"
99  // << std::endl;
100  if (name == "LJPair") {
101  ptr = new MdPairPotentialImpl<LJPair>(mdsystem);
102  } else
103  if (name == "WcaPair") {
104  ptr = new MdPairPotentialImpl<WcaPair>(mdsystem);
105  } else
106  if (name == "DpdPair") {
107  ptr = new MdPairPotentialImpl<DpdPair>(mdsystem);
108  }
109  #ifdef SIMP_BOND
110  else
111  if (name == "CompensatedPair<DpdPair,FeneBond>") {
112  ptr = new
114  }
115  #endif
116 
117  #ifdef SIMP_COULOMB
118  } else {
119  // std::cout << "Attempting to construct MdEwaldPairPotentialImpl instance - charged system"
120  // << std::endl;
121  if (name == "LJPair") {
122  ptr = new MdEwaldPairPotentialImpl<LJPair>(mdsystem);
123  } else
124  if (name == "WcaPair") {
125  ptr = new MdEwaldPairPotentialImpl<WcaPair>(mdsystem);
126  } else
127  if (name == "DpdPair") {
128  ptr = new MdEwaldPairPotentialImpl<DpdPair>(mdsystem);
129  }
130  #ifdef SIMP_BOND
131  else
132  if (name == "CompensatedPair<DpdPair,FeneBond>") {
133  ptr = new
135  }
136  #endif
137  }
138  #endif
139 
140  return ptr;
141  }
142 
143  /*
144  * Convert an McPairPotential to a MdPairPotential, if possible.
145  */
148  {
149  std::string name = potential.interactionClassName();
150  MdPairPotential* ptr = 0;
151 
152  // Try subfactories first
153  ptr = tryMdSubfactories(potential);
154  if (ptr) return ptr;
155 
156  if (name == "LJPair") {
158  = dynamic_cast< McPairPotentialImpl<LJPair>* >(&potential);
159  ptr = new MdPairPotentialImpl<LJPair>(*mcPtr);
160  } else
161  if (name == "WcaPair") {
163  = dynamic_cast< McPairPotentialImpl<WcaPair>* >(&potential);
164  ptr = new MdPairPotentialImpl<WcaPair>(*mcPtr);
165  } else
166  if (name == "DpdPair") {
168  = dynamic_cast< McPairPotentialImpl<DpdPair>* >(&potential);
169  ptr = new MdPairPotentialImpl<DpdPair>(*mcPtr);
170  }
171  #ifdef SIMP_BOND
172  else
173  if (name == "CompensatedPair<DpdPair,FeneBond>") {
175  = dynamic_cast< McPairPotentialImpl< CompensatedPair<DpdPair, FeneBond> >* >(&potential);
177  }
178  #endif
179  return ptr;
180  }
181 
182  /*
183  * Try all subfactories in sequence searching for a match.
184  */
186  PairFactory::tryMcSubfactories(const std::string& className, System& system) const
187  {
188  McPairPotential* typePtr = 0;
189  int n = subfactories_.size();
190  for (int i = 0; i < n && typePtr == 0; ++i) {
191  typePtr = subfactories_[i]->mcFactory(className, system);
192  }
193  return typePtr;
194  }
195 
196  /*
197  * Try all subfactories in sequence searching for a match.
198  */
200  PairFactory::tryMdSubfactories(const std::string& className, System& system) const
201  {
202  MdPairPotential* typePtr = 0;
203  int n = subfactories_.size();
204  for (int i = 0; i < n && typePtr == 0; ++i) {
205  typePtr = subfactories_[i]->mdFactory(className, system);
206  }
207  return typePtr;
208  }
209 
210  /*
211  * Try all subfactories in sequence searching for a match.
212  */
214  {
215  MdPairPotential* typePtr = 0;
216  int n = subfactories_.size();
217  for (int i = 0; i < n && typePtr == 0; ++i) {
218  typePtr = subfactories_[i]->mdFactory(potential);
219  }
220  return typePtr;
221  }
222 
223 }
224 
Implementation of a pair potential for a charged system.
Implementation template for an MdPairPotential.
A PairPotential for MC simulations (abstract).
Factory for subclasses MdPairPotential or McPairPotential.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
Classes used by all simpatico molecular simulations.
void addSubfactory(PairFactory &subfactory)
Add a new subfactory to the list.
int hasCoulomb() const
Does a Coulomb potential exist?
Simulation & simulation() const
Get the parent Simulation by reference.
Definition: System.h:1055
Implementation template for an McPairPotential.
virtual McPairPotential * mcFactory(const std::string &subclass, System &system) const
Return a pointer to a new McPairPotential, if possible.
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual MdPairPotential * mdFactory(const std::string &subclass, System &system) const
Return a pointer to a new McPairPotential, if possible.
An PairPotential for MD simulation.
MdPairPotential * tryMdSubfactories(const std::string &className, System &system) const
Search subfactories for match to MdPairPotential subclass name.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
McPairPotential * tryMcSubfactories(const std::string &className, System &system) const
Search subfactories for match to McPairPotential subclass name.
virtual std::string interactionClassName() const =0
Return name of pair interaction class (e.g., "LJPair").
A System for Molecular Dynamics simulation.
Definition: MdSystem.h:68