Skip to content
Snippets Groups Projects
Commit 643f732d authored by Franck Pérignon's avatar Franck Pérignon
Browse files

Add methods to serialize the problem and restart a simulation from a file

parent b8784c07
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,8 @@ class Problem(object): ...@@ -31,7 +31,8 @@ class Problem(object):
return object.__new__(cls, *args, **kw) return object.__new__(cls, *args, **kw)
@debug @debug
def __init__(self, operators, simulation, monitors=[], name=None): def __init__(self, operators, simulation, monitors=[],
dumpFreq=100, name=None):
""" """
Create a transport problem instance. Create a transport problem instance.
...@@ -40,6 +41,8 @@ class Problem(object): ...@@ -40,6 +41,8 @@ class Problem(object):
to describe simulation parameters. to describe simulation parameters.
@param monitors : list of monitors. @param monitors : list of monitors.
@param name : an id for the problem @param name : an id for the problem
@param dumpFreq : frequency of dump (i.e. saving to a file)
for the problem; set dumpFreq = -1 for no dumps. Default = 100.
""" """
## Problem operators ## Problem operators
self.operators = operators self.operators = operators
...@@ -58,8 +61,15 @@ class Problem(object): ...@@ -58,8 +61,15 @@ class Problem(object):
## A list of variables that must be initialized before ## A list of variables that must be initialized before
## any call to op.apply() ## any call to op.apply()
self.input = [] self.input = []
## call to problem.dump frequency during apply. 0 means never. ## call to problem.dump frequency during apply.
self.dumpFreq = 0 if dumpFreq >= 0:
## dump problem every self.dumpFreq iter
self.dumpFreq = dumpFreq
self._doDump = True
else:
self._doDump = False
self.dumpFreq = 100000
## Id for the problem. Used for dump file name. ## Id for the problem. Used for dump file name.
if name is None: if name is None:
self.name = 'parmesPb' self.name = 'parmesPb'
...@@ -136,7 +146,8 @@ class Problem(object): ...@@ -136,7 +146,8 @@ class Problem(object):
for op in self.operators: for op in self.operators:
op.apply(self.simulation) op.apply(self.simulation)
self.simulation.advance() self.simulation.advance()
if self.simulation.currentIteration % self.dumpFreq is 0: testdump = self.simulation.currentIteration % self.dumpFreq
if self._doDump and testdump:
self.dump() self.dump()
@debug @debug
...@@ -212,6 +223,8 @@ class Problem(object): ...@@ -212,6 +223,8 @@ class Problem(object):
@param rate : the frequency of output @param rate : the frequency of output
""" """
self.dumpFreq = freq self.dumpFreq = freq
if freq < 0:
self._doDump = False
if __name__ == "__main__": if __name__ == "__main__":
print __doc__ print __doc__
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment