-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopologicalVicsek.cpp
More file actions
129 lines (112 loc) · 4.61 KB
/
Copy pathtopologicalVicsek.cpp
File metadata and controls
129 lines (112 loc) · 4.61 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
#include "std_include.h"
#include "cuda_runtime.h"
#include "profiler.h"
#include "Simulation.h"
#include "voronoiModelBase.h"
#include "scalarVicsekModel.h"
#include "vectorVicsekModel.h"
#include "vicsekDatabase.h"
/*!
* This file is a simple implementation of either the scalar or vectorial vicsek model,
* where neighbors are chosen according to an instantaneous Voronoi tessellation of the point set.
* Good stuff.
*/
int main(int argc, char*argv[])
{
int c;
//...some default parameters
int numpts = 200; //number of cells
int USE_GPU = 0; //0 or greater uses a gpu, any negative number runs on the cpu
int tSteps = 5; //number of time steps to run after initialization
int initSteps = 1; //number of initialization steps
int oneRingSize = 32;//estimate of max number of voro neighbors...for now, best to set this deliberately high
double dt = 1.0; //the time step size
double v0 = 0.1; // the self-propulsion
double eta = 0.2; //the scalar- or vector- vicsek noise
double mu = 1.0; //the friction...not relevant at the moment
//The defaults can be overridden from the command line
while((c=getopt(argc,argv,"n:g:m:i:v:t:e:o:")) != -1)
switch(c)
{
case 'n': numpts = atoi(optarg); break;
case 'g': USE_GPU = atoi(optarg); break;
case 't': tSteps = atoi(optarg); break;
case 'i': initSteps = atoi(optarg); break;
case 'o': oneRingSize = atoi(optarg); break;
case 'd': dt = atof(optarg); break;
case 'e': eta = atof(optarg); break;
case 'm': mu = atof(optarg); break;
case 'v': v0 = atof(optarg); break;
case '?':
if(optopt=='c')
std::cerr<<"Option -" << optopt << "requires an argument.\n";
else if(isprint(optopt))
std::cerr<<"Unknown option '-" << optopt << "'.\n";
else
std::cerr << "Unknown option character.\n";
return 1;
default:
abort();
};
char dataname[256];
sprintf(dataname,"../data/test.nc");
vicsekDatabase ncdat(numpts,dataname,NcFile::Replace);
profiler prof("voroVicsek initial ");
profiler prof2("voroVicsek late stage");
clock_t t1,t2; //clocks for timing information
bool reproducible = true; // if you want random numbers with a more random seed each run, set this to false
//check to see if we should run on a GPU
bool initializeGPU = true;
bool gpu = chooseGPU(USE_GPU);
if (!gpu)
initializeGPU = false;
//just switch which line is commented out to use scalar or vector viscek model...
//for both the updaters and the model below the "initializeGPU,!initializeGPU" business is a kludge to declare "I'm not using the GPU and I never will" if gpu < 0.It's ugly, but it will stop memory from being allocated on devices that aren't being used for computation.
shared_ptr<scalarVicsekModel> vicsek = make_shared<scalarVicsekModel>(numpts,eta,mu,dt,initializeGPU,!initializeGPU);
//shared_ptr<vectorVicsekModel> vicsek = make_shared<vectorVicsekModel>(numpts,eta,mu,dt,initializeGPU,!initializeGPU);
//
shared_ptr<voronoiModelBase> model = make_shared<voronoiModelBase>(initializeGPU,!initializeGPU);
if (gpu)
model->setGPU();
else
model->setCPU();
model->initializeVoronoiModelBase(numpts,oneRingSize);
//set the cell activity to have D_r = 1. and a given v_0
model->setv0Dr(v0,1.0);
//combine the equation of motion and the cell configuration in a "Simulation"
SimulationPtr sim = make_shared<Simulation>();
sim->setConfiguration(model);
sim->addUpdater(vicsek,model);
//set the time step size
sim->setIntegrationTimestep(dt);
//set appropriate CPU and GPU flags
sim->setCPUOperation(!initializeGPU);
sim->setReproducible(reproducible);
//run for a few initialization timesteps
printf("starting initialization\n");
for(int ii = 0; ii < initSteps; ++ii)
{
if(ii%10 ==0)
prof.start();
sim->performTimestep();
if(ii%10 ==0)
prof.end();
};
printf("Finished with initialization\n");
printf("beginning primary loop\n");
for(int ii = 0; ii < tSteps; ++ii)
{
if(ii%10 ==0)
{
prof2.start();
// ncdat.WriteState(model);
}
sim->performTimestep();
if(ii%10 ==0)
prof2.end();
};
prof.print();
prof2.print();
ncdat.WriteState(model);
return 0;
};