-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
326 lines (235 loc) · 9.25 KB
/
main.cpp
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
#include <iostream>
#include <libconfig.h++>
#include <armadillo>
using namespace arma;
using namespace libconfig;
#ifdef USE_MPI
#include <mpi.h>
#endif
#include "cppMD.h"
int main(int argc, char* argv[])
{
srand(time(NULL));
wall_clock timer;
Config cfg;
std::string superPath;
if (argc > 1) {
superPath = std::string(argv[1]);
} else {
superPath = "./";
}
if (strcmp(&superPath.back(), "/") != 0){
superPath = superPath + "/";
}
std::string configPath = superPath + "configMD.cfg";
cfg.readFile(configPath.c_str());
const Setting & root = cfg.getRoot();
/*
* Parsing config file
*/
double dt = root["solver"]["dt"];
int N = root["solver"]["N"];
int therm = root["solver"]["therm"];
double m = root["solver"]["tightness"];
std::string outputPath = root["solver"]["outputPath"];
double T0 = root["mainThermostat"]["bathTemperature"];
double tau = ((double)root["mainThermostat"]["tauOverDt"])*dt;
int nSpecies = root["ensembleParameters"]["nSpecies"];
mat sigmaTable(nSpecies, nSpecies);
mat epsTable(nSpecies, nSpecies);
vec masses(nSpecies);
for (int i = 0; i < nSpecies; ++i) {
masses(i) = (double)root["ensembleParameters"]["masses"][i];
for (int j = 0; j < nSpecies; ++j) {
sigmaTable(i, j) = 0.5*((double)root["ensembleParameters"]["sigmas"][i] +
(double)root["ensembleParameters"]["sigmas"][j]);
epsTable(i, j) = sqrt((double)root["ensembleParameters"]["epses"][i]*
(double)root["ensembleParameters"]["epses"][j]);
}
}
assert(sigmaTable(0,0) == 1. && "We are working in reduced units.");
assert(epsTable(0,0) == 1. && "We are working in reduced units.");
assert(masses(0) == 1. && "We are working in reduced units.");
double delay = root["DCViz"]["delay"];
int compressionTime = (int)root["Events"]["Compression"]["timeMinusTherm"] + therm;
int compressionLength = (int)root["Events"]["Compression"]["length"];
double compressionDelta = (double)root["Events"]["Compression"]["delta"];
int expansionTime = (int)root["Events"]["Expansion"]["timeMinusCompressionTime"] + compressionTime;
int expansionLength = ((int)root["Events"]["Expansion"]["lengthOverCompressionLength"])*compressionLength;
double expansionDelta = (double)root["Events"]["Expansion"]["delta"];
double tScaleWarm = (double) root["Events"]["Thermostats"]["temperatureScaleFactorWarm"];
double tScaleCold = (double) root["Events"]["Thermostats"]["temperatureScaleFactorCold"];
double tWidth = (double) root["Events"]["Thermostats"]["widthFactor"];
double initialDelta = (double) root["solver"]["initialDelta"];
/*
* Creating the main mesh
*/
Ensemble ensemble(masses);
double Lx = ENS_NX*m;
double Ly = ENS_NY*m;
mat topology(2, 2);
topology << 0 << Lx << endr << 0 << Ly;
MainMesh mainMesh(topology, ensemble);
mainMesh.setOutputPath(outputPath);
int therm10 = therm/10;
VolumeChange expansion(initialDelta, true);
expansion.setOnsetTime(2*therm10-1);
expansion.setOffsetTime(3*therm10-1);
VolumeChange compression(1./(initialDelta*m), true);
compression.setOnsetTime(5*therm10);
compression.setOffsetTime(8*therm10);
mainMesh.addEvent(expansion);
mainMesh.addEvent(compression);
/*
* Creating and adding events to the MainMesh
*/
mdSolver molecularDynamicsSolver(T0, dt);
mainMesh.addEvent(molecularDynamicsSolver);
#ifndef NO_DCVIZ
SaveToFile saveToFile(1);
mainMesh.addEvent(saveToFile);
#endif
VelocityVerletFirstHalf VelocityVerlet1(dt);
mainMesh.addEvent(VelocityVerlet1);
LennardJonesForce lennardJonesForce(sigmaTable, epsTable);
mainMesh.addEvent(lennardJonesForce);
periodicScaling periodicBoundaries;
mainMesh.addEvent(periodicBoundaries);
VelocityVerletSecondHalf VelocityVerlet2(dt);
mainMesh.addEvent(VelocityVerlet2);
BerendsenThermostat mainThermostat(T0, tau, dt);
mainThermostat.setOnsetTime(0);
mainThermostat.setOffsetTime(therm);
mainMesh.addEvent(mainThermostat);
temperatureFluctuations mainFluctuations(&mainThermostat);
mainMesh.addEvent(mainFluctuations);
ReportProgress progressReport;
mainMesh.addEvent(progressReport);
checkEnergyConservation ekTest;
mainMesh.addEvent(ekTest);
checkMomentumConservation pTest;
mainMesh.addEvent(pTest);
#ifndef NO_DCVIZ
LauchDCViz launchDCViz(delay);
mainMesh.addEvent(launchDCViz);
#else
(void) delay;
QApplication app(argc, argv);
QtPlatform platform(argc, argv, NULL);
platform.setEnsemble(&ensemble);
platform.setMainMesh(&mainMesh);
QGraphicsView view;
view.setObjectName(QStringLiteral("graphicsView"));
view.setGeometry(QRect(0, 0, 600, 600));
platform.setGraphicsView(&view);
platform.setAdvanceTimerInterval(1./60);
platform.exec();
#endif
/*
* Onset Events
*/
VolumeChange compression2(compressionDelta, true);
compression2.setOnsetTime(compressionTime);
compression2.setOffsetTime(compressionTime + compressionLength);
mainMesh.addEvent(compression2);
VolumeChange expansion2(expansionDelta, true);
expansion2.setOnsetTime(expansionTime);
expansion2.setOffsetTime(expansionTime + expansionLength);
mainMesh.addEvent(expansion2);
/*
* Creating and adding three subFields on the solver, each with their own thermostat.
*/
mat topologyUpper (2, 2);
mat topologyMiddle(2, 2);
mat topologyLower (2, 2);
topologyLower << 0 << Lx << endr << 0 << tWidth*Ly;
topologyMiddle << 0 << Lx << endr << (1 - tWidth)*Ly/2 << (1 + tWidth)*Ly/2;
topologyUpper << 0 << Lx << endr << (1 - tWidth)*Ly << Ly;
MeshField subFieldUpper (topologyUpper , ensemble, "heatUpper");
MeshField subFieldMiddle(topologyMiddle, ensemble, "coolMiddle");
MeshField subFieldLower (topologyLower , ensemble, "heatLower");
density d1;
density d2;
density d3;
subFieldUpper.addEvent(d1);
subFieldMiddle.addEvent(d2);
subFieldLower.addEvent(d3);
pressureMOP press(1);
subFieldMiddle.addEvent(press);
mat topologyPressureTop(2, 2);
mat topologyPressureBottom(2, 2);
double pressureBoxHeight = 2.5;
topologyPressureTop << 0
<< Lx
<< endr
<< topologyMiddle(1, 1) - pressureBoxHeight/2
<< topologyMiddle(1, 1) + pressureBoxHeight/2;
topologyPressureBottom << 0
<< Lx
<< endr
<< topologyMiddle(1, 0) - pressureBoxHeight/2
<< topologyMiddle(1, 0) + pressureBoxHeight/2;
// MeshField solidToLiquidTop(topologyPressureTop, ensemble, "pressureTop");
// MeshField solidToLiquidBottom(topologyPressureBottom, ensemble, "pressureBottom");
// pressureMOP pT(1);
// pressureMOP pB(1);
// solidToLiquidTop.addEvent(pT);
// solidToLiquidBottom.addEvent(pB);
// mainMesh.addSubField(solidToLiquidBottom);
// mainMesh.addSubField(solidToLiquidTop);
// //DEBUG
// debugSubMeshResize debugMeshSize1(&mainMesh);
// debugSubMeshResize debugMeshSize2(&mainMesh);
// debugSubMeshResize debugMeshSize3(&mainMesh);
// subFieldUpper.addEvent(debugMeshSize1);
// subFieldMiddle.addEvent(debugMeshSize2);
// subFieldLower.addEvent(debugMeshSize3);
double tTop = T0*tScaleWarm;
double tMid = T0/tScaleCold;
double tLow = T0*tScaleWarm;
BerendsenThermostat thermoUpper (tTop, tau, dt);
BerendsenThermostat thermoMiddle(tMid, tau, dt);
BerendsenThermostat thermoLower (tLow, tau, dt);
thermoUpper.setOnsetTime (therm);
thermoMiddle.setOnsetTime(therm);
thermoLower.setOnsetTime (therm);
subFieldUpper.addEvent (thermoUpper);
subFieldMiddle.addEvent(thermoMiddle);
subFieldLower.addEvent (thermoLower);
diffusionConstant DUpper(dt);
diffusionConstant DMiddle(dt);
diffusionConstant DLower(dt);
DUpper.setOnsetTime(expansionTime + expansionLength + 500);
DMiddle.setOnsetTime(expansionTime + expansionLength + 500);
DLower.setOnsetTime(expansionTime + expansionLength + 500);
subFieldUpper.addEvent (DUpper);
subFieldMiddle.addEvent(DMiddle);
subFieldLower.addEvent (DLower);
temperatureFluctuations tFluctUpper(&thermoUpper);
temperatureFluctuations tFluctMiddle(&thermoMiddle);
temperatureFluctuations tFluctLower(&thermoLower);
subFieldUpper.addEvent (tFluctUpper);
subFieldMiddle.addEvent(tFluctMiddle);
subFieldLower.addEvent (tFluctLower);
mainMesh.addSubField(subFieldUpper);
mainMesh.addSubField(subFieldMiddle);
mainMesh.addSubField(subFieldLower);
/*
* Lauching the solver
*/
timer.tic();
#ifndef NO_DCVIZ
mainMesh.eventLoop(N);
#else
// stall smoothify(1./60);
// mainMesh.addEvent(smoothify);
platform.startAdvanceTimer();
MainWindow::startMDThread(N, &platform, &mainMesh);
#endif
std::cout << "Execution time: " << timer.toc() << std::endl;
#ifndef NO_DCVIZ
return 0;
#else
return app.exec();
#endif
}