refactor group access, enable and apply clang-format
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -24,36 +23,35 @@ using namespace LAMMPS_NS;
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) :
|
||||
Region(lmp, narg, arg), idsub(nullptr)
|
||||
Region(lmp, narg, arg), idsub(nullptr)
|
||||
{
|
||||
nregion = 0;
|
||||
|
||||
if (narg < 5) error->all(FLERR,"Illegal region command");
|
||||
int n = utils::inumeric(FLERR,arg[2],false,lmp);
|
||||
if (n < 2) error->all(FLERR,"Illegal region command");
|
||||
options(narg-(n+3),&arg[n+3]);
|
||||
if (narg < 5) error->all(FLERR, "Illegal region command");
|
||||
int n = utils::inumeric(FLERR, arg[2], false, lmp);
|
||||
if (n < 2) error->all(FLERR, "Illegal region command");
|
||||
options(narg - (n + 3), &arg[n + 3]);
|
||||
|
||||
// build list of regions to intersect
|
||||
// store sub-region IDs in idsub
|
||||
|
||||
idsub = new char*[n];
|
||||
list = new int[n];
|
||||
idsub = new char *[n];
|
||||
reglist = new Region *[n];
|
||||
nregion = 0;
|
||||
|
||||
for (int iarg = 0; iarg < n; iarg++) {
|
||||
idsub[nregion] = utils::strdup(arg[iarg+3]);
|
||||
int iregion = domain->find_region(idsub[nregion]);
|
||||
if (iregion == -1)
|
||||
error->all(FLERR,"Region intersect region ID does not exist");
|
||||
list[nregion++] = iregion;
|
||||
idsub[nregion] = utils::strdup(arg[iarg + 3]);
|
||||
reglist[nregion] = domain->get_region_by_id(idsub[nregion]);
|
||||
if (!reglist[nregion])
|
||||
error->all(FLERR, "Region intersect region {} does not exist", idsub[nregion]);
|
||||
nregion++;
|
||||
}
|
||||
|
||||
// this region is variable shape or dynamic if any of sub-regions are
|
||||
|
||||
Region **regions = domain->regions;
|
||||
for (int ilist = 0; ilist < nregion; ilist++) {
|
||||
if (regions[list[ilist]]->varshape) varshape = 1;
|
||||
if (regions[list[ilist]]->dynamic) dynamic = 1;
|
||||
if (reglist[ilist]->varshape) varshape = 1;
|
||||
if (reglist[ilist]->dynamic) dynamic = 1;
|
||||
}
|
||||
|
||||
// extent of intersection of regions
|
||||
@ -61,29 +59,29 @@ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
bboxflag = 0;
|
||||
for (int ilist = 0; ilist < nregion; ilist++)
|
||||
if (regions[list[ilist]]->bboxflag == 1) bboxflag = 1;
|
||||
if (reglist[ilist]->bboxflag == 1) bboxflag = 1;
|
||||
if (!interior) bboxflag = 0;
|
||||
|
||||
if (bboxflag) {
|
||||
int first = 1;
|
||||
for (int ilist = 0; ilist < nregion; ilist++) {
|
||||
if (regions[list[ilist]]->bboxflag == 0) continue;
|
||||
if (reglist[ilist]->bboxflag == 0) continue;
|
||||
if (first) {
|
||||
extent_xlo = regions[list[ilist]]->extent_xlo;
|
||||
extent_ylo = regions[list[ilist]]->extent_ylo;
|
||||
extent_zlo = regions[list[ilist]]->extent_zlo;
|
||||
extent_xhi = regions[list[ilist]]->extent_xhi;
|
||||
extent_yhi = regions[list[ilist]]->extent_yhi;
|
||||
extent_zhi = regions[list[ilist]]->extent_zhi;
|
||||
extent_xlo = reglist[ilist]->extent_xlo;
|
||||
extent_ylo = reglist[ilist]->extent_ylo;
|
||||
extent_zlo = reglist[ilist]->extent_zlo;
|
||||
extent_xhi = reglist[ilist]->extent_xhi;
|
||||
extent_yhi = reglist[ilist]->extent_yhi;
|
||||
extent_zhi = reglist[ilist]->extent_zhi;
|
||||
first = 0;
|
||||
}
|
||||
|
||||
extent_xlo = MAX(extent_xlo,regions[list[ilist]]->extent_xlo);
|
||||
extent_ylo = MAX(extent_ylo,regions[list[ilist]]->extent_ylo);
|
||||
extent_zlo = MAX(extent_zlo,regions[list[ilist]]->extent_zlo);
|
||||
extent_xhi = MIN(extent_xhi,regions[list[ilist]]->extent_xhi);
|
||||
extent_yhi = MIN(extent_yhi,regions[list[ilist]]->extent_yhi);
|
||||
extent_zhi = MIN(extent_zhi,regions[list[ilist]]->extent_zhi);
|
||||
extent_xlo = MAX(extent_xlo, reglist[ilist]->extent_xlo);
|
||||
extent_ylo = MAX(extent_ylo, reglist[ilist]->extent_ylo);
|
||||
extent_zlo = MAX(extent_zlo, reglist[ilist]->extent_zlo);
|
||||
extent_xhi = MIN(extent_xhi, reglist[ilist]->extent_xhi);
|
||||
extent_yhi = MIN(extent_yhi, reglist[ilist]->extent_yhi);
|
||||
extent_zhi = MIN(extent_zhi, reglist[ilist]->extent_zhi);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,14 +89,15 @@ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) :
|
||||
// for near contacts and touching contacts
|
||||
|
||||
cmax = 0;
|
||||
for (int ilist = 0; ilist < nregion; ilist++)
|
||||
cmax += regions[list[ilist]]->cmax;
|
||||
for (int ilist = 0; ilist < nregion; ilist++) cmax += reglist[ilist]->cmax;
|
||||
contact = new Contact[cmax];
|
||||
|
||||
tmax = 0;
|
||||
for (int ilist = 0; ilist < nregion; ilist++) {
|
||||
if (interior) tmax += regions[list[ilist]]->tmax;
|
||||
else tmax++;
|
||||
if (interior)
|
||||
tmax += reglist[ilist]->tmax;
|
||||
else
|
||||
tmax++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,10 +105,10 @@ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
RegIntersect::~RegIntersect()
|
||||
{
|
||||
for (int ilist = 0; ilist < nregion; ilist++) delete [] idsub[ilist];
|
||||
delete [] idsub;
|
||||
delete [] list;
|
||||
delete [] contact;
|
||||
for (int ilist = 0; ilist < nregion; ilist++) delete[] idsub[ilist];
|
||||
delete[] idsub;
|
||||
delete[] reglist;
|
||||
delete[] contact;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -122,17 +121,14 @@ void RegIntersect::init()
|
||||
// error if a sub-region was deleted
|
||||
|
||||
for (int ilist = 0; ilist < nregion; ilist++) {
|
||||
int iregion = domain->find_region(idsub[ilist]);
|
||||
if (iregion == -1)
|
||||
error->all(FLERR,"Region union region ID does not exist");
|
||||
list[ilist] = iregion;
|
||||
reglist[ilist] = domain->get_region_by_id(idsub[ilist]);
|
||||
if (!reglist[ilist])
|
||||
error->all(FLERR, "Region intersect region {} does not exist", idsub[ilist]);
|
||||
}
|
||||
|
||||
// init the sub-regions
|
||||
|
||||
Region **regions = domain->regions;
|
||||
for (int ilist = 0; ilist < nregion; ilist++)
|
||||
regions[list[ilist]]->init();
|
||||
for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->init();
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -143,9 +139,8 @@ void RegIntersect::init()
|
||||
int RegIntersect::inside(double x, double y, double z)
|
||||
{
|
||||
int ilist;
|
||||
Region **regions = domain->regions;
|
||||
for (ilist = 0; ilist < nregion; ilist++)
|
||||
if (!regions[list[ilist]]->match(x,y,z)) break;
|
||||
if (!reglist[ilist]->match(x, y, z)) break;
|
||||
|
||||
if (ilist == nregion) return 1;
|
||||
return 0;
|
||||
@ -159,39 +154,36 @@ int RegIntersect::inside(double x, double y, double z)
|
||||
|
||||
int RegIntersect::surface_interior(double *x, double cutoff)
|
||||
{
|
||||
int m,ilist,jlist,iregion,jregion,ncontacts;
|
||||
double xs,ys,zs;
|
||||
int m, ilist, jlist, ncontacts;
|
||||
double xs, ys, zs;
|
||||
|
||||
Region **regions = domain->regions;
|
||||
int n = 0;
|
||||
|
||||
int walloffset = 0;
|
||||
for (ilist = 0; ilist < nregion; ilist++) {
|
||||
iregion = list[ilist];
|
||||
ncontacts = regions[iregion]->surface(x[0],x[1],x[2],cutoff);
|
||||
auto region = reglist[ilist];
|
||||
ncontacts = region->surface(x[0], x[1], x[2], cutoff);
|
||||
for (m = 0; m < ncontacts; m++) {
|
||||
xs = x[0] - regions[iregion]->contact[m].delx;
|
||||
ys = x[1] - regions[iregion]->contact[m].dely;
|
||||
zs = x[2] - regions[iregion]->contact[m].delz;
|
||||
xs = x[0] - region->contact[m].delx;
|
||||
ys = x[1] - region->contact[m].dely;
|
||||
zs = x[2] - region->contact[m].delz;
|
||||
for (jlist = 0; jlist < nregion; jlist++) {
|
||||
if (jlist == ilist) continue;
|
||||
jregion = list[jlist];
|
||||
if (!regions[jregion]->match(xs,ys,zs)) break;
|
||||
if (!reglist[jlist]->match(xs, ys, zs)) break;
|
||||
}
|
||||
if (jlist == nregion) {
|
||||
contact[n].r = regions[iregion]->contact[m].r;
|
||||
contact[n].radius = regions[iregion]->contact[m].radius;
|
||||
contact[n].delx = regions[iregion]->contact[m].delx;
|
||||
contact[n].dely = regions[iregion]->contact[m].dely;
|
||||
contact[n].delz = regions[iregion]->contact[m].delz;
|
||||
contact[n].iwall = regions[iregion]->contact[m].iwall + walloffset;
|
||||
contact[n].varflag = regions[iregion]->contact[m].varflag;
|
||||
contact[n].r = region->contact[m].r;
|
||||
contact[n].radius = region->contact[m].radius;
|
||||
contact[n].delx = region->contact[m].delx;
|
||||
contact[n].dely = region->contact[m].dely;
|
||||
contact[n].delz = region->contact[m].delz;
|
||||
contact[n].iwall = region->contact[m].iwall + walloffset;
|
||||
contact[n].varflag = region->contact[m].varflag;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
// increment by cmax instead of tmax to insure
|
||||
// possible wall IDs for sub-regions are non overlapping
|
||||
walloffset += regions[iregion]->cmax;
|
||||
walloffset += region->cmax;
|
||||
}
|
||||
|
||||
return n;
|
||||
@ -208,42 +200,37 @@ int RegIntersect::surface_interior(double *x, double cutoff)
|
||||
|
||||
int RegIntersect::surface_exterior(double *x, double cutoff)
|
||||
{
|
||||
int m,ilist,jlist,iregion,jregion,ncontacts;
|
||||
double xs,ys,zs;
|
||||
int m, ilist, jlist, ncontacts;
|
||||
double xs, ys, zs;
|
||||
|
||||
Region **regions = domain->regions;
|
||||
int n = 0;
|
||||
|
||||
for (ilist = 0; ilist < nregion; ilist++)
|
||||
regions[list[ilist]]->interior ^= 1;
|
||||
for (ilist = 0; ilist < nregion; ilist++) reglist[ilist]->interior ^= 1;
|
||||
|
||||
for (ilist = 0; ilist < nregion; ilist++) {
|
||||
iregion = list[ilist];
|
||||
ncontacts = regions[iregion]->surface(x[0],x[1],x[2],cutoff);
|
||||
auto region = reglist[ilist];
|
||||
ncontacts = region->surface(x[0], x[1], x[2], cutoff);
|
||||
for (m = 0; m < ncontacts; m++) {
|
||||
xs = x[0] - regions[iregion]->contact[m].delx;
|
||||
ys = x[1] - regions[iregion]->contact[m].dely;
|
||||
zs = x[2] - regions[iregion]->contact[m].delz;
|
||||
xs = x[0] - region->contact[m].delx;
|
||||
ys = x[1] - region->contact[m].dely;
|
||||
zs = x[2] - region->contact[m].delz;
|
||||
for (jlist = 0; jlist < nregion; jlist++) {
|
||||
if (jlist == ilist) continue;
|
||||
jregion = list[jlist];
|
||||
if (regions[jregion]->match(xs,ys,zs)) break;
|
||||
if (reglist[jlist]->match(xs, ys, zs)) break;
|
||||
}
|
||||
if (jlist == nregion) {
|
||||
contact[n].r = regions[iregion]->contact[m].r;
|
||||
contact[n].radius = regions[iregion]->contact[m].radius;
|
||||
contact[n].delx = regions[iregion]->contact[m].delx;
|
||||
contact[n].dely = regions[iregion]->contact[m].dely;
|
||||
contact[n].delz = regions[iregion]->contact[m].delz;
|
||||
contact[n].r = region->contact[m].r;
|
||||
contact[n].radius = region->contact[m].radius;
|
||||
contact[n].delx = region->contact[m].delx;
|
||||
contact[n].dely = region->contact[m].dely;
|
||||
contact[n].delz = region->contact[m].delz;
|
||||
contact[n].iwall = ilist;
|
||||
contact[n].varflag = regions[iregion]->contact[m].varflag;
|
||||
contact[n].varflag = region->contact[m].varflag;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ilist = 0; ilist < nregion; ilist++)
|
||||
regions[list[ilist]]->interior ^= 1;
|
||||
for (ilist = 0; ilist < nregion; ilist++) reglist[ilist]->interior ^= 1;
|
||||
|
||||
return n;
|
||||
}
|
||||
@ -254,9 +241,7 @@ int RegIntersect::surface_exterior(double *x, double cutoff)
|
||||
|
||||
void RegIntersect::shape_update()
|
||||
{
|
||||
Region **regions = domain->regions;
|
||||
for (int ilist = 0; ilist < nregion; ilist++)
|
||||
regions[list[ilist]]->shape_update();
|
||||
for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->shape_update();
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -265,21 +250,16 @@ void RegIntersect::shape_update()
|
||||
|
||||
void RegIntersect::pretransform()
|
||||
{
|
||||
Region **regions = domain->regions;
|
||||
for (int ilist = 0; ilist < nregion; ilist++)
|
||||
regions[list[ilist]]->pretransform();
|
||||
for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->pretransform();
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
get translational/angular velocities of all subregions
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void RegIntersect::set_velocity()
|
||||
{
|
||||
Region **regions = domain->regions;
|
||||
for (int ilist = 0; ilist < nregion; ilist++)
|
||||
regions[list[ilist]]->set_velocity();
|
||||
for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->set_velocity();
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -287,13 +267,10 @@ void RegIntersect::set_velocity()
|
||||
used by restart of fix/wall/gran/region
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void RegIntersect::length_restart_string(int& n)
|
||||
void RegIntersect::length_restart_string(int &n)
|
||||
{
|
||||
n += sizeof(int) + strlen(id)+1 +
|
||||
sizeof(int) + strlen(style)+1 + sizeof(int);
|
||||
for (int ilist = 0; ilist < nregion; ilist++)
|
||||
domain->regions[list[ilist]]->length_restart_string(n);
|
||||
|
||||
n += sizeof(int) + strlen(id) + 1 + sizeof(int) + strlen(style) + 1 + sizeof(int);
|
||||
for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->length_restart_string(n);
|
||||
}
|
||||
/* ----------------------------------------------------------------------
|
||||
region writes its current position/angle
|
||||
@ -302,17 +279,15 @@ void RegIntersect::length_restart_string(int& n)
|
||||
|
||||
void RegIntersect::write_restart(FILE *fp)
|
||||
{
|
||||
int sizeid = (strlen(id)+1);
|
||||
int sizestyle = (strlen(style)+1);
|
||||
int sizeid = (strlen(id) + 1);
|
||||
int sizestyle = (strlen(style) + 1);
|
||||
fwrite(&sizeid, sizeof(int), 1, fp);
|
||||
fwrite(id, 1, sizeid, fp);
|
||||
fwrite(&sizestyle, sizeof(int), 1, fp);
|
||||
fwrite(style, 1, sizestyle, fp);
|
||||
fwrite(&nregion,sizeof(int),1,fp);
|
||||
fwrite(&nregion, sizeof(int), 1, fp);
|
||||
|
||||
for (int ilist = 0; ilist < nregion; ilist++) {
|
||||
domain->regions[list[ilist]]->write_restart(fp);
|
||||
}
|
||||
for (int ilist = 0; ilist < nregion; ilist++) { reglist[ilist]->write_restart(fp); }
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -324,12 +299,12 @@ int RegIntersect::restart(char *buf, int &n)
|
||||
{
|
||||
int size = *((int *) (&buf[n]));
|
||||
n += sizeof(int);
|
||||
if ((size <= 0) || (strcmp(&buf[n],id) != 0)) return 0;
|
||||
if ((size <= 0) || (strcmp(&buf[n], id) != 0)) return 0;
|
||||
n += size;
|
||||
|
||||
size = *((int *) (&buf[n]));
|
||||
n += sizeof(int);
|
||||
if ((size <= 0) || (strcmp(&buf[n],style) != 0)) return 0;
|
||||
if ((size <= 0) || (strcmp(&buf[n], style) != 0)) return 0;
|
||||
n += size;
|
||||
|
||||
int restart_nreg = *((int *) (&buf[n]));
|
||||
@ -337,7 +312,7 @@ int RegIntersect::restart(char *buf, int &n)
|
||||
if (restart_nreg != nregion) return 0;
|
||||
|
||||
for (int ilist = 0; ilist < nregion; ilist++)
|
||||
if (!domain->regions[list[ilist]]->restart(buf,n)) return 0;
|
||||
if (!reglist[ilist]->restart(buf, n)) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -348,7 +323,5 @@ int RegIntersect::restart(char *buf, int &n)
|
||||
|
||||
void RegIntersect::reset_vel()
|
||||
{
|
||||
for (int ilist = 0; ilist < nregion; ilist++)
|
||||
domain->regions[list[ilist]]->reset_vel();
|
||||
for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->reset_vel();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user