-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain0.cpp
94 lines (77 loc) · 3.13 KB
/
main0.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
#include <algorithm>
#include <math.h>
#include "env.hpp"
#include "fire.hpp"
#include "iteration.hpp"
#include "maths.hpp"
#include "particle.hpp"
int main() {
// VARIABLE DEFINITION
// random number generator
int seed = getEnvInt("SEED", 1); // random seed
// simulation
double dt = getEnvDouble("DT", 1e-3); // time step
int Niter = getEnvInt("NITER", 1000000); // number of iterations
// active work computation
int nWork = getEnvInt("NWORK", 0); // number of frames on which to compute active work
// output
std::string filename = getEnvString("FILE", "out.dat0"); // output file name
bool dump = getEnvBool("DUMP", 1); // dump positions and orientations to output file
int period = getEnvInt("PERIOD", 1); // period of dumping of positions and orientations in number of frames
// SYSTEM
// simulation
auto simulate = [&Niter] (System0* system) { // use of lambda function to enable conditional definition of system
// INITIALISATION
system->saveInitialState(); // save first frame
// ITERATION
iterate_ABP_WCA(system, Niter); // run simulations
};
// definition
std::string inputFilename = getEnvString("INPUT_FILENAME", ""); // input file from which to copy data
if ( inputFilename == "" ) { // set parameters from environment variables
// physical parameters
int N = getEnvInt("N", 1); // number of particles in the system
double Dr = getEnvDouble("DR", 1.0/2.0); // rotational diffusivity
double epsilon = getEnvDouble("EPSILON", Dr/3.0); // coefficient parameter of potential
double v0 = getEnvDouble("V0", 1); // self-propulsion velocity
double D = getEnvDouble("D", epsilon); // translational diffusivity
double phi = getEnvDouble("PHI", 0.02); // packing fraction
// diameters
double I = getEnvDouble("I", 0); // polydispersity index
std::vector<double> diameters (N, 1.0); // array of diameters
if ( N > 1 ) {
for (int i=0; i < N; i++) {
diameters[i] = 1 - I + 2*I*i/(N - 1);
}
}
// randomisation of diameters order
Random randomGenerator(seed);
std::random_shuffle(diameters.begin(), diameters.end(),
[&randomGenerator](int max) { return randomGenerator.randomInt(max); });
// system size
double totalArea = 0.0;
for (int i=0; i < N; i++) {
totalArea += M_PI*pow(diameters[i], 2)/4.0;
}
double L = sqrt(totalArea/phi);
Parameters parameters(N, epsilon, v0, D, Dr, phi, L, dt); // class of simulation parameters
// system
System0 system(
¶meters, diameters, seed, filename, nWork, dump, period); // define system
FIRE_WCA(&system, // FIRE minimisation algorithm
getEnvDouble("EMIN", 1),
getEnvInt("ITERMAX", (int) 100.0/dt),
getEnvDouble("DTMIN", dt*1e-3),
getEnvDouble("DT0", dt*1e-1),
getEnvDouble("DTMAX", dt));
simulate(&system);
}
else { // set parameters from file
// input file parameters
int inputFrame = getEnvInt("INPUT_FRAME", 0); // frame to copy as initial frame
// system
System0 system(
inputFilename, inputFrame, dt, seed, filename, nWork, dump, period); // define system
simulate(&system);
}
}