use auto type when assigning from cast or using new

This commit is contained in:
Axel Kohlmeyer
2022-04-10 18:16:36 -04:00
parent 6071376d42
commit 39b316729b
365 changed files with 1195 additions and 1233 deletions

View File

@ -290,7 +290,7 @@ multiple LAMMPS instances concurrently or sequentially. See
void lammps_close(void *handle)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
delete lmp;
}
@ -440,7 +440,7 @@ and :cpp:func:`Input::file()<void LAMMPS_NS::Input::file()>`.
void lammps_file(void *handle, const char *filename)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -477,7 +477,7 @@ passing a string without a command.
char *lammps_command(void *handle, const char *cmd)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
char *result = nullptr;
BEGIN_CAPTURE
@ -548,7 +548,7 @@ executing.
void lammps_commands_string(void *handle, const char *str)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
// copy str and convert from CR-LF (DOS-style) to LF (Unix style) line
int n = strlen(str);
@ -624,9 +624,9 @@ the size of a ``bigint`` integer.
double lammps_get_natoms(void *handle)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
double natoms = static_cast<double>(lmp->atom->natoms);
auto natoms = static_cast<double>(lmp->atom->natoms);
if (natoms > 9.0e15) return 0; // TODO:XXX why not -1?
return natoms;
}
@ -650,7 +650,7 @@ a ``double``, so it can also return information that is computed on-the-fly.
double lammps_get_thermo(void *handle, const char *keyword)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
double dval = 0.0;
BEGIN_CAPTURE
@ -690,7 +690,7 @@ void lammps_extract_box(void *handle, double *boxlo, double *boxhi,
double *xy, double *yz, double *xz,
int *pflags, int *boxflag)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
Domain *domain = lmp->domain;
BEGIN_CAPTURE
@ -752,7 +752,7 @@ are created.
void lammps_reset_box(void *handle, double *boxlo, double *boxhi,
double xy, double yz, double xz)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
Domain *domain = lmp->domain;
BEGIN_CAPTURE
@ -813,7 +813,7 @@ system it will be set to zero.
void lammps_memory_usage(void *handle, double *meminfo)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
Info info(lmp);
info.get_memory_info(meminfo);
}
@ -993,7 +993,7 @@ not recognized, the function returns -1.
int lammps_extract_setting(void *handle, const char *keyword)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
// This can be customized by adding keywords and documenting them in the section above.
if (strcmp(keyword,"bigint") == 0) return sizeof(bigint);
@ -1438,7 +1438,7 @@ report the "native" data type. The following tables are provided:
void *lammps_extract_global(void *handle, const char *name)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
if (strcmp(name,"units") == 0) return (void *) lmp->update->unit_style;
if (strcmp(name,"dt") == 0) return (void *) &lmp->update->dt;
@ -1450,7 +1450,7 @@ void *lammps_extract_global(void *handle, const char *name)
if (strcmp(name,"atimestep") == 0) return (void *) &lmp->update->atimestep;
if (utils::strmatch(lmp->update->integrate_style,"^respa")) {
Respa *respa = (Respa *)lmp->update->integrate;
auto respa = dynamic_cast<Respa *>(lmp->update->integrate);
if (strcmp(name,"respa_levels") == 0) return (void *) &respa->nlevels;
if (strcmp(name,"respa_dt") == 0) return (void *) respa->step;
}
@ -1537,7 +1537,7 @@ to then decide how to cast the (void*) pointer and access the data.
int lammps_extract_atom_datatype(void *handle, const char *name)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
return lmp->atom->extract_datatype(name);
}
@ -1571,7 +1571,7 @@ of the :cpp:func:`Atom::extract() <LAMMPS_NS::Atom::extract>` function.
void *lammps_extract_atom(void *handle, const char *name)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
return lmp->atom->extract(name);
}
@ -1685,7 +1685,7 @@ lists the available options.
void *lammps_extract_compute(void *handle, const char *id, int style, int type)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -1871,7 +1871,7 @@ The following table lists the available options.
void *lammps_extract_fix(void *handle, const char *id, int style, int type,
int nrow, int ncol)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -1881,19 +1881,19 @@ void *lammps_extract_fix(void *handle, const char *id, int style, int type,
if (style == LMP_STYLE_GLOBAL) {
if (type == LMP_TYPE_SCALAR) {
if (!fix->scalar_flag) return nullptr;
double *dptr = (double *) malloc(sizeof(double));
auto dptr = (double *) malloc(sizeof(double));
*dptr = fix->compute_scalar();
return (void *) dptr;
}
if (type == LMP_TYPE_VECTOR) {
if (!fix->vector_flag) return nullptr;
double *dptr = (double *) malloc(sizeof(double));
auto dptr = (double *) malloc(sizeof(double));
*dptr = fix->compute_vector(nrow);
return (void *) dptr;
}
if (type == LMP_TYPE_ARRAY) {
if (!fix->array_flag) return nullptr;
double *dptr = (double *) malloc(sizeof(double));
auto dptr = (double *) malloc(sizeof(double));
*dptr = fix->compute_array(nrow,ncol);
return (void *) dptr;
}
@ -1995,7 +1995,7 @@ a char pointer.
void *lammps_extract_variable(void *handle, const char *name, const char *group)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -2003,7 +2003,7 @@ void *lammps_extract_variable(void *handle, const char *name, const char *group)
if (ivar < 0) return nullptr;
if (lmp->input->variable->equalstyle(ivar)) {
double *dptr = (double *) malloc(sizeof(double));
auto dptr = (double *) malloc(sizeof(double));
*dptr = lmp->input->variable->compute_equal(ivar);
return (void *) dptr;
} else if (lmp->input->variable->atomstyle(ivar)) {
@ -2011,7 +2011,7 @@ void *lammps_extract_variable(void *handle, const char *name, const char *group)
int igroup = lmp->group->find(group);
if (igroup < 0) return nullptr;
int nlocal = lmp->atom->nlocal;
double *vector = (double *) malloc(nlocal*sizeof(double));
auto vector = (double *) malloc(nlocal*sizeof(double));
lmp->input->variable->compute_atom(ivar,igroup,vector,1,0);
return (void *) vector;
} else {
@ -2039,7 +2039,7 @@ void *lammps_extract_variable(void *handle, const char *name, const char *group)
*/
int lammps_set_variable(void *handle, char *name, char *str)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
int err = -1;
BEGIN_CAPTURE
@ -2078,7 +2078,7 @@ int lammps_set_variable(void *handle, char *name, char *str)
void lammps_gather_atoms(void *handle, char *name, int type, int count, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -2213,7 +2213,7 @@ void lammps_gather_atoms(void *handle, char *name, int type, int count, void *da
void lammps_gather_atoms_concat(void *handle, char *name, int type, int count, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -2362,7 +2362,7 @@ void lammps_gather_atoms_concat(void *handle, char *name, int type, int count, v
void lammps_gather_atoms_subset(void *handle, char *name, int type, int count,
int ndata, int *ids, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -2500,7 +2500,7 @@ void lammps_gather_atoms_subset(void *handle, char *name, int type, int count,
void lammps_scatter_atoms(void *handle, char *name, int type, int count, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -2576,7 +2576,7 @@ void lammps_scatter_atoms(void *handle, char *name, int type, int count, void *d
double **array = nullptr;
if (count == 1) vector = (double *) vptr;
else array = (double **) vptr;
double *dptr = (double *) data;
auto dptr = (double *) data;
if (count == 1) {
for (i = 0; i < natoms; i++)
@ -2619,7 +2619,7 @@ void lammps_scatter_atoms(void *handle, char *name, int type, int count, void *d
void lammps_scatter_atoms_subset(void *handle, char *name, int type, int count,
int ndata, int *ids, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -2699,7 +2699,7 @@ void lammps_scatter_atoms_subset(void *handle, char *name, int type, int count,
double **array = nullptr;
if (count == 1) vector = (double *) vptr;
else array = (double **) vptr;
double *dptr = (double *) data;
auto dptr = (double *) data;
if (count == 1) {
for (i = 0; i < ndata; i++) {
@ -2800,7 +2800,7 @@ Below is a brief C code demonstrating accessing this collected bond information.
void lammps_gather_bonds(void *handle, void *data)
{
LAMMPS *lmp = (LAMMPS *)handle;
auto lmp = (LAMMPS *)handle;
BEGIN_CAPTURE {
void *val = lammps_extract_global(handle,"nbonds");
bigint nbonds = *(bigint *)val;
@ -2861,7 +2861,7 @@ void lammps_gather_bonds(void *handle, void *data)
void lammps_gather(void *handle, char *name, int type, int count, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -3096,7 +3096,7 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data)
void lammps_gather_concat(void *handle, char *name, int type, int count, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -3350,7 +3350,7 @@ void lammps_gather_subset(void *handle, char *name,
int type, int count,
int ndata, int *ids, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -3596,7 +3596,7 @@ void lammps_gather_subset(void *handle, char *name,
void lammps_scatter(void *handle, char *name, int type, int count, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -3767,7 +3767,7 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data)
double **array = nullptr;
if (count == 1) vector = (double *) vptr;
else array = (double **) vptr;
double *dptr = (double *) data;
auto dptr = (double *) data;
if (count == 1) {
for (i = 0; i < natoms; i++)
@ -3814,7 +3814,7 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data)
void lammps_scatter_subset(void *handle, char *name,int type, int count,
int ndata, int *ids, void *data)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -3991,7 +3991,7 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count,
double **array = nullptr;
if (count == 1) vector = (double *) vptr;
else array = (double **) vptr;
double *dptr = (double *) data;
auto dptr = (double *) data;
if (count == 1) {
for (i = 0; i < ndata; i++) {
@ -4074,7 +4074,7 @@ int lammps_create_atoms(void *handle, int n, const tagint *id, const int *type,
const double *x, const double *v, const imageint *image,
int bexpand)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
bigint natoms_prev = lmp->atom->natoms;
BEGIN_CAPTURE
@ -4196,7 +4196,7 @@ int lammps_create_atoms(void *handle, int n, const tagint *id, const int *type,
* \return return neighbor list index if found, otherwise -1 */
int lammps_find_pair_neighlist(void *handle, const char *style, int exact, int nsub, int reqid) {
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
Pair *pair = lmp->force->pair_match(style, exact, nsub);
if (pair != nullptr) {
@ -4226,7 +4226,7 @@ int lammps_find_pair_neighlist(void *handle, const char *style, int exact, int n
* \return return neighbor list index if found, otherwise -1 */
int lammps_find_fix_neighlist(void *handle, const char *id, int reqid) {
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
auto fix = lmp->modify->get_fix_by_id(id);
if (!fix) return -1;
@ -4255,7 +4255,7 @@ int lammps_find_fix_neighlist(void *handle, const char *id, int reqid) {
* \return return neighbor list index if found, otherwise -1 */
int lammps_find_compute_neighlist(void* handle, const char *id, int reqid) {
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
auto compute = lmp->modify->get_compute_by_id(id);
if (!compute) return -1;
@ -4279,7 +4279,7 @@ int lammps_find_compute_neighlist(void* handle, const char *id, int reqid) {
* not a valid index
*/
int lammps_neighlist_num_elements(void *handle, int idx) {
LAMMPS * lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
Neighbor * neighbor = lmp->neighbor;
if (idx < 0 || idx >= neighbor->nlist) {
@ -4304,7 +4304,7 @@ int lammps_neighlist_num_elements(void *handle, int idx) {
* \param[out] neighbors pointer to array of neighbor atom local indices or NULL */
void lammps_neighlist_element_neighbors(void *handle, int idx, int element, int *iatom, int *numneigh, int **neighbors) {
LAMMPS * lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
Neighbor * neighbor = lmp->neighbor;
*iatom = -1;
*numneigh = 0;
@ -4348,7 +4348,7 @@ growing with every new LAMMPS release.
int lammps_version(void *handle)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
return lmp->num_ver;
}
@ -4662,7 +4662,7 @@ Valid categories are: *atom*\ , *integrate*\ , *minimize*\ ,
* \return 1 if included, 0 if not.
*/
int lammps_has_style(void *handle, const char *category, const char *name) {
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
Info info(lmp);
return info.has_style(category, name) ? 1 : 0;
}
@ -4683,7 +4683,7 @@ categories.
* \return number of styles in category
*/
int lammps_style_count(void *handle, const char *category) {
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
Info info(lmp);
return info.get_available_styles(category).size();
}
@ -4709,7 +4709,7 @@ int lammps_style_count(void *handle, const char *category) {
*/
int lammps_style_name(void *handle, const char *category, int idx,
char *buffer, int buf_size) {
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
Info info(lmp);
auto styles = info.get_available_styles(category);
@ -4741,7 +4741,7 @@ the given *name* exists. Valid categories are: *compute*\ , *dump*\ ,
* \return 1 if included, 0 if not.
*/
int lammps_has_id(void *handle, const char *category, const char *name) {
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
if (strcmp(category,"compute") == 0) {
int ncompute = lmp->modify->ncompute;
@ -4806,7 +4806,7 @@ categories.
* \return number of IDs in category
*/
int lammps_id_count(void *handle, const char *category) {
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
if (strcmp(category,"compute") == 0) {
return lmp->modify->ncompute;
} else if (strcmp(category,"dump") == 0) {
@ -4850,7 +4850,7 @@ set to an empty string, otherwise 1.
*/
int lammps_id_name(void *handle, const char *category, int idx,
char *buffer, int buf_size) {
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
if (strcmp(category,"compute") == 0) {
if ((idx >=0) && (idx < lmp->modify->ncompute)) {
@ -5065,8 +5065,8 @@ external code.
void lammps_set_fix_external_callback(void *handle, const char *id, FixExternalFnPtr funcptr, void *ptr)
{
LAMMPS *lmp = (LAMMPS *) handle;
FixExternal::FnPtr callback = (FixExternal::FnPtr) funcptr;
auto lmp = (LAMMPS *) handle;
auto callback = (FixExternal::FnPtr) funcptr;
BEGIN_CAPTURE
{
@ -5076,7 +5076,7 @@ void lammps_set_fix_external_callback(void *handle, const char *id, FixExternalF
if (strcmp("external",fix->style) != 0)
lmp->error->all(FLERR,"Fix '{}' is not of style 'external'", id);
FixExternal *fext = (FixExternal *) fix;
auto fext = dynamic_cast<FixExternal *>( fix);
fext->set_callback(callback, ptr);
}
END_CAPTURE
@ -5126,7 +5126,7 @@ external code.
double **lammps_fix_external_get_force(void *handle, const char *id)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
double **fexternal = nullptr;
BEGIN_CAPTURE
@ -5174,7 +5174,7 @@ external code.
void lammps_fix_external_set_energy_global(void *handle, const char *id, double eng)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -5184,7 +5184,7 @@ void lammps_fix_external_set_energy_global(void *handle, const char *id, double
if (strcmp("external",fix->style) != 0)
lmp->error->all(FLERR,"Fix '{}' is not of style external!", id);
FixExternal *fext = (FixExternal*) fix;
auto fext = dynamic_cast<FixExternal*>( fix);
fext->set_energy_global(eng);
}
END_CAPTURE
@ -5222,7 +5222,7 @@ external code.
void lammps_fix_external_set_virial_global(void *handle, const char *id, double *virial)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -5232,7 +5232,7 @@ void lammps_fix_external_set_virial_global(void *handle, const char *id, double
if (strcmp("external",fix->style) != 0)
lmp->error->all(FLERR,"Fix '{}' is not of style external!", id);
FixExternal * fext = (FixExternal*) fix;
auto fext = dynamic_cast<FixExternal*>( fix);
fext->set_virial_global(virial);
}
END_CAPTURE
@ -5270,7 +5270,7 @@ external code.
void lammps_fix_external_set_energy_peratom(void *handle, const char *id, double *eng)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -5280,7 +5280,7 @@ void lammps_fix_external_set_energy_peratom(void *handle, const char *id, double
if (strcmp("external",fix->style) != 0)
lmp->error->all(FLERR,"Fix '{}' is not of style external!", id);
FixExternal *fext = (FixExternal*) fix;
auto fext = dynamic_cast<FixExternal*>( fix);
fext->set_energy_peratom(eng);
}
END_CAPTURE
@ -5321,7 +5321,7 @@ external code.
void lammps_fix_external_set_virial_peratom(void *handle, const char *id, double **virial)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -5331,7 +5331,7 @@ void lammps_fix_external_set_virial_peratom(void *handle, const char *id, double
if (strcmp("external",fix->style) != 0)
lmp->error->all(FLERR,"Fix '{}' is not of style external!", id);
FixExternal * fext = (FixExternal*) fix;
auto fext = dynamic_cast<FixExternal*>( fix);
fext->set_virial_peratom(virial);
}
END_CAPTURE
@ -5365,7 +5365,7 @@ external code.
void lammps_fix_external_set_vector_length(void *handle, const char *id, int len)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -5375,7 +5375,7 @@ void lammps_fix_external_set_vector_length(void *handle, const char *id, int len
if (strcmp("external",fix->style) != 0)
lmp->error->all(FLERR,"Fix '{}' is not of style external!", id);
FixExternal *fext = (FixExternal*) fix;
auto fext = dynamic_cast<FixExternal*>( fix);
fext->set_vector_length(len);
}
END_CAPTURE
@ -5419,7 +5419,7 @@ external code.
void lammps_fix_external_set_vector(void *handle, const char *id, int idx, double val)
{
LAMMPS *lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
BEGIN_CAPTURE
{
@ -5429,7 +5429,7 @@ void lammps_fix_external_set_vector(void *handle, const char *id, int idx, doubl
if (strcmp("external",fix->style) != 0)
lmp->error->all(FLERR,"Fix '{}' is not of style external!", id);
FixExternal * fext = (FixExternal*) fix;
auto fext = dynamic_cast<FixExternal*>( fix);
fext->set_vector(idx, val);
}
END_CAPTURE
@ -5482,7 +5482,7 @@ void lammps_free(void *ptr)
int lammps_is_running(void *handle)
{
LAMMPS * lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
return lmp->update->whichflag;
}
@ -5495,7 +5495,7 @@ int lammps_is_running(void *handle)
void lammps_force_timeout(void *handle)
{
LAMMPS * lmp = (LAMMPS *) handle;
auto lmp = (LAMMPS *) handle;
return lmp->timer->force_timeout();
}