OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
RNEMD.hpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#ifndef OPENMD_RNEMD_RNEMD_HPP
46#define OPENMD_RNEMD_RNEMD_HPP
47
48#include <bitset>
49#include <fstream>
50#include <map>
51#include <memory>
52#include <string>
53#include <vector>
54
56#include "brains/SimInfo.hpp"
57#include "brains/Snapshot.hpp"
59#include "math/Vector3.hpp"
60#include "selection/SelectionEvaluator.hpp"
61#include "selection/SelectionManager.hpp"
62#include "types/AtomType.hpp"
63#include "utils/Accumulator.hpp"
64#include "utils/BaseAccumulator.hpp"
65
66namespace OpenMD::RNEMD {
67
68 class RNEMD {
69 public:
70 RNEMD(SimInfo* info, ForceManager*);
71 virtual ~RNEMD();
72
73 void getStarted();
74 void doRNEMD();
75 void collectData();
76 void writeOutputFile();
77
78 bool failedLastKick() const { return failedLastTrial_; }
79
80 protected:
81 enum RNEMDPrivilegedAxis { rnemdX = 0, rnemdY = 1, rnemdZ = 2 };
82
83 enum RNEMDFluxType {
84 rnemdKE, // translational kinetic energy flux
85 rnemdRotKE, // rotational kinetic energy flux
86 rnemdFullKE, // full kinetic energy flux
87 rnemdPx, // flux of momentum along x axis
88 rnemdPy, // flux of momentum along y axis
89 rnemdPz, // flux of momentum along z axis
90 rnemdPvector, // flux of momentum vector
91 rnemdLx, // flux of angular momentum along x axis
92 rnemdLy, // flux of angular momentum along y axis
93 rnemdLz, // flux of angular momentum along z axis
94 rnemdLvector, // flux of angular momentum vector
95 rnemdParticle, // flux of particles
96 rnemdParticleKE, // flux of particles and total kinetic energy
97 rnemdKePx, // flux of translational KE and x-momentum
98 rnemdKePy, // flux of translational KE and y-momentum
99 rnemdKePvector, // full combo flying platter
100 rnemdKeLx, // flux of translational KE and x-angular momentum
101 rnemdKeLy, // flux of translational KE and y-angular momentum
102 rnemdKeLz, // flux of translational KE and z-angular momentum
103 rnemdKeLvector, // full combo spinning platter
104 rnemdUnknownFluxType
105 };
106
107 SimInfo* info_ {nullptr};
108 Snapshot* currentSnap_ {nullptr};
109 Mat3x3d hmat_;
110 RealType slabWidth_;
111
112 std::string rnemdObjectSelection_;
113
114 SelectionManager commonA_;
115 SelectionManager commonB_;
116 RealType slabACenter_;
117 RealType slabBCenter_;
118
119 RNEMDPrivilegedAxis rnemdPrivilegedAxis_;
120 RNEMDFluxType rnemdFluxType_;
121
122 std::string rnemdFluxTypeLabel_;
123 std::string rnemdMethodLabel_;
124
125 bool doRNEMD_ {false};
126 bool usePeriodicBoundaryConditions_ {false};
127
128 Vector3d coordinateOrigin_;
129
130 // target or desired one-time exchanges
131 RealType kineticTarget_ {0.0};
132 RealType particleTarget_ {0.0};
133 Vector3d momentumTarget_ {V3Zero};
134 Vector3d angularMomentumTarget_ {V3Zero};
135
136 // actual exchanges (running total)
137 RealType kineticExchange_ {0.0};
138 RealType particleExchange_ {0.0};
139 Vector3d momentumExchange_ {V3Zero};
140 Vector3d angularMomentumExchange_ {V3Zero};
141
142 unsigned int trialCount_ {0};
143 unsigned int failTrialCount_ {0};
144 unsigned int failRootCount_ {0};
145
146 bool failedLastTrial_ {false};
147
148 void setKineticFlux(RealType kineticFlux);
149 void setParticleFlux(RealType particleFlux);
150 void setMomentumFluxVector(const std::vector<RealType>& momentumFluxVector);
151 void setAngularMomentumFluxVector(
152 const std::vector<RealType>& angularMomentumFluxVector);
153
154 private:
155 enum OutputFields {
156 BEGININDEX = 0,
157 Z = BEGININDEX,
158 R,
159 TEMPERATURE,
160 VELOCITY,
161 ANGULARVELOCITY,
162 DENSITY,
163 ACTIVITY,
164 ELECTRICFIELD,
165 ELECTROSTATICPOTENTIAL,
166 ENDINDEX
167 };
168
169 struct OutputData {
170 std::string title;
171 std::string units;
172 std::vector<std::unique_ptr<Utils::BaseAccumulator>> accumulator;
173 };
174
175 using OutputBitSet = std::bitset<ENDINDEX - BEGININDEX>;
176 using OutputMapType = std::map<std::string, OutputFields>;
177
178 std::string rnemdAxisLabel_;
179
180 // Object selection for specifying a particular species:
181 SelectionEvaluator evaluator_;
182 SelectionManager seleMan_;
183
184 // Geometric selections for the two regions for the exchange:
185 std::string selectionA_;
186 std::string selectionB_;
187 SelectionEvaluator evaluatorA_;
188 SelectionEvaluator evaluatorB_;
189 SelectionManager seleManA_;
190 SelectionManager seleManB_;
191 bool hasSelectionA_ {false};
192 bool hasSelectionB_ {false};
193
194 // Output selection for collecting data about a particular species:
195 std::string outputSelection_;
196 SelectionEvaluator outputEvaluator_;
197 SelectionManager outputSeleMan_;
198
199 unsigned int nBins_ {0};
200
201 RealType binWidth_;
202
203 RealType sphereARadius_;
204 RealType sphereBRadius_;
205 RealType areaA_;
206 RealType areaB_;
207 RealType volumeA_;
208 RealType volumeB_;
209
210 bool hasData_ {false};
211 bool hasDividingArea_ {false};
212
213 RealType dividingArea_;
214
215 // target or desired *flux*
216 RealType kineticFlux_ {0.0};
217 RealType particleFlux_ {0.0};
218 Vector3d momentumFluxVector_ {V3Zero};
219 Vector3d angularMomentumFluxVector_ {V3Zero};
220
221 RealType exchangeTime_ {}, runTime_ {}, statusTime_ {};
222
223 std::string rnemdFileName_;
224 std::ofstream rnemdFile_ {};
225
226 OutputBitSet outputMask_;
227 OutputMapType outputMap_;
228 std::vector<OutputData> data_;
229 std::vector<AtomType*> outputTypes_;
230
231 Utils::RealAccumulator areaAccumulator_ {};
232
233 void parseOutputFileFormat(const std::string& format);
234 std::string setSelection(RealType& slabCenter);
235 RealType getDefaultDividingArea();
236 int getBin(Vector3d pos);
237
238 virtual void doRNEMDImpl(SelectionManager& smanA,
239 SelectionManager& smanB) = 0;
240 };
241} // namespace OpenMD::RNEMD
242
243#endif // OPENMD_RNEMD_RNEMD_HPP
ForceManager is responsible for calculating both the short range (bonded) interactions and long range...
"selection/SelectionEvaluator"
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:93
The Snapshot class is a repository storing dynamic data during a Simulation.
Definition Snapshot.hpp:147