1 /* -*- c++ -*- */
2 #ifndef ENERGYSTRUCTURE_H
3 #define ENERGYSTRUCTURE_H
4 
5 #include "Proxy.h"
6 #include "Vector3D.h"
7 #include "pmconstants.h"
8 
9 namespace ProtoMol {
10   //_________________________________________________________________ ScalarStructure
11 
12   /**
13    * Container holding energies and all kind of scalar values of intreset.
14    * The values are kept in array of fixed size and in parallel environment
15    * the values are reduced from FIRST to LASTREDUCE.
16    */
17   class ScalarStructure : public Proxy {
18 
19     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20     //  Index type of the array of relevant scalars
21     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22   public:
23     /// Index of the array of relevant scalars
24     enum Index {
25       FIRST = 0,       // Only internal purpose
26       COULOMB = FIRST,
27       LENNARDJONES,
28       BOND,
29       ANGLE,
30       DIHEDRAL,
31       IMPROPER,
32       OTHER,
33       VIRIALXX,
34       VIRIALXY,
35       VIRIALXZ,
36       VIRIALYX,
37       VIRIALYY,
38       VIRIALYZ,
39       VIRIALZX,
40       VIRIALZY,
41       VIRIALZZ,
42       MOLVIRIALXX,
43       MOLVIRIALXY,
44       MOLVIRIALXZ,
45       MOLVIRIALYX,
46       MOLVIRIALYY,
47       MOLVIRIALYZ,
48       MOLVIRIALZX,
49       MOLVIRIALZY,
50       MOLVIRIALZZ,
51       COULOMB_DELTAMU,      ///< needed for iSG simulations
52       LENNARDJONES_DELTAMU, ///< needed for iSG simulations
53       BOND_DELTAMU,         ///< needed for iSG simulations
54       ANGLE_DELTAMU,        ///< needed for iSG simulations
55       DIHEDRAL_DELTAMU,     ///< needed for iSG simulations
56       IMPROPER_DELTAMU,     ///< needed for iSG simulations
57       CQFLUCTUATION,        ///< needed for iSG simulations
58       DELTATIME,            ///< needed for iSG simulations
59       INTEGRATOR,
60       LASTREDUCE,           ///< Last value to be reduced in parallel environment, only internal purpose
61       SHADOW=LASTREDUCE,
62       LAST             // Only internal purpose
63     };
64     // Index of relevant scalares
65 
66     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67     //  Constructors, destructors, assignment
68     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69   public:
70     ScalarStructure();
71 
72     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73     // New methods of class ScalarStructure
74     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75   public:
76     Real& operator [](Index i){return myTable[static_cast<int>(i)];}
77     Real operator [](Index i) const{return myTable[static_cast<int>(i)];}
78 
79     /// Clear all of the energies in this structure.
80     void clear();
81 
82     ScalarStructure &intoAdd(const ScalarStructure &e);
83     ScalarStructure &intoSubtract(const ScalarStructure &e);
84 
85     /// The potential energy.
86     Real potentialEnergy() const;
87 
88     /// The atomic pressure.
89     Real pressure(Real volume) const;
90 
91     /// The Molecular pressure.
92     Real molecularPressure(Real volume) const;
93 
94     /// The chemical potential difference
95     Real deltaMu() const;
96 
97     /// Add viral term for one force pair
98     void addVirial(const Vector3D & force12, const Vector3D &diff);
99 
100     ///  Add molecular viral term for one force pair.
101     void addMolVirial(const Vector3D & force12, const Vector3D &diff);
102 
103     ///  Add viral term for one force pair and molecular viral term for one force pair.
104     void addVirial(const Vector3D & force12, const Vector3D &diff, const Vector3D &comDiff);
105 
106     /// test if molecular virial tensor desired
molecularVirial()107     bool molecularVirial() const {return myDoMolecularVirial;}
108     bool molecularVirial(bool doMolecularVirial);
109     /// test if output desired, can be used to suppress output
output()110     bool output() const {return myDoOutput;}
111     bool output(bool doOutput);
112     /// test if virial tensor desired
virial()113     bool virial() const {return myDoVirial;}
114     bool virial(bool doVirial);
115 
116     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117     // My data members
118     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119   private:
120     Real myTable[LAST-FIRST];
121     // Table of all relevant scalars
122     bool myDoVirial;
123     bool myDoMolecularVirial;
124     bool myDoOutput;
125 
126   };
127 
128   //______________________________________________________________________ INLINES
potentialEnergy()129   inline Real ScalarStructure::potentialEnergy() const {
130     return (myTable[COULOMB] +
131 	    myTable[LENNARDJONES] +
132 	    myTable[BOND] +
133 	    myTable[ANGLE] +
134 	    myTable[DIHEDRAL] +
135 	    myTable[IMPROPER] +
136 	    myTable[OTHER]);
137   }
138 
deltaMu()139   inline Real ScalarStructure::deltaMu() const {
140     return (myTable[COULOMB_DELTAMU] +
141             myTable[LENNARDJONES_DELTAMU] +
142             myTable[BOND_DELTAMU] +
143             myTable[ANGLE_DELTAMU] +
144             myTable[DIHEDRAL_DELTAMU] +
145             myTable[IMPROPER_DELTAMU]);
146   }
147 
pressure(Real volume)148   inline Real ScalarStructure::pressure(Real volume) const {
149     return ((myTable[VIRIALXX]+myTable[VIRIALYY]+myTable[VIRIALZZ])/3.0/volume*Constant::PRESSUREFACTOR);
150   }
151 
molecularPressure(Real volume)152   inline Real ScalarStructure::molecularPressure(Real volume) const {
153     return (( myTable[MOLVIRIALXX]+myTable[MOLVIRIALYY]+myTable[MOLVIRIALZZ])/3.0/volume*Constant::PRESSUREFACTOR);
154   }
155 }
156 #endif /* ENERGYSTRUCTURE_H */
157