dump grid and compute property/grid

This commit is contained in:
Steve Plimpton
2022-07-21 15:08:44 -06:00
parent 465ac275db
commit d819c890b6
10 changed files with 622 additions and 121 deletions

View File

@ -130,6 +130,11 @@ class Compute : protected Pointers {
virtual int pack_reverse_comm(int, int, double *) { return 0; }
virtual void unpack_reverse_comm(int, int *, double *) {}
virtual int get_grid_by_name(char *, int &) { return -1; };
virtual void *get_grid_by_index(int) { return nullptr; };
virtual int get_griddata_by_name(int, char *, int &) { return -1; };
virtual void *get_griddata_by_index(int) { return nullptr; };
virtual void dof_remove_pre() {}
virtual int dof_remove(int) { return 0; }
virtual void remove_bias(int, double *) {}

View File

@ -0,0 +1,282 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "compute_property_grid.h"
#include "domain.h"
#include "error.h"
#include "memory.h"
#include "update.h"
#include <cstring>
using namespace LAMMPS_NS;
enum { ID, X, Y, Z, XS, YS, ZS, XC, YC, ZC, XSC, YSC, ZSC };
#define DELTA 10000
/* ---------------------------------------------------------------------- */
ComputePropertyGrid::ComputePropertyGrid(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg), pack_choice(nullptr)
{
if (narg < 7) error->all(FLERR, "Illegal compute property/grid command");
pergrid_flag = 1;
dimension = domain->dimension;
nx = utils::inumeric(FLERR,arg[3],false,lmp);
ny = utils::inumeric(FLERR,arg[4],false,lmp);
nz = utils::inumeric(FLERR,arg[5],false,lmp);
if (dimension == 2 && nz != 1)
error->all(FLERR,"Compute property/grid for 2d requires nz = 1");
if (nx <= 0 || ny <= 0 || nz <= 0)
error->all(FLERR, "Illegal compute property/grid command");
nvalues = narg - 6;
pack_choice = new FnPtrPack[nvalues];
for (int iarg = 6; iarg < narg; iarg++) {
if (strcmp(arg[iarg], "id") == 0) {
pack_choice[iarg] = &ComputePropertyGrid::pack_id;
} else if (strcmp(arg[iarg], "x") == 0) {
pack_choice[iarg] = &ComputePropertyGrid::pack_x;
} else if (strcmp(arg[iarg], "y") == 0) {
pack_choice[iarg] = &ComputePropertyGrid::pack_y;
} else if (strcmp(arg[iarg], "z") == 0) {
if (dimension == 2)
error->all(FLERR,"Compute property/grid for 2d cannot use z coord");
pack_choice[iarg] = &ComputePropertyGrid::pack_z;
} else if (strcmp(arg[iarg], "xs") == 0) {
pack_choice[iarg] = &ComputePropertyGrid::pack_xs;
} else if (strcmp(arg[iarg], "ys") == 0) {
pack_choice[iarg] = &ComputePropertyGrid::pack_ys;
} else if (strcmp(arg[iarg], "zs") == 0) {
if (dimension == 2)
error->all(FLERR,"Compute property/grid for 2d cannot use z coord");
pack_choice[iarg] = &ComputePropertyGrid::pack_zs;
} else if (strcmp(arg[iarg], "xc") == 0) {
pack_choice[iarg] = &ComputePropertyGrid::pack_xc;
} else if (strcmp(arg[iarg], "yc") == 0) {
pack_choice[iarg] = &ComputePropertyGrid::pack_yc;
} else if (strcmp(arg[iarg], "zc") == 0) {
if (dimension == 2)
error->all(FLERR,"Compute property/grid for 2d cannot use z coord");
pack_choice[iarg] = &ComputePropertyGrid::pack_zc;
} else if (strcmp(arg[iarg], "xsc") == 0) {
pack_choice[iarg] = &ComputePropertyGrid::pack_xsc;
} else if (strcmp(arg[iarg], "ysc") == 0) {
pack_choice[iarg] = &ComputePropertyGrid::pack_ysc;
} else if (strcmp(arg[iarg], "zsc") == 0) {
if (dimension == 2)
error->all(FLERR,"Compute property/grid for 2d cannot use z coord");
pack_choice[iarg] = &ComputePropertyGrid::pack_zsc;
} else error->all(FLERR, "Illegal compute property/grid command");
}
}
/* ---------------------------------------------------------------------- */
ComputePropertyGrid::~ComputePropertyGrid()
{
delete[] pack_choice;
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::compute_pergrid()
{
invoked_pergrid = update->ntimestep;
// fill vector or array with local values
/*
if (nvalues == 1) {
buf = vlocal;
(this->*pack_choice[0])(0);
} else {
if (alocal) buf = &alocal[0][0];
for (int n = 0; n < nvalues; n++) (this->*pack_choice[n])(n);
}
*/
}
/* ----------------------------------------------------------------------
return index of grid associated with name
this class can store M named grids, indexed 0 to M-1
also set dim for 2d vs 3d grid
------------------------------------------------------------------------- */
int ComputePropertyGrid::get_grid_by_name(char *name, int &dim)
{
if (strcmp(name,"grid") == 0) {
dim = 3;
return 0;
}
return -1;
}
/* ----------------------------------------------------------------------
return ptr to Grid data struct for grid with index
this class can store M named grids, indexed 0 to M-1
------------------------------------------------------------------------- */
void *ComputePropertyGrid::get_grid_by_index(int index)
{
if (index == 0) return gc;
return nullptr;
}
/* ----------------------------------------------------------------------
return index of data associated with name in grid with index igrid
this class can store M named grids, indexed 0 to M-1
each grid can store G named data sets, indexed 0 to G-1
a data set name can be associated with multiple grids
also set ncol for data set, 0 = vector, 1-N for array with N columns
vector = single value per grid pt, array = N values per grid pt
------------------------------------------------------------------------- */
int ComputePropertyGrid::get_griddata_by_name(int igrid, char *name, int &ncol)
{
if (igrid == 0 && strcmp(name,"data") == 0) {
ncol = nvalues;
return 0;
}
return -1;
}
/* ----------------------------------------------------------------------
return ptr to multidim data array associated with index
this class can store G named data sets, indexed 0 to M-1
------------------------------------------------------------------------- */
void *ComputePropertyGrid::get_griddata_by_index(int index)
{
if (index == 0) return data;
return nullptr;
}
/* ----------------------------------------------------------------------
memory usage of grid data
------------------------------------------------------------------------- */
double ComputePropertyGrid::memory_usage()
{
double bytes = 0.0;
//double bytes = (double) nmax * nvalues * sizeof(double);
//bytes += (double) nmax * 2 * sizeof(int);
return bytes;
}
/* ----------------------------------------------------------------------
one method for every keyword compute property/grid can output
packed into buf starting at n with stride nvalues
------------------------------------------------------------------------- */
void ComputePropertyGrid::pack_id(int n)
{
int i;
/*
for (int m = 0; m < ncount; m++) {
i = indices[m][0];
buf[n] = tag[i];
n += nvalues;
}
*/
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_x(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_y(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_z(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_xs(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_ys(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_zs(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_xc(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_yc(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_zc(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_xsc(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_ysc(int n)
{
}
/* ---------------------------------------------------------------------- */
void ComputePropertyGrid::pack_zsc(int n)
{
}

View File

@ -0,0 +1,77 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef COMPUTE_CLASS
// clang-format off
ComputeStyle(property/grid,ComputePropertyGrid);
// clang-format on
#else
#ifndef LMP_COMPUTE_PROPERTY_GRID_H
#define LMP_COMPUTE_PROPERTY_GRID_H
#include "compute.h"
namespace LAMMPS_NS {
class ComputePropertyGrid : public Compute {
public:
ComputePropertyGrid(class LAMMPS *, int, char **);
~ComputePropertyGrid() override;
void init() override {}
void compute_pergrid() override;
int get_grid_by_name(char *, int &);
void *get_grid_by_index(int);
int get_griddata_by_name(int, char *, int &);
void *get_griddata_by_index(int);
double memory_usage() override;
private:
int nx,ny,nz;
int nvalues;
int dimension;
class Grid3d *gc;
int ngc_buf1, ngc_buf2;
double *gc_buf1, *gc_buf2;
double ****data;
typedef void (ComputePropertyGrid::*FnPtrPack)(int);
FnPtrPack *pack_choice; // ptrs to pack functions
void pack_id(int);
void pack_x(int);
void pack_y(int);
void pack_z(int);
void pack_xs(int);
void pack_ys(int);
void pack_zs(int);
void pack_xc(int);
void pack_yc(int);
void pack_zc(int);
void pack_xsc(int);
void pack_ysc(int);
void pack_zsc(int);
};
} // namespace LAMMPS_NS
#endif
#endif

View File

@ -44,7 +44,8 @@ DumpGrid::DumpGrid(LAMMPS *lmp, int narg, char **arg) :
Dump(lmp, narg, arg), idregion(nullptr), earg(nullptr), vtype(nullptr),
vformat(nullptr), columns(nullptr), columns_default(nullptr),
choose(nullptr), dchoose(nullptr), clist(nullptr),
field2index(nullptr), argindex(nullptr), id_compute(nullptr), compute(nullptr),
field2index(nullptr), field2grid(nullptr), field2data(nullptr),
argindex(nullptr), id_compute(nullptr), compute(nullptr),
id_fix(nullptr), fix(nullptr), pack_choice(nullptr)
{
if (narg == 5) error->all(FLERR,"No dump grid arguments specified");
@ -67,12 +68,17 @@ DumpGrid::DumpGrid(LAMMPS *lmp, int narg, char **arg) :
pack_choice = new FnPtrPack[nfield];
vtype = new int[nfield];
memory->create(field2index,nfield,"dump:field2index");
memory->create(argindex,nfield,"dump:argindex");
field2source = new int[nfield];
field2index = new int[nfield];
field2grid = new int[nfield];
field2data = new int[nfield];
argindex = new int[nfield];
buffer_allow = 1;
buffer_flag = 1;
dimension = domain->dimension;
// computes and fixes which the dump accesses
ncompute = 0;
@ -144,9 +150,12 @@ DumpGrid::~DumpGrid()
delete[] pack_choice;
delete[] vtype;
memory->destroy(field2index);
memory->destroy(argindex);
delete[] field2source;
delete[] field2index;
delete[] field2grid;
delete[] field2data;
delete[] argindex;
delete[] idregion;
for (int i = 0; i < ncompute; i++) delete[] id_compute[i];
@ -256,6 +265,48 @@ void DumpGrid::init_style()
error->all(FLERR,"Could not find dump grid fix ID {}", id_fix[i]);
}
// check that grid sizes for all fields are the same
Compute *icompute;
Fix *ifix;
Grid2d *grid2d;
Grid3d *grid3d;
int nx,ny,nz,nxtmp,nytmp,nztmp;
for (int i = 1; i < nfield; i++) {
if (dimension == 2) {
if (field2source[i] == COMPUTE) {
icompute = compute[field2index[i]];
grid2d = (Grid2d *) icompute->get_grid_by_index(field2grid[i]);
} else {
ifix = fix[field2index[i]];
grid2d = (Grid2d *) ifix->get_grid_by_index(field2grid[i]);
}
if (i == 0) grid2d->query_global_size(nx,ny);
else {
grid2d->query_global_size(nxtmp,nytmp);
if (nxtmp != nx || nytmp != ny)
error->all(FLERR,"Dump grid field grid sizes do not match");
}
} else {
if (field2source[0] == COMPUTE) {
icompute = compute[field2index[i]];
grid3d = (Grid3d *) icompute->get_grid_by_index(field2grid[i]);
} else {
ifix = fix[field2index[i]];
grid3d = (Grid3d *) ifix->get_grid_by_index(field2grid[i]);
}
if (i == 0) grid3d->query_global_size(nx,ny,nz);
else {
grid3d->query_global_size(nxtmp,nytmp,nztmp);
if (nxtmp != nx || nytmp != ny || nztmp != nz)
error->all(FLERR,"Dump grid field grid sizes do not match");
}
}
}
// check validity of region
if (idregion && !domain->get_region_by_id(idregion))
@ -471,6 +522,30 @@ int DumpGrid::count()
}
*/
// set current size for portion of grid on each proc
// may change between dump snapshots due to load balancing
Grid2d *grid2d;
Grid3d *grid3d;
if (dimension == 2) {
if (field2source[0] == COMPUTE)
grid2d = (Grid2d *)
compute[field2index[0]]->get_grid_by_index(field2grid[0]);
else if (field2source[0] == FIX)
grid2d = (Grid2d *)
fix[field2index[0]]->get_grid_by_index(field2grid[0]);
grid2d->query_in_bounds(nxlo_in,nxhi_in,nylo_in,nyhi_in);
} else {
if (field2source[0] == COMPUTE)
grid3d = (Grid3d *)
compute[field2index[0]]->get_grid_by_index(field2grid[0]);
else if (field2source[0] == FIX)
grid3d = (Grid3d *)
fix[field2index[0]]->get_grid_by_index(field2grid[0]);
grid3d->query_in_bounds(nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in);
}
// invoke Computes for per-grid quantities
// only if within a run or minimize
// else require that computes are current
@ -491,6 +566,16 @@ int DumpGrid::count()
}
}
// return count of grid points I own
int ngrid;
if (dimension == 2)
ngrid = (nxhi_in-nxlo_in+1) * (nyhi_in-nylo_in+1);
else
ngrid = (nxhi_in-nxlo_in+1) * (nyhi_in-nylo_in+1) * (nzhi_in-nzlo_in+1);
return ngrid;
// choose all local grid pts for output
// NOTE: this needs to change
@ -499,29 +584,29 @@ int DumpGrid::count()
// un-choose if not in region
// NOTE: this needs to change
/*
if (idregion) {
auto region = domain->get_region_by_id(idregion);
region->prematch();
/*
double **x = atom->x;
for (i = 0; i < nlocal; i++)
if (choose[i] && region->match(x[i][0],x[i][1],x[i][2]) == 0)
choose[i] = 0;
*/
}
*/
// compress choose flags into clist
// nchoose = # of selected atoms
// clist[i] = local index of each selected atom
// NOTE: this neds to change
nchoose = 0;
/*
nchoose = 0;
for (i = 0; i < nlocal; i++)
if (choose[i]) clist[nchoose++] = i;
*/
return nchoose;
*/
}
/* ---------------------------------------------------------------------- */
@ -641,8 +726,10 @@ int DumpGrid::parse_fields(int narg, char **arg)
// if no trailing [], then arg is set to 0, else arg is int between []
case ArgInfo::COMPUTE: {
pack_choice[iarg] = &DumpGrid::pack_compute;
if (dimension == 2) pack_choice[iarg] = &DumpGrid::pack_grid2d;
else pack_choice[iarg] = &DumpGrid::pack_grid3d;
vtype[iarg] = Dump::DOUBLE;
field2source[iarg] = COMPUTE;
// name = idcompute:gname:fname, split into 3 strings
@ -657,13 +744,13 @@ int DumpGrid::parse_fields(int narg, char **arg)
int n = strlen(name) + 1;
char *idcompute = new char[n];
strcpy(idfix,name);
strcpy(idcompute,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);
char *dname = new char[n];
strcpy(dname,ptr2+1);
*ptr1 = ':';
*ptr2 = ':';
@ -676,55 +763,48 @@ int DumpGrid::parse_fields(int narg, char **arg)
idcompute);
int dim;
void *ggrid = icompute->grid_find_name(gname,dim);
if (!ggrid)
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);
Grid2d *grid2d;
Grid3d *grid3d;
if (dim == 2) grid2d = (Grid2d *) ggrid;
if (dim == 3) grid3d = (Grid3d *) ggrid;
int ncol;
void *gfield = icompute->grid_find_field(fname,ncol);
if (!gfield)
int idata = icompute->get_griddata_by_name(igrid,dname,ncol);
if (idata < 0)
error->all(FLERR,
"Dump grid compute {} does not recognize field name {}",
idcompute,fname);
"Dump grid compute {} does not recognize data name {}",
idcompute,dname);
if (argi.get_dim() == 0 && ncol)
error->all(FLERR,"Dump grid compute {} field {} is not per-grid vector",
idcompute,fname);
error->all(FLERR,"Dump grid compute {} data {} is not per-grid vector",
idcompute,dname);
if (argi.get_dim() > 0 && ncol == 0)
error->all(FLERR,"Dump grid compute {} field {} is not per-grid array",
idcompute,fname);
error->all(FLERR,"Dump grid compute {} data {} is not per-grid array",
idcompute,dname);
if (argi.get_dim() > 0 && argi.get_index1() > ncol)
error->all(FLERR,
"Dump grid compute {} array {} is accessed out-of-range",
idcompute,fname);
idcompute,dname);
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_compute(idcompute);
field2grid[iarg] = igrid;
field2data[iarg] = idata;
delete [] idcompute;
delete [] gname;
delete [] dname;
} 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;
if (dimension == 2) pack_choice[iarg] = &DumpGrid::pack_grid2d;
else pack_choice[iarg] = &DumpGrid::pack_grid3d;
vtype[iarg] = Dump::DOUBLE;
field2source[iarg] = FIX;
// name = idfix:gname:fname, split into 3 strings
@ -744,8 +824,8 @@ int DumpGrid::parse_fields(int narg, char **arg)
char *gname = new char[n];
strcpy(gname,ptr1+1);
n = strlen(ptr2+1) + 1;
char *fname = new char[n];
strcpy(fname,ptr2+1);
char *dname = new char[n];
strcpy(dname,ptr2+1);
*ptr1 = ':';
*ptr2 = ':';
@ -757,45 +837,35 @@ int DumpGrid::parse_fields(int narg, char **arg)
idfix);
int dim;
void *ggrid = ifix->grid_find_name(gname,dim);
if (!ggrid)
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);
Grid2d *grid2d;
Grid3d *grid3d;
if (dim == 2) grid2d = (Grid2d *) ggrid;
if (dim == 3) grid3d = (Grid3d *) ggrid;
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);
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 {} field {} is not per-grid vector",
idfix,fname);
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 {} field {} is not per-grid array",
idfix,fname);
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,fname);
idfix,dname);
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);
field2grid[iarg] = igrid;
field2data[iarg] = idata;
delete [] idfix;
delete [] gname;
delete [] dname;
} break;
// no match
@ -928,74 +998,86 @@ int DumpGrid::modify_param(int narg, char **arg)
double DumpGrid::memory_usage()
{
double bytes = Dump::memory_usage();
bytes += memory->usage(choose,maxlocal);
bytes += memory->usage(dchoose,maxlocal);
bytes += memory->usage(clist,maxlocal);
//NOTE: restre if use choose
//bytes += memory->usage(choose,maxlocal);
//bytes += memory->usage(dchoose,maxlocal);
//bytes += memory->usage(clist,maxlocal);
return bytes;
}
/* ----------------------------------------------------------------------
extraction of Compute and Fix data
extraction of 2d and 3d grid data
from either compute or fix
------------------------------------------------------------------------- */
void DumpGrid::pack_compute(int n)
void DumpGrid::pack_grid2d(int n)
{
double *vector = compute[field2index[n]]->vector_atom;
double **array = compute[field2index[n]]->array_atom;
int index = argindex[n];
if (index == 0) {
for (int i = 0; i < nchoose; i++) {
buf[n] = vector[clist[i]];
n += size_one;
}
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;
}
} 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 i = 0; i < nchoose; i++) {
buf[n] = array[clist[i]][index];
n += size_one;
}
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;
}
}
}
/* ---------------------------------------------------------------------- */
void DumpGrid::pack_fix(int n)
void DumpGrid::pack_grid3d(int n)
{
double *vector = fix[field2index[n]]->vector_atom;
double **array = fix[field2index[n]]->array_atom;
int index = argindex[n];
if (index == 0) {
double ***vec3d;
if (field2source[n] == COMPUTE)
vec3d = (double ***)
compute[field2index[n]]->get_griddata_by_index(field2data[n]);
else if (field2source[n] == FIX)
vec3d = (double ***)
fix[field2index[n]]->get_griddata_by_index(field2data[n]);
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++) {
buf[n] = vec3d[iz][iy][ix];
n += size_one;
}
for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
buf[n] = vec3d[iz][iy][ix];
n += size_one;
}
} else {
double ****array3d;
if (field2source[n] == COMPUTE)
array3d = (double ****)
compute[field2index[n]]->get_griddata_by_index(field2data[n]);
else if (field2source[n] == FIX)
array3d = (double ****)
fix[field2index[n]]->get_griddata_by_index(field2data[n]);
index--;
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++) {
buf[n] = array3d[iz][iy][ix][index];
for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
buf[n] = array3d[iz][iy][ix][index];
n += size_one;
}
}
}
/*
if (index == 0) {
for (int i = 0; i < nchoose; i++) {
buf[n] = vector[clist[i]];
n += size_one;
}
} else {
index--;
for (int i = 0; i < nchoose; i++) {
buf[n] = array[clist[i]][index];
n += size_one;
}
}
*/
}

View File

@ -47,6 +47,8 @@ class DumpGrid : public Dump {
char *columns; // column labels
char *columns_default;
int dimension;
int nchoose; // # of selected atoms
int maxlocal; // size of atom selection and variable arrays
int *choose; // local indices of selected atoms
@ -55,10 +57,15 @@ class DumpGrid : public Dump {
int nfield; // # of keywords listed by user
int ioptional; // index of start of optional args
//
int *field2index; // which compute,fix,variable,custom calcs this field
// per field info
int *field2index; // which compute/fix
int *field2source; // COMPUTE or FIX
int *field2grid; // index of grid within compute/fix
int *field2data; // index of data within compute/fix
int *argindex; // index into compute,fix,custom per-atom data
// 0 for per-atom vector, 1-N for cols of per-atom array
void **dataptr; // ptr to grid data
int ncompute; // # of Computes accessed by dump
char **id_compute; // their IDs
@ -68,6 +75,10 @@ class DumpGrid : public Dump {
char **id_fix; // their IDs
class Fix **fix; // list of ptrs to the Fixes
int nxlo_in,nxhi_in; // bounds of this proc's portion of grids
int nylo_in,nyhi_in;
int nzlo_in,nzhi_in;
// private methods
void init_style() override;
@ -109,8 +120,8 @@ class DumpGrid : public Dump {
typedef void (DumpGrid::*FnPtrPack)(int);
FnPtrPack *pack_choice; // ptrs to pack functions
void pack_compute(int);
void pack_fix(int);
void pack_grid2d(int);
void pack_grid3d(int);
};
} // namespace LAMMPS_NS

View File

@ -217,13 +217,15 @@ class Fix : protected Pointers {
virtual void pack_gather_grid(int, void *){};
virtual void unpack_gather_grid(int, void *, void *, int, int, int, int, int, int){};
virtual int get_grid_by_name(char *, int &) { return -1; };
virtual void *get_grid_by_index(int) { return nullptr; };
virtual int get_griddata_by_name(int, char *, int &) { return -1; };
virtual void *get_griddata_by_index(int) { return nullptr; };
virtual double compute_scalar() { return 0.0; }
virtual double compute_vector(int) { return 0.0; }
virtual double compute_array(int, int) { return 0.0; }
virtual void *grid_find_name(char *, int &) { return nullptr; };
virtual void *grid_find_field(char *, int &) { return nullptr; };
virtual int dof(int) { return 0; }
virtual void deform(int) {}
virtual void reset_target(double) {}

View File

@ -212,6 +212,24 @@ void Grid2d::initialize(MPI_Comm gcomm,
/* ---------------------------------------------------------------------- */
void Grid2d::query_global_size(int &nxgrid, int &nygrid)
{
nxgrid = nx;
nygrid = ny;
}
/* ---------------------------------------------------------------------- */
void Grid2d::query_in_bounds(int &xlo, int &xhi, int &ylo, int &yhi)
{
xlo = inxlo;
xhi = inxhi;
ylo = inylo;
yhi = inyhi;
}
/* ---------------------------------------------------------------------- */
void Grid2d::setup(int &nbuf1, int &nbuf2)
{
if (layout == REGULAR) setup_regular(nbuf1,nbuf2);

View File

@ -26,11 +26,12 @@ class Grid2d : protected Pointers {
Grid2d(class LAMMPS *, MPI_Comm, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int);
~Grid2d() override;
void query_global_size(int &, int &);
void query_in_bounds(int &, int &, int &, int &);
void setup(int &, int &);
int ghost_adjacent();
void forward_comm(int, void *, int, int, int, void *, void *, MPI_Datatype);
void reverse_comm(int, void *, int, int, int, void *, void *, MPI_Datatype);
void gather(int, void *, int, int, int, void *, MPI_Datatype);
protected:
int me, nprocs;

View File

@ -229,6 +229,27 @@ void Grid3d::initialize(MPI_Comm gcomm,
/* ---------------------------------------------------------------------- */
void Grid3d::query_global_size(int &nxgrid, int &nygrid, int &nzgrid)
{
nxgrid = nx;
nygrid = ny;
nzgrid = nz;
}
/* ---------------------------------------------------------------------- */
void Grid3d::query_in_bounds(int &xlo, int &xhi, int &ylo, int &yhi, int &zlo, int &zhi)
{
xlo = inxlo;
xhi = inxhi;
ylo = inylo;
yhi = inyhi;
zlo = inzlo;
zhi = inzhi;
}
/* ---------------------------------------------------------------------- */
void Grid3d::setup(int &nbuf1, int &nbuf2)
{
if (layout == REGULAR) setup_regular(nbuf1,nbuf2);

View File

@ -27,6 +27,8 @@ class Grid3d : protected Pointers {
Grid3d(class LAMMPS *, MPI_Comm, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int);
~Grid3d() override;
void query_global_size(int &, int &, int &);
void query_in_bounds(int &, int &, int &, int &, int &, int &);
void setup(int &, int &);
int ghost_adjacent();
void forward_comm(int, void *, int, int, int, void *, void *, MPI_Datatype);