support setting global virial for fix external from python
This commit is contained in:
@ -1795,20 +1795,38 @@ class lammps(object):
|
|||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
def fix_external_set_energy_global(self, fix_id, eng):
|
def fix_external_set_energy_global(self, fix_id, eng):
|
||||||
"""Get access to that array with per-atom forces of a fix external instance with a given fix ID.
|
"""Set the global energy contribution for a fix external instance with the given ID.
|
||||||
|
|
||||||
This is a wrapper around the :cpp:func:`lammps_fix_external_get_force` function
|
This is a wrapper around the :cpp:func:`lammps_fix_external_set_energy_global` function
|
||||||
of the C-library interface.
|
of the C-library interface.
|
||||||
|
|
||||||
:param fix_id: Fix-ID of a fix external instance
|
:param fix_id: Fix-ID of a fix external instance
|
||||||
:type: string
|
:type: string
|
||||||
:param eng: potential energy to be added by fix external
|
:param eng: potential energy value to be added by fix external
|
||||||
:type: float
|
:type: float
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with ExceptionCheck(self):
|
with ExceptionCheck(self):
|
||||||
return self.lib.lammps_fix_external_set_energy_global(self.lmp, fix_id.encode(), eng)
|
return self.lib.lammps_fix_external_set_energy_global(self.lmp, fix_id.encode(), eng)
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def fix_external_set_virial_global(self, fix_id, virial):
|
||||||
|
"""Set the global virial contribution for a fix external instance with the given ID.
|
||||||
|
|
||||||
|
This is a wrapper around the :cpp:func:`lammps_fix_external_set_virial_global` function
|
||||||
|
of the C-library interface.
|
||||||
|
|
||||||
|
:param fix_id: Fix-ID of a fix external instance
|
||||||
|
:type: string
|
||||||
|
:param eng: list of 6 floating point numbers with the virial to be added by fix external
|
||||||
|
:type: float
|
||||||
|
"""
|
||||||
|
|
||||||
|
cvirial = (6*c_double)(*virial)
|
||||||
|
with ExceptionCheck(self):
|
||||||
|
return self.lib.lammps_fix_external_set_virial_global(self.lmp, fix_id.encode(), cvirial)
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
def fix_external_set_vector_length(self, fix_id, length):
|
def fix_external_set_vector_length(self, fix_id, length):
|
||||||
"""Set the vector length for a global vector stored with fix external for analysis
|
"""Set the vector length for a global vector stored with fix external for analysis
|
||||||
|
|||||||
@ -5103,7 +5103,7 @@ void lammps_fix_external_set_vector_length(void *handle, const char *id, int len
|
|||||||
END_CAPTURE
|
END_CAPTURE
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Store global vector for a fix external instance with the given ID.
|
/** Store a global vector value for a fix external instance with the given ID.
|
||||||
|
|
||||||
\verbatim embed:rst
|
\verbatim embed:rst
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,8 @@ from lammps import lammps, LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR
|
|||||||
|
|
||||||
# add timestep dependent force
|
# add timestep dependent force
|
||||||
def callback_one(lmp, ntimestep, nlocal, tag, x, f):
|
def callback_one(lmp, ntimestep, nlocal, tag, x, f):
|
||||||
|
virial = [1.0, 1.0, 1.0, 0.0, 0.0, 0.0]
|
||||||
|
lmp.fix_external_set_virial_global("ext",virial)
|
||||||
for i in range(nlocal):
|
for i in range(nlocal):
|
||||||
f[i][0] = float(ntimestep)
|
f[i][0] = float(ntimestep)
|
||||||
f[i][1] = float(ntimestep)
|
f[i][1] = float(ntimestep)
|
||||||
@ -49,6 +51,7 @@ class PythonExternal(unittest.TestCase):
|
|||||||
lmp.command("run 10 post no")
|
lmp.command("run 10 post no")
|
||||||
self.assertAlmostEqual(lmp.get_thermo("temp"),1.0/30.0,14)
|
self.assertAlmostEqual(lmp.get_thermo("temp"),1.0/30.0,14)
|
||||||
self.assertAlmostEqual(lmp.get_thermo("pe"),1.0/8.0,14)
|
self.assertAlmostEqual(lmp.get_thermo("pe"),1.0/8.0,14)
|
||||||
|
self.assertAlmostEqual(lmp.get_thermo("press"),0.15416666666666667,14)
|
||||||
val = 0.0
|
val = 0.0
|
||||||
for i in range(0,6):
|
for i in range(0,6):
|
||||||
val += lmp.extract_fix("ext",LMP_STYLE_GLOBAL,LMP_TYPE_VECTOR,nrow=i)
|
val += lmp.extract_fix("ext",LMP_STYLE_GLOBAL,LMP_TYPE_VECTOR,nrow=i)
|
||||||
|
|||||||
Reference in New Issue
Block a user