Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lammps
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
multiscale
lammps
Commits
c4d0f070
Commit
c4d0f070
authored
7 years ago
by
Richard Berger
Browse files
Options
Downloads
Patches
Plain Diff
Allow fix python to only execute every N steps
parent
93f60330
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
doc/src/fix_python.txt
+7
-6
7 additions, 6 deletions
doc/src/fix_python.txt
examples/python/in.fix_python
+2
-2
2 additions, 2 deletions
examples/python/in.fix_python
src/PYTHON/fix_python.cpp
+9
-4
9 additions, 4 deletions
src/PYTHON/fix_python.cpp
with
18 additions
and
12 deletions
doc/src/fix_python.txt
+
7
−
6
View file @
c4d0f070
...
...
@@ -10,13 +10,14 @@ fix python command :h3
[Syntax:]
fix ID group-ID python callback function_name :pre
fix ID group-ID python
N
callback function_name :pre
ID, group-ID are ignored by this fix :ulb,l
python = style name of this fix command :l
N = execute every N steps :l
callback = {post_force} or {end_of_step} :l
{post_force} = callback after force computations on atoms
{end_of_step} = callback after each time step :pre
{post_force} = callback after force computations on atoms
every N time steps
{end_of_step} = callback after each
N
time step
s
:pre
:ule
[Examples:]
...
...
@@ -35,14 +36,14 @@ def end_of_step_callback(lammps_ptr):
# access LAMMPS state using Python interface
""" :pre
fix pf all python post_force post_force_callback
fix eos all python end_of_step end_of_step_callback :pre
fix pf all python
50
post_force post_force_callback
fix eos all python
50
end_of_step end_of_step_callback :pre
[Description:]
This fix allows you to call a Python function during a simulation run.
The callback is either executed after forces have been applied to atoms
or at the end of e
ach
time step.
or at the end of e
very N
time step
s
.
Callback functions must be declared in the global scope of the
active Python interpreter. This can either be done by defining it
...
...
This diff is collapsed.
Click to expand it.
examples/python/in.fix_python
+
2
−
2
View file @
c4d0f070
...
...
@@ -33,8 +33,8 @@ def post_force_callback(lmp, v):
"""
fix 1 all nve
fix 2 all python end_of_step end_of_step_callback
fix 3 all python post_force post_force_callback
fix 2 all python
50
end_of_step end_of_step_callback
fix 3 all python
50
post_force post_force_callback
#dump id all atom 50 dump.melt
...
...
This diff is collapsed.
Click to expand it.
src/PYTHON/fix_python.cpp
+
9
−
4
View file @
c4d0f070
...
...
@@ -36,14 +36,17 @@ using namespace FixConst;
FixPython
::
FixPython
(
LAMMPS
*
lmp
,
int
narg
,
char
**
arg
)
:
Fix
(
lmp
,
narg
,
arg
)
{
if
(
narg
!=
5
)
error
->
all
(
FLERR
,
"Illegal fix python command"
);
if
(
narg
!=
6
)
error
->
all
(
FLERR
,
"Illegal fix python command"
);
nevery
=
force
->
inumeric
(
FLERR
,
arg
[
3
]);
if
(
nevery
<=
0
)
error
->
all
(
FLERR
,
"Illegal fix python command"
);
// ensure Python interpreter is initialized
python
->
init
();
if
(
strcmp
(
arg
[
3
],
"post_force"
)
==
0
)
{
if
(
strcmp
(
arg
[
4
],
"post_force"
)
==
0
)
{
selected_callback
=
POST_FORCE
;
}
else
if
(
strcmp
(
arg
[
3
],
"end_of_step"
)
==
0
)
{
}
else
if
(
strcmp
(
arg
[
4
],
"end_of_step"
)
==
0
)
{
selected_callback
=
END_OF_STEP
;
}
...
...
@@ -57,7 +60,7 @@ FixPython::FixPython(LAMMPS *lmp, int narg, char **arg) :
error
->
all
(
FLERR
,
"Could not initialize embedded Python"
);
}
char
*
fname
=
arg
[
4
];
char
*
fname
=
arg
[
5
];
pFunc
=
PyObject_GetAttrString
(
pyMain
,
fname
);
if
(
!
pFunc
)
{
...
...
@@ -94,6 +97,8 @@ void FixPython::end_of_step()
void
FixPython
::
post_force
(
int
vflag
)
{
if
(
update
->
ntimestep
%
nevery
!=
0
)
return
;
PyGILState_STATE
gstate
=
PyGILState_Ensure
();
PyObject
*
ptr
=
PY_VOID_POINTER
(
lmp
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment