interface between dump grid and fixes

This commit is contained in:
Steve Plimpton
2022-07-20 10:53:34 -06:00
parent f69be2791b
commit d5113edc87
3 changed files with 133 additions and 77 deletions

View File

@ -19,6 +19,8 @@
#include "domain.h"
#include "error.h"
#include "fix.h"
#include "grid2d.h"
#include "grid3d.h"
#include "memory.h"
#include "modify.h"
#include "region.h"
@ -628,21 +630,23 @@ int DumpGrid::parse_fields(int narg, char **arg)
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::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:
pack_choice[iarg] = &DumpGrid::pack_compute;
vtype[iarg] = Dump::DOUBLE;
icompute = modify->get_compute_by_id(name);
if (!icompute) error->all(FLERR,"Could not find dump grid compute ID: {}",name);
if (icompute->pergrid_flag == 0)
error->all(FLERR,"Dump grid compute {} does not compute per-grid info",name);
case ArgInfo::COMPUTE: {
pack_choice[iarg] = &DumpGrid::pack_compute;
vtype[iarg] = Dump::DOUBLE;
icompute = modify->get_compute_by_id(name);
if (!icompute)
error->all(FLERR,"Could not find dump grid compute ID: {}",name);
if (icompute->pergrid_flag == 0)
error->all(FLERR,"Dump grid compute {} does not compute per-grid info",
name);
/*
if (argi.get_dim() == 0 && icompute->size_pergrid_cols > 0)
error->all(FLERR,"Dump grid compute {} does not calculate per-grid vector",name);
@ -652,80 +656,95 @@ int DumpGrid::parse_fields(int narg, char **arg)
error->all(FLERR,"Dump grid compute {} vector is accessed out-of-range",name);
*/
field2index[iarg] = add_compute(name);
break;
field2index[iarg] = add_compute(name);
} break;
// fix value = f_ID
// if no trailing [], then arg is set to 0, else arg is between []
case ArgInfo::FIX:
pack_choice[iarg] = &DumpGrid::pack_fix;
vtype[iarg] = Dump::DOUBLE;
// fix value = f_ID
// if no trailing [], then arg is set to 0, else arg is between []
// name = idfix:gname:fname, split into 3 strings
case ArgInfo::FIX: {
pack_choice[iarg] = &DumpGrid::pack_fix;
vtype[iarg] = Dump::DOUBLE;
char *ptr = strchr(name,':');
if (!ptr) error->all(FLERR,"Dump grid fix {} does not contain 2 ':' chars");
*ptr = '\0';
int n = strlen(name) + 1;
char *gname = new char[n];
strcpy(gname,name);
char *ptr2 = strchr(ptr+1,':');
if (!ptr) error->all(FLERR,"Dump grid fix {} does not contain 2 ':' chars");
int n = strlen(ptr+1) + 1;
char *fname = new char[n];
strcpy(fname,ptr+1);
*ptr = ':';
*ptr2 = ':';
// name = idfix:gname:fname, split into 3 strings
// error check
char *ptr1 = strchr((char *) name,':');
if (!ptr1)
error->all(FLERR,"Dump grid fix {} does not contain 2 ':' chars");
*ptr1 = '\0';
char *ptr2 = strchr(ptr1+1,':');
if (!ptr2)
error->all(FLERR,"Dump grid fix {} does not contain 2 ':' chars");
*ptr2 = '\0';
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-atom info",idfix);
int n = strlen(name) + 1;
char *idfix = new char[n];
strcpy(idfix,name);
n = strlen(ptr1+1) + 1;
char *gname = new char[n];
strcpy(gname,ptr1+1);
n = strlen(ptr2+1) + 1;
char *fname = new char[n];
strcpy(fname,ptr2+1);
*ptr1 = ':';
*ptr2 = ':';
// error check
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);
int dim;
void *grid = ifix->grid_find_name(gname,dim);
if (!grid) error->all(FLERR,"Dump grid fix {} does not recognize grid {}",
idfix,gname);
int dim;
void *ggrid = ifix->grid_find_name(gname,dim);
if (!ggrid)
error->all(FLERR,"Dump grid fix {} does not recognize grid name {}",
idfix,gname);
Grid2d *grid2d;
Grid3d *grid3d;
if (dim == 2) grid2d = (Grid2d *) grid;
if (dim == 3) grid2d = (Grid3d *) grid;
Grid2d *grid2d;
Grid3d *grid3d;
if (dim == 2) grid2d = (Grid2d *) ggrid;
if (dim == 3) grid3d = (Grid3d *) ggrid;
int ncol;
void *field = ifix->grid_find_field(fname,ncol);
if (!grid) error->all(FLERR,"Dump grid fix {} does not recognize field {}",
idfix,fname);
int ncol;
void *gfield = ifix->grid_find_field(fname,ncol);
if (!gfield)
error->all(FLERR,"Dump grid fix {} does not recognize field name {}",
idfix,fname);
if (argi.get_dim() == 0 && ncol)
error->all(FLERR,"Dump grid fix {} field {} is not per-grid vector",
idfix,fname);
if (argi.get_dim() > 0 && ncol == 0)
error->all(FLERR,"Dump grid fix {} field {} is not per-grid array",
idfix,fname);
if (argi.get_dim() > 0 && argi.get_index1() > ncol)
error->all(FLERR,"Dump grid fix {} array {} is accessed out-of-range",
idfix,fname);
if (ncol == 0) {
if (dim == 2) vec2d = (double **) field;
if (dim == 3) vec3d = (double ***) field;
} else if (ncol) {
if (dim == 2) array2d = (double ***) field;
if (dim == 3) array3d = (double ****) field;
}
if (argi.get_dim() == 0 && ncol)
error->all(FLERR,"Dump grid fix {} field {} is not per-grid vector",
idfix,fname);
if (argi.get_dim() > 0 && ncol == 0)
error->all(FLERR,"Dump grid fix {} field {} is not per-grid array",
idfix,fname);
if (argi.get_dim() > 0 && argi.get_index1() > ncol)
error->all(FLERR,"Dump grid fix {} array {} is accessed out-of-range",
idfix,fname);
double **vec2d;
double ***vec3d;
double ***array2d;
double ****array3d;
if (ncol == 0) {
if (dim == 2) vec2d = (double **) gfield;
if (dim == 3) vec3d = (double ***) gfield;
} else if (ncol) {
if (dim == 2) array2d = (double ***) gfield;
if (dim == 3) array3d = (double ****) gfield;
}
field2index[iarg] = add_fix(idfix);
break;
field2index[iarg] = add_fix(idfix);
} break;
// no match
default:
return iarg;
break;
// no match
default: {
return iarg;
} break;
}
}