File size: 11,213 Bytes
3af0570
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/* ----------------------------------------------------------------------
 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
 https://lammps.sandia.gov/, Sandia National Laboratories
 Steve Plimpton, sjplimp@sandia.gov

 Copyright (2003) Sandia Corporation.  Under the terms of Contract
 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
 certain rights in this software.  This software is distributed under
 the GNU General Public License.

 See the README file in the top-level LAMMPS directory.

 Modifed by NMC 19/01/2024 from sph style atom. Including settings for stmic, stfluid and gradv// Upgrqding to uptodate lammsp version

 ------------------------------------------------------------------------- */

#include "atom_vec_pi.h"

#include "atom.h"

#include <cstring>

using namespace LAMMPS_NS;

/* ---------------------------------------------------------------------- */

AtomVecPi::AtomVecPi(LAMMPS *lmp) : AtomVec(lmp)
{
  molecular = Atom::ATOMIC;
  mass_type = PER_TYPE;
  forceclearflag = 1;

  atom->esph_flag = 1;
  atom->rho_flag = 1;
  atom->cv_flag = 1;
  atom->vest_flag = 1;
  atom->stmic_flag =1; // Modifed by NMC
  atom->stfluid_flag =1; // Modifed by NMC
  atom->gradv_flag =1; // Modifed by NMC

  // strings with peratom variables to include in each AtomVec method
  // strings cannot contain fields in corresponding AtomVec default strings
  // order of fields in a string does not matter
  // except: fields_data_atom & fields_data_vel must match data fil


  fields_grow = {"rho", "drho", "esph", "desph", "cv", "vest", "stmic", "stfluid", "gradv"};
  fields_copy = {"rho", "drho", "esph", "desph", "cv", "vest", "stmic", "stfluid", "gradv"};
  fields_comm = {"rho", "esph", "vest", "stmic", "stfluid", "gradv"};
  fields_comm_vel = {"rho", "esph", "vest", "stmic", "stfluid", "gradv"};
  fields_reverse = {"drho", "desph", "gradv"}; //gradv is needed to communicate for sph pi for macroscale to compute gradv
  fields_border = {"rho", "esph", "cv", "vest", "stmic", "stfluid", "gradv"};
  fields_border_vel = {"rho", "esph", "cv", "vest", "stmic", "stfluid", "gradv"};
  fields_exchange = {"rho", "esph", "cv", "vest", "stmic", "stfluid", "gradv"};
  fields_restart = {"rho", "esph", "cv", "vest", "stmic", "stfluid", "gradv"};
  fields_create = {"rho", "esph", "cv", "vest", "desph", "drho", "stmic", "stfluid", "gradv"};
  fields_data_atom = {"id", "type", "rho", "esph", "cv", "x"};
  fields_data_vel = {"id", "v"};


  setup_fields();
}

/* ----------------------------------------------------------------------
   set local copies of all grow ptrs used by this class, except defaults
   needed in replicate when 2 atom classes exist and it calls pack_restart()
------------------------------------------------------------------------- */

void AtomVecPi::grow_pointers()
{
  rho = atom->rho;
  drho = atom->drho;
  esph = atom->esph;
  desph = atom->desph;
  cv = atom->cv;
  vest = atom->vest;
  //Modified by NMC
  stmic = atom->stmic;
  stfluid = atom->stfluid;
  gradv = atom->gradv;
}

/* ----------------------------------------------------------------------
   clear extra forces starting at atom N
   nbytes = # of bytes to clear for a per-atom vector
------------------------------------------------------------------------- */

void AtomVecPi::force_clear(int n, size_t nbytes)
{
  memset(&desph[n],0,nbytes);
  memset(&drho[n],0,nbytes);

  // LAMMPS stores 2D peratom arrays as one contiguous block (row-major,
  // gradv[i] points to gradv[0] + 9*i). Clearing nlocal rows of 9 doubles
  // each needs a single memset of 9*nbytes, NOT 9 memsets of nbytes.
  memset(&gradv[n][0], 0, 9 * nbytes);
}

/* ----------------------------------------------------------------------
   initialize non-zero atom quantities
------------------------------------------------------------------------- */

void AtomVecPi::create_atom_post(int ilocal)
{
  cv[ilocal] = 1.0;
}

/* ----------------------------------------------------------------------
   modify what AtomVec::data_atom() just unpacked
   or initialize other atom quantities
------------------------------------------------------------------------- */

void AtomVecPi::data_atom_post(int ilocal)
{
  vest[ilocal][0] = 0.0;
  vest[ilocal][1] = 0.0;
  vest[ilocal][2] = 0.0;
  desph[ilocal] = 0.0;
  drho[ilocal] = 0.0;

  // Modifed by NMC
  stmic[ilocal][0] = 0.0;
  stmic[ilocal][1] = 0.0;
  stmic[ilocal][2] = 0.0;
  stmic[ilocal][3] = 0.0;
  stmic[ilocal][4] = 0.0;
  stmic[ilocal][5] = 0.0;

  stfluid[ilocal][0] = 0.0;
  stfluid[ilocal][1] = 0.0;
  stfluid[ilocal][2] = 0.0;
  stfluid[ilocal][3] = 0.0;
  stfluid[ilocal][4] = 0.0;
  stfluid[ilocal][5] = 0.0;

// Modifed by NMC

  gradv[ilocal][0] = 0.0;
  gradv[ilocal][1] = 0.0;
  gradv[ilocal][2] = 0.0;
  gradv[ilocal][3] = 0.0;
  gradv[ilocal][4] = 0.0;
  gradv[ilocal][5] = 0.0;
  gradv[ilocal][6] = 0.0;
  gradv[ilocal][7] = 0.0;
  gradv[ilocal][8] = 0.0;

}

/* ----------------------------------------------------------------------
   assign an index to named atom property and return index
   return -1 if name is unknown to this atom style
------------------------------------------------------------------------- */

int AtomVecPi::property_atom(const std::string &name)
{

  if (name == "rho") return 0;
  if (name == "drho") return 1;
  if (name == "esph") return 2;
  if (name == "desph") return 3;
  if (name == "cv") return 4;



  //////////////Return each component of the tensors separately
  //Modified by NMC to include the prop atom for the new tensors
  if (name == "stfxx") return 5;
  if (name == "stfyy") return 6;
  if (name == "stfzz") return 7;
  if (name == "stfxy") return 8;
  if (name == "stfxz") return 9;
  if (name == "stfyz") return 10;

  if (name == "stmxx") return 11;
  if (name == "stmyy") return 12;
  if (name == "stmzz") return 13;
  if (name == "stmxy") return 14;
  if (name == "stmxz") return 15;
  if (name == "stmyz") return 16;

  if (name == "gdvxx") return 17;
  if (name == "gdvyy") return 18;
  if (name == "gdvzz") return 19;
  if (name == "gdvxy") return 20;
  if (name == "gdvxz") return 21;
  if (name == "gdvyz") return 22;
  if (name == "gdvyx") return 23;
  if (name == "gdvzx") return 24;
  if (name == "gdvzy") return 25;
  return -1;
}

/* ----------------------------------------------------------------------
   pack per-atom data into buf for ComputePropertyAtom
   index maps to data specific to this atom style
------------------------------------------------------------------------- */

void AtomVecPi::pack_property_atom(int index, double *buf,
                                     int nvalues, int groupbit)
{
  int *mask = atom->mask;
  int nlocal = atom->nlocal;
  int n = 0;

  if (index == 0) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = rho[i];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 1) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = drho[i];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 2) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = esph[i];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 3) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = desph[i];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 4) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = cv[i];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 5) {  //Modified from here to include the prop atome for the new tensors
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stfluid[i][0];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 6) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stfluid[i][1];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 7) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stfluid[i][2];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 8) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stfluid[i][3];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 9) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stfluid[i][4];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 10) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stfluid[i][5];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 11) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stmic[i][0];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 12) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stmic[i][1];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 13) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stmic[i][2];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 14) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stmic[i][3];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 15) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stmic[i][4];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 16) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = stmic[i][5];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 17) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = gradv[i][0];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 18) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = gradv[i][1];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 19) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = gradv[i][2];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 20) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = gradv[i][3];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 21) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = gradv[i][4];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 22) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = gradv[i][5];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 23) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = gradv[i][6];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 24) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = gradv[i][7];
      else buf[n] = 0.0;
      n += nvalues;
    }
  } else if (index == 25) {
    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) buf[n] = gradv[i][8];
      else buf[n] = 0.0;
      n += nvalues;
    }
  }
}