Simpatico  v1.10
ddMd/simulation/Simulation.h
1 #ifndef DDMD_SIMULATION_H
2 #define DDMD_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/param/ParamComposite.h> // base class
12 #include <ddMd/communicate/Domain.h> // member
13 #include <ddMd/communicate/Buffer.h> // member
14 #include <ddMd/communicate/Exchanger.h> // member
15 #include <ddMd/storage/AtomStorage.h> // member
16 #include <ddMd/storage/BondStorage.h> // member
17 #include <ddMd/storage/AngleStorage.h> // member
18 #include <ddMd/storage/DihedralStorage.h> // member
19 #include <ddMd/chemistry/AtomType.h> // member (template param)
20 #include <ddMd/chemistry/MaskPolicy.h> // member
21 #include <simp/boundary/Boundary.h> // member
22 #include <util/random/Random.h> // member
23 #include <util/space/Tensor.h> // member (template param)
24 #include <util/containers/DArray.h> // member (template)
25 #include <util/containers/DMatrix.h> // member (template)
26 #include <util/misc/Setable.h> // member (template)
27 #include <util/signal/Signal.h> // members
28 #include <util/archives/Serializable.h> // typedef in interface
29 
30 #include <fstream>
31 
32 namespace Util {
33  class FileMaster;
34  template <typename T> class Factory;
35 }
36 
37 namespace Simp {
38  class EnergyEnsemble;
39  class BoundaryEnsemble;
40 }
41 
42 namespace DdMd
43 {
44 
45  class Integrator;
46  class ConfigIo;
47  class SerializeConfigIo;
48  #ifdef DDMD_MODIFIERS
49  class ModifierManager;
50  #endif
51  class AnalyzerManager;
52  class PairPotential;
53  #ifdef SIMP_BOND
54  class BondPotential;
55  #endif
56  #ifdef SIMP_ANGLE
57  class AnglePotential;
58  #endif
59  #ifdef SIMP_DIHEDRAL
60  class DihedralPotential;
61  #endif
62  #ifdef SIMP_EXTERNAL
63  class ExternalPotential;
64  #endif
65 
66  using namespace Util;
67  using namespace Simp;
68 
84  class Simulation : public ParamComposite
85  {
86 
87  public:
88 
91 
92  // Lifetime
93 
94  #ifdef UTIL_MPI
95 
100  Simulation(MPI::Intracomm& communicator = MPI::COMM_WORLD);
101  #else
102 
105  Simulation();
106  #endif
107 
111  ~Simulation();
112 
114 
115 
156  void setOptions(int argc, char* const * argv);
157 
161  virtual void readParam();
162 
169  virtual void readParam(std::istream& in);
170 
177  virtual void readParameters(std::istream& in);
178 
193  void setReverseUpdateFlag(bool reverseUpdateFlag);
194 
196 
198 
209  void load(const std::string& filename);
210 
223  virtual void loadParameters(Serializable::IArchive& ar);
224 
233  void save(const std::string& filename);
234 
240  virtual void save(Serializable::OArchive& ar);
241 
243 
245 
254  void readCommands();
255 
264  void readCommands(std::istream &in);
265 
271  void setBoltzmannVelocities(double temperature);
272 
280  Vector removeDriftVelocity();
281 
285  void zeroForces();
286 
288 
290 
303  void readConfig(const std::string& filename);
304 
312  void writeConfig(const std::string& filename);
313 
317  Factory<ConfigIo>& configIoFactory();
318 
327  void setConfigIo(std::string& classname);
328 
330 
332 
343  void computeForces();
344 
357  void computeForcesAndVirial();
358 
365  void computeKineticEnergy();
366 
374  double kineticEnergy();
375 
379  void unsetKineticEnergy();
380 
386  void computePotentialEnergies();
387 
396  double potentialEnergy() const;
397 
401  void unsetPotentialEnergies();
402 
408  void computePairEnergies();
409 
417  DMatrix<double> pairEnergies() const;
418 
424  void computeKineticStress();
425 
433  Tensor kineticStress() const;
434 
442  double kineticPressure() const;
443 
447  void unsetKineticStress();
448 
455  void computeVirialStress();
456 
466  Tensor virialStress() const;
467 
477  double virialPressure() const;
478 
484  void unsetVirialStress();
485 
487 
489 
493  const PairPotential& pairPotential() const;
494 
498  PairPotential& pairPotential();
499 
503  std::string pairStyle() const;
504 
508  Factory<PairPotential>& pairFactory();
509 
510  #ifdef SIMP_BOND
511 
514  const BondPotential& bondPotential() const;
515 
519  BondPotential& bondPotential();
520 
524  std::string bondStyle() const;
525 
529  Factory<BondPotential>& bondFactory();
530  #endif
531 
532  #ifdef SIMP_ANGLE
533 
536  const AnglePotential& anglePotential() const;
537 
541  AnglePotential& anglePotential();
542 
546  std::string angleStyle() const;
547 
551  Factory<AnglePotential>& angleFactory();
552  #endif
553 
554  #ifdef SIMP_DIHEDRAL
555 
558  const DihedralPotential& dihedralPotential() const;
559 
563  DihedralPotential& dihedralPotential();
564 
568  std::string dihedralStyle() const;
569 
573  Factory<DihedralPotential>& dihedralFactory();
574  #endif
575 
576  #ifdef SIMP_EXTERNAL
577 
580  const ExternalPotential& externalPotential() const;
581 
585  ExternalPotential& externalPotential();
586 
590  std::string externalStyle() const;
591 
595  Factory<ExternalPotential>& externalFactory();
596  #endif
597 
599 
601 
605  AtomStorage& atomStorage();
606 
607  #ifdef SIMP_BOND
608 
611  BondStorage& bondStorage();
612  #endif
613 
614  #ifdef SIMP_ANGLE
615 
618  AngleStorage& angleStorage();
619  #endif
620 
621  #ifdef SIMP_DIHEDRAL
622 
625  DihedralStorage& dihedralStorage();
626  #endif
627 
629 
631 
635  Domain& domain();
636 
640  Boundary& boundary();
641 
647  AtomType& atomType(int i);
648 
652  Integrator& integrator();
653 
657  EnergyEnsemble& energyEnsemble();
658 
662  BoundaryEnsemble& boundaryEnsemble();
663 
667  FileMaster& fileMaster();
668 
672  Random& random();
673 
677  Exchanger& exchanger();
678 
682  Buffer& buffer();
683 
684  #ifdef DDMD_MODIFIERS
685 
688  ModifierManager& modifierManager();
689  #endif
690 
694  AnalyzerManager& analyzerManager();
695 
699  Factory<Integrator>& integratorFactory();
700 
702 
704 
708  int nAtomType();
709 
710  #ifdef SIMP_BOND
711 
714  int nBondType();
715  #endif
716 
717  #ifdef SIMP_ANGLE
718 
721  int nAngleType();
722  #endif
723 
724  #ifdef SIMP_DIHEDRAL
725 
728  int nDihedralType();
729  #endif
730 
731  #ifdef SIMP_EXTERNAL
732 
735  bool hasExternal();
736  #endif
737 
741  MaskPolicy maskedPairPolicy() const;
742 
746  bool reverseUpdateFlag() const;
747 
749 
751 
755  Signal<>& modifySignal();
756 
760  Signal<>& positionSignal();
761 
765  Signal<>& velocitySignal();
766 
770  Signal<>& exchangeSignal();
771 
773 
779  void outputOptions(std::ostream& out) const;
780 
784  bool isValid();
785 
786  protected:
787 
793  void readFileMaster(std::istream& in);
794 
800  void loadFileMaster(Serializable::IArchive& ar);
801 
807  void saveFileMaster(Serializable::OArchive& ar);
808 
814  void readPotentialStyles(std::istream& in);
815 
821  void loadPotentialStyles(Serializable::IArchive& ar);
822 
828  void savePotentialStyles(Serializable::OArchive& ar);
829 
835  void readEnsembles(std::istream& in);
836 
842  void loadEnsembles(Serializable::IArchive& ar);
843 
849  void saveEnsembles(Serializable::OArchive& ar);
850 
851  private:
852 
854  AtomStorage atomStorage_;
855 
856  #ifdef SIMP_BOND
857  BondStorage bondStorage_;
859  #endif
860 
861  #ifdef SIMP_ANGLE
862  AngleStorage angleStorage_;
864  #endif
865 
866  #ifdef SIMP_DIHEDRAL
867  DihedralStorage dihedralStorage_;
869  #endif
870 
872  Boundary boundary_;
873 
875  DArray<AtomType> atomTypes_;
876 
878  Domain domain_;
879 
881  Buffer buffer_;
882 
884  Exchanger exchanger_;
885 
887  Random random_;
888 
890  Boundary maxBoundary_;
891 
892  // Value of kinetic energy. Only valid on master.
893  Setable<double> kineticEnergy_;
894 
895  // Value of kinetic stress. Only valid on master.
896  Setable<Tensor> kineticStress_;
897 
899  PairPotential* pairPotentialPtr_;
900 
901  #ifdef SIMP_BOND
902  BondPotential* bondPotentialPtr_;
904  #endif
905 
906  #ifdef SIMP_ANGLE
907  AnglePotential* anglePotentialPtr_;
909  #endif
910 
911  #ifdef SIMP_DIHEDRAL
912  DihedralPotential* dihedralPotentialPtr_;
914  #endif
915 
916  #ifdef SIMP_EXTERNAL
917  ExternalPotential* externalPotentialPtr_;
919  #endif
920 
922  Integrator* integratorPtr_;
923 
925  EnergyEnsemble* energyEnsemblePtr_;
926 
928  BoundaryEnsemble* boundaryEnsemblePtr_;
929 
931  FileMaster* fileMasterPtr_;
932 
934  ConfigIo* configIoPtr_;
935 
937  SerializeConfigIo* serializeConfigIoPtr_;
938 
939  #ifdef DDMD_MODIFIERS
940  ModifierManager* modifierManagerPtr_;
942  #endif
943 
945  AnalyzerManager* analyzerManagerPtr_;
946 
948  Factory<PairPotential>* pairFactoryPtr_;
949 
950  #ifdef SIMP_BOND
951  Factory<BondPotential>* bondFactoryPtr_;
953  #endif
954 
955  #ifdef SIMP_ANGLE
956  Factory<AnglePotential>* angleFactoryPtr_;
958  #endif
959 
960  #ifdef SIMP_DIHEDRAL
961  Factory<DihedralPotential>* dihedralFactoryPtr_;
963  #endif
964 
965  #ifdef SIMP_EXTERNAL
966  Factory<ExternalPotential>* externalFactoryPtr_;
968  #endif
969 
971  Factory<Integrator>* integratorFactoryPtr_;
972 
974  Factory<ConfigIo>* configIoFactoryPtr_;
975 
977  std::string pairStyle_;
978 
979  #ifdef SIMP_BOND
980  std::string bondStyle_;
982  #endif
983 
984  #ifdef SIMP_ANGLE
985  std::string angleStyle_;
987  #endif
988 
989  #ifdef SIMP_DIHEDRAL
990  std::string dihedralStyle_;
992  #endif
993 
994  #ifdef SIMP_EXTERNAL
995  std::string externalStyle_;
997  #endif
998 
1000  int nAtomType_;
1001 
1002  #ifdef SIMP_BOND
1003  int nBondType_;
1005  #endif
1006 
1007  #ifdef SIMP_ANGLE
1008  int nAngleType_;
1010  #endif
1011 
1012  #ifdef SIMP_DIHEDRAL
1013  int nDihedralType_;
1015  #endif
1016 
1017  #ifdef SIMP_EXTERNAL
1018  bool hasExternal_;
1020  #endif
1021 
1023  bool hasAtomContext_;
1024 
1033  MaskPolicy maskedPairPolicy_;
1034 
1036  bool reverseUpdateFlag_;
1037 
1038  #ifdef UTIL_MPI
1039  MPI::Intracomm communicator_;
1041  #endif
1042 
1044  Signal<> modifySignal_;
1045 
1047  Signal<> positionSignal_;
1048 
1050  Signal<> velocitySignal_;
1051 
1053  Signal<> exchangeSignal_;
1054 
1056  std::ofstream logFile_;
1057 
1059  bool isInitialized_;
1060 
1062  bool isRestarting_;
1063 
1065  ConfigIo& configIo();
1066 
1068  SerializeConfigIo& serializeConfigIo();
1069 
1070  void setGroup(std::stringstream& inBuffer);
1071 
1072  // friends:
1073 
1074  friend class SimulationAccess;
1075 
1076  };
1077 
1078  // Inline method definitions
1079 
1080  inline Boundary& Simulation::boundary()
1081  { return boundary_; }
1082 
1083  inline Domain& Simulation::domain()
1084  { return domain_; }
1085 
1086  inline AtomStorage& Simulation::atomStorage()
1087  { return atomStorage_; }
1088 
1089  #ifdef SIMP_BOND
1090  inline BondStorage& Simulation::bondStorage()
1091  { return bondStorage_; }
1092  #endif
1093 
1094  #ifdef SIMP_ANGLE
1095  inline AngleStorage& Simulation::angleStorage()
1096  { return angleStorage_; }
1097  #endif
1098 
1099  #ifdef SIMP_DIHEDRAL
1100  inline DihedralStorage& Simulation::dihedralStorage()
1101  { return dihedralStorage_; }
1102  #endif
1103 
1104  inline Exchanger& Simulation::exchanger()
1105  { return exchanger_; }
1106 
1107  inline Buffer& Simulation::buffer()
1108  { return buffer_; }
1109 
1110  inline const PairPotential& Simulation::pairPotential() const
1111  {
1112  assert(pairPotentialPtr_);
1113  return *pairPotentialPtr_;
1114  }
1115 
1116  inline PairPotential& Simulation::pairPotential()
1117  {
1118  assert(pairPotentialPtr_);
1119  return *pairPotentialPtr_;
1120  }
1121 
1122  #ifdef SIMP_BOND
1123  inline const BondPotential& Simulation::bondPotential() const
1124  {
1125  assert(bondPotentialPtr_);
1126  return *bondPotentialPtr_;
1127  }
1128 
1129  inline BondPotential& Simulation::bondPotential()
1130  {
1131  assert(bondPotentialPtr_);
1132  return *bondPotentialPtr_;
1133  }
1134  #endif
1135 
1136  #ifdef SIMP_ANGLE
1137  inline const AnglePotential& Simulation::anglePotential() const
1138  {
1139  assert(anglePotentialPtr_);
1140  return *anglePotentialPtr_;
1141  }
1142 
1143  inline AnglePotential& Simulation::anglePotential()
1144  {
1145  assert(anglePotentialPtr_);
1146  return *anglePotentialPtr_;
1147  }
1148  #endif
1149 
1150  #ifdef SIMP_DIHEDRAL
1151  inline const DihedralPotential& Simulation::dihedralPotential() const
1152  {
1153  assert(dihedralPotentialPtr_);
1154  return *dihedralPotentialPtr_;
1155  }
1156 
1157  inline DihedralPotential& Simulation::dihedralPotential()
1158  {
1159  assert(dihedralPotentialPtr_);
1160  return *dihedralPotentialPtr_;
1161  }
1162  #endif
1163 
1164  #ifdef SIMP_EXTERNAL
1165  inline const ExternalPotential& Simulation::externalPotential() const
1166  {
1167  assert(externalPotentialPtr_);
1168  return *externalPotentialPtr_;
1169  }
1170 
1171  inline ExternalPotential& Simulation::externalPotential()
1172  {
1173  assert(externalPotentialPtr_);
1174  return *externalPotentialPtr_;
1175  }
1176  #endif
1177 
1179  inline Integrator& Simulation::integrator()
1180  {
1181  assert(integratorPtr_);
1182  return *integratorPtr_;
1183  }
1184 
1186  inline Random& Simulation::random()
1187  { return random_; }
1188 
1190  inline EnergyEnsemble& Simulation::energyEnsemble()
1191  {
1192  assert(energyEnsemblePtr_);
1193  return *energyEnsemblePtr_;
1194  }
1195 
1197  inline BoundaryEnsemble& Simulation::boundaryEnsemble()
1198  {
1199  assert(boundaryEnsemblePtr_);
1200  return *boundaryEnsemblePtr_;
1201  }
1202 
1204  inline FileMaster& Simulation::fileMaster()
1205  {
1206  assert(fileMasterPtr_);
1207  return *fileMasterPtr_;
1208  }
1209 
1210  #ifdef DDMD_MODIFIERS
1211  inline ModifierManager& Simulation::modifierManager()
1213  {
1214  assert(modifierManagerPtr_);
1215  return *modifierManagerPtr_;
1216  }
1217  #endif
1218 
1220  inline AnalyzerManager& Simulation::analyzerManager()
1221  {
1222  assert(analyzerManagerPtr_);
1223  return *analyzerManagerPtr_;
1224  }
1225 
1227  inline int Simulation::nAtomType()
1228  { return nAtomType_; }
1229 
1230  #ifdef SIMP_BOND
1231  inline int Simulation::nBondType()
1233  { return nBondType_; }
1234  #endif
1235 
1236  #ifdef SIMP_ANGLE
1237  inline int Simulation::nAngleType()
1239  { return nAngleType_; }
1240  #endif
1241 
1242  #ifdef SIMP_DIHEDRAL
1243  inline int Simulation::nDihedralType()
1245  { return nDihedralType_; }
1246  #endif
1247 
1248  #ifdef SIMP_EXTERNAL
1249  inline bool Simulation::hasExternal()
1251  { return hasExternal_; }
1252  #endif
1253 
1255  inline AtomType& Simulation::atomType(int i)
1256  { return atomTypes_[i]; }
1257 
1259  inline MaskPolicy Simulation::maskedPairPolicy() const
1260  { return maskedPairPolicy_; }
1261 
1263  inline bool Simulation::reverseUpdateFlag() const
1264  { return reverseUpdateFlag_; }
1265 
1266  // Signals
1267 
1269  inline Signal<>& Simulation::modifySignal()
1270  { return modifySignal_; }
1271 
1273  inline Signal<>& Simulation::positionSignal()
1274  { return positionSignal_; }
1275 
1277  inline Signal<>& Simulation::velocitySignal()
1278  { return velocitySignal_; }
1279 
1281  inline Signal<>& Simulation::exchangeSignal()
1282  { return exchangeSignal_; }
1283 
1284 }
1285 #endif
Provides access to members of Simulation object.
A Vector is a Cartesian vector.
Definition: Vector.h:75
Abstract base class for computation of angle force and energies.
An orthorhombic periodic unit cell.
Calculates external forces and energies for a parent Simulation.
Manager for a list of Analyzer objects.
Statistical ensemble for changes in the periodic unit cell size.
Abstract base class for computing bond forces and energies.
Parallel domain decomposition (DD) MD simulation.
Classes used by all simpatico molecular simulations.
Main object for a domain-decomposition MD simulation.
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:32
Saving / output archive for binary ostream.
A statistical ensemble for energy.
An Integrator numerically integrates the equations of motion.
Definition: Integrator.h:29
Utility classes for scientific computation.
Definition: accumulators.mod:1
MaskPolicy
Enumeration of policies for suppressing ("masking") some pair interactions.
Abstract base class for computing dihedral forces and energies.
A container for all the atoms and ghost atoms on this processor.
Buffer for interprocessor communication.
Definition: Buffer.h:217
Decomposition of the system into domains associated with processors.
Definition: Domain.h:31
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:142
Manager for a set of Modifier objects.
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
virtual void load(Serializable::IArchive &ar)
Load all parameters from an input archive.
Saving archive for binary istream.
Abstract reader/writer for configuration files.
Class for exchanging Atoms, Ghosts and Groups between processors.
Definition: Exchanger.h:35
virtual void readParam(std::istream &in)
Read the parameter file block.
Container for Group<3> (angle) objects.
Definition: AngleStorage.h:25
Save / load configuration from / to an archive.
Notifier (or subject) in the Observer design pattern.
Definition: Signal.h:38
Random number generator.
Definition: Random.h:46
Container for Group<4> (dihedral) objects.
An object that can read multiple parameters from file.
Descriptor for a type of Atom.
Abstract base class for computing nonbonded pair forces and energies.
Container for for Group<2> (bond) objects.
Definition: BondStorage.h:25