add identical check between 2 grids

This commit is contained in:
Steve Plimpton
2022-10-12 17:34:42 -06:00
parent 6658b95dac
commit ab51c53dfd
5 changed files with 90 additions and 0 deletions

View File

@ -368,6 +368,20 @@ void FixTTMGrid::read_electron_temperatures(const std::string &filename)
void FixTTMGrid::reset_grid() void FixTTMGrid::reset_grid()
{ {
// check if new grid partitioning is different on any proc
// if not, just return
int tmp[12];
double maxdist = 0.5 * neighbor->skin;
Grid3d *gridnew = new Grid3d(lmp, world, nxgrid, nygrid, nzgrid, maxdist, 1, SHIFT,
tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5],
tmp[6],tmp[7],tmp[8],tmp[9],tmp[10],tmp[11]);
if (grid->identical(gridnew)) {
delete gridnew;
return;
} else delete gridnew;
// delete grid data which doesn't need to persist from previous to new decomp // delete grid data which doesn't need to persist from previous to new decomp
memory->destroy(grid_buf1); memory->destroy(grid_buf1);

View File

@ -352,6 +352,29 @@ void Grid2d::store(int ixlo, int ixhi, int iylo, int iyhi,
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Grid2d::identical(Grid2d *grid2)
{
int inxlo2,inxhi2,inylo2,inyhi2;
int outxlo2,outxhi2,outylo2,outyhi2;
grid2->get_bounds(inxlo2,inxhi2,inylo2,inyhi2);
grid2->get_bounds_ghost(outxlo2,outxhi2,outylo2,outyhi2);
int flag = 0;
if (inxlo != inxlo2 || inxhi != inxhi2 ||
inylo != inylo2 || inyhi != inyhi2) flag = 1;
if (outxlo != outxlo2 || outxhi != outxhi2 ||
outylo != outylo2 || outyhi != outyhi2) flag = 1;
int flagall;
MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,gridcomm);
if (flagall) return 0;
return 1;
}
/* ---------------------------------------------------------------------- */
void Grid2d::get_size(int &nxgrid, int &nygrid) void Grid2d::get_size(int &nxgrid, int &nygrid)
{ {
nxgrid = nx; nxgrid = nx;
@ -368,6 +391,16 @@ void Grid2d::get_bounds(int &xlo, int &xhi, int &ylo, int &yhi)
yhi = inyhi; yhi = inyhi;
} }
/* ---------------------------------------------------------------------- */
void Grid2d::get_bounds_ghost(int &xlo, int &xhi, int &ylo, int &yhi)
{
xlo = outxlo;
xhi = outxhi;
ylo = outylo;
yhi = outyhi;
}
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
return sizes of two buffers needed for communication return sizes of two buffers needed for communication
either on regular grid or procs or irregular tiling either on regular grid or procs or irregular tiling

View File

@ -29,8 +29,10 @@ class Grid2d : protected Pointers {
Grid2d(class LAMMPS *, MPI_Comm, int, int, int, int, int, int, int, int, int, int, Grid2d(class LAMMPS *, MPI_Comm, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int); int, int, int, int, int);
~Grid2d() override; ~Grid2d() override;
int identical(Grid2d *);
void get_size(int &, int &); void get_size(int &, int &);
void get_bounds(int &, int &, int &, int &); void get_bounds(int &, int &, int &, int &);
void get_bounds_ghost(int &, int &, int &, int &);
void setup(int &, int &); void setup(int &, int &);
int ghost_adjacent(); int ghost_adjacent();
void forward_comm(int, void *, int, int, int, void *, void *, MPI_Datatype); void forward_comm(int, void *, int, int, int, void *, void *, MPI_Datatype);

View File

@ -381,6 +381,31 @@ void Grid3d::store(int ixlo, int ixhi, int iylo, int iyhi,
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Grid3d::identical(Grid3d *grid2)
{
int inxlo2,inxhi2,inylo2,inyhi2,inzlo2,inzhi2;
int outxlo2,outxhi2,outylo2,outyhi2,outzlo2,outzhi2;
grid2->get_bounds(inxlo2,inxhi2,inylo2,inyhi2,inzlo2,inzhi2);
grid2->get_bounds_ghost(outxlo2,outxhi2,outylo2,outyhi2,outzlo2,outzhi2);
int flag = 0;
if (inxlo != inxlo2 || inxhi != inxhi2 ||
inylo != inylo2 || inyhi != inyhi2 ||
inzlo != inzlo2 || inzhi != inzhi2) flag = 1;
if (outxlo != outxlo2 || outxhi != outxhi2 ||
outylo != outylo2 || outyhi != outyhi2 ||
outzlo != outzlo2 || outzhi != outzhi2) flag = 1;
int flagall;
MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,gridcomm);
if (flagall) return 0;
return 1;
}
/* ---------------------------------------------------------------------- */
void Grid3d::get_size(int &nxgrid, int &nygrid, int &nzgrid) void Grid3d::get_size(int &nxgrid, int &nygrid, int &nzgrid)
{ {
nxgrid = nx; nxgrid = nx;
@ -401,6 +426,19 @@ void Grid3d::get_bounds(int &xlo, int &xhi, int &ylo, int &yhi,
zhi = inzhi; zhi = inzhi;
} }
/* ---------------------------------------------------------------------- */
void Grid3d::get_bounds_ghost(int &xlo, int &xhi, int &ylo, int &yhi,
int &zlo, int &zhi)
{
xlo = outxlo;
xhi = outxhi;
ylo = outylo;
yhi = outyhi;
zlo = outzlo;
zhi = outzhi;
}
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
return sizes of two buffers needed for communication return sizes of two buffers needed for communication
either on regular grid or procs or irregular tiling either on regular grid or procs or irregular tiling
@ -1332,6 +1370,7 @@ void Grid3d::remap_setup(Grid3d *old, int &ngrid1_buf, int &ngrid2_buf)
void Grid3d::remap_setup_regular(Grid3d *old, int &ngrid1_buf, int &ngrid2_buf) void Grid3d::remap_setup_regular(Grid3d *old, int &ngrid1_buf, int &ngrid2_buf)
{ {
// NOTE: when to clean up data structs when multiple remaps occur // NOTE: when to clean up data structs when multiple remaps occur
// NOTE: does a remap also require ghost comm in fix ttm/grid ?
ngrid1_buf = 0; ngrid1_buf = 0;
ngrid2_buf = 0; ngrid2_buf = 0;

View File

@ -31,8 +31,10 @@ class Grid3d : protected Pointers {
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int); int, int, int, int, int, int);
~Grid3d() override; ~Grid3d() override;
int identical(Grid3d *);
void get_size(int &, int &, int &); void get_size(int &, int &, int &);
void get_bounds(int &, int &, int &, int &, int &, int &); void get_bounds(int &, int &, int &, int &, int &, int &);
void get_bounds_ghost(int &, int &, int &, int &, int &, int &);
void setup(int &, int &); void setup(int &, int &);
int ghost_adjacent(); int ghost_adjacent();
void forward_comm(int, void *, int, int, int, void *, void *, MPI_Datatype); void forward_comm(int, void *, int, int, int, void *, void *, MPI_Datatype);