move version and num_ver from Universe to LAMMPS and make num_ver an int

This commit is contained in:
Axel Kohlmeyer
2020-09-19 11:32:53 -04:00
parent 56d9222156
commit 4c51a8ae57
17 changed files with 30 additions and 32 deletions

View File

@ -26,7 +26,6 @@ the ``delete`` operator. Here is a simple example:
.. code-block:: c++ .. code-block:: c++
#include "lammps.h" #include "lammps.h"
#include "universe.h"
#include <mpi.h> #include <mpi.h>
#include <iostream> #include <iostream>
@ -44,7 +43,7 @@ the ``delete`` operator. Here is a simple example:
// create LAMMPS instance // create LAMMPS instance
lmp = new LAMMPS_NS::LAMMPS(lmpargc, (char **)lmpargv, MPI_COMM_WORLD); lmp = new LAMMPS_NS::LAMMPS(lmpargc, (char **)lmpargv, MPI_COMM_WORLD);
// output numerical version string // output numerical version string
std::cout << "LAMMPS version: " << lmp->universe->num_ver << std::endl; std::cout << "LAMMPS version ID: " << lmp->num_ver << std::endl;
// delete LAMMPS instance // delete LAMMPS instance
delete lmp; delete lmp;
@ -53,8 +52,8 @@ the ``delete`` operator. Here is a simple example:
return 0; return 0;
} }
Please note that this requires to include the ``lammps.h`` header for accessing This minimal example only requires to include the ``lammps.h`` header
the members of the LAMMPS class and then the ``universe.h`` header for accessing the ``num_ver`` member of the :cpp:class:`Universe` class. file since it only accesses a non-pointer member of the LAMMPS class.
Executing LAMMPS commands Executing LAMMPS commands

View File

@ -313,7 +313,7 @@ void KimInit::do_init(char *model_name, char *user_units, char *model_units, KIM
mesg += "# For Simulator : "; mesg += "# For Simulator : ";
mesg += std::string(sim_name) + " " + sim_version + "\n"; mesg += std::string(sim_name) + " " + sim_version + "\n";
mesg += "# Running on : LAMMPS "; mesg += "# Running on : LAMMPS ";
mesg += universe->version; mesg += lmp->version;
mesg += "\n"; mesg += "\n";
mesg += "#\n"; mesg += "#\n";

View File

@ -337,9 +337,9 @@ void DumpAtomADIOS::init_style()
internal->io.DefineAttribute<std::string>("boundarystr", boundstr); internal->io.DefineAttribute<std::string>("boundarystr", boundstr);
internal->io.DefineAttribute<std::string>("LAMMPS/dump_style", "atom"); internal->io.DefineAttribute<std::string>("LAMMPS/dump_style", "atom");
internal->io.DefineAttribute<std::string>("LAMMPS/version", internal->io.DefineAttribute<std::string>("LAMMPS/version",
universe->version); lmp->version);
internal->io.DefineAttribute<std::string>("LAMMPS/num_ver", internal->io.DefineAttribute<std::string>("LAMMPS/num_ver",
universe->num_ver); std::to_string(lmp->num_ver));
internal->io.DefineVariable<uint64_t>( internal->io.DefineVariable<uint64_t>(
"nme", {adios2::LocalValueDim}); // local dimension variable "nme", {adios2::LocalValueDim}); // local dimension variable

View File

@ -424,9 +424,9 @@ void DumpCustomADIOS::init_style()
internal->io.DefineAttribute<std::string>("boundarystr", boundstr); internal->io.DefineAttribute<std::string>("boundarystr", boundstr);
internal->io.DefineAttribute<std::string>("LAMMPS/dump_style", "custom"); internal->io.DefineAttribute<std::string>("LAMMPS/dump_style", "custom");
internal->io.DefineAttribute<std::string>("LAMMPS/version", internal->io.DefineAttribute<std::string>("LAMMPS/version",
universe->version); lmp->version);
internal->io.DefineAttribute<std::string>("LAMMPS/num_ver", internal->io.DefineAttribute<std::string>("LAMMPS/num_ver",
universe->num_ver); std::to_string(lmp->num_ver));
internal->io.DefineVariable<uint64_t>( internal->io.DefineVariable<uint64_t>(
"nme", {adios2::LocalValueDim}); // local dimension variable "nme", {adios2::LocalValueDim}); // local dimension variable

View File

@ -512,7 +512,7 @@ void DumpNetCDF::openfile()
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "program", NCERR( nc_put_att_text(ncid, NC_GLOBAL, "program",
6, "LAMMPS") ); 6, "LAMMPS") );
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "programVersion", NCERR( nc_put_att_text(ncid, NC_GLOBAL, "programVersion",
strlen(universe->version), universe->version) ); strlen(lmp->version), lmp->version) );
// units // units
if (!strcmp(update->unit_style, "lj")) { if (!strcmp(update->unit_style, "lj")) {

View File

@ -497,7 +497,7 @@ void DumpNetCDFMPIIO::openfile()
NCERR( ncmpi_put_att_text(ncid, NC_GLOBAL, "program", NCERR( ncmpi_put_att_text(ncid, NC_GLOBAL, "program",
6, "LAMMPS") ); 6, "LAMMPS") );
NCERR( ncmpi_put_att_text(ncid, NC_GLOBAL, "programVersion", NCERR( ncmpi_put_att_text(ncid, NC_GLOBAL, "programVersion",
strlen(universe->version), universe->version) ); strlen(lmp->version), lmp->version) );
// units // units
if (!strcmp(update->unit_style, "lj")) { if (!strcmp(update->unit_style, "lj")) {

View File

@ -267,7 +267,7 @@ void Info::command(int narg, char **arg)
if (flags & CONFIG) { if (flags & CONFIG) {
fmt::print(out,"\nLAMMPS version: {} / {}\n", fmt::print(out,"\nLAMMPS version: {} / {}\n",
universe->version, universe->num_ver); lmp->version, lmp->num_ver);
if (lmp->has_git_info) if (lmp->has_git_info)
fmt::print(out,"Git info: {} / {} / {}\n", fmt::print(out,"Git info: {} / {} / {}\n",

View File

@ -114,6 +114,9 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
error = new Error(this); error = new Error(this);
universe = new Universe(this,communicator); universe = new Universe(this,communicator);
version = (const char *) LAMMPS_VERSION;
num_ver = utils::date2num(version);
clientserver = 0; clientserver = 0;
cslib = nullptr; cslib = nullptr;
cscomm = 0; cscomm = 0;
@ -460,7 +463,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
} }
if ((universe->me == 0) && !helpflag) if ((universe->me == 0) && !helpflag)
utils::logmesg(this,fmt::format("LAMMPS ({})\n",universe->version)); utils::logmesg(this,fmt::format("LAMMPS ({})\n",version));
// universe is one or more worlds, as setup by partition switch // universe is one or more worlds, as setup by partition switch
// split universe communicator into separate world communicators // split universe communicator into separate world communicators
@ -538,15 +541,15 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
if ((universe->me == 0) && (!helpflag)) { if ((universe->me == 0) && (!helpflag)) {
const char fmt[] = "LAMMPS ({})\nRunning on {} partitions of processors\n"; const char fmt[] = "LAMMPS ({})\nRunning on {} partitions of processors\n";
if (universe->uscreen) if (universe->uscreen)
fmt::print(universe->uscreen,fmt,universe->version,universe->nworlds); fmt::print(universe->uscreen,fmt,version,universe->nworlds);
if (universe->ulogfile) if (universe->ulogfile)
fmt::print(universe->ulogfile,fmt,universe->version,universe->nworlds); fmt::print(universe->ulogfile,fmt,version,universe->nworlds);
} }
if ((me == 0) && (!helpflag)) if ((me == 0) && (!helpflag))
utils::logmesg(this,fmt::format("LAMMPS ({})\nProcessor partition = {}\n", utils::logmesg(this,fmt::format("LAMMPS ({})\nProcessor partition = {}\n",
universe->version, universe->iworld)); version, universe->iworld));
} }
// check consistency of datatype settings in lmptype.h // check consistency of datatype settings in lmptype.h

View File

@ -38,6 +38,12 @@ class LAMMPS {
class Output *output; // thermo/dump/restart class Output *output; // thermo/dump/restart
class Timer *timer; // CPU timing info class Timer *timer; // CPU timing info
const char *version; // LAMMPS version string = date
int num_ver; // numeric version id derived from *version*
// that is constructed so that will be greater
// for newer versions in numeric or string
// value comparisons
MPI_Comm world; // MPI communicator MPI_Comm world; // MPI communicator
FILE *infile; // infile FILE *infile; // infile
FILE *screen; // screen output FILE *screen; // screen output

View File

@ -559,7 +559,7 @@ growing with every new LAMMPS release.
int lammps_version(void *handle) int lammps_version(void *handle)
{ {
LAMMPS *lmp = (LAMMPS *) handle; LAMMPS *lmp = (LAMMPS *) handle;
return atoi(lmp->universe->num_ver); return lmp->num_ver;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -621,7 +621,7 @@ void ReadRestart::header()
char *version = read_string(); char *version = read_string();
if (me == 0) if (me == 0)
utils::logmesg(lmp,fmt::format(" restart file = {}, LAMMPS = {}\n", utils::logmesg(lmp,fmt::format(" restart file = {}, LAMMPS = {}\n",
version,universe->version)); version,lmp->version));
delete [] version; delete [] version;
// we have no forward compatibility, thus exit with error // we have no forward compatibility, thus exit with error

View File

@ -30,11 +30,6 @@ using namespace LAMMPS_NS;
Universe::Universe(LAMMPS *lmp, MPI_Comm communicator) : Pointers(lmp) Universe::Universe(LAMMPS *lmp, MPI_Comm communicator) : Pointers(lmp)
{ {
version = (const char *) LAMMPS_VERSION;
auto tmp_ver = new char[10];
snprintf(tmp_ver,10,"%08d",utils::date2num(version));
num_ver = tmp_ver;
uworld = uorig = communicator; uworld = uorig = communicator;
MPI_Comm_rank(uworld,&me); MPI_Comm_rank(uworld,&me);
MPI_Comm_size(uworld,&nprocs); MPI_Comm_size(uworld,&nprocs);
@ -59,7 +54,6 @@ Universe::~Universe()
memory->destroy(procs_per_world); memory->destroy(procs_per_world);
memory->destroy(root_proc); memory->destroy(root_proc);
memory->destroy(uni2orig); memory->destroy(uni2orig);
delete [] num_ver;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

View File

@ -20,10 +20,6 @@ namespace LAMMPS_NS {
class Universe : protected Pointers { class Universe : protected Pointers {
public: public:
const char *version; // LAMMPS version string = date
const char *num_ver; // numeric version id derived from version that
// can be used for string or numeric comparisons
MPI_Comm uworld; // communicator for entire universe MPI_Comm uworld; // communicator for entire universe
int me,nprocs; // my place in universe int me,nprocs; // my place in universe

View File

@ -4713,7 +4713,7 @@ int Variable::is_constant(char *word)
double Variable::constant(char *word) double Variable::constant(char *word)
{ {
if (strcmp(word,"PI") == 0) return MY_PI; if (strcmp(word,"PI") == 0) return MY_PI;
if (strcmp(word,"version") == 0) return atof(universe->num_ver); if (strcmp(word,"version") == 0) return lmp->num_ver;
if (strcmp(word,"yes") == 0) return 1.0; if (strcmp(word,"yes") == 0) return 1.0;
if (strcmp(word,"no") == 0) return 0.0; if (strcmp(word,"no") == 0) return 0.0;
if (strcmp(word,"on") == 0) return 1.0; if (strcmp(word,"on") == 0) return 1.0;

View File

@ -95,7 +95,7 @@ void WriteCoeff::command(int narg, char **arg)
file+4, utils::getsyserror())); file+4, utils::getsyserror()));
fprintf(two,"# LAMMPS coeff file via write_coeff, version %s\n", fprintf(two,"# LAMMPS coeff file via write_coeff, version %s\n",
universe->version); lmp->version);
while(1) { while(1) {
int coeff_mode = REGULAR_MODE; int coeff_mode = REGULAR_MODE;

View File

@ -229,7 +229,7 @@ void WriteData::write(const std::string &file)
void WriteData::header() void WriteData::header()
{ {
fmt::print(fp,"LAMMPS data file via write_data, version {}, " fmt::print(fp,"LAMMPS data file via write_data, version {}, "
"timestep = {}\n\n",universe->version,update->ntimestep); "timestep = {}\n\n",lmp->version,update->ntimestep);
fmt::print(fp,"{} atoms\n{} atom types\n",atom->natoms,atom->ntypes); fmt::print(fp,"{} atoms\n{} atom types\n",atom->natoms,atom->ntypes);

View File

@ -424,7 +424,7 @@ void WriteRestart::write(std::string file)
void WriteRestart::header() void WriteRestart::header()
{ {
write_string(VERSION,universe->version); write_string(VERSION,lmp->version);
write_int(SMALLINT,sizeof(smallint)); write_int(SMALLINT,sizeof(smallint));
write_int(IMAGEINT,sizeof(imageint)); write_int(IMAGEINT,sizeof(imageint));
write_int(TAGINT,sizeof(tagint)); write_int(TAGINT,sizeof(tagint));