-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedCell.h
301 lines (257 loc) · 8.23 KB
/
linkedCell.h
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
#ifndef LINKEDCELL_H
#define LINKEDCELL_H
//#include "vector2d.h"
#include "forces.h"
#include "wall.h"
#include <iostream>
#include "Particle.h"
#include "StormerVerlet.h"
#include <vector>
#include <fstream>
#include <cstdlib>
//#include <random>
//std::random_device rd_LC;
//std::mt19937 gen_LC(rd_LC());
//std::uniform_real_distribution<> random_gen(0.,1.);
//#include "helpers.h"
#define index(ic, nc) ((ic)[0] + (nc)[0] * (ic)[1]) // macro to iterate the cells
typedef struct ParticleList
{
Particle p;
struct ParticleList *next;
} ParticleList;
typedef struct socialForceHandler
{
Vec2D socialForce;
int indexI, indexJ;
} socialForceHandler;
typedef struct contactForceHandler
{
Vec2D contactForce;
Vec2D shearForce;
Vec2D contactPoint;
int indexI, indexJ;
} contactForceHandler;
typedef ParticleList *Cell;
class List
{
private:
bool PBC[2];
double l[2];
double pbcLength[2];
int nc[2];
Vec2D minDom;
Vec2D maxDom;
Cell *grid_;
std::vector<contactForceHandler> contactList;
std::vector<socialForceHandler> socialList;
std::vector<Wall> walls;
std::vector<Particle> particles;
Forces force;
double time, delta_t, t_end;
double r_cut, long_axis;
std::string nameFileSF, nameFileCF, nameFilePos, nameFileOut;
std::ofstream fileSF, fileCF, filePos, fileOut;
int frequence_print, nStep;
int NP, NW; // noumber of particles and walls, respectively
int Nout;
public:
List(){PBC[0] = false; PBC[1] = false;
nameFileSF = "social_force.txt"; nameFileCF = "contact_force.txt"; nameFilePos = "data_pos.txt";
nameFileOut = "flux.txt";
nStep =1; NP = 0; NW = -1;
}
List(Vec2D minDomain, Vec2D maxDomain, Vec2D deltaL, bool pbcX, bool pbcY)
{
PBC[0] = pbcX;
PBC[1] = pbcY;
l[0] = deltaL.X;
l[1] = deltaL.Y;
minDom = minDomain;
maxDom = maxDomain;
pbcLength[0] = (maxDomain.X - minDomain.X);
pbcLength[1] = (maxDomain.Y - minDomain.Y);
nc[0] = (int)floor(pbcLength[0] / l[0]);
nc[1] = (int)floor(pbcLength[1] / l[1]);
int pnc=1;
for (int d=0; d<2; d++)
pnc *= nc[d];
//grid_ = (Cell*)malloc(pnc*sizeof(*grid));
time = 0.;
nameFileSF = "social_force.txt"; nameFileCF = "contact_force.txt"; nameFilePos = "data_pos.txt";
nameFileOut = "flux.txt";
nStep =1;
NP=0;
NW=-1;
Nout =0;
}
void setup(Vec2D minDomain, Vec2D maxDomain, Vec2D deltaL, bool pbcX, bool pbcY)
{
PBC[0] = pbcX;
PBC[1] = pbcY;
l[0] = deltaL.X;
l[1] = deltaL.Y;
minDom = minDomain;
maxDom = maxDomain;
pbcLength[0] = (maxDomain.X - minDomain.X);
pbcLength[1] = (maxDomain.Y - minDomain.Y);
nc[0] = (int)ceil(pbcLength[0] / l[0]) ;
nc[1] = (int)ceil(pbcLength[1] / l[1]) ;
time = 0.;
nameFileSF = "social_force.txt"; nameFileCF = "contact_force.txt"; nameFilePos = "data_pos.txt";
nameFileOut = "flux.txt";
nStep =1;
int pnc=1;
for (int d=0; d<2; d++)
pnc *= nc[d];
grid_ = (Cell*)malloc(pnc*sizeof(*grid_));
long_axis =0.7 + 0.001;
//r_cut = (long_axis>5*0.08)?long_axis:5*0.08;
r_cut = 0.6*5 + 0.7 + 0.001;
NP = 0;
NW = -1;
Nout = 0;
}
void insertList(ParticleList **root_list, ParticleList *i)
{
i->next = *root_list;
*root_list = i;
}
void deleteList(ParticleList **q)
{
*q = (*q)->next; // (*q)->next points to element to be removed
}
void compForceLC(Cell *grid);
void moveParticlesLC(Cell *grid);
void initLC(Cell *grid);
void freeLC()
{
free(grid_);
}
void compXLC(Cell *grid, double delta_t)
{
int ic[2];
for (ic[0] = 0; ic[0] < nc[0]; ic[0]++)
for (ic[1] = 0; ic[1] < nc[1]; ic[1]++)
for (ParticleList *i = grid[index(ic, nc)]; NULL != i; i = i->next)
{
updateX(&i->p, delta_t);
//std::cout<< i->p.getIndex() <<" "<<i->p.getContactF()<<std::endl;
}
moveParticlesLC(grid);
}
void compVLC(Cell *grid, double delta_t)
{
int ic[2];
for (ic[0] = 0; ic[0] < nc[0]; ic[0]++)
for (ic[1] = 0; ic[1] < nc[1]; ic[1]++)
for (ParticleList *i = grid[index(ic, nc)]; NULL != i; i = i->next)
updateV(&i->p, delta_t);
}
void outputResultsLC(){
filePos << time << " "<< NP <<std::endl;
int ic[2];
for (ic[0] = 0; ic[0] < nc[0]; ic[0]++)
for (ic[1] = 0; ic[1] < nc[1]; ic[1]++)
for (ParticleList *i = grid_[index(ic, nc)]; NULL != i; i = i->next){
//filePos <<i->p.getIndex()<<" "<<i->p.getPosition() << " "<< i->p.getVelocity()<<
//" "<< i->p.getAngularPos() <<" "<<i->p.getAngularVel() <<" "<<i->p.getRadius()<<std::endl;
filePos <<i->p.getIndex()<<" "<<i->p.getPosition() << " "<< i->p.getVelocity()<<" "<<i->p.getRadius()<<std::endl;
}
}
void outputTerminal(){
std::cout << time << " "<< NP <<std::endl;
int ic[2];
for (ic[0] = 0; ic[0] < nc[0]; ic[0]++)
for (ic[1] = 0; ic[1] <= nc[1]; ic[1]++)
for (ParticleList *i = grid_[index(ic, nc)]; NULL != i; i = i->next){
std::cout<<i->p.getIndex()<<" "<<i->p.getRadius()<<" "<<i->p.getPosition() << " "<< i->p.getVelocity()<<
" "<< i->p.getAngularPos() <<" "<<i->p.getAngularVel() << std::endl;
}
}
void outputSocialForce(){
fileSF << time << " "<< socialList.size()<<std::endl;
for(auto &sf: socialList){
fileSF << sf.indexI <<" "<< sf.indexJ<<" "<< sf.socialForce <<std::endl;
}
}
void outputContactForce(){
fileCF << time<< " "<< contactList.size()<<std::endl;
for(auto &cf: contactList){
//fileCF << cf.indexI <<" "<< cf.indexJ<<" "<< cf.contactForce <<" "<<cf.contactPoint<<std::endl;
fileCF << cf.indexI <<" "<< cf.indexJ<<" "<< cf.contactForce<<" "<<cf.shearForce <<std::endl;
}
}
void timeIntegrationLC();
virtual void setupInitialConditions(){}
virtual void actionsAfterTimeStep(){}
virtual void actionsBeforeTimeStep(){}
void clearForceHandlers(){
contactList.clear();
socialList.clear();
}
void setTime(double timeIn){
time = timeIn;
}
void setTimeMax(double timeIn){
t_end = timeIn;
}
void setTimeStep(double dt){
delta_t = dt;
}
void setFreqPrint(int Nref){
frequence_print = Nref;
}
double getTime(){
return time;
}
int getTimeStep(){
return delta_t;
}
int getNStep(){
return nStep;
}
int getFreqPrint(){
return frequence_print;
}
void addParticle(Particle *part){
part->setIndex(NP);
particles.push_back(*part);
NP++;
}
void addWall(Wall *wall){
wall->setIndex(NW);
walls.push_back(*wall);
NW--;
}
void setDrivingDT(double DT)
{
force.setDrivingDT(DT);
}
bool checkIsInContact(Particle *part);
~List()
{
freeLC();
}
void setSocialParams(const double Aconst,const double Bconst){
force.setSocialParams(Aconst,Bconst);
//r_cut = 5*Bconst + 0.7;
r_cut = 5*Bconst + 0.5 + 0.001;
//r_cut = (0.7>5*0.08)?(0.7+ 0.001):5*0.08;
//r_cut = 0.7;
}
void setSocialParams(const double Aconst,const double Bconst, const double inTau){
force.setSocialParams(Aconst,Bconst, inTau);
//r_cut = 5*Bconst + 0.7;
r_cut = 5*Bconst + 0.5 + 0.001;
//r_cut = (0.7>5*0.08)?(0.7+ 0.001):5*0.08;
//r_cut = 0.7;
}
void setVisualParam(const double inLambda){
force.setVisualParam(inLambda);
}
void setContactParams(const double stiffnessIn,const double dissipationIn){
force.setContactParams(stiffnessIn, dissipationIn);
}
};
#endif