OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48#ifndef OPENMD_RNEMD_RNEMD_HPP
49#define OPENMD_RNEMD_RNEMD_HPP
50
51#include <bitset>
52#include <fstream>
53#include <map>
54#include <memory>
55#include <string>
56#include <vector>
57
59#include "brains/SimInfo.hpp"
60#include "brains/Snapshot.hpp"
62#include "math/Vector3.hpp"
63#include "selection/SelectionEvaluator.hpp"
64#include "selection/SelectionManager.hpp"
65#include "types/AtomType.hpp"
66#include "utils/Accumulator.hpp"
67#include "utils/BaseAccumulator.hpp"
68
69namespace OpenMD::RNEMD {
70
71 class RNEMD {
72 public:
73 RNEMD(SimInfo* info, ForceManager*);
74 virtual ~RNEMD();
75
76 void getStarted();
77 void doRNEMD();
78 void collectData();
79 void writeOutputFile();
80
81 protected:
82 enum RNEMDPrivilegedAxis { rnemdX = 0, rnemdY = 1, rnemdZ = 2 };
83
84 enum RNEMDFluxType {
85 rnemdKE, // translational kinetic energy flux
86 rnemdRotKE, // rotational kinetic energy flux
87 rnemdFullKE, // full kinetic energy flux
88 rnemdPx, // flux of momentum along x axis
89 rnemdPy, // flux of momentum along y axis
90 rnemdPz, // flux of momentum along z axis
91 rnemdPvector, // flux of momentum vector
92 rnemdLx, // flux of angular momentum along x axis
93 rnemdLy, // flux of angular momentum along y axis
94 rnemdLz, // flux of angular momentum along z axis
95 rnemdLvector, // flux of angular momentum vector
96 rnemdParticle, // flux of particles
97 rnemdParticleKE, // flux of particles and total kinetic energy
98 rnemdCurrentDensity, // flux of electrons/charge
99 rnemdKePx, // flux of translational KE and x-momentum
100 rnemdKePy, // flux of translational KE and y-momentum
101 rnemdKePvector, // full combo flying platter
102 rnemdKeLx, // flux of translational KE and x-angular momentum
103 rnemdKeLy, // flux of translational KE and y-angular momentum
104 rnemdKeLz, // flux of translational KE and z-angular momentum
105 rnemdKeLvector, // full combo spinning platter
106 rnemdUnknownFluxType
107 };
108
109 SimInfo* info_ {nullptr};
110 Snapshot* currentSnap_ {nullptr};
111 Mat3x3d hmat_;
112 RealType slabWidth_;
113
114 std::string rnemdObjectSelection_;
115 std::vector<MoleculeStamp*> objectTypes_;
116
117 SelectionManager commonA_;
118 SelectionManager commonB_;
119 RealType slabACenter_;
120 RealType slabBCenter_;
121
122 RNEMDPrivilegedAxis rnemdPrivilegedAxis_;
123 RNEMDFluxType rnemdFluxType_;
124
125 std::string rnemdFluxTypeLabel_;
126 std::string rnemdMethodLabel_;
127
128 bool doRNEMD_ {false};
129 bool usePeriodicBoundaryConditions_ {false};
130 bool useChargedSPF_ {false};
131
132 Vector3d coordinateOrigin_;
133
134 // target or desired one-time exchanges
135 RealType kineticTarget_ {0.0};
136 RealType particleTarget_ {0.0};
137 Vector3d momentumTarget_ {V3Zero};
138 Vector3d angularMomentumTarget_ {V3Zero};
139
140 // actual exchanges (running total)
141 RealType kineticExchange_ {0.0};
142 RealType particleExchange_ {0.0};
143 Vector3d momentumExchange_ {V3Zero};
144 Vector3d angularMomentumExchange_ {V3Zero};
145
146 unsigned int trialCount_ {0};
147 unsigned int failTrialCount_ {0};
148 unsigned int failRootCount_ {0};
149
150 void setKineticFlux(RealType kineticFlux);
151 void setParticleFlux(RealType particleFlux);
152 void setMomentumFluxVector(const std::vector<RealType>& momentumFluxVector);
153 void setAngularMomentumFluxVector(
154 const std::vector<RealType>& angularMomentumFluxVector);
155
156 private:
157 enum OutputFields {
158 BEGININDEX = 0,
159 Z = BEGININDEX,
160 R,
161 TEMPERATURE,
162 VELOCITY,
163 ANGULARVELOCITY,
164 DENSITY,
165 ACTIVITY,
166 ELECTRICFIELD,
167 ELECTROSTATICPOTENTIAL,
168 ENDINDEX
169 };
170
171 struct OutputData {
172 std::string title;
173 std::string units;
174 std::vector<std::unique_ptr<Utils::BaseAccumulator>> accumulator;
175 };
176
177 using OutputBitSet = std::bitset<ENDINDEX - BEGININDEX>;
178 using OutputMapType = std::map<std::string, OutputFields>;
179
180 std::string rnemdAxisLabel_;
181
182 // Object selection for specifying a particular species:
183 SelectionEvaluator evaluator_;
184 SelectionManager seleMan_;
185
186 // Geometric selections for the two regions for the exchange:
187 std::string selectionA_;
188 std::string selectionB_;
189 SelectionEvaluator evaluatorA_;
190 SelectionEvaluator evaluatorB_;
191 SelectionManager seleManA_;
192 SelectionManager seleManB_;
193 bool hasSelectionA_ {false};
194 bool hasSelectionB_ {false};
195
196 // Output selection for collecting data about a particular species:
197 std::string outputSelection_;
198 SelectionEvaluator outputEvaluator_;
199 SelectionManager outputSeleMan_;
200
201 unsigned int nBins_ {0};
202
203 RealType binWidth_;
204
205 RealType sphereARadius_;
206 RealType sphereBRadius_;
207 RealType areaA_;
208 RealType areaB_;
209 RealType volumeA_;
210 RealType volumeB_;
211
212 bool hasData_ {false};
213 bool hasDividingArea_ {false};
214
215 RealType dividingArea_;
216
217 // target or desired *flux*
218 RealType kineticFlux_ {0.0};
219 RealType particleFlux_ {0.0};
220 Vector3d momentumFluxVector_ {V3Zero};
221 Vector3d angularMomentumFluxVector_ {V3Zero};
222
223 RealType exchangeTime_ {}, runTime_ {}, statusTime_ {};
224
225 std::string rnemdFileName_;
226 std::ofstream rnemdFile_ {};
227
228 OutputBitSet outputMask_;
229 OutputMapType outputMap_;
230 std::vector<OutputData> data_;
231 std::vector<AtomType*> outputTypes_;
232
233 Utils::RealAccumulator areaAccumulator_ {};
234
235 void parseOutputFileFormat(const std::string& format);
236 std::string setSelection(RealType& slabCenter);
237 RealType getDefaultDividingArea();
238 int getBin(Vector3d pos);
239
240 virtual void doRNEMDImpl(SelectionManager& smanA,
241 SelectionManager& smanB) = 0;
242 };
243} // namespace OpenMD::RNEMD
244
245#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:96
The Snapshot class is a repository storing dynamic data during a Simulation.
Definition Snapshot.hpp:166