improve error messages and apply clang-format

This commit is contained in:
Axel Kohlmeyer
2022-08-19 06:11:28 -04:00
parent 7639d57657
commit 6bc48f0882
2 changed files with 131 additions and 148 deletions

View File

@ -32,24 +32,24 @@ enum { UNSCALED, SCALED };
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
ComputePropertyGrid::ComputePropertyGrid(LAMMPS *lmp, int narg, char **arg) : ComputePropertyGrid::ComputePropertyGrid(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg), grid2d(nullptr), grid3d(nullptr), vec2d(nullptr), vec3d(nullptr), Compute(lmp, narg, arg), grid2d(nullptr), grid3d(nullptr), vec2d(nullptr), vec3d(nullptr),
array2d(nullptr), array3d(nullptr), pack_choice(nullptr) array2d(nullptr), array3d(nullptr), pack_choice(nullptr)
{ {
if (narg < 7) error->all(FLERR, "Illegal compute property/grid command"); if (narg < 7) utils::missing_cmd_args(FLERR, "compute property/grid", error);
pergrid_flag = 1; pergrid_flag = 1;
dimension = domain->dimension; dimension = domain->dimension;
nxgrid = utils::inumeric(FLERR,arg[3],false,lmp); nxgrid = utils::inumeric(FLERR, arg[3], false, lmp);
nygrid = utils::inumeric(FLERR,arg[4],false,lmp); nygrid = utils::inumeric(FLERR, arg[4], false, lmp);
nzgrid = utils::inumeric(FLERR,arg[5],false,lmp); nzgrid = utils::inumeric(FLERR, arg[5], false, lmp);
if (dimension == 2 && nzgrid != 1) if (dimension == 2 && nzgrid != 1)
error->all(FLERR,"Compute property/grid for 2d requires nz = 1"); error->all(FLERR, "Compute property/grid for 2d requires nz = 1");
if (nxgrid <= 0 || nygrid <= 0 || nzgrid <= 0) if (nxgrid <= 0 || nygrid <= 0 || nzgrid <= 0)
error->all(FLERR, "Illegal compute property/grid command"); error->all(FLERR, "All compute property/grid grid counts must be > 0");
nvalues = narg - 6; nvalues = narg - 6;
pack_choice = new FnPtrPack[nvalues]; pack_choice = new FnPtrPack[nvalues];
@ -65,47 +65,43 @@ ComputePropertyGrid::ComputePropertyGrid(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[iarg], "iy") == 0) { } else if (strcmp(arg[iarg], "iy") == 0) {
pack_choice[jarg] = &ComputePropertyGrid::pack_indices<1>; pack_choice[jarg] = &ComputePropertyGrid::pack_indices<1>;
} else if (strcmp(arg[iarg], "iz") == 0) { } else if (strcmp(arg[iarg], "iz") == 0) {
if (dimension == 2) if (dimension == 2) error->all(FLERR, "Compute property/grid for 2d cannot use z coord");
error->all(FLERR,"Compute property/grid for 2d cannot use z coord");
pack_choice[jarg] = &ComputePropertyGrid::pack_indices<2>; pack_choice[jarg] = &ComputePropertyGrid::pack_indices<2>;
} else if (strcmp(arg[iarg], "x") == 0) { } else if (strcmp(arg[iarg], "x") == 0) {
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW,UNSCALED,0>; pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW, UNSCALED, 0>;
} else if (strcmp(arg[iarg], "y") == 0) { } else if (strcmp(arg[iarg], "y") == 0) {
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW,UNSCALED,1>; pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW, UNSCALED, 1>;
} else if (strcmp(arg[iarg], "z") == 0) { } else if (strcmp(arg[iarg], "z") == 0) {
if (dimension == 2) if (dimension == 2) error->all(FLERR, "Compute property/grid for 2d cannot use z coord");
error->all(FLERR,"Compute property/grid for 2d cannot use z coord"); pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW, UNSCALED, 2>;
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW,UNSCALED,2>;
} else if (strcmp(arg[iarg], "xs") == 0) { } else if (strcmp(arg[iarg], "xs") == 0) {
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW,SCALED,0>; pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW, SCALED, 0>;
} else if (strcmp(arg[iarg], "ys") == 0) { } else if (strcmp(arg[iarg], "ys") == 0) {
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW,SCALED,1>; pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW, SCALED, 1>;
} else if (strcmp(arg[iarg], "zs") == 0) { } else if (strcmp(arg[iarg], "zs") == 0) {
if (dimension == 2) if (dimension == 2) error->all(FLERR, "Compute property/grid for 2d cannot use z coord");
error->all(FLERR,"Compute property/grid for 2d cannot use z coord"); pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW, SCALED, 2>;
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<LOW,SCALED,2>;
} else if (strcmp(arg[iarg], "xc") == 0) { } else if (strcmp(arg[iarg], "xc") == 0) {
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR,UNSCALED,0>; pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR, UNSCALED, 0>;
} else if (strcmp(arg[iarg], "yc") == 0) { } else if (strcmp(arg[iarg], "yc") == 0) {
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR,UNSCALED,1>; pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR, UNSCALED, 1>;
} else if (strcmp(arg[iarg], "zc") == 0) { } else if (strcmp(arg[iarg], "zc") == 0) {
if (dimension == 2) if (dimension == 2) error->all(FLERR, "Compute property/grid for 2d cannot use z coord");
error->all(FLERR,"Compute property/grid for 2d cannot use z coord"); pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR, UNSCALED, 2>;
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR,UNSCALED,2>;
} else if (strcmp(arg[iarg], "xsc") == 0) { } else if (strcmp(arg[iarg], "xsc") == 0) {
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR,SCALED,0>; pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR, SCALED, 0>;
} else if (strcmp(arg[iarg], "ysc") == 0) { } else if (strcmp(arg[iarg], "ysc") == 0) {
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR,SCALED,1>; pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR, SCALED, 1>;
} else if (strcmp(arg[iarg], "zsc") == 0) { } else if (strcmp(arg[iarg], "zsc") == 0) {
if (dimension == 2) if (dimension == 2) error->all(FLERR, "Compute property/grid for 2d cannot use z coord");
error->all(FLERR,"Compute property/grid for 2d cannot use z coord"); pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR, SCALED, 2>;
pack_choice[jarg] = &ComputePropertyGrid::pack_coords<CTR,SCALED,2>;
} else error->all(FLERR, "Illegal compute property/grid command"); } else
error->all(FLERR, "Unknown compute property/grid keyword: {}", arg[iarg]);
} }
// initial setup of distributed grid // initial setup of distributed grid
@ -182,8 +178,10 @@ int ComputePropertyGrid::get_grid_by_name(const std::string &name, int &dim)
void *ComputePropertyGrid::get_grid_by_index(int index) void *ComputePropertyGrid::get_grid_by_index(int index)
{ {
if (index == 0) { if (index == 0) {
if (dimension == 2) return grid2d; if (dimension == 2)
else return grid3d; return grid2d;
else
return grid3d;
} }
return nullptr; return nullptr;
@ -202,8 +200,10 @@ void *ComputePropertyGrid::get_grid_by_index(int index)
int ComputePropertyGrid::get_griddata_by_name(int igrid, const std::string &name, int &ncol) int ComputePropertyGrid::get_griddata_by_name(int igrid, const std::string &name, int &ncol)
{ {
if ((igrid == 0) && (name == "data")) { if ((igrid == 0) && (name == "data")) {
if (nvalues == 1) ncol = 0; if (nvalues == 1)
else ncol = nvalues; ncol = 0;
else
ncol = nvalues;
return 0; return 0;
} }
@ -220,11 +220,15 @@ void *ComputePropertyGrid::get_griddata_by_index(int index)
{ {
if (index == 0) { if (index == 0) {
if (dimension == 2) { if (dimension == 2) {
if (nvalues == 1) return vec2d; if (nvalues == 1)
else return array2d; return vec2d;
else
return array2d;
} else { } else {
if (nvalues == 1) return vec3d; if (nvalues == 1)
else return array3d; return vec3d;
else
return array3d;
} }
} }
@ -238,32 +242,26 @@ void *ComputePropertyGrid::get_griddata_by_index(int index)
void ComputePropertyGrid::allocate_grid() void ComputePropertyGrid::allocate_grid()
{ {
if (dimension == 2) { if (dimension == 2) {
grid2d = new Grid2d(lmp, world, nxgrid, nygrid, 0.0, 0, 0.0, grid2d = new Grid2d(lmp, world, nxgrid, nygrid, 0.0, 0, 0.0, nxlo_in, nxhi_in, nylo_in, nyhi_in,
nxlo_in, nxhi_in, nylo_in, nyhi_in,
nxlo_out, nxhi_out, nylo_out, nyhi_out); nxlo_out, nxhi_out, nylo_out, nyhi_out);
if (nvalues == 1) if (nvalues == 1)
memory->create2d_offset(vec2d, nylo_out, nyhi_out, nxlo_out, nxhi_out, memory->create2d_offset(vec2d, nylo_out, nyhi_out, nxlo_out, nxhi_out, "property/grid:vec2d");
"property/grid:vec2d");
else else
memory->create3d_offset_last(array2d, nylo_out, nyhi_out, nxlo_out, memory->create3d_offset_last(array2d, nylo_out, nyhi_out, nxlo_out, nxhi_out, nvalues,
nxhi_out, nvalues, "property/grid:array2d"); "property/grid:array2d");
ngridout = (nxhi_out - nxlo_out + 1) * (nyhi_out - nylo_out + 1); ngridout = (nxhi_out - nxlo_out + 1) * (nyhi_out - nylo_out + 1);
} else { } else {
grid3d = new Grid3d(lmp, world, nxgrid, nygrid, nzgrid, 0.0, 0, 0.0, grid3d = new Grid3d(lmp, world, nxgrid, nygrid, nzgrid, 0.0, 0, 0.0, nxlo_in, nxhi_in, nylo_in,
nxlo_in, nxhi_in, nylo_in, nyhi_in, nzlo_in, nzhi_in, nyhi_in, nzlo_in, nzhi_in, nxlo_out, nxhi_out, nylo_out, nyhi_out, nzlo_out,
nxlo_out, nxhi_out, nylo_out, nyhi_out, nzhi_out);
nzlo_out, nzhi_out);
if (nvalues == 1) if (nvalues == 1)
memory->create3d_offset(vec3d, nzlo_out, nzhi_out, nylo_out, memory->create3d_offset(vec3d, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out,
nyhi_out, nxlo_out, "property/grid:vec3d");
nxhi_out, "property/grid:vec3d");
else else
memory->create4d_offset_last(array3d, nzlo_out, nzhi_out, nylo_out, memory->create4d_offset_last(array3d, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out,
nyhi_out, nxlo_out,
nxhi_out, nvalues, "property/grid:array3d"); nxhi_out, nvalues, "property/grid:array3d");
ngridout = (nxhi_out - nxlo_out + 1) * (nyhi_out - nylo_out + 1) * ngridout = (nxhi_out - nxlo_out + 1) * (nyhi_out - nylo_out + 1) * (nzhi_out - nzlo_out + 1);
(nzhi_out - nzlo_out + 1);
} }
} }
@ -273,10 +271,10 @@ void ComputePropertyGrid::deallocate_grid()
{ {
delete grid2d; delete grid2d;
delete grid3d; delete grid3d;
memory->destroy2d_offset(vec2d,nylo_out,nxlo_out); memory->destroy2d_offset(vec2d, nylo_out, nxlo_out);
memory->destroy2d_offset(array2d,nylo_out,nxlo_out); memory->destroy2d_offset(array2d, nylo_out, nxlo_out);
memory->destroy3d_offset(vec3d,nzlo_out,nylo_out,nxlo_out); memory->destroy3d_offset(vec3d, nzlo_out, nylo_out, nxlo_out);
memory->destroy4d_offset_last(array3d,nzlo_out,nylo_out,nxlo_out); memory->destroy4d_offset_last(array3d, nzlo_out, nylo_out, nxlo_out);
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -298,24 +296,22 @@ void ComputePropertyGrid::pack_id(int n)
if (dimension == 2) { if (dimension == 2) {
if (nvalues == 0) { if (nvalues == 0) {
for (int iy = nylo_in; iy <= nyhi_in; iy++) for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) for (int ix = nxlo_in; ix <= nxhi_in; ix++) vec2d[iy][ix] = iy * nxgrid + ix + 1;
vec2d[iy][ix] = iy*nxgrid + ix + 1;
} else { } else {
for (int iy = nylo_in; iy <= nyhi_in; iy++) for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) for (int ix = nxlo_in; ix <= nxhi_in; ix++) array2d[iy][ix][n] = iy * nxgrid + ix + 1;
array2d[iy][ix][n] = iy*nxgrid + ix + 1;
} }
} else if (dimension == 3) { } else if (dimension == 3) {
if (nvalues == 0) { if (nvalues == 0) {
for (int iz = nzlo_in; iz <= nzhi_in; iz++) for (int iz = nzlo_in; iz <= nzhi_in; iz++)
for (int iy = nylo_in; iy <= nyhi_in; iy++) for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) for (int ix = nxlo_in; ix <= nxhi_in; ix++)
vec3d[iz][iy][ix] = iz*nygrid*nxgrid + iy*nxgrid + ix + 1; vec3d[iz][iy][ix] = iz * nygrid * nxgrid + iy * nxgrid + ix + 1;
} else { } else {
for (int iz = nzlo_in; iz <= nzhi_in; iz++) for (int iz = nzlo_in; iz <= nzhi_in; iz++)
for (int iy = nylo_in; iy <= nyhi_in; iy++) for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) for (int ix = nxlo_in; ix <= nxhi_in; ix++)
array3d[iz][iy][ix][n] = iz*nygrid*nxgrid + iy*nxgrid + ix + 1; array3d[iz][iy][ix][n] = iz * nygrid * nxgrid + iy * nxgrid + ix + 1;
} }
} }
} }
@ -367,11 +363,10 @@ template <int IDIM> void ComputePropertyGrid::pack_indices(int n)
via templating via templating
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
template <int POS, int MODE, int IDIM> template <int POS, int MODE, int IDIM> void ComputePropertyGrid::pack_coords(int n)
void ComputePropertyGrid::pack_coords(int n)
{ {
double boxlo,delta; double boxlo, delta;
double lamda[3],xone[3]; double lamda[3], xone[3];
// 2d grid // 2d grid
@ -381,23 +376,23 @@ void ComputePropertyGrid::pack_coords(int n)
if (!triclinic || MODE == SCALED) { if (!triclinic || MODE == SCALED) {
if (MODE == UNSCALED) grid2d->get_box(IDIM,boxlo,delta); if (MODE == UNSCALED) grid2d->get_box(IDIM, boxlo, delta);
if (MODE == SCALED) { if (MODE == SCALED) {
boxlo = 0.0; boxlo = 0.0;
if (IDIM == 0) delta = 1.0/nxgrid; if (IDIM == 0) delta = 1.0 / nxgrid;
if (IDIM == 1) delta = 1.0/nygrid; if (IDIM == 1) delta = 1.0 / nygrid;
} }
if (nvalues == 0) { if (nvalues == 0) {
for (int iy = nylo_in; iy <= nyhi_in; iy++) for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) { for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
if (POS == LOW) { if (POS == LOW) {
if (IDIM == 0) vec2d[iy][ix] = boxlo + ix*delta; if (IDIM == 0) vec2d[iy][ix] = boxlo + ix * delta;
if (IDIM == 1) vec2d[iy][ix] = boxlo + iy*delta; if (IDIM == 1) vec2d[iy][ix] = boxlo + iy * delta;
} }
if (POS == CTR) { if (POS == CTR) {
if (IDIM == 0) vec2d[iy][ix] = boxlo + (ix+0.5)*delta; if (IDIM == 0) vec2d[iy][ix] = boxlo + (ix + 0.5) * delta;
if (IDIM == 1) vec2d[iy][ix] = boxlo + (iy+0.5)*delta; if (IDIM == 1) vec2d[iy][ix] = boxlo + (iy + 0.5) * delta;
} }
} }
@ -405,30 +400,30 @@ void ComputePropertyGrid::pack_coords(int n)
for (int iy = nylo_in; iy <= nyhi_in; iy++) for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) { for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
if (POS == LOW) { if (POS == LOW) {
if (IDIM == 0) array2d[iy][ix][n] = boxlo + ix*delta; if (IDIM == 0) array2d[iy][ix][n] = boxlo + ix * delta;
if (IDIM == 1) array2d[iy][ix][n] = boxlo + iy*delta; if (IDIM == 1) array2d[iy][ix][n] = boxlo + iy * delta;
} }
if (POS == CTR) { if (POS == CTR) {
if (IDIM == 0) array2d[iy][ix][n] = boxlo + (ix+0.5)*delta; if (IDIM == 0) array2d[iy][ix][n] = boxlo + (ix + 0.5) * delta;
if (IDIM == 1) array2d[iy][ix][n] = boxlo + (iy+0.5)*delta; if (IDIM == 1) array2d[iy][ix][n] = boxlo + (iy + 0.5) * delta;
} }
} }
} }
// only for coords which are triclinic AND unscaled // only for coords which are triclinic AND unscaled
} else { } else {
double dx = 1.0/nxgrid; double dx = 1.0 / nxgrid;
double dy = 1.0/nygrid; double dy = 1.0 / nygrid;
lamda[2] = 0.0; lamda[2] = 0.0;
if (nvalues == 0) { if (nvalues == 0) {
for (int iy = nylo_in; iy <= nyhi_in; iy++) { for (int iy = nylo_in; iy <= nyhi_in; iy++) {
lamda[1] = iy*dy; lamda[1] = iy * dy;
for (int ix = nxlo_in; ix <= nxhi_in; ix++) { for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
lamda[0] = ix*dx; lamda[0] = ix * dx;
domain->lamda2x(lamda,xone); domain->lamda2x(lamda, xone);
if (IDIM == 0) vec2d[iy][ix] = xone[0]; if (IDIM == 0) vec2d[iy][ix] = xone[0];
if (IDIM == 1) vec2d[iy][ix] = xone[1]; if (IDIM == 1) vec2d[iy][ix] = xone[1];
} }
@ -436,10 +431,10 @@ void ComputePropertyGrid::pack_coords(int n)
} else { } else {
for (int iy = nylo_in; iy <= nyhi_in; iy++) { for (int iy = nylo_in; iy <= nyhi_in; iy++) {
lamda[1] = iy*dy; lamda[1] = iy * dy;
for (int ix = nxlo_in; ix <= nxhi_in; ix++) { for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
lamda[0] = ix*dx; lamda[0] = ix * dx;
domain->lamda2x(lamda,xone); domain->lamda2x(lamda, xone);
if (IDIM == 0) array2d[iy][ix][n] = xone[0]; if (IDIM == 0) array2d[iy][ix][n] = xone[0];
if (IDIM == 1) array2d[iy][ix][n] = xone[1]; if (IDIM == 1) array2d[iy][ix][n] = xone[1];
} }
@ -447,7 +442,7 @@ void ComputePropertyGrid::pack_coords(int n)
} }
} }
// 3d grid // 3d grid
} else if (dimension == 3) { } else if (dimension == 3) {
@ -455,12 +450,12 @@ void ComputePropertyGrid::pack_coords(int n)
if (!triclinic || MODE == SCALED) { if (!triclinic || MODE == SCALED) {
if (MODE == UNSCALED) grid3d->get_box(IDIM,boxlo,delta); if (MODE == UNSCALED) grid3d->get_box(IDIM, boxlo, delta);
if (MODE == SCALED) { if (MODE == SCALED) {
boxlo = 0.0; boxlo = 0.0;
if (IDIM == 0) delta = 1.0/nxgrid; if (IDIM == 0) delta = 1.0 / nxgrid;
if (IDIM == 1) delta = 1.0/nygrid; if (IDIM == 1) delta = 1.0 / nygrid;
if (IDIM == 2) delta = 1.0/nzgrid; if (IDIM == 2) delta = 1.0 / nzgrid;
} }
if (nvalues == 0) { if (nvalues == 0) {
@ -468,14 +463,14 @@ void ComputePropertyGrid::pack_coords(int n)
for (int iy = nylo_in; iy <= nyhi_in; iy++) for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) { for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
if (POS == LOW) { if (POS == LOW) {
if (IDIM == 0) vec3d[iz][iy][ix] = boxlo + ix*delta; if (IDIM == 0) vec3d[iz][iy][ix] = boxlo + ix * delta;
if (IDIM == 1) vec3d[iz][iy][ix] = boxlo + iy*delta; if (IDIM == 1) vec3d[iz][iy][ix] = boxlo + iy * delta;
if (IDIM == 2) vec3d[iz][iy][ix] = boxlo + iz*delta; if (IDIM == 2) vec3d[iz][iy][ix] = boxlo + iz * delta;
} }
if (POS == CTR) { if (POS == CTR) {
if (IDIM == 0) vec3d[iz][iy][ix] = boxlo + (ix+0.5)*delta; if (IDIM == 0) vec3d[iz][iy][ix] = boxlo + (ix + 0.5) * delta;
if (IDIM == 1) vec3d[iz][iy][ix] = boxlo + (iy+0.5)*delta; if (IDIM == 1) vec3d[iz][iy][ix] = boxlo + (iy + 0.5) * delta;
if (IDIM == 2) vec3d[iz][iy][ix] = boxlo + (iz+0.5)*delta; if (IDIM == 2) vec3d[iz][iy][ix] = boxlo + (iz + 0.5) * delta;
} }
} }
@ -484,34 +479,34 @@ void ComputePropertyGrid::pack_coords(int n)
for (int iy = nylo_in; iy <= nyhi_in; iy++) for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) { for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
if (POS == LOW) { if (POS == LOW) {
if (IDIM == 0) array3d[iz][iy][ix][n] = boxlo + ix*delta; if (IDIM == 0) array3d[iz][iy][ix][n] = boxlo + ix * delta;
if (IDIM == 1) array3d[iz][iy][ix][n] = boxlo + iy*delta; if (IDIM == 1) array3d[iz][iy][ix][n] = boxlo + iy * delta;
if (IDIM == 2) array3d[iz][iy][ix][n] = boxlo + iz*delta; if (IDIM == 2) array3d[iz][iy][ix][n] = boxlo + iz * delta;
} }
if (POS == CTR) { if (POS == CTR) {
if (IDIM == 0) array3d[iz][iy][ix][n] = boxlo + (ix+0.5)*delta; if (IDIM == 0) array3d[iz][iy][ix][n] = boxlo + (ix + 0.5) * delta;
if (IDIM == 1) array3d[iz][iy][ix][n] = boxlo + (iy+0.5)*delta; if (IDIM == 1) array3d[iz][iy][ix][n] = boxlo + (iy + 0.5) * delta;
if (IDIM == 2) array3d[iz][iy][ix][n] = boxlo + (iz+0.5)*delta; if (IDIM == 2) array3d[iz][iy][ix][n] = boxlo + (iz + 0.5) * delta;
} }
} }
} }
// only for coords which are triclinic AND unscaled // only for coords which are triclinic AND unscaled
} else { } else {
double dx = 1.0/nxgrid; double dx = 1.0 / nxgrid;
double dy = 1.0/nygrid; double dy = 1.0 / nygrid;
double dz = 1.0/nzgrid; double dz = 1.0 / nzgrid;
if (nvalues == 0) { if (nvalues == 0) {
for (int iz = nzlo_in; iz <= nzhi_in; iz++) { for (int iz = nzlo_in; iz <= nzhi_in; iz++) {
lamda[2] = iz*dz; lamda[2] = iz * dz;
for (int iy = nylo_in; iy <= nyhi_in; iy++) { for (int iy = nylo_in; iy <= nyhi_in; iy++) {
lamda[1] = iy*dy; lamda[1] = iy * dy;
for (int ix = nxlo_in; ix <= nxhi_in; ix++) { for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
lamda[0] = ix*dx; lamda[0] = ix * dx;
domain->lamda2x(lamda,xone); domain->lamda2x(lamda, xone);
if (IDIM == 0) vec3d[iz][iy][ix] = xone[0]; if (IDIM == 0) vec3d[iz][iy][ix] = xone[0];
if (IDIM == 1) vec3d[iz][iy][ix] = xone[1]; if (IDIM == 1) vec3d[iz][iy][ix] = xone[1];
if (IDIM == 2) vec3d[iz][iy][ix] = xone[2]; if (IDIM == 2) vec3d[iz][iy][ix] = xone[2];
@ -521,12 +516,12 @@ void ComputePropertyGrid::pack_coords(int n)
} else { } else {
for (int iz = nzlo_in; iz <= nzhi_in; iz++) { for (int iz = nzlo_in; iz <= nzhi_in; iz++) {
lamda[2] = iz*dz; lamda[2] = iz * dz;
for (int iy = nylo_in; iy <= nyhi_in; iy++) { for (int iy = nylo_in; iy <= nyhi_in; iy++) {
lamda[1] = iy*dy; lamda[1] = iy * dy;
for (int ix = nxlo_in; ix <= nxhi_in; ix++) { for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
lamda[0] = ix*dx; lamda[0] = ix * dx;
domain->lamda2x(lamda,xone); domain->lamda2x(lamda, xone);
if (IDIM == 0) array3d[iz][iy][ix][n] = xone[0]; if (IDIM == 0) array3d[iz][iy][ix][n] = xone[0];
if (IDIM == 1) array3d[iz][iy][ix][n] = xone[1]; if (IDIM == 1) array3d[iz][iy][ix][n] = xone[1];
if (IDIM == 2) array3d[iz][iy][ix][n] = xone[2]; if (IDIM == 2) array3d[iz][iy][ix][n] = xone[2];

View File

@ -264,41 +264,31 @@ void DumpGrid::init_style()
// check that grid sizes for all fields are the same // check that grid sizes for all fields are the same
Compute *icompute; Grid2d *grid2d = nullptr;
Fix *ifix; Grid3d *grid3d = nullptr;
Grid2d *grid2d;
Grid3d *grid3d;
int nxtmp,nytmp,nztmp; int nxtmp,nytmp,nztmp;
for (int i = 0; i < nfield; i++) { for (int i = 0; i < nfield; i++) {
if (dimension == 2) { if (dimension == 2) {
if (field2source[i] == COMPUTE) { if (field2source[i] == COMPUTE)
icompute = compute[field2index[i]]; grid2d = (Grid2d *) compute[field2index[i]]->get_grid_by_index(field2grid[i]);
grid2d = (Grid2d *) icompute->get_grid_by_index(field2grid[i]); else
} else { grid2d = (Grid2d *) fix[field2index[i]]->get_grid_by_index(field2grid[i]);
ifix = fix[field2index[i]];
grid2d = (Grid2d *) ifix->get_grid_by_index(field2grid[i]);
}
if (i == 0) grid2d->get_size(nxgrid,nygrid); if (i == 0) grid2d->get_size(nxgrid,nygrid);
else { else {
grid2d->get_size(nxtmp,nytmp); grid2d->get_size(nxtmp,nytmp);
if (nxtmp != nxgrid || nytmp != nygrid) if ((nxtmp != nxgrid) || (nytmp != nygrid))
error->all(FLERR,"Dump grid field grid sizes do not match"); error->all(FLERR,"Dump grid field grid sizes do not match");
} }
} else { } else {
if (field2source[i] == COMPUTE) { if (field2source[i] == COMPUTE)
icompute = compute[field2index[i]]; grid3d = (Grid3d *) compute[field2index[i]]->get_grid_by_index(field2grid[i]);
grid3d = (Grid3d *) icompute->get_grid_by_index(field2grid[i]); else
} else { grid3d = (Grid3d *) fix[field2index[i]]->get_grid_by_index(field2grid[i]);
ifix = fix[field2index[i]];
grid3d = (Grid3d *) ifix->get_grid_by_index(field2grid[i]);
}
if (i == 0) grid3d->get_size(nxgrid,nygrid,nzgrid); if (i == 0) grid3d->get_size(nxgrid,nygrid,nzgrid);
else { else {
grid3d->get_size(nxtmp,nytmp,nztmp); grid3d->get_size(nxtmp,nytmp,nztmp);
if (nxtmp != nxgrid || nytmp != nygrid || nztmp != nzgrid) if ((nxtmp != nxgrid) || (nytmp != nygrid) || (nztmp != nzgrid))
error->all(FLERR,"Dump grid field grid sizes do not match"); error->all(FLERR,"Dump grid field grid sizes do not match");
} }
} }
@ -505,8 +495,8 @@ int DumpGrid::count()
// set current size for portion of grid on each proc // set current size for portion of grid on each proc
// may change between dump snapshots due to load balancing // may change between dump snapshots due to load balancing
Grid2d *grid2d; Grid2d *grid2d = nullptr;
Grid3d *grid3d; Grid3d *grid3d = nullptr;
if (dimension == 2) { if (dimension == 2) {
if (field2source[0] == COMPUTE) if (field2source[0] == COMPUTE)
@ -531,7 +521,7 @@ int DumpGrid::count()
if (update->whichflag == 0) { if (update->whichflag == 0) {
for (i = 0; i < ncompute; i++) for (i = 0; i < ncompute; i++)
if (compute[i]->invoked_pergrid != update->ntimestep) if (compute[i]->invoked_pergrid != update->ntimestep)
error->all(FLERR,"Compute used in dump between runs is not current"); error->all(FLERR,"Compute {} used in dump between runs is not current", compute[i]->id);
} else { } else {
for (i = 0; i < ncompute; i++) { for (i = 0; i < ncompute; i++) {
if (!(compute[i]->invoked_flag & Compute::INVOKED_PERGRID)) { if (!(compute[i]->invoked_flag & Compute::INVOKED_PERGRID)) {
@ -600,8 +590,7 @@ int DumpGrid::convert_string(int n, double *mybuf)
else if (vtype[j] == Dump::DOUBLE) else if (vtype[j] == Dump::DOUBLE)
offset += sprintf(&sbuf[offset],vformat[j],mybuf[m]); offset += sprintf(&sbuf[offset],vformat[j],mybuf[m]);
else if (vtype[j] == Dump::BIGINT) else if (vtype[j] == Dump::BIGINT)
offset += sprintf(&sbuf[offset],vformat[j], offset += sprintf(&sbuf[offset],vformat[j], static_cast<bigint> (mybuf[m]));
static_cast<bigint> (mybuf[m]));
m++; m++;
} }
offset += sprintf(&sbuf[offset],"\n"); offset += sprintf(&sbuf[offset],"\n");
@ -645,8 +634,7 @@ void DumpGrid::write_lines(int n, double *mybuf)
for (j = 0; j < nfield; j++) { for (j = 0; j < nfield; j++) {
if (vtype[j] == Dump::INT) fprintf(fp,vformat[j],static_cast<int> (mybuf[m])); if (vtype[j] == Dump::INT) fprintf(fp,vformat[j],static_cast<int> (mybuf[m]));
else if (vtype[j] == Dump::DOUBLE) fprintf(fp,vformat[j],mybuf[m]); else if (vtype[j] == Dump::DOUBLE) fprintf(fp,vformat[j],mybuf[m]);
else if (vtype[j] == Dump::BIGINT) else if (vtype[j] == Dump::BIGINT) fprintf(fp,vformat[j],static_cast<bigint> (mybuf[m]));
fprintf(fp,vformat[j],static_cast<bigint> (mybuf[m]));
m++; m++;
} }
fprintf(fp,"\n"); fprintf(fp,"\n");