From df5cfd18eb987fb8d8091f4838603476469abf3a Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 16 Nov 2022 15:35:21 -0700 Subject: [PATCH] start adding support for dump image of grid cell values --- doc/src/dump_image.rst | 45 ++++++++++++++++++++++++++++----------- src/dump_grid_vtk.cpp | 48 ++++++++++++++++++++---------------------- src/dump_image.cpp | 38 +++++++++++++++++++++++++++++---- src/dump_image.h | 2 ++ 4 files changed, 92 insertions(+), 41 deletions(-) diff --git a/doc/src/dump_image.rst b/doc/src/dump_image.rst index bc2373afac..45bea21459 100644 --- a/doc/src/dump_image.rst +++ b/doc/src/dump_image.rst @@ -24,7 +24,7 @@ Syntax * color = atom attribute that determines color of each atom * diameter = atom attribute that determines size of each atom * zero or more keyword/value pairs may be appended -* keyword = *atom* or *adiam* or *bond* or *line* or *tri* or *body* or *fix* or *size* or *view* or *center* or *up* or *zoom* or *box* or *axes* or *subbox* or *shiny* or *ssao* +* keyword = *atom* or *adiam* or *bond* or *grid* or *line* or *tri* or *body* or *fix* or *size* or *view* or *center* or *up* or *zoom* or *box* or *axes* or *subbox* or *shiny* or *ssao* .. parsed-literal:: @@ -34,6 +34,14 @@ Syntax color = *atom* or *type* or *none* width = number or *atom* or *type* or *none* number = numeric value for bond width (distance units) + *grid* = per-grid value to use when coloring each grid cell + per-grid value = c_ID:gname:dname, c_ID:gname:dname[I], f_ID:gname:dname, f_ID:gname:dname[I] + gname = name of grid defined by compute or fix + dname = name of data field defined by compute or fix + c_ID = per-grid vector calculated by a compute with ID + c_ID[I] = Ith column of per-grid array calculated by a compute with ID + f_ID = per-grid vector calculated by a fix with ID + f_ID[I] = Ith column of per-grid array calculated by a fix with ID *line* = color width color = *type* width = numeric value for line width (distance units) @@ -95,7 +103,7 @@ Syntax dump_modify dump-ID keyword values ... * these keywords apply only to the *image* and *movie* styles and are documented on this page -* keyword = *acolor* or *adiam* or *amap* or *backcolor* or *bcolor* or *bdiam* or *boxcolor* or *color* or *bitrate* or *framerate* +* keyword = *acolor* or *adiam* or *amap* or *gmap* or *backcolor* or *bcolor* or *bdiam* or *bitrate* or *boxcolor* or *color* or *framerate* or *gmap* * see the :doc:`dump modify ` doc page for more general keywords .. parsed-literal:: @@ -134,15 +142,16 @@ Syntax *bdiam* args = type diam type = bond type or range of types (see below) diam = diameter of bonds of that type (distance units) + *bitrate* arg = rate + rate = target bitrate for movie in kbps *boxcolor* arg = color color = name of color for simulation box lines and processor sub-domain lines *color* args = name R G B name = name of color R,G,B = red/green/blue numeric values from 0.0 to 1.0 - *bitrate* arg = rate - rate = target bitrate for movie in kbps *framerate* arg = fps fps = frames per second for movie + *gmap* args = identical to *amap* args Examples """""""" @@ -214,7 +223,7 @@ Similarly, the format of the resulting movie is chosen with the and thus details have to be looked up in the `FFmpeg documentation `_. Typical examples are: .avi, .mpg, .m4v, .mp4, .mkv, .flv, .mov, .gif Additional settings of the movie -compression like bitrate and framerate can be set using the +compression like *bitrate* and *framerate* can be set using the dump_modify command as described below. To write out JPEG and PNG format files, you must build LAMMPS with @@ -300,13 +309,13 @@ settings, they are interpreted in the following way. If "vx", for example, is used as the *color* setting, then the color of the atom will depend on the x-component of its velocity. The association of a per-atom value with a specific color is determined by -a "color map", which can be specified via the dump_modify command, as -described below. The basic idea is that the atom-attribute will be -within a range of values, and every value within the range is mapped -to a specific color. Depending on how the color map is defined, that -mapping can take place via interpolation so that a value of -3.2 is -halfway between "red" and "blue", or discretely so that the value of --3.2 is "orange". +a "color map", which can be specified via the dump_modify amap +command, as described below. The basic idea is that the +atom-attribute will be within a range of values, and every value +within the range is mapped to a specific color. Depending on how the +color map is defined, that mapping can take place via interpolation so +that a value of -3.2 is halfway between "red" and "blue", or +discretely so that the value of -3.2 is "orange". If "vx", for example, is used as the *diameter* setting, then the atom will be rendered using the x-component of its velocity as the @@ -948,6 +957,17 @@ frequently. ---------- +The *gmap* keyword can be used with the dump image command, with its +*grid* keyword, to setup a color map. The color map is used to assign +a specific RGB (red/green/blue) color value to an individual grid cell +when it is drawn, based on the grid cell value, which is a numeric +quantity specified with the *grid* keyword. + +The arguments for the *gmap* keyword are identical to those for the +*amap* keyword (for atom coloring) described above. + +---------- + Restrictions """""""""""" @@ -1031,6 +1051,7 @@ The defaults for the dump_modify keywords specific to dump image and dump movie * boxcolor = yellow * color = 140 color names are pre-defined as listed below * framerate = 24 +* gmap = min max cf 0.0 2 min blue max red ---------- diff --git a/src/dump_grid_vtk.cpp b/src/dump_grid_vtk.cpp index c338e14333..d2a32ec160 100644 --- a/src/dump_grid_vtk.cpp +++ b/src/dump_grid_vtk.cpp @@ -56,7 +56,7 @@ void DumpGridVTK::init_style() { DumpGrid::init_style(); - if (multifile == 0) + if (multifile == 0) error->all(FLERR,"Dump grid/vtk requires one snapshot per file"); if (sort_flag == 0 || sortcol > 0) error->all(FLERR,"Dump grid/vtk requires sorting on IDs"); @@ -66,9 +66,9 @@ void DumpGridVTK::init_style() if (binary) error->all(FLERR,"Dump grid/vtk cannot write binary files\n"); if (!xcoord) { - memory->create(xcoord,nxgrid,"dumpgridVTK:xcoord"); - memory->create(ycoord,nygrid,"dumpgridVTK:ycoord"); - memory->create(zcoord,nzgrid,"dumpgridVTK:zcoord"); + memory->create(xcoord,nxgrid+1,"dumpgridVTK:xcoord"); + memory->create(ycoord,nygrid+1,"dumpgridVTK:ycoord"); + memory->create(zcoord,nzgrid+1,"dumpgridVTK:zcoord"); } } @@ -81,7 +81,7 @@ void DumpGridVTK::write_header(bigint ndump) xyz_grid(); fprintf(fp,"\n"); - fprintf(fp,"\n"); fprintf(fp,"\n",nxgrid,nygrid,nzgrid); fprintf(fp,"\n",nxgrid,nygrid,nzgrid); @@ -91,29 +91,27 @@ void DumpGridVTK::write_header(bigint ndump) // coords of center point of grid cells in each of xyz dimensions - fprintf(fp,"\n"); + for (int i = 0; i <= nxgrid; i++) fprintf(fp,"%g ",xcoord[i]); - fprintf(fp,"\n"); - fprintf(fp,"\n"); - fprintf(fp,"\n"); + fprintf(fp,"\n"); + for (int i = 0; i <= nygrid; i++) fprintf(fp,"%g ",ycoord[i]); - fprintf(fp,"\n"); - fprintf(fp,"\n"); - fprintf(fp,"\n"); + fprintf(fp,"\n"); + for (int i = 0; i <= nzgrid; i++) fprintf(fp,"%g ",zcoord[i]); - fprintf(fp,"\n"); - fprintf(fp,"\n"); + fprintf(fp,"\n\n"); fprintf(fp,"\n"); fprintf(fp,"\n"); if (mode == SCALAR) - fprintf(fp,"\n"); else if (mode == VECTOR) - fprintf(fp,"\n"); } /* ---------------------------------------------------------------------- */ @@ -158,12 +156,12 @@ void DumpGridVTK::xyz_grid() double dy = domain->prd[1] / nygrid; double dz = domain->prd[2] / nzgrid; - for (int ix = 0; ix < nxgrid; ix++) - xcoord[ix] = boxlo[0] + (ix + 0.5) * dx; + for (int ix = 0; ix <= nxgrid; ix++) + xcoord[ix] = boxlo[0] + ix*dx; - for (int iy = 0; iy < nygrid; iy++) - ycoord[iy] = boxlo[1] + (iy + 0.5) * dy; + for (int iy = 0; iy <= nygrid; iy++) + ycoord[iy] = boxlo[1] + iy*dy; - for (int iz = 0; iz < nzgrid; iz++) - zcoord[iz] = boxlo[2] + (iz + 0.5) * dz; + for (int iz = 0; iz <= nzgrid; iz++) + zcoord[iz] = boxlo[2] + iz*dz; } diff --git a/src/dump_image.cpp b/src/dump_image.cpp index 0259b44662..4247ebfa95 100644 --- a/src/dump_image.cpp +++ b/src/dump_image.cpp @@ -104,10 +104,10 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[6],"type") == 0) adiam = TYPE; else if (strcmp(arg[6],"element") == 0) adiam = ELEMENT; - // create Image class with single colormap for atoms + // create Image class with two colormaps for atoms and grid cells // change defaults for 2d - image = new Image(lmp,1); + image = new Image(lmp,2); if (domain->dimension == 2) { image->theta = 0.0; @@ -118,6 +118,7 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) : // set defaults for optional args atomflag = YES; + gridflag = NO; lineflag = triflag = bodyflag = fixflag = NO; if (atom->nbondtypes == 0) bondflag = NO; else { @@ -175,6 +176,14 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) : else error->all(FLERR,"Illegal dump image command"); iarg += 3; + } else if (strcmp(arg[iarg],"grid") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal dump image command"); + gridflag = YES; + if (strcmp(arg[iarg+1],"type") == 0) lcolor = TYPE; + else error->all(FLERR,"Illegal dump image command"); + ldiam = NUMERIC; + ldiamvalue = utils::numeric(FLERR,arg[iarg+2],false,lmp); + iarg += 2; } else if (strcmp(arg[iarg],"line") == 0) { if (iarg+3 > narg) error->all(FLERR,"Illegal dump image command"); @@ -576,6 +585,25 @@ void DumpImage::write() if (flag) error->all(FLERR,"Invalid color map min/max values"); } + // set minmax color range if using dynamic grid color map + + if (acolor == ATTRIBUTE && image->map_dynamic(1)) { + double two[2],twoall[2]; + double lo = BIG; + double hi = -BIG; + int m = 0; + for (int i = 0; i < nchoose; i++) { + lo = MIN(lo,buf[m]); + hi = MAX(hi,buf[m]); + m += size_one; + } + two[0] = -lo; + two[1] = hi; + MPI_Allreduce(two,twoall,2,MPI_DOUBLE,MPI_MAX,world); + int flag = image->map_minmax(0,-twoall[0],twoall[1]); + if (flag) error->all(FLERR,"Invalid color map min/max values"); + } + // create image on each proc, then merge them image->clear(); @@ -1217,7 +1245,7 @@ int DumpImage::modify_param(int narg, char **arg) return 3; } - if (strcmp(arg[0],"amap") == 0) { + if ((strcmp(arg[0],"amap") == 0) || (strcmp(arg[0],"gmap") == 0)) { if (narg < 6) error->all(FLERR,"Illegal dump_modify command"); if (strlen(arg[3]) != 2) error->all(FLERR,"Illegal dump_modify command"); int factor = 0; @@ -1229,7 +1257,9 @@ int DumpImage::modify_param(int narg, char **arg) if (nentry < 1) error->all(FLERR,"Illegal dump_modify command"); n = 6 + factor*nentry; if (narg < n) error->all(FLERR,"Illegal dump_modify command"); - int flag = image->map_reset(0,n-1,&arg[1]); + int flag; + if (strcmp(arg[0],"amap") == 0) flag = image->map_reset(0,n-1,&arg[1]); + if (strcmp(arg[0],"gmap") == 0) flag = image->map_reset(1,n-1,&arg[1]); if (flag) error->all(FLERR,"Illegal dump_modify command"); return n; } diff --git a/src/dump_image.h b/src/dump_image.h index 06dded2dbe..a455e5df19 100644 --- a/src/dump_image.h +++ b/src/dump_image.h @@ -41,6 +41,8 @@ class DumpImage : public DumpCustom { int acolor, adiam; // what determines color/diam of atoms double adiamvalue; // atom diameter value + int gridflag; // 0/1 for draw grid cells + int lineflag; // 0/1 for draw atoms as lines int lcolor, ldiam; // what determines color/diam of lines double ldiamvalue; // line diameter value