Merge pull request #3349 from akohlmey/collected-small-changes

Collected small changes
This commit is contained in:
Axel Kohlmeyer
2022-07-18 16:39:42 -04:00
committed by GitHub
15 changed files with 117 additions and 72 deletions

View File

@ -685,7 +685,9 @@ of a run, according to this formula:
The run begins on startstep and ends on stopstep. Startstep and
stopstep can span multiple runs, using the *start* and *stop* keywords
of the :doc:`run <run>` command. See the :doc:`run <run>` command for
details of how to do this.
details of how to do this. If called in between runs or during a
:doc:`run 0 <run>` command, the ramp(x,y) function will return the
value of x.
The stagger(x,y) function uses the current timestep to generate a new
timestep. X,y > 0 and x > y are required. The generated timesteps
@ -781,10 +783,14 @@ according to this formula:
where dt = the timestep size.
The run begins on startstep. Startstep can span multiple runs, using
the *start* keyword of the :doc:`run <run>` command. See the
:doc:`run <run>` command for details of how to do this. Note that the
:doc:`thermo_style <thermo_style>` keyword elaplong =
timestep-startstep.
the *start* keyword of the :doc:`run <run>` command. See the :doc:`run
<run>` command for details of how to do this. Note that the
:doc:`thermo_style <thermo_style>` keyword elaplong = timestep-startstep.
If used between runs this function will return
the value according to the end of the last run or the value of x if
used before *any* runs. This function assumes the length of the time
step does not change and thus may not be used in combination with
:doc:`fix dt/reset <fix_dt_reset>`.
The swiggle(x,y,z) and cwiggle(x,y,z) functions each take 3 arguments:
x = value0, y = amplitude, z = period. They use the elapsed time to
@ -799,10 +805,14 @@ run, according to one of these formulas, where omega = 2 PI / period:
where dt = the timestep size.
The run begins on startstep. Startstep can span multiple runs, using
the *start* keyword of the :doc:`run <run>` command. See the
:doc:`run <run>` command for details of how to do this. Note that the
:doc:`thermo_style <thermo_style>` keyword elaplong =
timestep-startstep.
the *start* keyword of the :doc:`run <run>` command. See the :doc:`run
<run>` command for details of how to do this. Note that the
:doc:`thermo_style <thermo_style>` keyword elaplong = timestep-startstep.
If used between runs these functions will return
the value according to the end of the last run or the value of x if
used before *any* runs. These functions assume the length of the time
step does not change and thus may not be used in combination with
:doc:`fix dt/reset <fix_dt_reset>`.
----------

View File

@ -3742,6 +3742,7 @@ wallstyle
walltime
Waltham
Waroquier
Wataru
wavepacket
wB
Wbody

View File

@ -306,13 +306,13 @@ do
-A)
;;
#strip of -std=c++98 due to nvcc warnings and Tribits will place both -std=c++11 and -std=c++98
#strip off -std=c++98 due to nvcc warnings and Tribits will place both -std=c++11 and -std=c++98
-std=c++98|--std=c++98)
;;
#strip of pedantic because it produces endless warnings about #LINE added by the preprocessor
-pedantic|-Wpedantic|-ansi)
#strip off pedantic because it produces endless warnings about #LINE added by the preprocessor
-pedantic|-pedantic-errors|-Wpedantic|-ansi)
;;
#strip of -Woverloaded-virtual to avoid "cc1: warning: command line option -Woverloaded-virtual is valid for C++/ObjC++ but not for C"
#strip off -Woverloaded-virtual to avoid "cc1: warning: command line option -Woverloaded-virtual is valid for C++/ObjC++ but not for C"
-Woverloaded-virtual)
;;
#strip -Xcompiler because we add it

View File

@ -275,7 +275,7 @@ void FixGPU::init()
// also disallow GPU neighbor lists for hybrid styles
if (force->pair_match("^hybrid",0) != nullptr) {
auto hybrid = dynamic_cast<PairHybrid *>( force->pair);
auto hybrid = dynamic_cast<PairHybrid *>(force->pair);
for (int i = 0; i < hybrid->nstyles; i++)
if (!utils::strmatch(hybrid->keywords[i],"/gpu$"))
force->pair->no_virial_fdotr_compute = 1;

View File

@ -77,7 +77,7 @@ void FixNHGPU::remap()
double oldlo,oldhi;
double expfac;
auto * _noalias const x = (dbl3_t *) atom->x[0];
dbl3_t * _noalias const x = (dbl3_t *) atom->x[0];
int *mask = atom->mask;
int nlocal = atom->nlocal;
double *h = domain->h;
@ -414,7 +414,7 @@ void FixNHGPU::nh_v_press()
return;
}
auto * _noalias const v = (dbl3_t *)atom->v[0];
dbl3_t * _noalias const v = (dbl3_t *)atom->v[0];
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup) nlocal = atom->nfirst;

View File

@ -235,8 +235,8 @@ void ComputeGrid::set_grid_local()
double ComputeGrid::memory_usage()
{
double nbytes = size_array_rows * size_array_cols * sizeof(double); // grid
nbytes += size_array_rows * size_array_cols * sizeof(double); // gridall
nbytes += size_array_cols * ngridlocal * sizeof(double); // gridlocal
double nbytes = (double) size_array_rows * size_array_cols * sizeof(double); // grid
nbytes += (double) size_array_rows * size_array_cols * sizeof(double); // gridall
nbytes += (double) size_array_cols * ngridlocal * sizeof(double); // gridlocal
return nbytes;
}

View File

@ -265,6 +265,6 @@ void ComputeGridLocal::assign_coords()
double ComputeGridLocal::memory_usage()
{
int nbytes = size_local_rows * size_local_cols * sizeof(double); // gridlocal
double nbytes = (double) size_local_rows * size_local_cols * sizeof(double); // gridlocal
return nbytes;
}

View File

@ -292,7 +292,7 @@ void ComputeSNAGrid::compute_array()
}
}
memset(&grid[0][0], 0, size_array_rows * size_array_cols * sizeof(double));
memset(&grid[0][0], 0, sizeof(double) * size_array_rows * size_array_cols);
for (int iz = nzlo; iz <= nzhi; iz++)
for (int iy = nylo; iy <= nyhi; iy++)

View File

@ -1151,7 +1151,8 @@ void Dump::modify_params(int narg, char **arg)
}
}
if ((icol < 0) || (icol >= (int)keyword_user.size()))
error->all(FLERR, "Illegal thermo_modify command");
error->all(FLERR, "Incorrect dump_modify arguments: {} {} {}",
arg[iarg], arg[iarg+1], arg[iarg+2]);
keyword_user[icol] = arg[iarg+2];
iarg += 3;
}

View File

@ -34,9 +34,9 @@ using namespace LAMMPS_NS;
DumpLocal::DumpLocal(LAMMPS *lmp, int narg, char **arg) :
Dump(lmp, narg, arg),
label(nullptr), vtype(nullptr), vformat(nullptr), columns(nullptr), field2index(nullptr),
argindex(nullptr), id_compute(nullptr), compute(nullptr), id_fix(nullptr), fix(nullptr),
pack_choice(nullptr)
label(nullptr), vtype(nullptr), vformat(nullptr), columns(nullptr), columns_default(nullptr),
field2index(nullptr), argindex(nullptr), id_compute(nullptr), compute(nullptr),
id_fix(nullptr), fix(nullptr), pack_choice(nullptr)
{
if (narg == 5) error->all(FLERR,"No dump local arguments specified");
@ -87,25 +87,30 @@ DumpLocal::DumpLocal(LAMMPS *lmp, int narg, char **arg) :
// setup format strings
vformat = new char*[size_one];
std::string fdefault;
std::string cols;
for (int i = 0; i < size_one; i++) {
if (vtype[i] == Dump::INT) fdefault += "%d ";
else if (vtype[i] == Dump::DOUBLE) fdefault += "%g ";
if (vtype[i] == Dump::INT) cols += "%d ";
else if (vtype[i] == Dump::DOUBLE) cols += "%g ";
vformat[i] = nullptr;
}
format_default = utils::strdup(fdefault);
cols.resize(cols.size()-1);
format_default = utils::strdup(cols);
format_column_user = new char*[size_one];
for (int i = 0; i < size_one; i++) format_column_user[i] = nullptr;
// setup column string
std::string cols;
cols.clear();
keyword_user.resize(nfield);
for (int iarg = 0; iarg < nfield; iarg++) {
key2col[earg[iarg]] = iarg;
keyword_user[iarg].clear();
if (cols.size()) cols += " ";
cols += earg[iarg];
cols += " ";
}
columns = utils::strdup(cols);
columns_default = utils::strdup(cols);
// setup default label string
@ -143,6 +148,7 @@ DumpLocal::~DumpLocal()
delete[] format_column_user;
delete[] columns;
delete[] columns_default;
delete[] label;
}
@ -150,6 +156,19 @@ DumpLocal::~DumpLocal()
void DumpLocal::init_style()
{
// assemble ITEMS: column string from defaults and user values
delete[] columns;
std::string combined;
int icol = 0;
for (auto item : utils::split_words(columns_default)) {
if (combined.size()) combined += " ";
if (keyword_user[icol].size()) combined += keyword_user[icol];
else combined += item;
++icol;
}
columns = utils::strdup(combined);
if (sort_flag && sortcol == 0)
error->all(FLERR,"Dump local cannot sort by atom ID");

View File

@ -37,7 +37,8 @@ class DumpLocal : public Dump {
int *vtype; // type of each vector (INT, DOUBLE)
char **vformat; // format string for each vector element
char *columns; // column labels
char *columns; // column labels
char *columns_default;
int nfield; // # of keywords listed by user

View File

@ -77,7 +77,7 @@ vstore(nullptr), astore(nullptr), rbuf(nullptr)
else if (narg == 6) arrayflag = 1;
else tensorflag = 1;
nvalues = n2*n3;
nbytes = n2*n3 * sizeof(double);
nbytes = nvalues * sizeof(double);
}
vstore = nullptr;
@ -194,7 +194,7 @@ void FixStore::write_restart(FILE *fp)
rbuf[0] = n1;
rbuf[1] = n2;
if (vecflag) memcpy(&rbuf[2],vstore,n1*sizeof(double));
else if (arrayflag) memcpy(&rbuf[2],&astore[0][0],n1*n2*sizeof(double));
else if (arrayflag) memcpy(&rbuf[2],&astore[0][0],sizeof(double)*n1*n2);
int n = n1*n2 + 2;
if (comm->me == 0) {
@ -391,8 +391,8 @@ int FixStore::size_restart(int /*nlocal*/)
double FixStore::memory_usage()
{
double bytes = 0.0;
if (flavor == GLOBAL) bytes += n1*n2 * sizeof(double);
if (flavor == PERATOM) bytes += atom->nmax*n2*n3 * sizeof(double);
double bytes = (double) n1 * n2;
if (flavor == GLOBAL) bytes *= sizeof(double);
if (flavor == PERATOM) bytes *= atom->nmax * sizeof(double);
return bytes;
}

View File

@ -33,9 +33,9 @@ using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
PairHybrid::PairHybrid(LAMMPS *lmp) : Pair(lmp),
styles(nullptr), keywords(nullptr), multiple(nullptr), nmap(nullptr),
map(nullptr), special_lj(nullptr), special_coul(nullptr), compute_tally(nullptr), cutmax_style(nullptr)
PairHybrid::PairHybrid(LAMMPS *lmp) :
Pair(lmp), styles(nullptr), cutmax_style(nullptr), keywords(nullptr), multiple(nullptr),
nmap(nullptr), map(nullptr), special_lj(nullptr), special_coul(nullptr), compute_tally(nullptr)
{
nstyles = 0;

View File

@ -2561,9 +2561,14 @@ double Variable::collapse_tree(Tree *tree)
arg2 = collapse_tree(tree->second);
if (tree->first->type != VALUE || tree->second->type != VALUE) return 0.0;
tree->type = VALUE;
double delta = update->ntimestep - update->beginstep;
if (delta != 0.0) delta /= update->endstep - update->beginstep;
tree->value = arg1 + delta*(arg2-arg1);
if (update->whichflag == 0) {
tree->value = arg1;
} else {
double delta = update->ntimestep - update->beginstep;
if ((delta != 0.0) && (update->beginstep != update->endstep))
delta /= update->endstep - update->beginstep;
tree->value = arg1 + delta*(arg2-arg1);
}
return tree->value;
}
@ -2730,7 +2735,7 @@ double Variable::collapse_tree(Tree *tree)
tree->extra[0]->type != VALUE) return 0.0;
tree->type = VALUE;
if (arg3 == 0.0)
error->one(FLERR,"Invalid math function in variable formula");
error->one(FLERR,"Invalid swiggle(x,y,z) function in variable formula: z must be > 0");
double delta = update->ntimestep - update->beginstep;
double omega = 2.0*MY_PI/arg3;
tree->value = arg1 + arg2*sin(omega*delta*update->dt);
@ -2745,7 +2750,7 @@ double Variable::collapse_tree(Tree *tree)
tree->extra[0]->type != VALUE) return 0.0;
tree->type = VALUE;
if (arg3 == 0.0)
error->one(FLERR,"Invalid math function in variable formula");
error->one(FLERR,"Invalid cwiggle(x,y,z) function in variable formula: z must be > 0");
double delta = update->ntimestep - update->beginstep;
double omega = 2.0*MY_PI/arg3;
tree->value = arg1 + arg2*(1.0-cos(omega*delta*update->dt));
@ -2935,9 +2940,14 @@ double Variable::eval_tree(Tree *tree, int i)
if (tree->type == RAMP) {
arg1 = eval_tree(tree->first,i);
arg2 = eval_tree(tree->second,i);
double delta = update->ntimestep - update->beginstep;
if (delta != 0.0) delta /= update->endstep - update->beginstep;
arg = arg1 + delta*(arg2-arg1);
if (update->whichflag == 0) {
arg = arg1;
} else {
double delta = update->ntimestep - update->beginstep;
if ((delta != 0.0) && (update->beginstep != update->endstep))
delta /= update->endstep - update->beginstep;
arg = arg1 + delta*(arg2-arg1);
}
return arg;
}
@ -3054,7 +3064,7 @@ double Variable::eval_tree(Tree *tree, int i)
arg2 = eval_tree(tree->second,i);
arg3 = eval_tree(tree->extra[0],i);
if (arg3 == 0.0)
error->one(FLERR,"Invalid math function in variable formula");
error->one(FLERR,"Invalid swiggle(x,y,z) function in variable formula: z must be > 0");
double delta = update->ntimestep - update->beginstep;
double omega = 2.0*MY_PI/arg3;
arg = arg1 + arg2*sin(omega*delta*update->dt);
@ -3066,7 +3076,7 @@ double Variable::eval_tree(Tree *tree, int i)
arg2 = eval_tree(tree->second,i);
arg3 = eval_tree(tree->extra[0],i);
if (arg3 == 0.0)
error->one(FLERR,"Invalid math function in variable formula");
error->one(FLERR,"Invalid cwiggle(x,y,z) function in variable formula: z must be > 0");
double delta = update->ntimestep - update->beginstep;
double omega = 2.0*MY_PI/arg3;
arg = arg1 + arg2*(1.0-cos(omega*delta*update->dt));
@ -3445,14 +3455,17 @@ int Variable::math_function(char *word, char *contents, Tree **tree, Tree **tree
} else if (strcmp(word,"ramp") == 0) {
if (narg != 2)
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
if (update->whichflag == 0)
print_var_error(FLERR,"Cannot use ramp in variable formula between runs",ivar);
if (tree) newtree->type = RAMP;
else {
double delta = update->ntimestep - update->beginstep;
if (delta != 0.0) delta /= update->endstep - update->beginstep;
double value = value1 + delta*(value2-value1);
argstack[nargstack++] = value;
if (update->whichflag == 0) {
argstack[nargstack++] = value1;
} else {
double delta = update->ntimestep - update->beginstep;
if ((delta != 0.0) && (update->beginstep != update->endstep))
delta /= update->endstep - update->beginstep;
double value = value1 + delta*(value2-value1);
argstack[nargstack++] = value;
}
}
} else if (strcmp(word,"stagger") == 0) {
@ -3610,9 +3623,9 @@ int Variable::math_function(char *word, char *contents, Tree **tree, Tree **tree
} else if (strcmp(word,"vdisplace") == 0) {
if (narg != 2)
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
if (update->whichflag == 0)
print_var_error(FLERR,"Cannot use vdisplace in variable formula between runs",ivar);
print_var_error(FLERR,"Invalid vdisplace function in variable formula: must have 2 arguments",ivar);
if (modify->get_fix_by_style("dt/reset").size() > 0)
print_var_error(FLERR,"Must not use vdisplace(x,y) function with fix dt/reset",ivar);
if (tree) newtree->type = VDISPLACE;
else {
double delta = update->ntimestep - update->beginstep;
@ -3622,13 +3635,13 @@ int Variable::math_function(char *word, char *contents, Tree **tree, Tree **tree
} else if (strcmp(word,"swiggle") == 0) {
if (narg != 3)
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
if (update->whichflag == 0)
print_var_error(FLERR,"Cannot use swiggle in variable formula between runs",ivar);
if (tree) newtree->type = CWIGGLE;
print_var_error(FLERR,"Invalid swiggle function in variable formula: must have 3 arguments",ivar);
if (modify->get_fix_by_style("dt/reset").size() > 0)
print_var_error(FLERR,"Must not use swiggle(x,y,z) function with fix dt/reset",ivar);
if (tree) newtree->type = SWIGGLE;
else {
if (values[0] == 0.0)
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
print_var_error(FLERR,"Invalid swiggle(x,y,z) function in variable formula: z must be > 0",ivar);
double delta = update->ntimestep - update->beginstep;
double omega = 2.0*MY_PI/values[0];
double value = value1 + value2*sin(omega*delta*update->dt);
@ -3637,13 +3650,13 @@ int Variable::math_function(char *word, char *contents, Tree **tree, Tree **tree
} else if (strcmp(word,"cwiggle") == 0) {
if (narg != 3)
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
if (update->whichflag == 0)
print_var_error(FLERR,"Cannot use cwiggle in variable formula between runs",ivar);
print_var_error(FLERR,"Invalid cwiggle function in variable formula: must have 3 arguments",ivar);
if (modify->get_fix_by_style("dt/reset").size() > 0)
print_var_error(FLERR,"Must not use cwiggle(x,y,z) function with fix dt/reset",ivar);
if (tree) newtree->type = CWIGGLE;
else {
if (values[0] == 0.0)
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
print_var_error(FLERR,"Invalid cwiggle(x,y,z) function in variable formula: z must be > 0",ivar);
double delta = update->ntimestep - update->beginstep;
double omega = 2.0*MY_PI/values[0];
double value = value1 + value2*(1.0-cos(omega*delta*update->dt));

View File

@ -89,7 +89,7 @@ TEST_F(DumpLocalTest, run0)
ASSERT_EQ(utils::split_words(lines[5]).size(), 2);
ASSERT_EQ(utils::split_words(lines[6]).size(), 2);
ASSERT_EQ(utils::split_words(lines[7]).size(), 2);
ASSERT_THAT(lines[8], Eq("ITEM: ENTRIES index c_comp[1] "));
ASSERT_THAT(lines[8], Eq("ITEM: ENTRIES index c_comp[1]"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 2);
ASSERT_THAT(lines[9], Eq("1 1.18765 "));
delete_file(dump_file);
@ -103,7 +103,7 @@ TEST_F(DumpLocalTest, label_run0)
ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
ASSERT_THAT(lines[2], Eq("ITEM: NUMBER OF ELEMENTS"));
ASSERT_THAT(lines[8], Eq("ITEM: ELEMENTS index c_comp[1] "));
ASSERT_THAT(lines[8], Eq("ITEM: ELEMENTS index c_comp[1]"));
delete_file(dump_file);
}
@ -178,7 +178,7 @@ TEST_F(DumpLocalTest, no_buffer_run0)
ASSERT_EQ(utils::split_words(lines[5]).size(), 2);
ASSERT_EQ(utils::split_words(lines[6]).size(), 2);
ASSERT_EQ(utils::split_words(lines[7]).size(), 2);
ASSERT_THAT(lines[8], Eq("ITEM: ENTRIES index c_comp[1] "));
ASSERT_THAT(lines[8], Eq("ITEM: ENTRIES index c_comp[1]"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 2);
ASSERT_THAT(lines[9], Eq("1 1.18765 "));
delete_file(dump_file);