more work on dump image

This commit is contained in:
Steve Plimpton
2022-11-22 16:40:39 -07:00
parent 3683f144a6
commit 9ab4c65f31
6 changed files with 300 additions and 298 deletions

View File

@ -77,6 +77,10 @@ DumpGrid::DumpGrid(LAMMPS *lmp, int narg, char **arg) :
dimension = domain->dimension;
// for 2d, set nzgrid = 1 for dump grid and grid/vtk files
if (dimension == 2) nzgrid = 1;
// computes and fixes which the dump accesses
ncompute = 0;
@ -269,9 +273,9 @@ void DumpGrid::init_style()
int nxtmp,nytmp,nztmp;
for (int i = 0; i < nfield; i++) {
if (dimension == 2) {
if (field2source[i] == COMPUTE)
grid2d = (Grid2d *) compute[field2index[i]]->get_grid_by_index(field2grid[i]);
else
if (field2source[i] == COMPUTE)
grid2d = (Grid2d *) compute[field2index[i]]->get_grid_by_index(field2grid[i]);
else
grid2d = (Grid2d *) fix[field2index[i]]->get_grid_by_index(field2grid[i]);
if (i == 0) grid2d->get_size(nxgrid,nygrid);
else {
@ -651,146 +655,40 @@ int DumpGrid::parse_fields(int narg, char **arg)
char *id;
int igrid,idata,index;
int iflag =
utils::check_grid_reference((char *) "Dump grid",
arg[iarg],igrid,idata,index,lmp);
arg[iarg],nevery,id,igrid,idata,index,lmp);
// arg is not a Grid reference
// arg is not a valid Grid reference
// assume it's an additional dump grid option and return
if (iflag < 0) return iarg;
// grid reference is to a compute
// grid reference is to a compute or fix
if (iflag == ArgInfo::COMPUTE) {
// grid reference is to a fix
auto icompute = lmp->modify->get_compute_by_id(id);
field2index[iarg] = add_compute(id,icompute);
field2source[iarg] = COMPUTE;
} else if (iflag == ArgInfo::FIX) {
auto ifix = modify->get_fix_by_id(id);
field2index[iarg] = add_fix(id,ifix);
field2source[iarg] = FIX;
}
delete [] id;
argindex[iarg] = index;
vtype[iarg] = Dump::DOUBLE;
field2grid[iarg] = igrid;
field2data[iarg] = idata;
if (dimension == 2) pack_choice[iarg] = &DumpGrid::pack_grid2d;
else pack_choice[iarg] = &DumpGrid::pack_grid3d;
}
return narg;
}
/*
ArgInfo argi(arg[iarg], ArgInfo::COMPUTE | ArgInfo::FIX);
argindex[iarg] = argi.get_index1();
auto name = argi.get_name();
switch (argi.get_type()) {
case ArgInfo::UNKNOWN: {
error->all(FLERR,"Invalid attribute in dump grid command");
} break;
// compute value = c_ID
// if no trailing [], then arg is set to 0, else arg is int between []
case ArgInfo::COMPUTE: {
if (dimension == 2) pack_choice[iarg] = &DumpGrid::pack_grid2d;
else pack_choice[iarg] = &DumpGrid::pack_grid3d;
vtype[iarg] = Dump::DOUBLE;
field2source[iarg] = COMPUTE;
// split name = idcompute:gname:dname into 3 strings
auto words = utils::parse_gridid(FLERR,name,error);
const auto &idcompute = words[0];
const auto &gname = words[1];
const auto &dname = words[2];
auto icompute = modify->get_compute_by_id(idcompute);
if (!icompute) error->all(FLERR,"Could not find dump grid compute ID: {}",idcompute);
if (icompute->pergrid_flag == 0)
error->all(FLERR,"Dump grid compute {} does not compute per-grid info",idcompute);
int dim;
int igrid = icompute->get_grid_by_name(gname,dim);
if (igrid < 0)
error->all(FLERR,"Dump grid compute {} does not recognize grid name {}",idcompute,gname);
int ncol;
int idata = icompute->get_griddata_by_name(igrid,dname,ncol);
if (idata < 0)
error->all(FLERR,"Dump grid compute {} does not recognize data name {}",idcompute,dname);
if (argi.get_dim() == 0 && ncol)
error->all(FLERR,"Dump grid compute {} data {} is not per-grid vector",idcompute,dname);
if (argi.get_dim() && ncol == 0)
error->all(FLERR,"Dump grid compute {} data {} is not per-grid array",idcompute,dname);
if (argi.get_dim() && argi.get_index1() > ncol)
error->all(FLERR,"Dump grid compute {} array {} is accessed out-of-range",idcompute,dname);
field2index[iarg] = add_compute(idcompute,icompute);
field2grid[iarg] = igrid;
field2data[iarg] = idata;
} break;
// fix value = f_ID
// if no trailing [], then arg is set to 0, else arg is between []
case ArgInfo::FIX: {
if (dimension == 2) pack_choice[iarg] = &DumpGrid::pack_grid2d;
else pack_choice[iarg] = &DumpGrid::pack_grid3d;
vtype[iarg] = Dump::DOUBLE;
field2source[iarg] = FIX;
// split name = idfix:gname:dname into 3 strings
auto words = utils::parse_gridid(FLERR,name,error);
const auto &idfix = words[0];
const auto &gname = words[1];
const auto &dname = words[2];
auto ifix = modify->get_fix_by_id(idfix);
if (!ifix) error->all(FLERR,"Could not find dump grid fix ID: {}",idfix);
if (ifix->pergrid_flag == 0)
error->all(FLERR,"Dump grid fix {} does not compute per-grid info",idfix);
if (nevery % ifix->pergrid_freq)
error->all(FLERR,"Fix ID {} for dump grid not computed at compatible time",idfix);
int dim;
int igrid = ifix->get_grid_by_name(gname,dim);
if (igrid < 0)
error->all(FLERR,"Dump grid fix {} does not recognize grid name {}",idfix,gname);
int ncol;
int idata = ifix->get_griddata_by_name(igrid,dname,ncol);
if (idata < 0)
error->all(FLERR,"Dump grid fix {} does not recognize data name {}",idfix,dname);
if (argi.get_dim() == 0 && ncol)
error->all(FLERR,"Dump grid fix {} data {} is not per-grid vector",idfix,dname);
if (argi.get_dim() > 0 && ncol == 0)
error->all(FLERR,"Dump grid fix {} data {} is not per-grid array",idfix,dname);
if (argi.get_dim() > 0 && argi.get_index1() > ncol)
error->all(FLERR,"Dump grid fix {} array {} is accessed out-of-range",idfix,dname);
field2index[iarg] = add_fix(idfix,ifix);
field2grid[iarg] = igrid;
field2data[iarg] = idata;
} break;
// no match
default: {
return iarg;
} break;
}
}
return narg;
}
*/
/* ----------------------------------------------------------------------
add Compute to list of Compute objects used by dump
return index of where this Compute is in list

View File

@ -14,6 +14,7 @@
#include "dump_image.h"
#include "arg_info.h"
#include "atom.h"
#include "atom_vec.h"
#include "atom_vec_body.h"
@ -124,6 +125,8 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) :
atomflag = YES;
gridflag = NO;
lineflag = triflag = bodyflag = fixflag = NO;
id_grid_compute = id_grid_fix = nullptr;
if (atom->nbondtypes == 0) bondflag = NO;
else {
bondflag = YES;
@ -188,8 +191,16 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) :
int igrid,idata,index;
int iflag =
utils::check_grid_reference((char *) "Dump image",
arg[iarg+1],igrid,idata,index,lmp);
arg[iarg+1],nevery,id,
igrid,idata,index,lmp);
if (iflag < 0) error->all(FLERR,"Invalid grid reference in dump image command");
if (iflag == ArgInfo::COMPUTE) id_grid_compute = utils::strdup(id);
else if (iflag == ArgInfo::FIX) id_grid_fix = utils::strdup(id);
delete [] id;
grid_igrid = igrid;
grid_idata = idata;
grid_index = index;
iarg += 2;
} else if (strcmp(arg[iarg],"line") == 0) {
@ -432,6 +443,9 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) :
maxbufcopy = 0;
chooseghost = nullptr;
bufcopy = nullptr;
maxgrid = 0;
gbuf = nullptr;
}
/* ---------------------------------------------------------------------- */
@ -448,6 +462,7 @@ DumpImage::~DumpImage()
delete [] bcolortype;
memory->destroy(chooseghost);
memory->destroy(bufcopy);
memory->destroy(gbuf);
}
/* ---------------------------------------------------------------------- */
@ -609,21 +624,33 @@ void DumpImage::write()
}
// pack grid gbuf with grid cell values
// ngrid_mine = # of grid cells this proc owns
// ngrid = # of grid cells this proc owns
if (gridflag) {
if (domain->dimension == 2) {
if (grid_compute)
grid2d = (Grid2d *) grid_compute->get_grid_by_index(grid_index);
grid2d = (Grid2d *) grid_compute->get_grid_by_index(grid_igrid);
else if (grid_fix)
grid2d = (Grid2d *) grid_fix->get_grid_by_index(grid_index);
grid2d = (Grid2d *) grid_fix->get_grid_by_index(grid_igrid);
grid2d->get_size(nxgrid,nygrid);
grid2d->get_bounds_owned(nxlo_in,nxhi_in,nylo_in,nyhi_in);
ngrid = (nxhi_in-nxlo_in+1) * (nyhi_in-nylo_in+1);
} else {
if (grid_compute)
grid3d = (Grid3d *) grid_compute->get_grid_by_index(grid_index);
grid3d = (Grid3d *) grid_compute->get_grid_by_index(grid_igrid);
else if (grid_fix)
grid3d = (Grid3d *) grid_fix->get_grid_by_index(grid_index);
grid3d = (Grid3d *) grid_fix->get_grid_by_index(grid_igrid);
grid3d->get_size(nxgrid,nygrid,nzgrid);
grid3d->get_bounds_owned(nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in);
ngrid = (nxhi_in-nxlo_in+1) * (nyhi_in-nylo_in+1) * (nzhi_in-nzlo_in+1);
}
// insure gbuf is large enough
if (ngrid > maxgrid) {
memory->destroy(gbuf);
maxgrid = ngrid;
memory->create(gbuf,maxgrid,"dump/image:gbuf");
}
// invoke Compute for per-grid quantities
@ -646,37 +673,65 @@ void DumpImage::write()
// access grid data and load gbuf
/*
if (index == 0) {
double **vec2d;
if (field2source[n] == COMPUTE)
vec2d = (double **)
compute[field2index[n]]->get_griddata_by_index(field2data[n]);
else if (field2source[n] == FIX)
vec2d = (double **)
fix[field2index[n]]->get_griddata_by_index(field2data[n]);
for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
buf[n] = vec2d[iy][ix];
n += size_one;
if (domain->dimension == 2) {
if (grid_index == 0) {
double **vec2d;
if (grid_compute)
vec2d = (double **)
grid_compute->get_griddata_by_index(grid_idata);
else if (grid_fix)
vec2d = (double **)
grid_fix->get_griddata_by_index(grid_idata);
int n = 0;
for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++)
gbuf[n++] = vec2d[iy][ix];
} else {
double ***array2d;
if (grid_compute)
array2d = (double ***)
grid_compute->get_griddata_by_index(grid_idata);
else if (grid_fix)
array2d = (double ***)
grid_fix->get_griddata_by_index(grid_idata);
int index = grid_index - 1;
int n = 0;
for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++)
gbuf[n++] = array2d[iy][ix][index];
}
} else if (domain->dimension == 3) {
if (grid_index == 0) {
double ***vec3d;
if (grid_compute)
vec3d = (double ***)
grid_compute->get_griddata_by_index(grid_idata);
else if (grid_fix)
vec3d = (double ***)
grid_fix->get_griddata_by_index(grid_idata);
int n = 0;
for (int iz = nzlo_in; iz <= nzhi_in; iz++)
for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++)
gbuf[n++] = vec3d[iz][iy][ix];
}
} else {
double ***array2d;
if (field2source[n] == COMPUTE)
array2d = (double ***)
compute[field2index[n]]->get_griddata_by_index(field2data[n]);
else if (field2source[n] == FIX)
array2d = (double ***)
fix[field2index[n]]->get_griddata_by_index(field2data[n]);
index--;
for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
buf[n] = array2d[iy][ix][index];
n += size_one;
}
}
*/
double ****array3d;
if (grid_compute)
array3d = (double ****)
grid_compute->get_griddata_by_index(grid_idata);
else if (grid_fix)
array3d = (double ****)
grid_fix->get_griddata_by_index(grid_idata);
int index = grid_index - 1;
int n = 0;
for (int iz = nzlo_in; iz <= nzhi_in; iz++)
for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++)
gbuf[n++] = array3d[iz][iy][ix][index];
}
}
// set minmax color range if using dynamic grid color map
@ -685,7 +740,7 @@ void DumpImage::write()
double two[2],twoall[2];
double lo = BIG;
double hi = -BIG;
for (int i = 0; i < ngrid_owned; i++) {
for (int i = 0; i < ngrid; i++) {
lo = MIN(lo,gbuf[i]);
hi = MAX(hi,gbuf[i]);
}
@ -861,13 +916,46 @@ void DumpImage::create_image()
}
// render my grid cells
// 2 triangles for 2d rectangle, 12 triangles for 3d cube surface
// grid_cell_corners_2d/3d calculates orthogonal vs triclinic corner pts
// for 3d, outward normals on all 6 faces
if (gridflag) {
// draw 2 or 12 triangles
//image->draw_triangle(x,y,z,color);
int n = 0;
if (domain->dimension == 2) {
for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
grid_cell_corners_2d(ix,iy);
color = image->map_value2color(1,gbuf[n++]);
image->draw_triangle(gcorners[0],gcorners[1],gcorners[3],color);
image->draw_triangle(gcorners[0],gcorners[3],gcorners[2],color);
}
} else {
for (int iz = nzlo_in; iz <= nzhi_in; iz++)
for (int iy = nylo_in; iy <= nyhi_in; iy++)
for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
grid_cell_corners_3d(ix,iy,iz);
color = image->map_value2color(1,gbuf[n++]);
// lower x face
image->draw_triangle(gcorners[0],gcorners[4],gcorners[6],color);
image->draw_triangle(gcorners[0],gcorners[6],gcorners[2],color);
// upper x face
image->draw_triangle(gcorners[1],gcorners[5],gcorners[7],color);
image->draw_triangle(gcorners[1],gcorners[7],gcorners[3],color);
// lower y face
image->draw_triangle(gcorners[0],gcorners[1],gcorners[5],color);
image->draw_triangle(gcorners[0],gcorners[5],gcorners[4],color);
// upper y face
image->draw_triangle(gcorners[2],gcorners[6],gcorners[7],color);
image->draw_triangle(gcorners[2],gcorners[7],gcorners[3],color);
// lower z face
image->draw_triangle(gcorners[0],gcorners[2],gcorners[3],color);
image->draw_triangle(gcorners[0],gcorners[3],gcorners[1],color);
// upper z face
image->draw_triangle(gcorners[4],gcorners[5],gcorners[7],color);
image->draw_triangle(gcorners[4],gcorners[7],gcorners[6],color);
}
}
}
// render atoms that are lines
@ -1266,6 +1354,83 @@ void DumpImage::create_image()
/* ---------------------------------------------------------------------- */
void DumpImage::grid_cell_corners_2d(int ix, int iy)
{
double *boxlo = domain->boxlo;
double *prd = domain->prd;
if (!domain->triclinic) {
double xdelta = prd[0] / nxgrid;
double ydelta = prd[1] / nygrid;
int n = 0;
for (int y = 0; y < 2; y++)
for (int x = 0; x < 2; x++) {
gcorners[n][0] = boxlo[0] + (ix+x) * xdelta;
gcorners[n][1] = boxlo[1] + (iy+y) * ydelta;
n++;
}
} else {
double lamda[3],xone[3];
lamda[2] = 0.0;
double dx = 1.0 / nxgrid;
double dy = 1.0 / nygrid;
int n = 0;
for (int y = 0; y < 2; y++)
for (int x = 0; x < 2; x++) {
lamda[0] = (ix+x) * dx;
lamda[1] = (iy+y) * dy;
domain->lamda2x(lamda,gcorners[n++]);
}
}
}
/* ---------------------------------------------------------------------- */
void DumpImage::grid_cell_corners_3d(int ix, int iy, int iz)
{
double *boxlo = domain->boxlo;
double *prd = domain->prd;
if (!domain->triclinic) {
double xdelta = prd[0] / nxgrid;
double ydelta = prd[1] / nygrid;
double zdelta = prd[2] / nzgrid;
int n = 0;
for (int z = 0; z < 2; z++)
for (int y = 0; y < 2; y++)
for (int x = 0; x < 2; x++) {
gcorners[n][0] = boxlo[0] + (ix+x) * xdelta;
gcorners[n][1] = boxlo[1] + (iy+y) * ydelta;
gcorners[n][2] = boxlo[2] + (iz+z) * zdelta;
n++;
}
} else {
double lamda[3],xone[3];
double dx = 1.0 / nxgrid;
double dy = 1.0 / nygrid;
double dz = 1.0 / nzgrid;
int n = 0;
for (int z = 0; z < 2; z++)
for (int y = 0; y < 2; y++)
for (int x = 0; x < 2; x++) {
lamda[0] = (ix+x) * dx;
lamda[1] = (iy+y) * dy;
lamda[2] = (iz+z) * dz;
domain->lamda2x(lamda,gcorners[n++]);
}
}
}
/* ---------------------------------------------------------------------- */
int DumpImage::pack_forward_comm(int n, int *list, double *buf,
int /*pbc_flag*/, int * /*pbc*/)
{

View File

@ -85,10 +85,12 @@ class DumpImage : public DumpCustom {
char *id_grid_compute,*id_grid_fix;
class Compute *grid_compute;
class Fix *grid_fix;
int grid_index;
double *gbuf;
int grid_igrid,grid_idata,grid_index;
int nxgrid,nygrid,nzgrid;
int nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in;
int ngrid_owned;
double *gbuf;
int ngrid,maxgrid;
double gcorners[8][3];
class AtomVecLine *avec_line; // ptrs to atom style (sub)classes
class AtomVecTri *avec_tri;
@ -111,6 +113,8 @@ class DumpImage : public DumpCustom {
void box_bounds();
void create_image();
void grid_cell_corners_2d(int, int);
void grid_cell_corners_3d(int, int, int);
};
} // namespace LAMMPS_NS

View File

@ -59,6 +59,11 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
pergrid_freq = utils::inumeric(FLERR,arg[5],false,lmp);
time_depend = 1;
if (nevery <= 0 || nrepeat <= 0 || pergrid_freq <= 0)
error->all(FLERR,"Illegal fix ave/grid command");
if (pergrid_freq % nevery || nrepeat*nevery > pergrid_freq)
error->all(FLERR,"Illegal fix ave/grid command");
// NOTE: allow Dxyz as well at some point ?
nxgrid = utils::inumeric(FLERR,arg[6],false,lmp);
@ -135,21 +140,38 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
modeatom = 1;
} else {
// if arg is not a per-atom or per-grid value
// then it's an optional arg after the values
ArgInfo argi(arg[iarg]);
if (argi.get_type() == ArgInfo::NONE || argi.get_type() == ArgInfo::UNKNOWN) break;
if (argi.get_dim() > 1) error->all(FLERR,"Invalid fix ave/grid command");
if (argi.get_type() == ArgInfo::NONE) break;
if ((argi.get_type() == ArgInfo::UNKNOWN) || (argi.get_dim() > 1))
error->all(FLERR,"Invalid fix ave/grid command");
// atom value has no colon
which[nvalues] = argi.get_type();
argindex[nvalues] = argi.get_index1();
ids[nvalues] = argi.copy_name();
if (!strchr(arg[iarg],':')) {
modeatom = 1;
ids[nvalues] = argi.copy_name();
which[nvalues] = argi.get_type();
argindex[nvalues] = argi.get_index1();
if (strchr(ids[nvalues],':')) modegrid = 1;
else modeatom = 1;
// per-grid value has colons
if (modegrid && which[nvalues] == ArgInfo::VARIABLE)
error->all(FLERR,"Fix ave/grid cannot use variable for grid info");
} else {
modegrid = 1;
int igrid,idata,index;
int iflag =
utils::check_grid_reference((char *) "Fix ave/grid",
arg[iarg],nevery,ids[nvalues],igrid,idata,index,lmp);
if (iflag < 0) error->all(FLERR,"Invalid grid reference in fix ave/grid command");
which[nvalues] = iflag;
value2grid[nvalues] = igrid;
value2data[nvalues] = idata;
argindex[nvalues] = index;
}
}
nvalues++;
@ -231,16 +253,11 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
memory->sfree(earg);
}
// setup and error check
// more error checks
// for fix inputs, check that fix frequency is acceptable
dimension = domain->dimension;
if (nevery <= 0 || nrepeat <= 0 || pergrid_freq <= 0)
error->all(FLERR,"Illegal fix ave/grid command");
if (pergrid_freq % nevery || nrepeat*nevery > pergrid_freq)
error->all(FLERR,"Illegal fix ave/grid command");
if (nxgrid < 1 || nygrid < 1 || nzgrid < 1)
error->all(FLERR,"Invalid fix ave/grid grid size");
if (dimension == 2 && nzgrid != 1)
@ -306,88 +323,6 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
}
}
// setup and error checks for GRID mode
if (modegrid) {
for (int i = 0; i < nvalues; i++) {
if (which[i] == ArgInfo::COMPUTE) {
auto words = utils::parse_grid_id(FLERR,ids[i],error);
const auto &idcompute = words[0];
const auto &gname = words[1];
const auto &dname = words[2];
delete[] ids[i];
ids[i] = utils::strdup(idcompute);
auto icompute = modify->get_compute_by_id(idcompute);
if (!icompute) error->all(FLERR,"Could not find fix ave/grid compute ID: {}",idcompute);
if (icompute->pergrid_flag == 0)
error->all(FLERR,"Fix ave/grid compute {} does not compute per-grid info",idcompute);
int dim;
int igrid = icompute->get_grid_by_name(gname,dim);
if (igrid < 0)
error->all(FLERR,"Fix ave/grid compute {} does not recognize grid name {}",
idcompute,gname);
int ncol;
int idata = icompute->get_griddata_by_name(igrid,dname,ncol);
if (idata < 0)
error->all(FLERR,"Fix ave/grid compute {} does not recognize data name {}",
idcompute,dname);
if (argindex[i] == 0 && ncol)
error->all(FLERR,"Fix ave/grid compute {} data {} is not per-grid vector",idcompute,dname);
if (argindex[i] && ncol == 0)
error->all(FLERR,"Fix ave/grid compute {} data {} is not per-grid array",idcompute,dname);
if (argindex[i] && argindex[i] > ncol)
error->all(FLERR,"Fix ave/grid compute {} array {} is accessed out-of-range",
idcompute,dname);
value2grid[i] = igrid;
value2data[i] = idata;
} else if (which[i] == ArgInfo::FIX) {
auto words = utils::parse_grid_id(FLERR,ids[i],error);
const auto &idfix = words[0];
const auto &gname = words[1];
const auto &dname = words[2];
delete[] ids[i];
ids[i] = utils::strdup(idfix);
Fix *ifix = modify->get_fix_by_id(idfix);
if (!ifix) error->all(FLERR,"Could not find fix ave/grid fix ID: {}",idfix);
if (ifix->pergrid_flag == 0)
error->all(FLERR,"Fix ave/grid fix {} does not compute per-grid info",idfix);
if (nevery % ifix->pergrid_freq)
error->all(FLERR, "Fix ID {} for fix grid/atom not computed at compatible time",idfix);
int dim;
int igrid = ifix->get_grid_by_name(gname,dim);
if (igrid < 0)
error->all(FLERR,"Fix ave/grid fix {} does not recognize grid name {}",idfix,gname);
int ncol;
int idata = ifix->get_griddata_by_name(igrid,dname,ncol);
if (idata < 0)
error->all(FLERR,"Fix ave/grid fix {} does not recognize data name {}",idfix,dname);
if (argindex[i] == 0 && ncol)
error->all(FLERR, "Fix ave/grid fix {} data {} is not per-grid vector",idfix,dname);
if (argindex[i] && ncol == 0)
error->all(FLERR,"Fix ave/grid fix {} data {} is not per-grid array",idfix,dname);
if (argindex[i] && argindex[i] > ncol)
error->all(FLERR,"Fix ave/grid fix {} array {} is accessed out-of-range",idfix,dname);
value2grid[i] = igrid;
value2data[i] = idata;
}
}
}
// instantiate Grid class and buffers
// allocate/zero per-grid data

View File

@ -877,8 +877,8 @@ char *utils::expand_type(const char *file, int line, const std::string &str, int
caller decides what to do if not COMPUTE or FIX
------------------------------------------------------------------------- */
int utils::check_grid_reference(char *errstr, char *ref, int &igrid, int &idata, int &index,
LAMMPS *lmp)
int utils::check_grid_reference(char *errstr, char *ref, int nevery,
char *&id, int &igrid, int &idata, int &index, LAMMPS *lmp)
{
ArgInfo argi(ref, ArgInfo::COMPUTE | ArgInfo::FIX);
index = argi.get_index1();
@ -902,28 +902,28 @@ int utils::check_grid_reference(char *errstr, char *ref, int &igrid, int &idata,
const auto &dname = words[2];
auto icompute = lmp->modify->get_compute_by_id(idcompute);
if (!icompute) lmp->error->all(FLERR,"%s compute ID {} not found",errstr,idcompute);
if (!icompute) lmp->error->all(FLERR,"{} compute ID {} not found",errstr,idcompute);
if (icompute->pergrid_flag == 0)
lmp->error->all(FLERR,"%s compute {} does not compute per-grid info",errstr,idcompute);
lmp->error->all(FLERR,"{} compute {} does not compute per-grid info",errstr,idcompute);
int dim;
igrid = icompute->get_grid_by_name(gname,dim);
if (igrid < 0)
lmp->error->all(FLERR,"%s compute {} does not recognize grid name {}",errstr,idcompute,gname);
lmp->error->all(FLERR,"{} compute {} does not recognize grid name {}",errstr,idcompute,gname);
int ncol;
idata = icompute->get_griddata_by_name(igrid,dname,ncol);
if (idata < 0)
lmp->error->all(FLERR,"%s compute {} does not recognize data name {}",errstr,idcompute,dname);
lmp->error->all(FLERR,"{} compute {} does not recognize data name {}",errstr,idcompute,dname);
if (argi.get_dim() == 0 && ncol)
lmp->error->all(FLERR,"%s compute {} data {} is not per-grid vector",errstr,idcompute,dname);
lmp->error->all(FLERR,"{} compute {} data {} is not per-grid vector",errstr,idcompute,dname);
if (argi.get_dim() && ncol == 0)
lmp->error->all(FLERR,"%s compute {} data {} is not per-grid array",errstr,idcompute,dname);
lmp->error->all(FLERR,"{} compute {} data {} is not per-grid array",errstr,idcompute,dname);
if (argi.get_dim() && argi.get_index1() > ncol)
lmp->error->all(FLERR,"%s compute {} array {} is accessed out-of-range",errstr,idcompute,dname);
lmp->error->all(FLERR,"{} compute {} array {} is accessed out-of-range",errstr,idcompute,dname);
//id = utils::strdup(idcompute);
id = utils::strdup(idcompute);
return ArgInfo::COMPUTE;
} break;
@ -939,30 +939,30 @@ int utils::check_grid_reference(char *errstr, char *ref, int &igrid, int &idata,
const auto &dname = words[2];
auto ifix = lmp->modify->get_fix_by_id(idfix);
if (!ifix) lmp->error->all(FLERR,"%s fix ID {} not found",errstr,idfix);
if (!ifix) lmp->error->all(FLERR,"{} fix ID {} not found",errstr,idfix);
if (ifix->pergrid_flag == 0)
lmp->error->all(FLERR,"%s fix {} does not compute per-grid info",errstr,idfix);
//if (nevery % ifix->pergrid_freq)
// lmp->error->all(FLERR,"%s fix {} not computed at compatible time",errstr,if);
lmp->error->all(FLERR,"{} fix {} does not compute per-grid info",errstr,idfix);
if (nevery % ifix->pergrid_freq)
lmp->error->all(FLERR,"{} fix {} not computed at compatible time",errstr,idfix);
int dim;
int igrid = ifix->get_grid_by_name(gname,dim);
igrid = ifix->get_grid_by_name(gname,dim);
if (igrid < 0)
lmp->error->all(FLERR,"%s fix {} does not recognize grid name {}",errstr,idfix,gname);
lmp->error->all(FLERR,"{} fix {} does not recognize grid name {}",errstr,idfix,gname);
int ncol;
int idata = ifix->get_griddata_by_name(igrid,dname,ncol);
idata = ifix->get_griddata_by_name(igrid,dname,ncol);
if (idata < 0)
lmp->error->all(FLERR,"%s fix {} does not recognize data name {}",errstr,idfix,dname);
lmp->error->all(FLERR,"{} fix {} does not recognize data name {}",errstr,idfix,dname);
if (argi.get_dim() == 0 && ncol)
lmp->error->all(FLERR,"%s fix {} data {} is not per-grid vector",errstr,idfix,dname);
lmp->error->all(FLERR,"{} fix {} data {} is not per-grid vector",errstr,idfix,dname);
if (argi.get_dim() > 0 && ncol == 0)
lmp->error->all(FLERR,"%s fix {} data {} is not per-grid array",errstr,idfix,dname);
lmp->error->all(FLERR,"{} fix {} data {} is not per-grid array",errstr,idfix,dname);
if (argi.get_dim() > 0 && argi.get_index1() > ncol)
lmp->error->all(FLERR,"%s fix {} array {} is accessed out-of-range",errstr,idfix,dname);
lmp->error->all(FLERR,"{} fix {} array {} is accessed out-of-range",errstr,idfix,dname);
//id = utils::strdup(idfix);
id = utils::strdup(idfix);
return ArgInfo::FIX;
} break;
}

View File

@ -383,8 +383,8 @@ namespace utils {
int check_grid_reference(char *errstr, char *ref, int &igrid, int &idata, int &index,
LAMMPS *lmp);
int check_grid_reference(char *errstr, char *ref, int nevery,
char *& id, int &igrid, int &idata, int &index, LAMMPS *lmp);
/*! Parse grid reference into 3 sub-strings