programming style changes to reduce warnings from static code analysis
This commit is contained in:
@ -189,7 +189,7 @@ void DumpGrid::init_style()
|
||||
delete[] columns;
|
||||
std::string combined;
|
||||
int icol = 0;
|
||||
for (auto item : utils::split_words(columns_default)) {
|
||||
for (const auto &item : utils::split_words(columns_default)) {
|
||||
if (combined.size()) combined += " ";
|
||||
if (keyword_user[icol].size()) combined += keyword_user[icol];
|
||||
else combined += item;
|
||||
@ -506,12 +506,14 @@ int DumpGrid::count()
|
||||
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]);
|
||||
else error->all(FLERR, "Unsupported grid data source type {}", field2source[0]);
|
||||
grid2d->get_bounds_owned(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]);
|
||||
else error->all(FLERR, "Unsupported grid data source type {}", field2source[0]);
|
||||
grid3d->get_bounds_owned(nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in);
|
||||
}
|
||||
|
||||
@ -818,11 +820,10 @@ void DumpGrid::pack_grid2d(int n)
|
||||
if (index == 0) {
|
||||
double **vec2d;
|
||||
if (field2source[n] == COMPUTE)
|
||||
vec2d = (double **)
|
||||
compute[field2index[n]]->get_griddata_by_index(field2data[n]);
|
||||
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]);
|
||||
vec2d = (double **) fix[field2index[n]]->get_griddata_by_index(field2data[n]);
|
||||
else error->all(FLERR, "Unsupported grid data source type {}", field2source[n]);
|
||||
for (int iy = nylo_in; iy <= nyhi_in; iy++)
|
||||
for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
|
||||
buf[n] = vec2d[iy][ix];
|
||||
@ -831,11 +832,10 @@ void DumpGrid::pack_grid2d(int n)
|
||||
} else {
|
||||
double ***array2d;
|
||||
if (field2source[n] == COMPUTE)
|
||||
array2d = (double ***)
|
||||
compute[field2index[n]]->get_griddata_by_index(field2data[n]);
|
||||
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]);
|
||||
array2d = (double ***) fix[field2index[n]]->get_griddata_by_index(field2data[n]);
|
||||
else error->all(FLERR, "Unsupported grid data source type {}", field2source[n]);
|
||||
index--;
|
||||
for (int iy = nylo_in; iy <= nyhi_in; iy++)
|
||||
for (int ix = nxlo_in; ix <= nxhi_in; ix++) {
|
||||
@ -854,11 +854,10 @@ void DumpGrid::pack_grid3d(int n)
|
||||
if (index == 0) {
|
||||
double ***vec3d;
|
||||
if (field2source[n] == COMPUTE)
|
||||
vec3d = (double ***)
|
||||
compute[field2index[n]]->get_griddata_by_index(field2data[n]);
|
||||
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]);
|
||||
vec3d = (double ***) fix[field2index[n]]->get_griddata_by_index(field2data[n]);
|
||||
else error->all(FLERR, "Unsupported grid data source type {}", field2source[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++) {
|
||||
@ -868,11 +867,10 @@ void DumpGrid::pack_grid3d(int n)
|
||||
} else {
|
||||
double ****array3d;
|
||||
if (field2source[n] == COMPUTE)
|
||||
array3d = (double ****)
|
||||
compute[field2index[n]]->get_griddata_by_index(field2data[n]);
|
||||
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]);
|
||||
array3d = (double ****) fix[field2index[n]]->get_griddata_by_index(field2data[n]);
|
||||
else error->all(FLERR, "Unsupported grid data source type {}", field2source[n]);
|
||||
index--;
|
||||
for (int iz = nzlo_in; iz <= nzhi_in; iz++)
|
||||
for (int iy = nylo_in; iy <= nyhi_in; iy++)
|
||||
|
||||
@ -45,13 +45,15 @@ static constexpr int OFFSET = 16384;
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg),
|
||||
which(nullptr), argindex(nullptr), ids(nullptr),
|
||||
value2index(nullptr), value2grid(nullptr), value2data(nullptr),
|
||||
grid2d(nullptr), grid3d(nullptr),
|
||||
grid_buf1(nullptr), grid_buf2(nullptr)
|
||||
Fix(lmp, narg, arg), id_bias(nullptr), which(nullptr), argindex(nullptr), ids(nullptr),
|
||||
value2index(nullptr), value2grid(nullptr), value2data(nullptr), grid2d(nullptr), grid3d(nullptr),
|
||||
grid_buf1(nullptr), grid_buf2(nullptr), grid_output(nullptr), grid_sample(nullptr),
|
||||
grid_nfreq(nullptr), grid_running(nullptr), grid_window(nullptr), grid2d_previous(nullptr),
|
||||
grid3d_previous(nullptr), grid_sample_previous(nullptr), grid_nfreq_previous(nullptr),
|
||||
grid_running_previous(nullptr), grid_window_previous(nullptr), bin(nullptr), skip(nullptr),
|
||||
vresult(nullptr)
|
||||
{
|
||||
if (narg < 10) error->all(FLERR,"Illegal fix ave/grid command");
|
||||
if (narg < 10) utils::missing_cmd_args(FLERR,"fix ave/grid", error);
|
||||
|
||||
pergrid_flag = 1;
|
||||
nevery = utils::inumeric(FLERR,arg[3],false,lmp);
|
||||
@ -258,7 +260,7 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
dimension = domain->dimension;
|
||||
|
||||
if (nxgrid < 1 || nygrid < 1 || nzgrid < 1)
|
||||
if ((nxgrid < 1) || (nygrid < 1) || (nzgrid < 1))
|
||||
error->all(FLERR,"Invalid fix ave/grid grid size");
|
||||
if (dimension == 2 && nzgrid != 1)
|
||||
error->all(FLERR,"Fix ave/grid grid Nz must be 1 for 2d simulation");
|
||||
@ -282,17 +284,13 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
|
||||
if (icompute < 0)
|
||||
error->all(FLERR,"Compute ID for fix ave/grid does not exist");
|
||||
if (modify->compute[icompute]->peratom_flag == 0)
|
||||
error->all(FLERR,
|
||||
"Fix ave/atom compute does not calculate per-atom values");
|
||||
error->all(FLERR, "Fix ave/atom compute does not calculate per-atom values");
|
||||
if (argindex[i] == 0 &&
|
||||
modify->compute[icompute]->size_peratom_cols != 0)
|
||||
error->all(FLERR,"Fix ave/atom compute does not "
|
||||
"calculate a per-atom vector");
|
||||
error->all(FLERR,"Fix ave/atom compute does not calculate a per-atom vector");
|
||||
if (argindex[i] && modify->compute[icompute]->size_peratom_cols == 0)
|
||||
error->all(FLERR,"Fix ave/atom compute does not "
|
||||
"calculate a per-atom array");
|
||||
if (argindex[i] &&
|
||||
argindex[i] > modify->compute[icompute]->size_peratom_cols)
|
||||
error->all(FLERR,"Fix ave/atom compute does not calculate a per-atom array");
|
||||
if (argindex[i] && argindex[i] > modify->compute[icompute]->size_peratom_cols)
|
||||
error->all(FLERR,"Fix ave/atom compute array is accessed out-of-range");
|
||||
|
||||
} else if (which[i] == ArgInfo::FIX) {
|
||||
@ -302,16 +300,13 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
|
||||
if (modify->fix[ifix]->peratom_flag == 0)
|
||||
error->all(FLERR,"Fix ave/atom fix does not calculate per-atom values");
|
||||
if (argindex[i] == 0 && modify->fix[ifix]->size_peratom_cols != 0)
|
||||
error->all(FLERR,
|
||||
"Fix ave/atom fix does not calculate a per-atom vector");
|
||||
error->all(FLERR, "Fix ave/atom fix does not calculate a per-atom vector");
|
||||
if (argindex[i] && modify->fix[ifix]->size_peratom_cols == 0)
|
||||
error->all(FLERR,
|
||||
"Fix ave/atom fix does not calculate a per-atom array");
|
||||
error->all(FLERR, "Fix ave/atom fix does not calculate a per-atom array");
|
||||
if (argindex[i] && argindex[i] > modify->fix[ifix]->size_peratom_cols)
|
||||
error->all(FLERR,"Fix ave/atom fix array is accessed out-of-range");
|
||||
if (nevery % modify->fix[ifix]->peratom_freq)
|
||||
error->all(FLERR,
|
||||
"Fix for fix ave/atom not computed at compatible time");
|
||||
error->all(FLERR, "Fix for fix ave/atom not computed at compatible time");
|
||||
|
||||
} else if (which[i] == ArgInfo::VARIABLE) {
|
||||
int ivariable = input->variable->find(ids[i]);
|
||||
@ -1798,7 +1793,7 @@ void FixAveGrid::pack_reverse_grid(int /*which*/, void *vbuf, int nlist, int *li
|
||||
count = &grid_sample->count2d[nylo_out][nxlo_out];
|
||||
if (nvalues == 1) data = &grid_sample->vec2d[nylo_out][nxlo_out];
|
||||
else data = &grid_sample->array2d[nylo_out][nxlo_out][0];
|
||||
} else if (dimension == 3) {
|
||||
} else {
|
||||
count = &grid_sample->count3d[nzlo_out][nylo_out][nxlo_out];
|
||||
if (nvalues == 1) data = &grid_sample->vec3d[nzlo_out][nylo_out][nxlo_out];
|
||||
else data = &grid_sample->array3d[nzlo_out][nylo_out][nxlo_out][0];
|
||||
@ -1836,7 +1831,7 @@ void FixAveGrid::unpack_reverse_grid(int /*which*/, void *vbuf, int nlist, int *
|
||||
count = &grid_sample->count2d[nylo_out][nxlo_out];
|
||||
if (nvalues == 1) data = &grid_sample->vec2d[nylo_out][nxlo_out];
|
||||
else data = &grid_sample->array2d[nylo_out][nxlo_out][0];
|
||||
} else if (dimension == 3) {
|
||||
} else {
|
||||
count = &grid_sample->count3d[nzlo_out][nylo_out][nxlo_out];
|
||||
if (nvalues == 1) data = &grid_sample->vec3d[nzlo_out][nylo_out][nxlo_out];
|
||||
else data = &grid_sample->array3d[nzlo_out][nylo_out][nxlo_out][0];
|
||||
@ -1921,7 +1916,7 @@ int FixAveGrid::pack_one_grid(GridData *grid, int index, double *buf)
|
||||
count = &grid->count2d[nylo_out_previous][nxlo_out_previous];
|
||||
if (nvalues == 1) data = &grid->vec2d[nylo_out_previous][nxlo_out_previous];
|
||||
else data = &grid->array2d[nylo_out_previous][nxlo_out_previous][0];
|
||||
} else if (dimension == 3) {
|
||||
} else {
|
||||
count = &grid->count3d[nzlo_out_previous][nylo_out_previous][nxlo_out_previous];
|
||||
if (nvalues == 1) data = &grid->vec3d[nzlo_out_previous][nylo_out_previous][nxlo_out_previous];
|
||||
else data = &grid->array3d[nzlo_out_previous][nylo_out_previous][nxlo_out_previous][0];
|
||||
@ -1952,7 +1947,7 @@ int FixAveGrid::unpack_one_grid(double *buf, GridData *grid, int index)
|
||||
count = &grid->count2d[nylo_out][nxlo_out];
|
||||
if (nvalues == 1) data = &grid->vec2d[nylo_out][nxlo_out];
|
||||
else data = &grid->array2d[nylo_out][nxlo_out][0];
|
||||
} else if (dimension == 3) {
|
||||
} else {
|
||||
count = &grid->count3d[nzlo_out][nylo_out][nxlo_out];
|
||||
if (nvalues == 1) data = &grid->vec3d[nzlo_out][nylo_out][nxlo_out];
|
||||
else data = &grid->array3d[nzlo_out][nylo_out][nxlo_out][0];
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -17,12 +16,12 @@
|
||||
#include "comm.h"
|
||||
#include "domain.h"
|
||||
#include "error.h"
|
||||
#include "irregular.h"
|
||||
#include "pair.h"
|
||||
#include "kspace.h"
|
||||
#include "fix.h"
|
||||
#include "irregular.h"
|
||||
#include "kspace.h"
|
||||
#include "math_extra.h"
|
||||
#include "memory.h"
|
||||
#include "pair.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
@ -47,7 +46,11 @@ static constexpr int OFFSET = 16384;
|
||||
gnx,gny,gnz = global grid size
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Grid2d::Grid2d(LAMMPS *lmp, MPI_Comm gcomm, int gnx, int gny) : Pointers(lmp)
|
||||
Grid2d::Grid2d(LAMMPS *lmp, MPI_Comm gcomm, int gnx, int gny) :
|
||||
Pointers(lmp), swap(nullptr), requests(nullptr), srequest(nullptr), rrequest(nullptr),
|
||||
sresponse(nullptr), rresponse(nullptr), send(nullptr), recv(nullptr), copy(nullptr),
|
||||
send_remap(nullptr), recv_remap(nullptr), overlap_procs(nullptr), xsplit(nullptr),
|
||||
ysplit(nullptr), zsplit(nullptr), grid2proc(nullptr), rcbinfo(nullptr), overlap_list(nullptr)
|
||||
{
|
||||
gridcomm = gcomm;
|
||||
MPI_Comm_rank(gridcomm, &me);
|
||||
@ -81,10 +84,13 @@ Grid2d::Grid2d(LAMMPS *lmp, MPI_Comm gcomm, int gnx, int gny) : Pointers(lmp)
|
||||
ghost indices can extend < 0 or >= N
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Grid2d::Grid2d(LAMMPS *lmp, MPI_Comm gcomm, int gnx, int gny,
|
||||
int ixlo, int ixhi, int iylo, int iyhi,
|
||||
int oxlo, int oxhi, int oylo, int oyhi) :
|
||||
Pointers(lmp)
|
||||
Grid2d::Grid2d(LAMMPS *lmp, MPI_Comm gcomm, int gnx, int gny, int ixlo, int ixhi, int iylo,
|
||||
int iyhi, int oxlo, int oxhi, int oylo, int oyhi) :
|
||||
Pointers(lmp),
|
||||
swap(nullptr), requests(nullptr), srequest(nullptr), rrequest(nullptr), sresponse(nullptr),
|
||||
rresponse(nullptr), send(nullptr), recv(nullptr), copy(nullptr), send_remap(nullptr),
|
||||
recv_remap(nullptr), overlap_procs(nullptr), xsplit(nullptr), ysplit(nullptr), zsplit(nullptr),
|
||||
grid2proc(nullptr), rcbinfo(nullptr), overlap_list(nullptr)
|
||||
{
|
||||
gridcomm = gcomm;
|
||||
MPI_Comm_rank(gridcomm, &me);
|
||||
@ -129,12 +135,10 @@ Grid2d::~Grid2d()
|
||||
|
||||
// tiled comm data structs
|
||||
|
||||
for (int i = 0; i < nsend; i++)
|
||||
memory->destroy(send[i].packlist);
|
||||
for (int i = 0; i < nsend; i++) memory->destroy(send[i].packlist);
|
||||
memory->sfree(send);
|
||||
|
||||
for (int i = 0; i < nrecv; i++)
|
||||
memory->destroy(recv[i].unpacklist);
|
||||
for (int i = 0; i < nrecv; i++) memory->destroy(recv[i].unpacklist);
|
||||
memory->sfree(recv);
|
||||
|
||||
for (int i = 0; i < ncopy; i++) {
|
||||
@ -223,8 +227,10 @@ void Grid2d::set_shift_atom(double shift_lo, double shift_hi)
|
||||
|
||||
void Grid2d::set_yfactor(double factor)
|
||||
{
|
||||
if (factor == 1.0) yextra = 0;
|
||||
else yextra = 1;
|
||||
if (factor == 1.0)
|
||||
yextra = 0;
|
||||
else
|
||||
yextra = 1;
|
||||
yfactor = factor;
|
||||
}
|
||||
|
||||
@ -269,10 +275,9 @@ int Grid2d::identical(Grid2d *grid2)
|
||||
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;
|
||||
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);
|
||||
@ -324,8 +329,8 @@ void Grid2d::get_bounds_ghost(int &xlo, int &xhi, int &ylo, int &yhi)
|
||||
since no grid comm is done across non-periodic boundaries
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Grid2d::setup_grid(int &ixlo, int &ixhi, int &iylo, int &iyhi,
|
||||
int &oxlo, int &oxhi, int &oylo, int &oyhi)
|
||||
void Grid2d::setup_grid(int &ixlo, int &ixhi, int &iylo, int &iyhi, int &oxlo, int &oxhi, int &oylo,
|
||||
int &oyhi)
|
||||
{
|
||||
// owned grid cells = those whose grid point is within proc subdomain
|
||||
// shift_grid = 0.5 for grid point at cell center, 0.0 for lower-left corner
|
||||
@ -379,8 +384,7 @@ void Grid2d::initialize()
|
||||
// error check on size of grid stored by this proc
|
||||
|
||||
bigint total = (bigint) (outxhi - outxlo + 1) * (outyhi - outylo + 1);
|
||||
if (total > MAXSMALLINT)
|
||||
error->one(FLERR, "Too many owned+ghost grid2d points");
|
||||
if (total > MAXSMALLINT) error->one(FLERR, "Too many owned+ghost grid2d points");
|
||||
|
||||
// default = caller grid is allocated to ghost grid
|
||||
// used when computing pack/unpack lists in indices()
|
||||
@ -437,8 +441,8 @@ void Grid2d::initialize()
|
||||
2 if test equalties insure a consistent decision as to which proc owns it
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Grid2d::partition_grid(int ngrid, double fraclo, double frachi,
|
||||
double shift, int extra, int &lo, int &hi)
|
||||
void Grid2d::partition_grid(int ngrid, double fraclo, double frachi, double shift, int extra,
|
||||
int &lo, int &hi)
|
||||
{
|
||||
if (extra == 0) {
|
||||
lo = static_cast<int>(fraclo * ngrid);
|
||||
@ -453,6 +457,7 @@ void Grid2d::partition_grid(int ngrid, double fraclo, double frachi,
|
||||
}
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
extend ghost grid cells in each direction beyond owned grid
|
||||
indices into the global grid range from 0 to N-1 in each dim
|
||||
|
||||
@ -48,7 +48,11 @@ static constexpr int OFFSET = 16384;
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Grid3d::Grid3d(LAMMPS *lmp, MPI_Comm gcomm, int gnx, int gny, int gnz) :
|
||||
Pointers(lmp)
|
||||
Pointers(lmp), swap(nullptr), requests(nullptr), srequest(nullptr), rrequest(nullptr),
|
||||
sresponse(nullptr), rresponse(nullptr), send(nullptr), recv(nullptr), copy(nullptr),
|
||||
send_remap(nullptr), recv_remap(nullptr), overlap_procs(nullptr), xsplit(nullptr),
|
||||
ysplit(nullptr), zsplit(nullptr), grid2proc(nullptr), rcbinfo(nullptr), overlap_list(nullptr)
|
||||
|
||||
{
|
||||
gridcomm = gcomm;
|
||||
MPI_Comm_rank(gridcomm,&me);
|
||||
@ -87,7 +91,10 @@ Grid3d::Grid3d(LAMMPS *lmp, MPI_Comm gcomm, int gnx, int gny, int gnz) :
|
||||
Grid3d::Grid3d(LAMMPS *lmp, MPI_Comm gcomm, int gnx, int gny, int gnz,
|
||||
int ixlo, int ixhi, int iylo, int iyhi, int izlo, int izhi,
|
||||
int oxlo, int oxhi, int oylo, int oyhi, int ozlo, int ozhi) :
|
||||
Pointers(lmp)
|
||||
Pointers(lmp), swap(nullptr), requests(nullptr), srequest(nullptr), rrequest(nullptr),
|
||||
sresponse(nullptr), rresponse(nullptr), send(nullptr), recv(nullptr), copy(nullptr),
|
||||
send_remap(nullptr), recv_remap(nullptr), overlap_procs(nullptr), xsplit(nullptr),
|
||||
ysplit(nullptr), zsplit(nullptr), grid2proc(nullptr), rcbinfo(nullptr), overlap_list(nullptr)
|
||||
{
|
||||
gridcomm = gcomm;
|
||||
MPI_Comm_rank(gridcomm,&me);
|
||||
|
||||
Reference in New Issue
Block a user