-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathIons.h
More file actions
390 lines (324 loc) · 13.3 KB
/
Copy pathIons.h
File metadata and controls
390 lines (324 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
// Copyright (c) 2017, Lawrence Livermore National Security, LLC and
// UT-Battelle, LLC.
// Produced at the Lawrence Livermore National Laboratory and the Oak Ridge
// National Laboratory.
// LLNL-CODE-743438
// All rights reserved.
// This file is part of MGmol. For details, see https://github.com/llnl/mgmol.
// Please also read this link https://github.com/llnl/mgmol/LICENSE
#ifndef MGMOL_IONS_H
#define MGMOL_IONS_H
#include "DistributedIonicData.h"
#include "HDFrestart.h"
#include "Ion.h"
#include <fstream>
#include <map>
#include <vector>
class Ions
{
private:
/*!
* map species to atomic numbers
*/
static std::map<std::string, short> map_species_;
static int num_ions_;
// max l over all the ions
static short max_num_proj_;
static double max_Vl_radius_;
static double max_Vnl_radius_;
const std::vector<Species>& species_;
bool setup_;
bool has_locked_atoms_;
std::vector<Ion*> list_ions_;
/*!
* ions located in local sub-domain
*/
std::vector<Ion*> local_ions_;
std::vector<Ion*> interacting_ions_; // for ion-ion interactions
std::vector<Ion*>
overlappingNL_ions_; // with projectors overlapping local sub-domain
std::vector<Ion*> overlappingVL_ions_; // with local potential overlapping
// local sub-domain
double lattice_[3];
double div_lattice_[3];
// boundaries to determine which ions are known on local processor
double list_boundary_left_[3];
double list_boundary_right_[3];
int source_[3];
int dest_[3];
MPI_Comm cart_comm_; // MPI cartesian communicator for data distribution
/*!
* Prevent usage of copy constructor by making it private and
* non-implemented
*/
Ions(const Ions&);
void operator=(const Ions&);
void readRestartVelocities(HDFrestart& h5_file);
void readRestartRandomStates(HDFrestart& h5_file);
void readRestartPositions(HDFrestart& h5_file);
int read1atom(std::ifstream* tfile, const bool cell_relative);
void setupSubdomains(const double lat[3]);
void setupInteractingIons();
void setupListOverlappingIons();
void setMapVL();
double computeMaxVlRadius() const;
double computeMaxNLprojRadius() const;
/*
* Evaluate maximum pseudopotential radius among all species in class
*/
double getSpeciesMaxNLradius() const;
double getSpeciesMaxLradius() const;
void updateListIons();
void augmentIonsData(const int nsteps, const int dir, const int disp,
const int locSize, const int maxLocSize, std::vector<IonData>& data,
int* offset);
bool inListIons(const double x, const double y, const double z);
bool inLocalIons(const double x, const double y, const double z);
/* local arrays for controlling ionic positions */
std::vector<std::string> local_names_; // local ion names
std::vector<double> taum_; // previous ion positions
std::vector<double> tau0_; // current ion positions
std::vector<double> taup_; // next ion positions
std::vector<double> fion_; // ionic forces
std::vector<double> velocity_; // ionic velocities
std::vector<double> pmass_;
std::vector<short> atmove_;
std::vector<unsigned short> rand_states_;
std::vector<IonData> ions_data_;
std::vector<int> gids_;
// arrays with extra (beyond local) atomic data needed for enforcing
// constraints.
// made from list of interacting ions
std::vector<double*> interacting_tau0_;
std::vector<double*> interacting_taup_;
std::vector<double*> interacting_fion_;
std::vector<std::string> interacting_names_;
std::vector<double> interacting_pmass_;
std::vector<short> interacting_atmove_;
// extra data involved in constraints, but not local
std::vector<double> tau0_dummy_;
std::vector<double> taup_dummy_;
std::vector<double> fion_dummy_;
std::vector<std::string> names_dummy_;
std::vector<double> pmass_dummy_;
std::vector<short> atmove_dummy_;
int lstep_[3]; // number of steps to the left for each dimension to gather
// data
int rstep_[3]; // number of steps to the right for each dimension to gather
// data
void gatherLockedData(std::vector<int>& locked_data, const int root) const;
void computeNumIons(void);
int readNatoms(const std::string& input_file, const bool cell_relative);
int readNatoms(std::ifstream* tfile, const bool cell_relative);
int readAtomsFromXYZ(const std::string& filename, const bool cell_relative);
void setupContraintsData();
void clearStepperData();
void initStepperData();
void computeMaxNumProjs();
void augmentIonicData(DistributedIonicData&, const int nsteps,
const int dir, const int disp, const int locSize, const int maxLocSize,
DistributedIonicData& data);
void gatherNames(std::map<int, std::string>& names, const int root,
const MPI_Comm comm) const;
void gatherPositions(
std::vector<double>& positions, const int root = 0) const;
void gatherForces(std::vector<double>& forces, const int root = 0) const;
void gatherNames(std::vector<std::string>& names, const int root,
const MPI_Comm comm) const;
void gatherPositions(std::vector<double>& positions, const int root,
const MPI_Comm comm) const;
void gatherPreviousPositions(std::vector<double>& positions, const int root,
const MPI_Comm comm) const;
void gatherLockedNames(std::vector<std::string>& names, const int root,
const MPI_Comm comm) const;
void gatherIndexes(
std::vector<int>& indexes, const int root, const MPI_Comm comm) const;
void gatherNLprojIds(
std::vector<int>& nlprojids, const int root, const MPI_Comm comm) const;
void gatherVelocities(std::vector<double>& velocities, const int root,
const MPI_Comm comm) const;
void gatherAtomicNumbers(
std::vector<int>& atnumbers, const int root, const MPI_Comm comm) const;
void gatherRandStates(std::vector<unsigned short>& rstates, const int root,
const MPI_Comm comm) const;
void gatherForces(
std::vector<double>& forces, const int root, const MPI_Comm comm) const;
bool hasLockedAtoms() const;
void clearLists();
void rescaleVelocities(const double factor);
public:
Ions(const double lat[3], const std::vector<Species>& sp);
Ions(const Ions&, const double shift[3]);
Ions(const std::vector<double>& p, const std::vector<short>& anum,
const double lat[3], const std::vector<Species>& sp);
~Ions();
void setup();
// compute boundary for box containing all atoms to be known on local
// processor that is values for list_boundary_left_, list_boundary_right_
void setupListIonsBoundaries(const double rmax);
std::vector<std::string>& getLocalNames() { return local_names_; }
std::vector<double>& getTau0() { return tau0_; }
std::vector<double>& getTaup() { return taup_; }
std::vector<double>& getTaum() { return taum_; }
std::vector<double>& getVelocities() { return velocity_; }
std::vector<double>& getFion() { return fion_; }
std::vector<double>& getPmass() { return pmass_; }
std::vector<short>& getAtmove() { return atmove_; }
std::vector<unsigned short>& getRandStates() { return rand_states_; }
std::vector<int>& getGids() { return gids_; }
void resetForces()
{
for (auto& ion : local_ions_)
{
ion->resetForce();
}
}
void resetPositionsToPrevious();
void removeMassCenterMotion();
bool hasNLprojectors()
{
assert(max_num_proj_ >= 0);
return (max_num_proj_ > 0);
}
double energySelf() const;
double energyDiff(const short bc[3]) const;
void printPositions(std::ostream& os, const int root = 0) const;
void printPositionsLocal(std::ostream& os, const int root = 0) const;
void printPositionsGlobal(std::ostream& os, const int root = 0) const;
void printForces(std::ostream& os, const int root = 0) const;
void printForcesLocal(std::ostream& os, const int root = 0) const;
void printForcesGlobal(std::ostream& os, const int root = 0) const;
int getNumIons(void);
int getNumLocIons(void) const { return local_ions_.size(); }
int getNumListIons(void) const { return list_ions_.size(); }
std::vector<Ion*>& local_ions() { return local_ions_; }
const std::vector<Ion*>& local_ions() const { return local_ions_; }
const std::vector<Ion*>& list_ions() const { return list_ions_; }
const std::vector<Ion*>& overlappingNL_ions() const
{
return overlappingNL_ions_;
}
const std::vector<Ion*>& overlappingVL_ions() const
{
return overlappingVL_ions_;
}
double computeIonicCharge() const;
void iiforce(const short periodic[3]);
double kinetic_E(void) const;
void writePositions(HDFrestart& h5f_file);
void writePreviousPositions(HDFrestart& h5f_file);
void writeVelocities(HDFrestart& h5f_file);
void writeRandomStates(HDFrestart& h5f_file);
void writeForces(HDFrestart& h5f_file);
void writeAtomicIDs(HDFrestart& h5f_file);
void writeAtomicNLprojIDs(HDFrestart& h5f_file);
void writeAtomicNumbers(HDFrestart& h5f_file);
void writeAtomNames(HDFrestart& h5f_file);
void readLockedAtomNames(HDFrestart& h5f_file);
void writeLockedAtomNames(HDFrestart& h5f_file);
int countProjectors() const;
int countProjectorsSubdomain() const;
int countProjectorsHere() const;
int countIonsHere() const;
Ion* findIon(const std::string& name) const;
Ion* findIon(const int index) const;
Ion* findLocalIon(const int index) const;
// check if ion is in list of local ions
bool isLocal(const std::string& ion_name) const;
void setLocalPositions(const std::vector<double>& tau);
void lockAtom(const std::string& name);
// functions to initialize atomic coordinates
// either from input file, or restart file
int readAtoms(const std::string& filename, const bool cell_relative);
int readAtoms(std::ifstream* tfile, const bool cell_relative);
void initFromRestartFile(HDFrestart& h5_file);
int setAtoms(
const std::vector<double>& crds, const std::vector<short>& spec);
int getNValenceElectrons() const;
void syncForces();
void setVelocities(
const std::vector<double>&, const std::vector<double>&, const double);
void setTau0();
void setPositionsToTau0();
void setVelocitiesToVel();
void setPositions(
const std::vector<double>& tau, const std::vector<short>& anumbers);
void getLocalPositions(std::vector<double>& tau) const;
void getLocalNames(std::vector<std::string>& names) const;
void getNames(std::vector<std::string>& names) const;
void getPositions(std::vector<double>& tau) const;
void getAtomicNumbers(std::vector<short>& atnumbers) const;
void getForces(std::vector<double>& forces) const;
void getLocalForces(std::vector<double>& tau) const;
/*!
* set forces for ions in local_ions_ based on names matching
*/
void setLocalForces(const std::vector<double>& forces,
const std::vector<std::string>& names);
/*!
* set forces for ions in local_ions_ based on coordinates matching
*/
void setLocalForces(
const std::vector<double>& forces, const std::vector<double>& coords);
void syncData(const std::vector<Species>& sp);
// void syncNames(const int nions, std::vector<std::string>& local_names,
// std::vector<std::string>& names);
double getMaxVlRadius() const { return max_Vl_radius_; }
double getMaxVnlRadius() const
{
assert(max_Vnl_radius_ >= 0.);
return max_Vnl_radius_;
}
double getMaxListRadius() const;
void updateIons();
void shiftIons(const Vector3D& shift);
const std::vector<double>& getMassesInteractingIons() const
{
return interacting_pmass_;
}
const std::vector<std::string>& getNamesInteractingIons() const
{
return interacting_names_;
}
std::vector<double*>& getPositionsInteractingIons()
{
return interacting_tau0_;
}
std::vector<double*>& getTaupInteractingIons() { return interacting_taup_; }
std::vector<double*>& getForcesInteractingIons()
{
return interacting_fion_;
}
const std::vector<short>& getMovesInteractingIons() const
{
return interacting_atmove_;
}
void addIon2Lists(const IonData& data);
const Species& getSpecies(short atomic_num) const
{
std::vector<Species>::const_iterator spi = species_.begin();
while (spi != species_.end())
{
if (atomic_num == spi->getAtomicNumber())
{
break;
}
spi++;
}
return *spi;
}
const std::vector<Species>& getSpecies() const { return species_; }
void updateForcesInteractingIons();
void updateTaupInteractingIons();
void updateDataInteractingIons(
std::vector<double>& data, std::vector<double*>& interacting_data);
/*!
* Calculate minimum distance between local pairs
*/
double computeMinLocalSpacing() const;
void addIonToList(const Species& sp, const std::string& name,
const double crds[3], const double velocity[3], const bool lock);
void readRestartPreviousPositions(HDFrestart& h5_file);
// void checkUnicityLocalIons();
};
#endif