-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearExtendActive.cpp
More file actions
235 lines (232 loc) · 8.87 KB
/
Copy pathlinearExtendActive.cpp
File metadata and controls
235 lines (232 loc) · 8.87 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
//
// Author: Francesco Arceri
// Date: 10-25-2021
//
// 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, centered = false, saveFinal = true;
long step, maxStep = atof(argv[9]), checkPointFreq = int(maxStep / 10), linFreq = int(checkPointFreq / 2);
long numParticles = atol(argv[10]), nDim = 2, updateCount = 0, direction = 1;
double timeStep = atof(argv[2]), timeUnit, LJcut = 4, damping, inertiaOverDamping = atof(argv[11]), strain, otherStrain, width, range = 3;
double sigma, forceUnit, waveQ, Tinject = atof(argv[3]), Dr, tp = atof(argv[4]), driving = atof(argv[5]), strainFreq = 0.01;
double ec = atof(argv[12]), cutDistance, cutoff = 0.5, maxStrain = atof(argv[6]), strainStep = atof(argv[7]), initStrain = atof(argv[8]);
std::string inDir = argv[1], strainType = argv[13], potType = argv[14], outDir, currentDir, 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);
sp.setParticleType(simControlStruct::particleEnum::active);
if(strainType == "compress") {
direction = 0;
if(biaxial == true) {
dirSample = "biaxial-comp";
} else {
dirSample = "comp";
}
} else if(strainType == "extend") {
direction = 1;
if(biaxial == true) {
dirSample = "biaxial-ext";
} else {
dirSample = "ext";
}
} else {
cout << "Please specify a strain type between compression and extension" << endl;
exit(1);
}
if(saveForce == true) {
dirSample += "-wall";
}
sp.setEnergyCostant(ec);
if(potType == "lj") {
sp.setPotentialType(simControlStruct::potentialEnum::lennardJones);
cout << "Setting Lennard-Jones potential" << endl;
sp.setLJcutoff(LJcut);
} else if(potType == "wca") {
sp.setPotentialType(simControlStruct::potentialEnum::WCA);
cout << "Setting WCA potential" << endl;
} else if(potType == "harmonic") {
cout << "Default harmonic potential" << endl;
} else {
cout << "Please specify a potential type between lj, wca and harmonic" << endl;
exit(1);
}
ioSPFile ioSP(&sp);
outDir = inDir + dirSample + argv[7] + "-tmax" + argv[9] + "/";
if(initStrain != 0) {
// read initial boxSize
initBoxSize = ioSP.readBoxSize(inDir, nDim);
strain = initStrain + strainStep;
inDir = inDir + dirSample + argv[7] + "-tmax" + argv[9] + "/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);
}
// save initial configuration
ioSP.saveParticlePacking(outDir);
sigma = sp.getMeanParticleSigma();
damping = sqrt(inertiaOverDamping) / sigma;
timeUnit = sigma / sqrt(ec);
forceUnit = ec / sigma;
timeStep = sp.setTimeStep(timeStep * timeUnit);
cout << "Units - time: " << timeUnit << " space: " << sigma << " force: " << forceUnit << " time step: " << timeStep << endl;
cout << "Thermostat - damping: " << damping << " Tinject: " << Tinject << " noise magnitude: " << sqrt(2*damping*Tinject) << endl;
cout << "Activity - Peclet: " << driving * tp / (damping * sigma) << " taup: " << tp << " f0: " << driving << endl;
damping /= timeUnit;
driving = driving*forceUnit;
Dr = 1/(tp * timeUnit);
sp.setSelfPropulsionParams(driving, tp);
ioSP.saveLangevinParams(outDir, damping);
range *= LJcut * sigma;
//sp.initSoftParticleActiveLangevin(Tinject, Dr, driving, damping, readState);
sp.initSoftParticleLangevin(Tinject, 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;
}
if(centered == true) {
sp.applyCenteredBiaxialExtension(newBoxSize, strainStep, direction);
} else {
sp.applyBiaxialExtension(newBoxSize, strainStep, direction);
}
} else {
newBoxSize = initBoxSize;
newBoxSize[direction] = (1 + strain) * initBoxSize[direction];
if(centered == true) {
sp.applyCenteredUniaxialExtension(newBoxSize, strainStep, direction);
} else {
sp.applyUniaxialExtension(newBoxSize, strainStep, direction);
}
cout << "\nStrain: " << strain << endl;
}
boxSize = sp.getBoxSize();
width = boxSize[0] * 0.5;
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.softParticleActiveLangevinLoop();
sp.softParticleLangevinLoop();
if((step + 1) % linFreq == 0) {
if(saveCurrent == true and save == true) {
if(saveForce == true) {
if(centered == true) {
ioSP.saveParticleColumnWallEnergy(step, timeStep, numParticles, range, width);
} else {
ioSP.saveParticleWallEnergy(step, timeStep, numParticles, range);
}
} else {
ioSP.saveStrainEnergy(step, timeStep, numParticles, strain);
}
} else {
if(saveForce == true) {
if(centered == true) {
ioSP.saveParticleColumnWallEnergy(step + countStep * maxStep, timeStep, numParticles, range, width);
} else {
ioSP.saveParticleWallEnergy(step + countStep * maxStep, timeStep, numParticles, range);
}
} else {
ioSP.saveStrainEnergy(step + countStep * maxStep, timeStep, numParticles, strain);
}
}
}
step += 1;
}
if(saveCurrent == true) {
ioSP.saveParticlePacking(currentDir);
}
cout << "Active: current step: " << step;
cout << " E/N: " << sp.getParticleEnergy() / numParticles;
cout << " W/N: " << sp.getParticleWork() / 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);
if(save == true) {
ioSP.closeEnergyFile();
}
}
strain += strainStep;
}
if(save == false) {
ioSP.closeEnergyFile();
}
if(saveFinal == true) {
ioSP.saveParticlePacking(outDir);
}
return 0;
}