add support for extracting respa levels and timestep values

This commit is contained in:
Axel Kohlmeyer
2021-03-25 11:22:22 -04:00
committed by Richard Berger
parent e0fdd2ad89
commit b8f02d759a
3 changed files with 30 additions and 1 deletions

View File

@ -758,6 +758,8 @@ class lammps(object):
'sublo_lambda':3, 'subhi_lambda':3, 'periodicity':3 } 'sublo_lambda':3, 'subhi_lambda':3, 'periodicity':3 }
if name in vec_dict: if name in vec_dict:
veclen = vec_dict[name] veclen = vec_dict[name]
elif name == 'respa_dt':
veclen = self.extract_global('respa_levels',LAMMPS_INT)
else: else:
veclen = 1 veclen = 1

View File

@ -31,12 +31,14 @@
#include "group.h" #include "group.h"
#include "info.h" #include "info.h"
#include "input.h" #include "input.h"
#include "integrate.h"
#include "memory.h" #include "memory.h"
#include "modify.h" #include "modify.h"
#include "molecule.h" #include "molecule.h"
#include "neigh_list.h" #include "neigh_list.h"
#include "neighbor.h" #include "neighbor.h"
#include "region.h" #include "region.h"
#include "respa.h"
#include "output.h" #include "output.h"
#include "thermo.h" #include "thermo.h"
#include "timer.h" #include "timer.h"
@ -984,12 +986,14 @@ to then decide how to cast the (void*) pointer and access the data.
* \return integer constant encoding the data type of the property * \return integer constant encoding the data type of the property
* or -1 if not found. */ * or -1 if not found. */
int lammps_extract_global_datatype(void *handle, const char *name) int lammps_extract_global_datatype(void * /*handle*/, const char *name)
{ {
if (strcmp(name,"dt") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"dt") == 0) return LAMMPS_DOUBLE;
if (strcmp(name,"ntimestep") == 0) return LAMMPS_BIGINT; if (strcmp(name,"ntimestep") == 0) return LAMMPS_BIGINT;
if (strcmp(name,"atime") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"atime") == 0) return LAMMPS_DOUBLE;
if (strcmp(name,"atimestep") == 0) return LAMMPS_BIGINT; if (strcmp(name,"atimestep") == 0) return LAMMPS_BIGINT;
if (strcmp(name,"respa_levels") == 0) return LAMMPS_INT;
if (strcmp(name,"respa_dt") == 0) return LAMMPS_DOUBLE;
if (strcmp(name,"boxlo") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"boxlo") == 0) return LAMMPS_DOUBLE;
if (strcmp(name,"boxhi") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"boxhi") == 0) return LAMMPS_DOUBLE;
@ -1116,6 +1120,14 @@ report the "native" data type. The following tables are provided:
- bigint - bigint
- 1 - 1
- the number of the timestep when "atime" was last updated. - the number of the timestep when "atime" was last updated.
* - respa_levels
- int
- 1
- number of r-RESPA levels. See :doc:`run_style`.
* - respa_dt
- double
- number of r-RESPA levels
- length of the time steps with r-RESPA. See :doc:`run_style`.
.. _extract_box_settings: .. _extract_box_settings:
@ -1366,6 +1378,11 @@ void *lammps_extract_global(void *handle, const char *name)
if (strcmp(name,"atime") == 0) return (void *) &lmp->update->atime; if (strcmp(name,"atime") == 0) return (void *) &lmp->update->atime;
if (strcmp(name,"atimestep") == 0) return (void *) &lmp->update->atimestep; if (strcmp(name,"atimestep") == 0) return (void *) &lmp->update->atimestep;
if (utils::strmatch(lmp->update->integrate_style,"^respa")) {
Respa *respa = (Respa *)lmp->update->integrate;
if (strcmp(name,"respa_levels") == 0) return (void *) &respa->nlevels;
if (strcmp(name,"respa_dt") == 0) return (void *) respa->step;
}
if (strcmp(name,"boxlo") == 0) return (void *) lmp->domain->boxlo; if (strcmp(name,"boxlo") == 0) return (void *) lmp->domain->boxlo;
if (strcmp(name,"boxhi") == 0) return (void *) lmp->domain->boxhi; if (strcmp(name,"boxhi") == 0) return (void *) lmp->domain->boxhi;
if (strcmp(name,"sublo") == 0) return (void *) lmp->domain->sublo; if (strcmp(name,"sublo") == 0) return (void *) lmp->domain->sublo;

View File

@ -274,6 +274,16 @@ create_atoms 1 single &
self.assertEqual(self.lmp.extract_global("subhi"), [1.0, 2.0, 3.0]) self.assertEqual(self.lmp.extract_global("subhi"), [1.0, 2.0, 3.0])
self.assertEqual(self.lmp.extract_global("periodicity"), [1,1,1]) self.assertEqual(self.lmp.extract_global("periodicity"), [1,1,1])
# only valid for triclinic box # only valid for triclinic box
self.assertEqual(self.lmp.extract_global("respa_levels"), None)
self.assertEqual(self.lmp.extract_global("respa_dt"), None)
# set and initialize r-RESPA
self.lmp.command("run_style respa 3 5 2 pair 2 kspace 3")
self.lmp.command("mass * 1.0")
self.lmp.command("run 1 post no")
self.assertEqual(self.lmp.extract_global("ntimestep"), 1)
self.assertEqual(self.lmp.extract_global("respa_levels"), 3)
self.assertEqual(self.lmp.extract_global("respa_dt"), [0.0005, 0.0025, 0.005])
self.lmp.command("change_box all triclinic") self.lmp.command("change_box all triclinic")
self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0]) self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0])
self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0]) self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0])