diff --git a/HySoP/hysop/domain/box.py b/HySoP/hysop/domain/box.py index 650df43c44f8c43e0dc92a216c448442868f4822..92fcd9755f8932452ea5160423506e9dad4303c4 100644 --- a/HySoP/hysop/domain/box.py +++ b/HySoP/hysop/domain/box.py @@ -28,13 +28,13 @@ class Box(Domain): @param dimension : Box dimension. Default: 3 @param length : Box length. Default [1.0, 1.0, 1.0] @param origin : Box minimum position. Default [0., 0., 0.] - + \code >>> import parmepy as pp >>> import numpy as np >>> b = pp.Box() >>> (b.max == np.asarray([1.0, 1.0, 1.0])).all() True - + \endcode """ if not (dimension == len(length) and dimension == len(origin)): raise ValueError("Box parameters inconsistents dimensions") diff --git a/HySoP/hysop/fields/discrete.py b/HySoP/hysop/fields/discrete.py index da71fd982e460da6013545ec3116def7e28e0ce1..8502f487b5e17b4ef78d61b81e09fe678c04a23a 100644 --- a/HySoP/hysop/fields/discrete.py +++ b/HySoP/hysop/fields/discrete.py @@ -145,8 +145,11 @@ class DiscreteField(object): filename += '_rk_' filename += str(main_rank) db = NumPyDB_cPickle(filename, mode='load') + print "lllll", self.name if self.isVector: for dim in xrange(self.dimension): + print dim, len(self.data) + print db.load(self.name) self.data[dim] = db.load(self.name)[0][dim] else: self.data = db.load(self.name)[0] diff --git a/HySoP/hysop/operator/monitors/printer.py b/HySoP/hysop/operator/monitors/printer.py index f433e94db387a194483adb6ec6973e5409fd8c1c..2e0f1c32d63d5d6439b11e2661bb77771046c51a 100644 --- a/HySoP/hysop/operator/monitors/printer.py +++ b/HySoP/hysop/operator/monitors/printer.py @@ -3,7 +3,6 @@ Classes for handling ouputs. """ -from parmepy import __VERBOSE__ from parmepy.constants import np, S_DIR, PARMES_REAL, debug from parmepy.operator.monitors.monitoring import Monitoring import evtk.hl as evtk @@ -48,6 +47,14 @@ class Printer(Monitoring): self.step = self._printStep else: self.step = self._passStep + ## Internal counter + self._call_number = 0 + + def setUp(self): + """ + Print initial state + """ + self.step(0) @debug @timed_function @@ -86,7 +93,7 @@ class Printer(Monitoring): raise ValueError("Cannot set non callable method to get data " + "to print. Given method : " + str(method)) - def _passStep(self, ite): + def _passStep(self, ite=None): """A code method that do nothing.""" pass @@ -97,8 +104,7 @@ class Printer(Monitoring): @param iter : current iteration number """ if (ite % self.freq) == 0: - if __VERBOSE__: - print "== IO" + self._call_number += 1 # Transfer from GPU to CPU if required for f in self.variables: for df in f.discreteFields.values(): @@ -109,8 +115,6 @@ class Printer(Monitoring): # Set output file name filename = self.prefix + '_it_' + str(ite) + self.ext print "Print to file " + filename - if __VERBOSE__: - print "Print file : " + filename ## VTK output \todo: Need fix in 2D, getting an IOError. try: evtk.imageToVTK(filename, pointData=self._build_vtk_dict()) @@ -159,10 +163,9 @@ class Printer(Monitoring): df[i, j, k])) f.write("\n") f.close() - if __VERBOSE__: - print "==" + print "==\n" if __name__ == "__main__": print __doc__ - print "- Provided class : " + providedClass - print eval(providedClass).__doc__ + print "- Provided class : " + Printer + print Printer.__doc__ diff --git a/HySoP/hysop/operator/poisson.py b/HySoP/hysop/operator/poisson.py index 43967904ac710cbe5853f68a398d70afa9d93cc2..0782abf014968b8fff401a34ba52d4d684a97ac2 100644 --- a/HySoP/hysop/operator/poisson.py +++ b/HySoP/hysop/operator/poisson.py @@ -42,8 +42,6 @@ class Poisson(Operator): ## the same resolution. self.resolutions = resolutions - self.input = [self.vorticity] - self.output = [self.velocity] Operator.__init__(self, [velocity, vorticity], method, name="Poisson") self.config = other_config if method is None: @@ -53,6 +51,8 @@ class Poisson(Operator): assert self.resolution == self.resolutions[self.vorticity],\ 'Poisson error : for fftw, all variables must have\ the same global resolution.' + self.input = [self.vorticity] + self.output = [self.velocity] @debug def setUp(self): diff --git a/HySoP/hysop/problem/problem.py b/HySoP/hysop/problem/problem.py index 3b87aa76ff2999b6a647c0b87001f304bd942af9..a1c30c3297ec598a310fc2af4b5792e609e9b106 100644 --- a/HySoP/hysop/problem/problem.py +++ b/HySoP/hysop/problem/problem.py @@ -79,7 +79,7 @@ class Problem(object): else: self.name = name ## Default file name prefix for dump. - self.filename = str(name) + self.filename = str(self.name) self._filedump = self.filename + '_rk_' + str(main_rank) @debug @@ -92,11 +92,6 @@ class Problem(object): if not isinstance(op, Monitoring): if not isinstance(op, Redistribute): op.setUp() - for op in self.operators: - if isinstance(op, Monitoring): - op.setUp() - if isinstance(op, Redistribute): - op.setUp() if __VERBOSE__: print "==== Variables initialization ====" @@ -116,6 +111,12 @@ class Problem(object): for v in self.input: v.initialize() + for op in self.operators: + if isinstance(op, Monitoring): + op.setUp() + if isinstance(op, Redistribute): + op.setUp() + if __VERBOSE__: print "====" for op in self.operators: @@ -138,9 +139,6 @@ class Problem(object): Displays timings at simulation end. """ print "\n\n Start solving ..." - for op in self.operators: - if isinstance(op, Monitoring): - op.apply(self.simulation) try: ## Pass the main loop to the OpenGL viewer if not self.glRenderer is None: @@ -203,6 +201,8 @@ class Problem(object): db = NumPyDB_cPickle(self._filedump, mode='store') db.dump(self.simulation, 'simulation') for v in self.input: + print 'dump v ...' + print v v.dump(self.filename, mode='append') def restart(self, filename=None): @@ -221,8 +221,15 @@ class Problem(object): self.simulation = db.load('simulation')[0] self.simulation.reset() for v in self.input: + print "load ...", self.filename v.load(self.filename) + for op in self.operators: + if isinstance(op, Monitoring): + op.setUp() + if isinstance(op, Redistribute): + op.setUp() + def setDumpFreq(self, freq): """ set rate of problem.dump call (every 'rate' iteration) diff --git a/HySoP/hysop/problem/simulation.py b/HySoP/hysop/problem/simulation.py index ae8590bd62a086345bbc17c5af12494fec8fd1a3..2d484fd91db893074a6efaffd38c17541202bc30 100644 --- a/HySoP/hysop/problem/simulation.py +++ b/HySoP/hysop/problem/simulation.py @@ -28,7 +28,7 @@ class Simulation(object): ## Is simulation is terminated self.isOver = False ## Iteration counter - self.currentIteration = 0 + self.currentIteration = 1 ## Simulation time step self.timeStep = timeStep ## Maximum number of iterations @@ -38,18 +38,20 @@ class Simulation(object): """ Proceed to next time """ - if self.currentIteration < self.iterMax and self.time < self.end: + if self.currentIteration < self.iterMax: self.currentIteration += 1 self.time += self.timeStep else: self.isOver = True + if self.time >= self.end: + self.isOver = True def printState(self): """ print current state """ if main_rank == 0: - print "\n==== Iteration : {0:3d} t={1:6.3f} ====".format( + print "==== Iteration : {0:3d}, start from t ={1:6.3f} ====".format( self.currentIteration, self.time) def reset(self): @@ -59,7 +61,7 @@ class Simulation(object): """ self.start = self.time self.isOver = False - self.currentIteration = 0 + self.currentIteration = 1 def __str__(self): s = "Simulation parameters : " diff --git a/HySoP/hysop/problem/transport.py b/HySoP/hysop/problem/transport.py index 39ddd844fee8f8d212a7dfc4980bb6a18c3600f7..2360ee801c3b033babe74cb0678ba54a98b4103f 100644 --- a/HySoP/hysop/problem/transport.py +++ b/HySoP/hysop/problem/transport.py @@ -10,9 +10,10 @@ class TransportProblem(Problem): """ Transport problem description. """ - def __init__(self, operators, simulation, monitors=[]): + def __init__(self, operators, simulation, monitors=[], + dumpFreq=100, name=None): Problem.__init__(self, operators, simulation, monitors, - name="Transport Problem") + dumpFreq, name) self.advection, self.velocity = None, None for op in self.operators: if isinstance(op, Advection):