From ab51c53dfd0a83d9ca9fdc770a0c3fa01f40e28c Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 12 Oct 2022 17:34:42 -0600 Subject: [PATCH] add identical check between 2 grids --- src/EXTRA-FIX/fix_ttm_grid.cpp | 14 ++++++++++++ src/grid2d.cpp | 33 ++++++++++++++++++++++++++++ src/grid2d.h | 2 ++ src/grid3d.cpp | 39 ++++++++++++++++++++++++++++++++++ src/grid3d.h | 2 ++ 5 files changed, 90 insertions(+) diff --git a/src/EXTRA-FIX/fix_ttm_grid.cpp b/src/EXTRA-FIX/fix_ttm_grid.cpp index f513647226..54cb0f550d 100644 --- a/src/EXTRA-FIX/fix_ttm_grid.cpp +++ b/src/EXTRA-FIX/fix_ttm_grid.cpp @@ -368,6 +368,20 @@ void FixTTMGrid::read_electron_temperatures(const std::string &filename) 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 memory->destroy(grid_buf1); diff --git a/src/grid2d.cpp b/src/grid2d.cpp index deba57033c..51afc3bf89 100644 --- a/src/grid2d.cpp +++ b/src/grid2d.cpp @@ -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) { nxgrid = nx; @@ -368,6 +391,16 @@ void Grid2d::get_bounds(int &xlo, int &xhi, int &ylo, int &yhi) 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 either on regular grid or procs or irregular tiling diff --git a/src/grid2d.h b/src/grid2d.h index 8d1b21af6f..86bde517f6 100644 --- a/src/grid2d.h +++ b/src/grid2d.h @@ -29,8 +29,10 @@ 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; + int identical(Grid2d *); void get_size(int &, int &); void get_bounds(int &, int &, int &, int &); + void get_bounds_ghost(int &, int &, int &, int &); void setup(int &, int &); int ghost_adjacent(); void forward_comm(int, void *, int, int, int, void *, void *, MPI_Datatype); diff --git a/src/grid3d.cpp b/src/grid3d.cpp index 5433aaef09..2701b81c6f 100644 --- a/src/grid3d.cpp +++ b/src/grid3d.cpp @@ -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) { nxgrid = nx; @@ -401,6 +426,19 @@ void Grid3d::get_bounds(int &xlo, int &xhi, int &ylo, int &yhi, 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 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) { // 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; ngrid2_buf = 0; diff --git a/src/grid3d.h b/src/grid3d.h index f484f2664d..5e4cee30ed 100644 --- a/src/grid3d.h +++ b/src/grid3d.h @@ -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); ~Grid3d() override; + int identical(Grid3d *); void get_size(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 &); int ghost_adjacent(); void forward_comm(int, void *, int, int, int, void *, void *, MPI_Datatype);