-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearExtendNH2LJ.cpp
More file actions
215 lines (212 loc) · 7.85 KB
/
Copy pathlinearExtendNH2LJ.cpp
File metadata and controls
215 lines (212 loc) · 7.85 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
//
// Author: Francesco Arceri
// Date: 03-22-2024
//
// Include C++ header files
#include "include/SP2D.h"
#include "include/FileIO.h"
#include "include/Simulator.h"
#include "include/FIRE.h"
#include "include/defs.h"
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <functional>
#include <utility>
#include <thrust/host_vector.h>
#include <experimental/filesystem>
using namespace std;
int main(int argc, char **argv) {
// variables
bool readState = true, biaxial = true, save = false, saveCurrent, saveForce = false, saveFinal = true;
long step, maxStep = atof(argv[7]), checkPointFreq = int(maxStep / 10), linFreq = int(checkPointFreq / 2);
long numParticles = atol(argv[8]), nDim = 2, updateCount = 0, direction = 1, num1 = atol(argv[9]);
double timeStep = atof(argv[2]), timeUnit, LJcut = 4, strain, otherStrain, strainFreq = 0.01;
double ec = 1, cutDistance, cutoff = 0.5, sigma, waveQ, Tinject = atof(argv[3]), range = 3, mass = 10, damping = 1;
double ea = atof(argv[10]), eb = ea, eab = 0.5, maxStrain = atof(argv[4]), strainStep = atof(argv[5]), initStrain = atof(argv[6]);
std::string inDir = argv[1], strainType = argv[11], potType = argv[12], outDir, currentDir, timeDir, energyFile, dirSample;
thrust::host_vector<double> boxSize(nDim);
thrust::host_vector<double> initBoxSize(nDim);
thrust::host_vector<double> newBoxSize(nDim);
// initialize sp object
SP2D sp(numParticles, nDim);
if(strainType == "compress") {
direction = 0;
if(biaxial == true) {
dirSample = "nh-biaxial-comp";
} else {
dirSample = "nh-comp";
}
} else if(strainType == "extend") {
direction = 1;
if(biaxial == true) {
dirSample = "nh-biaxial-ext";
} else {
dirSample = "nh-ext";
}
} else {
cout << "Please specify a strain type between compression and extension" << endl;
exit(1);
}
if(saveForce == true) {
dirSample += "-wall";
}
if(potType == "ljwca") {
sp.setPotentialType(simControlStruct::potentialEnum::LJWCA);
sp.setEnergyCostant(ec);
sp.setLJWCAparams(LJcut, num1);
} else if(potType == "ljmp") {
sp.setPotentialType(simControlStruct::potentialEnum::LJMinusPlus);
sp.setEnergyCostant(ec);
sp.setLJMinusPlusParams(LJcut, num1);
} else if(potType == "2lj") {
sp.setPotentialType(simControlStruct::potentialEnum::doubleLJ);
sp.setDoubleLJconstants(LJcut, ea, eab, eb, num1);
} else {
cout << "Please specify a potential type between ljwca, ljmp and 2lj" << endl;
exit(1);
}
ioSPFile ioSP(&sp);
outDir = inDir + dirSample + argv[5] + "-tmax" + argv[7] + "/";
//outDir = inDir + dirSample + "/";
if(initStrain != 0) {
// read initial boxSize
initBoxSize = ioSP.readBoxSize(inDir, nDim);
strain = initStrain + strainStep;
inDir = inDir + dirSample + argv[5] + "-tmax" + argv[7] + "/strain" + argv[6] + "/";
//inDir = inDir + dirSample + "/strain" + argv[8] + "/";
ioSP.readParticlePackingFromDirectory(inDir, numParticles, nDim);
} else {
strain = strainStep;
ioSP.readParticlePackingFromDirectory(inDir, numParticles, nDim);
initBoxSize = sp.getBoxSize();
}
double boxRatio = initBoxSize[direction] / initBoxSize[!direction];
double targetBoxRatio = 1 / boxRatio;
cout << "Direction: " << direction << " other direction: " << !direction;
cout << " starting from box ratio: " << boxRatio << " target: " << targetBoxRatio << endl;
std::experimental::filesystem::create_directory(outDir);
if(save == false) {
currentDir = outDir;
energyFile = outDir + "energy.dat";
if(initStrain != 0) {
ioSP.reopenEnergyFile(energyFile);
} else {
ioSP.openEnergyFile(energyFile);
}
}
if(readState == true) {
ioSP.readParticleState(inDir, numParticles, nDim);
ioSP.readNoseHooverParams(inDir, mass, damping);
}
ioSP.saveParticlePacking(outDir);
sigma = sp.getMeanParticleSigma();
timeUnit = sigma;//epsilon and mass are 1 sqrt(m sigma^2 / epsilon)
timeStep = sp.setTimeStep(timeStep * timeUnit);
cout << "Time step: " << timeStep << " sigma: " << sigma;
if(readState == false) {
cout << " Tinject: " << Tinject << endl;
} else {
cout << endl;
}
range *= LJcut * sigma;
sp.initSoftParticleNoseHoover(Tinject, mass, damping, readState);
cutDistance = sp.setDisplacementCutoff(cutoff);
// strain by strainStep up to maxStrain
long countStep = 0;
long saveFreq = int(strainFreq / strainStep);
if(saveFreq % 10 != 0) saveFreq += 1;
cout << "Saving frequency: " << saveFreq << endl;
boxSize = sp.getBoxSize();
while (strain < (maxStrain + strainStep) || (boxSize[direction]/boxSize[!direction]) > targetBoxRatio) {
if(biaxial == true) {
newBoxSize[direction] = (1 + strain) * initBoxSize[direction];
otherStrain = -strain / (1 + strain);
newBoxSize[!direction] = (1 + otherStrain) * initBoxSize[!direction];
if(direction == 1) {
cout << "\nStrain y: " << strain << ", x: " << otherStrain << endl;
} else {
cout << "\nStrain x: " << strain << ", y: " << otherStrain << endl;
}
sp.applyCenteredBiaxialExtension(newBoxSize, strainStep, direction);
} else {
newBoxSize = initBoxSize;
newBoxSize[direction] = (1 + strain) * initBoxSize[direction];
sp.applyCenteredUniaxialExtension(newBoxSize, strainStep, direction);
cout << "\nStrain: " << strain << endl;
}
boxSize = sp.getBoxSize();
cout << "new box - Lx: " << boxSize[0] << ", Ly: " << boxSize[1];
cout << ", box ratio: " << boxSize[direction] / boxSize[!direction] << endl;
cout << "Abox / Abox0: " << (boxSize[0]*boxSize[1]) / (initBoxSize[0]*initBoxSize[1]) << endl;
saveCurrent = false;
if((countStep + 1) % saveFreq == 0) {
cout << "SAVING AT STRAIN: " << strain << endl;
saveCurrent = true;
currentDir = outDir + "strain" + std::to_string(strain).substr(0,6) + "/";
std::experimental::filesystem::create_directory(currentDir);
sp.setInitialPositions();
if(save == true) {
energyFile = currentDir + "energy.dat";
ioSP.openEnergyFile(energyFile);
}
}
sp.calcParticleNeighbors(cutDistance);
sp.calcParticleForceEnergy();
sp.resetUpdateCount();
step = 0;
waveQ = sp.getSoftWaveNumber();
while(step != maxStep) {
sp.softParticleNoseHooverLoop();
if((step + 1) % linFreq == 0) {
if(saveCurrent == true and save == true) {
if(saveForce == true) {
ioSP.saveParticleWallEnergy(step, timeStep, numParticles, range);
} else {
ioSP.saveStrainSimpleEnergy(step, timeStep, numParticles, strain);
}
} else {
if(saveForce == true) {
ioSP.saveParticleWallEnergy(step + countStep * maxStep, timeStep, numParticles, range);
} else {
ioSP.saveStrainSimpleEnergy(step + countStep * maxStep, timeStep, numParticles, strain);
}
}
}
step += 1;
}
if(saveCurrent == true) {
ioSP.saveParticlePacking(currentDir);
ioSP.saveNoseHooverParams(currentDir);
}
cout << "NH2LJ: current step: " << step;
cout << " E/N: " << sp.getParticleEnergy() / numParticles;
cout << " T: " << sp.getParticleTemperature();
cout << " ISF: " << sp.getParticleISF(waveQ);
updateCount = sp.getUpdateCount();
if(updateCount > 0) {
cout << " number of updates: " << updateCount << " frequency " << checkPointFreq / updateCount << endl;
} else {
cout << " no updates" << endl;
}
countStep += 1;
// save current configuration
if(saveCurrent == true) {
ioSP.saveParticlePacking(currentDir);
ioSP.saveNoseHooverParams(currentDir);
if(save == true) {
ioSP.closeEnergyFile();
}
}
strain += strainStep;
}
if(save == false) {
ioSP.closeEnergyFile();
}
if(saveFinal == true) {
ioSP.saveParticlePacking(outDir);
}
return 0;
}