From 643f732d46b97e9a2bbe8a9b54f4a0788edd4def Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franck=20P=C3=A9rignon?= <franck.perignon@imag.fr>
Date: Fri, 24 May 2013 12:56:19 +0000
Subject: [PATCH] Add methods to serialize the problem and restart a simulation
 from a file

---
 HySoP/hysop/problem/problem.py | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/HySoP/hysop/problem/problem.py b/HySoP/hysop/problem/problem.py
index a622b07c9..566130b38 100644
--- a/HySoP/hysop/problem/problem.py
+++ b/HySoP/hysop/problem/problem.py
@@ -31,7 +31,8 @@ class Problem(object):
         return object.__new__(cls, *args, **kw)
 
     @debug
-    def __init__(self, operators, simulation, monitors=[], name=None):
+    def __init__(self, operators, simulation, monitors=[],
+                 dumpFreq=100, name=None):
         """
         Create a transport problem instance.
 
@@ -40,6 +41,8 @@ class Problem(object):
         to describe simulation parameters.
         @param monitors : list of monitors.
         @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
         self.operators = operators
@@ -58,8 +61,15 @@ 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
+        ## call to problem.dump frequency during apply.
+        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.
         if name is None:
             self.name = 'parmesPb'
@@ -136,7 +146,8 @@ class Problem(object):
                 for op in self.operators:
                     op.apply(self.simulation)
                 self.simulation.advance()
-                if self.simulation.currentIteration % self.dumpFreq is 0:
+                testdump = self.simulation.currentIteration % self.dumpFreq
+                if self._doDump and testdump:
                     self.dump()
 
     @debug
@@ -212,6 +223,8 @@ class Problem(object):
         @param rate : the frequency of output
         """
         self.dumpFreq = freq
+        if freq < 0:
+            self._doDump = False
 
 if __name__ == "__main__":
     print __doc__
-- 
GitLab