Simpatico  v1.10
mcMd/simulation/Simulation.h
1 #ifndef MCMD_SIMULATION_H
2 #define MCMD_SIMULATION_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/global.h>
12 
13 #include <util/param/ParamComposite.h> // base class
14 #include <mcMd/chemistry/Atom.h> // member container template argument
15 #include <mcMd/chemistry/Molecule.h> // member container template argument
16 #ifndef SIMP_NOPAIR
17 #include <mcMd/chemistry/MaskPolicy.h> // member
18 #endif
19 #ifdef SIMP_BOND
20 #include <mcMd/chemistry/Bond.h> // typedef
21 #endif
22 #ifdef SIMP_ANGLE
23 #include <mcMd/chemistry/Angle.h> // typedef
24 #endif
25 #ifdef SIMP_DIHEDRAL
26 #include <mcMd/chemistry/Dihedral.h> // typedef
27 #endif
28 #include <mcMd/chemistry/AtomType.h> // member container template parameter
29 #include <util/misc/FileMaster.h> // member
30 #include <util/random/Random.h> // member
31 #include <util/containers/RArray.h> // member container for Atoms
32 #include <util/containers/DArray.h> // member containers (Molecules, Bonds, ...)
33 #include <util/containers/ArrayStack.h> // member containers (molecules reservoirs)
34 
35 namespace Util
36 {
37  template <typename T> class ArraySet;
38  template <typename T> class Factory;
39  class Vector;
40 }
41 
42 namespace Simp {
43  class Species;
44 }
45 
46 namespace McMd
47 {
48 
49  class SpeciesManager;
50  class Analyzer;
51  class AnalyzerManager;
52  class CommandManager;
53 
54  using namespace Util;
55  using namespace Simp;
56 
101  class Simulation : public ParamComposite
102  {
103 
104  public:
105 
106  #ifdef UTIL_MPI
107 
110  Simulation(MPI::Intracomm& communicator);
111  #endif
112 
116  Simulation();
117 
121  virtual ~Simulation();
122 
124 
125 
126  #ifdef UTIL_MPI
127 
138  virtual void setIoCommunicator(MPI::Intracomm& communicator);
139 
145  void setIoCommunicator();
146  #endif
147 
153  virtual void readParameters(std::istream &in);
154 
156 
166  void writeParam(std::string filename);
167 
177  void
178  allocateMoleculeSet(Util::ArraySet<Molecule> &set, int speciesId) const;
179 
181 
183 
189  virtual void loadParameters(Serializable::IArchive &ar);
190 
196  virtual void save(Serializable::OArchive &ar);
197 
199 
201 
207  Molecule& getMolecule(int speciesId);
208 
214  void returnMolecule(Molecule& molecule);
215 
217 
219 
223  Random& random();
224 
231  Species& species(int i);
232 
236  Factory<Analyzer>& analyzerFactory();
237 
241  Factory<Species>& speciesFactory();
242 
246  FileMaster& fileMaster();
247 
248  #ifdef UTIL_MPI
249 
252  MPI::Intracomm& communicator();
253  #endif
254 
256 
258 
262  int iStep() const;
263 
267  int nAtomType() const;
268 
274  const AtomType& atomType(int i) const;
275 
279  const Array<AtomType>& atomTypes() const;
280 
284  int nSpecies() const;
285 
291  const Species& species(int i) const;
292 
296  int moleculeCapacity() const;
297 
301  int atomCapacity() const;
302 
308  int nSystem() const;
309 
313  virtual bool isValid() const;
314 
318  bool hasSpecies() const;
319 
320  #ifndef SIMP_NOPAIR
321 
324  MaskPolicy maskedPairPolicy() const;
325  #endif
326 
327  #ifdef SIMP_BOND
328 
331  int nBondType() const;
332 
336  int bondCapacity() const;
337  #endif
338 
339  #ifdef SIMP_ANGLE
340 
343  int nAngleType() const;
344 
348  int angleCapacity() const;
349  #endif
350 
351  #ifdef SIMP_DIHEDRAL
352 
355  int nDihedralType() const;
356 
360  int dihedralCapacity() const;
361  #endif
362 
363  #ifdef SIMP_COULOMB
364 
367  int hasCoulomb() const;
368  #endif
369 
370  #ifdef SIMP_EXTERNAL
371 
374  int hasExternal() const;
375  #endif
376 
377  #ifdef MCMD_LINK
378 
381  int nLinkType() const;
382  #endif
383 
384  #ifdef SIMP_TETHER
385 
388  int hasTether() const;
389  #endif
390 
391  #ifdef SIMP_SPECIAL
392 
399  int hasSpecial() const;
400  #endif
401 
402  #ifdef UTIL_MPI
403 
406  bool hasCommunicator() const;
407  #endif
408 
409 
415  void outputOptions(std::ostream& out) const;
416 
417  protected:
418 
422  int iStep_;
423 
430  int nSystem_;
431 
439  void setAnalyzerManager(AnalyzerManager* ptr);
440 
444  AnalyzerManager& analyzerManager();
445 
449  void setCommandManager(CommandManager* ptr);
450 
454  CommandManager& commandManager();
455 
456  private:
457 
461  Random random_;
462 
466  FileMaster fileMaster_;
467 
473  SpeciesManager* speciesManagerPtr_;
474 
481  AnalyzerManager* analyzerManagerPtr_;
482 
489  CommandManager* commandManagerPtr_;
490 
494  DArray<Molecule> molecules_;
495 
502  DArray<int> firstMoleculeIds_;
503 
510  DArray< ArrayStack<Molecule> > reservoirs_;
511 
519  int moleculeCapacity_;
520 
526  DArray<AtomType> atomTypes_;
527 
539  RArray<Atom> atoms_;
540 
547  DArray<int> firstAtomIds_;
548 
552  int nAtomType_;
553 
561  int atomCapacity_;
562 
563  #ifndef SIMP_NOPAIR
564 
572  MaskPolicy maskedPairPolicy_;
573  #endif
574 
575  #ifdef SIMP_BOND
576 
584  DArray<Bond> bonds_;
585 
592  DArray<int> firstBondIds_;
593 
597  int nBondType_;
598 
605  int bondCapacity_;
606  #endif
607 
608  #ifdef SIMP_ANGLE
609 
617  DArray<Angle> angles_;
618 
625  DArray<int> firstAngleIds_;
626 
630  int nAngleType_;
631 
638  int angleCapacity_;
639  #endif
640 
641  #ifdef SIMP_DIHEDRAL
642 
650  DArray<Dihedral> dihedrals_;
651 
659  DArray<int> firstDihedralIds_;
660 
664  int nDihedralType_;
665 
672  int dihedralCapacity_;
673  #endif
674 
675  #ifdef SIMP_COULOMB
676  int hasCoulomb_;
678  #endif
679 
680  #ifdef SIMP_EXTERNAL
681 
684  int hasExternal_;
685  #endif
686 
687  #ifdef MCMD_LINK
688  int nLinkType_;
690  #endif
691 
692  #ifdef SIMP_TETHER
693  int hasTether_;
695  #endif
696 
697  #ifdef SIMP_SPECIAL
698  int hasSpecial_;
700  #endif
701 
703  bool hasSpecies_;
704 
705  #ifdef UTIL_MPI
706 
709  std::ofstream logFile_;
710 
714  MPI::Intracomm* communicatorPtr_;
715  #endif
716 
718 
724  void initializeSpeciesData();
725 
731  void initializeSpeciesMolecules(int speciesId);
732 
733  #ifdef SIMP_BOND
734 
739  void initializeSpeciesBonds(int speciesId);
740  #endif
741 
742  #ifdef SIMP_ANGLE
743 
748  void initializeSpeciesAngles(int speciesId);
749  #endif
750 
751  #ifdef SIMP_DIHEDRAL
752 
757  void initializeSpeciesDihedrals(int speciesId);
758  #endif
759 
760  }; // end class Simulation
761 
762 
763  // Public inline accessor member functions
764 
765  inline int Simulation::nSystem() const
766  { return nSystem_; }
767 
768  inline int Simulation::nAtomType() const
769  { return nAtomType_; }
770 
771  inline int Simulation::moleculeCapacity() const
772  { return moleculeCapacity_; }
773 
774  inline int Simulation::atomCapacity() const
775  { return atomCapacity_; }
776 
777  inline const Array<AtomType>& Simulation::atomTypes() const
778  { return atomTypes_; }
779 
780  inline const AtomType& Simulation::atomType(int i) const
781  { return atomTypes_[i]; }
782 
783  #ifdef SIMP_BOND
784  inline int Simulation::nBondType() const
785  { return nBondType_; }
786 
787  inline int Simulation::bondCapacity() const
788  { return bondCapacity_; }
789  #endif
790 
791  #ifdef SIMP_ANGLE
792  inline int Simulation::nAngleType() const
793  { return nAngleType_; }
794 
795  inline int Simulation::angleCapacity() const
796  { return angleCapacity_; }
797  #endif
798 
799  #ifdef SIMP_DIHEDRAL
800  inline int Simulation::nDihedralType() const
801  { return nDihedralType_; }
802 
803  inline int Simulation::dihedralCapacity() const
804  { return dihedralCapacity_; }
805  #endif
806 
807  #ifdef SIMP_COULOMB
808  inline int Simulation::hasCoulomb() const
809  { return hasCoulomb_; }
810  #endif
811 
812  #ifdef SIMP_EXTERNAL
813  inline int Simulation::hasExternal() const
814  { return hasExternal_; }
815  #endif
816 
817  #ifdef MCMD_LINK
818  inline int Simulation::nLinkType() const
819  { return nLinkType_; }
820  #endif
821 
822  #ifdef SIMP_TETHER
823  inline int Simulation::hasTether() const
824  { return hasTether_; }
825  #endif
826 
827  #ifdef SIMP_SPECIAL
828  inline int Simulation::hasSpecial() const
829  { return hasSpecial_; }
830  #endif
831 
832  #ifndef SIMP_NOPAIR
833  inline MaskPolicy Simulation::maskedPairPolicy() const
834  { return maskedPairPolicy_; }
835  #endif
836 
837  inline Random& Simulation::random()
838  { return random_; }
839 
840  inline bool Simulation::hasSpecies() const
841  { return hasSpecies_; }
842 
843  #ifdef UTIL_MPI
844  inline bool Simulation::hasCommunicator() const
845  { return communicatorPtr_ != 0; }
846 
847  inline MPI::Intracomm& Simulation::communicator()
848  {
849  assert(communicatorPtr_);
850  return *communicatorPtr_;
851  }
852  #endif
853 
854  // Protected inline member functions
855 
856  inline int Simulation::iStep() const
857  { return iStep_; }
858 
859  inline FileMaster& Simulation::fileMaster()
860  { return fileMaster_; }
861 
862  inline AnalyzerManager& Simulation::analyzerManager()
863  {
864  UTIL_CHECK(analyzerManagerPtr_);
865  return *analyzerManagerPtr_;
866  }
867 
868  inline CommandManager& Simulation::commandManager()
869  {
870  UTIL_CHECK(commandManagerPtr_);
871  return *commandManagerPtr_;
872  }
873 
874 }
875 #endif
Manager for Command objects in an MdSimulation.
int iStep_
Step index for main MC or MD loop.
MaskPolicy
Enumeration of policies for suppressing ("masking") some pair interactions.
Array container class template.
Definition: AutoCorrArray.h:28
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
int nSystem_
Number of Systems of interacting molecules (> 1 in Gibbs ensemble).
The main object in a simulation, which coordinates others.
Saving / output archive for binary ostream.
Descriptor for a type of Atom.
virtual void writeParam(std::ostream &out)
Write all parameters to an output stream.
A container for pointers to a subset of elements of an associated array.
Definition: ArraySet.h:46
Utility classes for scientific computation.
Definition: accumulators.mod:1
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:142
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
Manager for a list of Analyzer objects.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
A Manager for a set of Species objects.
An Array that acts as a reference to another Array or C array.
Definition: RArray.h:46
Random number generator.
Definition: Random.h:46
A physical molecule (a set of covalently bonded Atoms).
An object that can read multiple parameters from file.
A Species represents a set of chemically similar molecules.