1 // clang-format off
2 /* ----------------------------------------------------------------------
3  LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
4  https://www.lammps.org/, Sandia National Laboratories
5  Steve Plimpton, sjplimp@sandia.gov
6 
7  Copyright (2003) Sandia Corporation.  Under the terms of Contract
8  DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
9  certain rights in this software.  This software is distributed under
10  the GNU General Public License.
11 
12  See the README file in the top-level LAMMPS directory.
13  ------------------------------------------------------------------------- */
14 
15 #include "atom_vec_sph.h"
16 
17 #include "atom.h"
18 
19 #include <cstring>
20 
21 using namespace LAMMPS_NS;
22 
23 /* ---------------------------------------------------------------------- */
24 
AtomVecSPH(LAMMPS * lmp)25 AtomVecSPH::AtomVecSPH(LAMMPS *lmp) : AtomVec(lmp)
26 {
27   molecular = Atom::ATOMIC;
28   mass_type = PER_TYPE;
29   forceclearflag = 1;
30 
31   atom->esph_flag = 1;
32   atom->rho_flag = 1;
33   atom->cv_flag = 1;
34   atom->vest_flag = 1;
35 
36   // strings with peratom variables to include in each AtomVec method
37   // strings cannot contain fields in corresponding AtomVec default strings
38   // order of fields in a string does not matter
39   // except: fields_data_atom & fields_data_vel must match data file
40 
41   fields_grow = (char *) "rho drho esph desph cv vest";
42   fields_copy = (char *) "rho drho esph desph cv vest";
43   fields_comm = (char *) "rho esph vest";
44   fields_comm_vel = (char *) "rho esph vest";
45   fields_reverse = (char *) "drho desph";
46   fields_border = (char *) "rho esph cv vest";
47   fields_border_vel = (char *) "rho esph cv vest";
48   fields_exchange = (char *) "rho esph cv vest";
49   fields_restart = (char * ) "rho esph cv vest";
50   fields_create = (char *) "rho esph cv vest desph drho";
51   fields_data_atom = (char *) "id type rho esph cv x";
52   fields_data_vel = (char *) "id v";
53 
54   setup_fields();
55 }
56 
57 /* ----------------------------------------------------------------------
58    set local copies of all grow ptrs used by this class, except defaults
59    needed in replicate when 2 atom classes exist and it calls pack_restart()
60 ------------------------------------------------------------------------- */
61 
grow_pointers()62 void AtomVecSPH::grow_pointers()
63 {
64   rho = atom->rho;
65   drho = atom->drho;
66   esph = atom->esph;
67   desph = atom->desph;
68   cv = atom->cv;
69   vest = atom->vest;
70 }
71 
72 /* ----------------------------------------------------------------------
73    clear extra forces starting at atom N
74    nbytes = # of bytes to clear for a per-atom vector
75 ------------------------------------------------------------------------- */
76 
force_clear(int n,size_t nbytes)77 void AtomVecSPH::force_clear(int n, size_t nbytes)
78 {
79   memset(&desph[n],0,nbytes);
80   memset(&drho[n],0,nbytes);
81 }
82 
83 /* ----------------------------------------------------------------------
84    initialize non-zero atom quantities
85 ------------------------------------------------------------------------- */
86 
create_atom_post(int ilocal)87 void AtomVecSPH::create_atom_post(int ilocal)
88 {
89   cv[ilocal] = 1.0;
90 }
91 
92 /* ----------------------------------------------------------------------
93    modify what AtomVec::data_atom() just unpacked
94    or initialize other atom quantities
95 ------------------------------------------------------------------------- */
96 
data_atom_post(int ilocal)97 void AtomVecSPH::data_atom_post(int ilocal)
98 {
99   vest[ilocal][0] = 0.0;
100   vest[ilocal][1] = 0.0;
101   vest[ilocal][2] = 0.0;
102   desph[ilocal] = 0.0;
103   drho[ilocal] = 0.0;
104 }
105 
106 /* ----------------------------------------------------------------------
107    assign an index to named atom property and return index
108    return -1 if name is unknown to this atom style
109 ------------------------------------------------------------------------- */
110 
property_atom(char * name)111 int AtomVecSPH::property_atom(char *name)
112 {
113   if (strcmp(name,"rho") == 0) return 0;
114   if (strcmp(name,"drho") == 0) return 1;
115   if (strcmp(name,"esph") == 0) return 2;
116   if (strcmp(name,"desph") == 0) return 3;
117   if (strcmp(name,"cv") == 0) return 4;
118   return -1;
119 }
120 
121 /* ----------------------------------------------------------------------
122    pack per-atom data into buf for ComputePropertyAtom
123    index maps to data specific to this atom style
124 ------------------------------------------------------------------------- */
125 
pack_property_atom(int index,double * buf,int nvalues,int groupbit)126 void AtomVecSPH::pack_property_atom(int index, double *buf,
127                                      int nvalues, int groupbit)
128 {
129   int *mask = atom->mask;
130   int nlocal = atom->nlocal;
131   int n = 0;
132 
133   if (index == 0) {
134     for (int i = 0; i < nlocal; i++) {
135       if (mask[i] & groupbit) buf[n] = rho[i];
136       else buf[n] = 0.0;
137       n += nvalues;
138     }
139   } else if (index == 1) {
140     for (int i = 0; i < nlocal; i++) {
141       if (mask[i] & groupbit) buf[n] = drho[i];
142       else buf[n] = 0.0;
143       n += nvalues;
144     }
145   } else if (index == 2) {
146     for (int i = 0; i < nlocal; i++) {
147       if (mask[i] & groupbit) buf[n] = esph[i];
148       else buf[n] = 0.0;
149       n += nvalues;
150     }
151   } else if (index == 3) {
152     for (int i = 0; i < nlocal; i++) {
153       if (mask[i] & groupbit) buf[n] = desph[i];
154       else buf[n] = 0.0;
155       n += nvalues;
156     }
157   } else if (index == 4) {
158     for (int i = 0; i < nlocal; i++) {
159       if (mask[i] & groupbit) buf[n] = cv[i];
160       else buf[n] = 0.0;
161       n += nvalues;
162     }
163   }
164 }
165