diff --git a/python/examples/demo.py b/python/examples/demo.py index 015fcba4cc..958ebcd04b 100755 --- a/python/examples/demo.py +++ b/python/examples/demo.py @@ -39,6 +39,9 @@ print("Energy from equal-style variable =",eng) vy = lmp.extract_variable("vy","all",1) print("Velocity component from atom-style variable =",vy[1]) +vol = lmp.get_thermo("vol") +print("Volume from get_thermo = ",vol) + natoms = lmp.get_natoms() print("Natoms from get_natoms =",natoms) diff --git a/python/lammps.py b/python/lammps.py index 597cf4fb57..1931e5e0c7 100644 --- a/python/lammps.py +++ b/python/lammps.py @@ -248,6 +248,13 @@ class lammps(object): if value: value = str(value).encode() return self.lib.lammps_set_variable(self.lmp,name,str(value)) + # return current value of thermo keyword + + def get_thermo(self,name): + if name: name = name.encode() + self.lib.lammps_get_thermo.restype = c_double + return self.lib.lammps_get_thermo(self.lmp,name) + # return total number of atoms in system def get_natoms(self): diff --git a/src/library.cpp b/src/library.cpp index a21ad90cb5..99fa2cee41 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -28,6 +28,8 @@ #include "input.h" #include "variable.h" #include "modify.h" +#include "output.h" +#include "thermo.h" #include "compute.h" #include "fix.h" #include "comm.h" @@ -387,6 +389,23 @@ int lammps_set_variable(void *ptr, char *name, char *str) return err; } +/* ---------------------------------------------------------------------- + return the current value of a thermo keyword as double. + unlike lammps_extract_global() this does not give access to the + storage of the data in question, and thus needs to be called + again to retrieve an updated value. The upshot is that it allows + accessing information that is only computed on-the-fly. +------------------------------------------------------------------------- */ + +double lammps_get_thermo(void *ptr, char *name) +{ + LAMMPS *lmp = (LAMMPS *) ptr; + double dval; + + lmp->output->thermo->evaluate_keyword(name,&dval); + return dval; +} + /* ---------------------------------------------------------------------- return the total number of atoms in the system useful before call to lammps_get_atoms() so can pre-allocate vector diff --git a/src/library.h b/src/library.h index 3bdeddbac4..8b7dc43f08 100644 --- a/src/library.h +++ b/src/library.h @@ -39,7 +39,9 @@ void *lammps_extract_fix(void *, char *, int, int, int, int); void *lammps_extract_variable(void *, char *, char *); int lammps_set_variable(void *, char *, char *); +double lammps_get_thermo(void *, char *); int lammps_get_natoms(void *); + void lammps_gather_atoms(void *, char *, int, int, void *); void lammps_scatter_atoms(void *, char *, int, int, void *);