forked from CFDEMproject/LIGGGHTS-PUBLIC
-
Notifications
You must be signed in to change notification settings - Fork 11
/
compute_pair_gran_local.cpp
601 lines (480 loc) · 17.1 KB
/
compute_pair_gran_local.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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
/* ----------------------------------------------------------------------
LIGGGHTS - LAMMPS Improved for General Granular and Granular Heat
Transfer Simulations
LIGGGHTS is part of the CFDEMproject
www.liggghts.com | www.cfdem.com
Christoph Kloss, christoph.kloss@cfdem.com
Copyright 2009-2012 JKU Linz
Copyright 2012- DCS Computing GmbH, Linz
LIGGGHTS is based on LAMMPS
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
This software is distributed under the GNU General Public License.
See the README file in the top-level directory.
------------------------------------------------------------------------- */
#include "math.h"
#include "string.h"
#include "compute_pair_gran_local.h"
#include "atom.h"
#include "update.h"
#include "force.h"
#include "pair.h"
#include "pair_gran.h"
#include "modify.h"
#include "neighbor.h"
#include "neigh_request.h"
#include "neigh_list.h"
#include "group.h"
#include "memory.h"
#include "error.h"
#include "pair_gran.h"
#include "domain.h"
#include "fix_heat_gran_conduction.h"
#include "fix_wall_gran.h"
#include "vector_liggghts.h"
using namespace LAMMPS_NS;
#define DELTA 10000
/* ---------------------------------------------------------------------- */
ComputePairGranLocal::ComputePairGranLocal(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg)
{
if (narg < 3) error->all(FLERR,"Illegal compute pair/gran/local or wall/gran/local command");
local_flag = 1;
nmax = 0;
array = NULL;
// store everything by default expect heat flux
posflag = velflag = idflag = fflag = tflag = hflag = aflag = 1;
// do not store heat flux by default
hfflag = 0;
// if further args, store only the properties that are listed
if(narg > 3)
posflag = velflag = idflag = fflag = tflag = hflag = aflag = 0;
for (int iarg = 3; iarg < narg; iarg++)
{
//int i = iarg-3;
if (strcmp(arg[iarg],"pos") == 0) posflag = 1;
else if (strcmp(arg[iarg],"vel") == 0) velflag = 1;
else if (strcmp(arg[iarg],"id") == 0) idflag = 1;
else if (strcmp(arg[iarg],"force") == 0) fflag = 1;
else if (strcmp(arg[iarg],"torque") == 0) tflag = 1;
else if (strcmp(arg[iarg],"history") == 0) hflag = 1;
else if (strcmp(arg[iarg],"contactArea") == 0) aflag = 1;
else if (strcmp(arg[iarg],"heatFlux") == 0) hfflag = 1;
else error->all(FLERR,"Invalid keyword in compute pair/gran/local or wall/gran/local command");
}
// default: pair data
wall = 0;
reference_exists = 0;
fixwall = NULL;
fixheat = NULL;
pairgran = NULL;
if(update->ntimestep > 0 && !modify->fix_restart_in_progress())
error->all(FLERR,"Need to define compute pair/gran/local or wall/gran/local before first run");
}
/* ---------------------------------------------------------------------- */
ComputePairGranLocal::~ComputePairGranLocal()
{
memory->destroy(array);
if(reference_exists == 0) return;
if(wall == 0) pairgran->unregister_compute_pair_local(this);
else fixwall->unregister_compute_wall_local(this);
if(fixheat) fixheat->unregister_compute_pair_local(this);
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::post_create()
{
// check if wall data requested
if(strcmp(style,"wall/gran/local") == 0) wall = 1;
// initialize once as dump parses in constructor for length of per-atom data
init_cpgl(false);
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::init()
{
init_cpgl(false);
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::init_cpgl(bool requestflag)
{
int ifix, n_wall_fixes;
FixWallGran *fwg;
newton_pair = force->newton_pair;
if (idflag && atom->tag_enable == 0)
error->all(FLERR,"Compute pair/gran/local requested to compute IDs, this requires atoms have IDs.");
// if available from previous run, unregister
if(pairgran && reference_exists)
pairgran->unregister_compute_pair_local(this);
if(fixwall && reference_exists)
fixwall->unregister_compute_wall_local(this);
if(fixheat && reference_exists)
fixheat->unregister_compute_pair_local(this);
fixwall = NULL;
fixheat = NULL;
pairgran = NULL;
// register heat transfer fix for pair data
if(wall == 0)
{
if (force->pair == NULL)
error->all(FLERR,"No pair style is defined for compute pair/gran/local");
pairgran = (PairGran*)force->pair_match("gran",0);
if (pairgran == NULL)
error->all(FLERR,"No valid granular pair style found for use with compute pair/gran/local");
if (pairgran->cplenable() == 0)
error->all(FLERR,"Pair style does not support compute pair/gran/local");
pairgran->register_compute_pair_local(this,dnum);
if(requestflag)
{
int irequest = neighbor->request((void *) this);
neighbor->requests[irequest]->pair = 0;
neighbor->requests[irequest]->compute = 1;
neighbor->requests[irequest]->half = 0;
neighbor->requests[irequest]->gran = 1;
//neighbor->requests[irequest]->granhistory = 1;
neighbor->requests[irequest]->occasional = 1;
}
// register heat transfer fix if applicable
if(hfflag)
{
for(ifix = 0; ifix < modify->nfix; ifix++)
{
if(strcmp(modify->fix[ifix]->style,"heat/gran/conduction") == 0)
{
fixheat = static_cast<FixHeatGranCond*>(modify->fix[ifix]);
}
}
if(!fixheat) error->warning(FLERR,"Compute pair/gran/local can not calculate heat flux values since no fix heat/gran/conduction not compute them");
// group of this compute and heat transfer fix must be same so same number of pairs is computed
if(groupbit != fixheat->groupbit) error->all(FLERR,"Compute pair/gran/local group and fix heat/gran/conduction group cannot be different");
fixheat->register_compute_pair_local(this);
}
}
// register with granular wall, only accept mesh walls
else
{
if(fixwall) fixwall->unregister_compute_wall_local(this);
fixwall = NULL;
n_wall_fixes = modify->n_fixes_style("wall/gran");
for(ifix = 0; ifix < n_wall_fixes; ifix++)
{
fwg = static_cast<FixWallGran*>(modify->find_fix_style("wall/gran",ifix));
if(fwg->is_mesh_wall()) fixwall = fwg;
}
if(!fixwall) error->all(FLERR,"Compute wall/gran/local requires a fix of type wall/gran using one or more mesh walls. This fix has come before the compute in the script");
fixwall->register_compute_wall_local(this,dnum);
}
// at this point we know that ptr is valid
reference_exists = 1;
if(hflag && dnum == 0) error->all(FLERR,"Compute pair/gran/local or wall/gran/local can not calculate history values since pair or wall style does not compute them");
// standard values: pos1,pos2,id1,id2,extra id for mesh wall,force,torque,contact area
nvalues = posflag*6 + velflag*6 + idflag*3 + fflag*3 + tflag*3 + hflag*dnum + aflag*5 + hfflag; //added ri,rj,distance,overlap to area-computation output
size_local_cols = nvalues;
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::init_list(int id, NeighList *ptr)
{
list = ptr;
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::reference_deleted()
{
reference_exists = 0;
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::compute_local()
{
invoked_local = update->ntimestep;
if(!reference_exists) error->one(FLERR,"Compute pair/gran/local or wall/gran/local reference does no longer exist (pair or fix deleted)");
// count local entries and compute pair info
if(wall == 0) ncount = count_pairs(); // # pairs is ensured to be the same for pair and heat
else ncount = count_wallcontacts(); // # wall contacts ensured to be same for wall/gran and heat
if (ncount > nmax) reallocate(ncount);
size_local_rows = ncount;
// get pair data
if(wall == 0)
{
ipair = 0;
if(pairgran == NULL) error->one(FLERR,"null");
pairgran->compute_pgl(0,0);
// get heat flux data
if(fixheat)
{
ipair = 0;
fixheat->cpl_evaluate(this);
}
}
// get wall data
else
{
ipair = 0;
// this also calls heat transfer if necessary
fixwall->post_force_pgl();
}
}
/* ----------------------------------------------------------------------
count pairs on this proc
------------------------------------------------------------------------- */
int ComputePairGranLocal::count_pairs()
{
int i,j,m,n,ii,jj,inum,jnum;
double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
int *ilist,*jlist,*numneigh,**firstneigh;
double **x = atom->x;
double *radius = atom->radius;
int *mask = atom->mask;
int nlocal = atom->nlocal;
int nall = nlocal + atom->nghost;
//neighbor->build_one(list->index);
list = pairgran->list;
inum = list->inum;
ilist = list->ilist;
numneigh = list->numneigh;
firstneigh = list->firstneigh;
// loop over neighbors of my atoms
// skip if I or J are not in group
m = n = 0;
for (ii = 0; ii < inum; ii++) {
i = ilist[ii];
if (!(mask[i] & groupbit)) continue;
xtmp = x[i][0];
ytmp = x[i][1];
ztmp = x[i][2];
jlist = firstneigh[i];
jnum = numneigh[i];
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
if (j >= nall) j %= nall;
if (!(mask[j] & groupbit)) continue;
if (newton_pair == 0 && j >= nlocal && atom->tag[i] <= atom->tag[j]) continue;
delx = xtmp - x[j][0];
dely = ytmp - x[j][1];
delz = ztmp - x[j][2];
rsq = delx*delx + dely*dely + delz*delz;
if (rsq >= (radius[i]+radius[j])*(radius[i]+radius[j])) continue;
m++;
}
}
return m;
}
/* ----------------------------------------------------------------------
count wall contacts on this proc
------------------------------------------------------------------------- */
int ComputePairGranLocal::count_wallcontacts()
{
// account for fix group
return fixwall->n_contacts_local(groupbit);
}
/* ----------------------------------------------------------------------
add data from particle-particle contact on this proc
------------------------------------------------------------------------- */
void ComputePairGranLocal::add_pair(int i,int j,double fx,double fy,double fz,double tor1,double tor2,double tor3,double *hist)
{
double del[3],r,rsq,radi,radj,contactArea;
double *xi,*xj,xi_w[3],xj_w[3],*vi,*vj;
int nlocal;
if (!(atom->mask[i] & groupbit)) return;
if (!(atom->mask[j] & groupbit)) return;
nlocal = atom->nlocal;
if (newton_pair == 0 && j >= nlocal && atom->tag[i] <= atom->tag[j]) return;
xi = atom->x[i];
xj = atom->x[j];
vi = atom->v[i];
vj = atom->v[j];
int n = 0;
if(posflag)
{
vectorCopy3D(xi,xi_w);
vectorCopy3D(xj,xj_w);
domain->remap(xi_w);
domain->remap(xj_w);
vectorToBuf3D(xi_w,array[ipair],n);
vectorToBuf3D(xj_w,array[ipair],n);
}
if(velflag)
{
vectorToBuf3D(vi,array[ipair],n);
vectorToBuf3D(vj,array[ipair],n);
}
if(idflag)
{
array[ipair][n++] = static_cast<double>(atom->tag[i]);
array[ipair][n++] = static_cast<double>(atom->tag[j]);
if(i < nlocal && j < nlocal)
array[ipair][n++] = 0.;
else
{
if(domain->is_periodic_ghost(i) || domain->is_periodic_ghost(j))
array[ipair][n++] = 1.;
else
array[ipair][n++] = 0.;
}
}
if(fflag)
{
array[ipair][n++] = fx;
array[ipair][n++] = fy;
array[ipair][n++] = fz;
}
if(tflag)
{
array[ipair][n++] = tor1;
array[ipair][n++] = tor2;
array[ipair][n++] = tor3;
}
if(hflag)
{
for(int d = 0; d < dnum; d++)
array[ipair][n++] = hist[d];
}
if(aflag)
{
radi = atom->radius[i];
radj = atom->radius[j];
vectorSubtract3D(atom->x[i],atom->x[j],del);
rsq = vectorMag3DSquared(del);
r = sqrt(rsq);
contactArea = - M_PI/4 * ( (r-radi-radj)*(r+radi-radj)*(r-radi+radj)*(r+radi+radj) )/rsq;
array[ipair][n++] = contactArea;
array[ipair][n++] = radi; //CR radius of 1st particle
array[ipair][n++] = radj; //CR radius of 2nd particle
array[ipair][n++] = r; //CR =sqrt(vectorMag3DSquared(x[i]-x[j])) =distance
array[ipair][n++] = radi+radj-r; //CR overlap
//printf("[%d]DEBUG: %f %f %f %f %f\n",update->ntimestep,contactArea,radi,radj,r,radi+radj-r);
}
ipair++;
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::add_heat(int i,int j,double hf)
{
if (newton_pair == 0 && j >= atom->nlocal && atom->tag[i] <= atom->tag[j]) return;
if (!(atom->mask[i] & groupbit)) return;
if (!(atom->mask[j] & groupbit)) return;
if(hfflag)
{
// heat flux is always last value
array[ipair][nvalues-1] = hf;
}
else error->one(FLERR,"Illegal situation in ComputePairGranLocal::add_heat");
// inc counter again, since reset in compute_local() after getting pair data
ipair++;
}
/* ----------------------------------------------------------------------
add data from particle-wall contact on this proc
------------------------------------------------------------------------- */
void ComputePairGranLocal::add_wall_1(int iFMG,int idTri,int iP,double *contact_point,double *v_wall)
{
if (!(atom->mask[iP] & groupbit)) return;
int n = 0;
if(posflag)
{
array[ipair][n++] = contact_point[0];
array[ipair][n++] = contact_point[1];
array[ipair][n++] = contact_point[2];
n += 3;
}
if(velflag)
{
if(v_wall)
{
array[ipair][n++] = v_wall[0];
array[ipair][n++] = v_wall[1];
array[ipair][n++] = v_wall[2];
}
else
{
array[ipair][n++] = 0.;
array[ipair][n++] = 0.;
array[ipair][n++] = 0.;
}
n += 3;
}
if(idflag)
{
array[ipair][n++] = static_cast<double>(iFMG);
array[ipair][n++] = static_cast<double>(idTri);
n += 1;
}
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::add_wall_2(int i,double fx,double fy,double fz,double tor1,double tor2,double tor3,double *hist,double rsq)
{
double contactArea;
if (!(atom->mask[i] & groupbit)) return;
int n = 0;
if(posflag)
{
n += 3;
array[ipair][n++] = atom->x[i][0];
array[ipair][n++] = atom->x[i][1];
array[ipair][n++] = atom->x[i][2];
}
if(velflag)
{
n += 3;
array[ipair][n++] = atom->v[i][0];
array[ipair][n++] = atom->v[i][1];
array[ipair][n++] = atom->v[i][2];
}
if(idflag)
{
n += 2;
array[ipair][n++] = static_cast<double>(atom->tag[i]);
}
if(fflag)
{
array[ipair][n++] = fx;
array[ipair][n++] = fy;
array[ipair][n++] = fz;
}
if(tflag)
{
array[ipair][n++] = tor1;
array[ipair][n++] = tor2;
array[ipair][n++] = tor3;
}
if(hflag)
{
for(int d = 0; d < dnum; d++)
array[ipair][n++] = hist[d];
}
if(aflag)
{
contactArea = (atom->radius[i]*atom->radius[i]-rsq)*M_PI;
array[ipair][n++] = contactArea;
array[ipair][n++] = atom->radius[i]; //CR radius of particle
array[ipair][n++] = 0; //CR dummy to match particle-particle format
array[ipair][n++] = sqrt(rsq); //CR =sqrt(vectorMag3DSquared(x[i]-x[j])) =distance
array[ipair][n++] = atom->radius[i]*atom->radius[i]-rsq; //CR overlap
}
// wall_1 and wall_2 are always called
ipair++;
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::add_heat_wall(int ip,double hf)
{
if (!(atom->mask[ip] & groupbit)) return;
if(hfflag)
{
// heat flux is always last value
// use ipair -1 , add_heat_wall is not always called
array[ipair-1][nvalues-1] = hf;
}
else error->one(FLERR,"Illegal situation in ComputePairGranLocal::add_heat_wall");
}
/* ---------------------------------------------------------------------- */
void ComputePairGranLocal::reallocate(int n)
{
// grow vector or array and indices array
while (nmax < n) nmax += DELTA;
memory->destroy(array);
memory->create(array,nmax,nvalues,"pair/local:array");
array_local = array;
}
/* ----------------------------------------------------------------------
memory usage of local data
------------------------------------------------------------------------- */
double ComputePairGranLocal::memory_usage()
{
double bytes = nmax*nvalues * sizeof(double);
return bytes;
}