Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hysop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
particle_methods
hysop
Commits
b8784c07
Commit
b8784c07
authored
11 years ago
by
Franck Pérignon
Browse files
Options
Downloads
Patches
Plain Diff
Add methods to serialize the problem and restart a simulation from a file
parent
c2d1d5fc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
HySoP/hysop/problem/problem.py
+37
-10
37 additions, 10 deletions
HySoP/hysop/problem/problem.py
with
37 additions
and
10 deletions
HySoP/hysop/problem/problem.py
+
37
−
10
View file @
b8784c07
...
...
@@ -31,7 +31,7 @@ class Problem(object):
return
object
.
__new__
(
cls
,
*
args
,
**
kw
)
@debug
def
__init__
(
self
,
operators
,
simulation
,
monitors
=
[]):
def
__init__
(
self
,
operators
,
simulation
,
monitors
=
[]
,
name
=
None
):
"""
Create a transport problem instance.
...
...
@@ -39,6 +39,7 @@ class Problem(object):
@param simulation : a parmepy.simulation.Simulation object
to describe simulation parameters.
@param monitors : list of monitors.
@param name : an id for the problem
"""
## Problem operators
self
.
operators
=
operators
...
...
@@ -57,6 +58,16 @@ class Problem(object):
## A list of variables that must be initialized before
## any call to op.apply()
self
.
input
=
[]
## call to problem.dump frequency during apply. 0 means never.
self
.
dumpFreq
=
0
## Id for the problem. Used for dump file name.
if
name
is
None
:
self
.
name
=
'
parmesPb
'
else
:
self
.
name
=
name
## Default file name prefix for dump.
self
.
filename
=
str
(
name
)
self
.
_filedump
=
self
.
filename
+
'
_rk_
'
+
str
(
main_rank
)
@debug
def
setUp
(
self
):
...
...
@@ -125,6 +136,8 @@ class Problem(object):
for
op
in
self
.
operators
:
op
.
apply
(
self
.
simulation
)
self
.
simulation
.
advance
()
if
self
.
simulation
.
currentIteration
%
self
.
dumpFreq
is
0
:
self
.
dump
()
@debug
def
finalize
(
self
):
...
...
@@ -158,33 +171,47 @@ class Problem(object):
return
s
def
dump
(
self
,
filename
):
def
dump
(
self
,
filename
=
None
):
"""
Serialize some data of the problem to file
(only data required for a proper restart, namely fields in self.input
and simulation).
@param filename : prefix for output file. Real name = filename_rk_N,
N being current process number.
N being current process number. If None use default value from problem
parameters (self.filename)
"""
filedump
=
filename
+
'
_rk_
'
+
str
(
main_rank
)
db
=
NumPyDB_cPickle
(
filedump
,
mode
=
'
store
'
)
if
filename
is
not
None
:
self
.
filename
=
filename
self
.
_filedump
=
filename
+
'
_rk_
'
+
str
(
main_rank
)
db
=
NumPyDB_cPickle
(
self
.
_filedump
,
mode
=
'
store
'
)
db
.
dump
(
self
.
simulation
,
'
simulation
'
)
for
v
in
self
.
input
:
v
.
dump
(
filename
,
mode
=
'
append
'
)
v
.
dump
(
self
.
filename
,
mode
=
'
append
'
)
def
restart
(
self
,
filename
):
def
restart
(
self
,
filename
=
None
):
"""
Load serialized data to restart from a previous state.
self.input variables and simulation are loaded.
@param filename : prefix for downloaded file.
Real name = filename_rk_N, N being current process number.
If None use default value from problem
parameters (self.filename)
"""
filedump
=
filename
+
'
_rk_
'
+
str
(
main_rank
)
db
=
NumPyDB_cPickle
(
filedump
,
mode
=
'
load
'
)
if
filename
is
not
None
:
self
.
filename
=
filename
self
.
_filedump
=
filename
+
'
_rk_
'
+
str
(
main_rank
)
db
=
NumPyDB_cPickle
(
self
.
_filedump
,
mode
=
'
load
'
)
self
.
simulation
=
db
.
load
(
'
simulation
'
)[
0
]
self
.
simulation
.
reset
()
for
v
in
self
.
input
:
v
.
load
(
filename
)
v
.
load
(
self
.
filename
)
def
setDumpFreq
(
self
,
freq
):
"""
set rate of problem.dump call (every
'
rate
'
iteration)
@param rate : the frequency of output
"""
self
.
dumpFreq
=
freq
if
__name__
==
"
__main__
"
:
print
__doc__
...
...
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