From ee4933fbd3566c12336c3ac4e775f019ae8020be Mon Sep 17 00:00:00 2001 From: Jean-Matthieu Etancelin <jean-matthieu.etancelin@imag.fr> Date: Fri, 29 Nov 2013 13:47:22 +0000 Subject: [PATCH] Fix poisson output when use vorticity projection. Fix adaptative timestep integration. --- HySoP/hysop/operator/discrete/poisson_fft.py | 3 ++ HySoP/hysop/operator/poisson.py | 8 +++ HySoP/hysop/problem/problem.py | 3 +- HySoP/hysop/problem/simulation.py | 53 ++++++++------------ 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/HySoP/hysop/operator/discrete/poisson_fft.py b/HySoP/hysop/operator/discrete/poisson_fft.py index 6ef2fee18..8fdbaff80 100644 --- a/HySoP/hysop/operator/discrete/poisson_fft.py +++ b/HySoP/hysop/operator/discrete/poisson_fft.py @@ -51,6 +51,9 @@ class PoissonFFT(DiscreteOperator): self.input = [self.vorticity] self.output = [self.velocity] + # If there is a projection, vorticity is also an output + if self.projection is not None and self.projection[0]: + self.output.append(self.vorticity) @debug @prof diff --git a/HySoP/hysop/operator/poisson.py b/HySoP/hysop/operator/poisson.py index fc0ea2812..785932740 100644 --- a/HySoP/hysop/operator/poisson.py +++ b/HySoP/hysop/operator/poisson.py @@ -55,6 +55,14 @@ class Poisson(Operator): self.input = [self.vorticity] self.output = [self.velocity] + # If there is a projection, vorticity is also an output + try: + proj = other_config['projection'] + except KeyError: + proj = None + if proj is not None and proj[0]: + self.output.append(self.vorticity) + def discretize(self): # Poisson solver based on fftw if self.method is not 'fftw': diff --git a/HySoP/hysop/problem/problem.py b/HySoP/hysop/problem/problem.py index 732621b9c..7d8c8b2c0 100644 --- a/HySoP/hysop/problem/problem.py +++ b/HySoP/hysop/problem/problem.py @@ -192,12 +192,13 @@ class Problem(object): self.glRenderer.startMainLoop() except AttributeError: while not self.simulation.isOver: - self.simulation.printState() + for op in self.operators: if __VERBOSE__: print main_rank, op.__class__.__name__ op.apply(self.simulation) + testdump = \ self.simulation.currentIteration % self.dumpFreq is 0 self.simulation.advance() diff --git a/HySoP/hysop/problem/simulation.py b/HySoP/hysop/problem/simulation.py index 8cddd3fbf..a479f1701 100644 --- a/HySoP/hysop/problem/simulation.py +++ b/HySoP/hysop/problem/simulation.py @@ -4,17 +4,7 @@ Description of the simulation parameters (time, iteration ...) """ from parmepy.mpi import main_rank -from parmepy.numerics.differential_operations import GradV from parmepy.variables.variables import Variables -from parmepy.numerics.finite_differences import FD_C_4 -from parmepy.numerics.integrators.euler import Euler -from parmepy.numerics.integrators.runge_kutta2 import RK2 -from parmepy.numerics.integrators.runge_kutta3 import RK3 -from parmepy.numerics.integrators.runge_kutta4 import RK4 -from parmepy.numerics.updateGhosts import UpdateGhosts -import parmepy.tools.numpywrappers as npw -from parmepy.mpi import MPI -from parmepy.constants import np, PARMES_MPI_REAL class Simulation(object): @@ -27,17 +17,17 @@ class Simulation(object): Creates a Timer. @param tend : Simulation final time. - @param isAdaptative: Boolean value which determines if + @param isAdaptative: Boolean value which determines if the time step is adaptative. @param timeStep : Time step. This is a "variable" object. - Its data attribute is a list made of a real-type value - corresponding to the initial timestep. If the time step is - not chosen to be adaptative, then this initial timestep + Its data attribute is a list made of a real-type value + corresponding to the initial timestep. If the time step is + not chosen to be adaptative, then this initial timestep will be considered as the fixed timestep for the whole simulation. @param tinit : Simulation starting time. @param iterMax : Simulation maximum iteration number. @param bridgeOp : Redistribute operator - @param computeTimeStepOp : Operator which evaluates + @param computeTimeStepOp : Operator which evaluates the adaptative time step according to the flow fields """ ## Simulation final time @@ -61,7 +51,7 @@ class Simulation(object): self.timeStep = timeStep.data[0] ## Save the initial timestep value self.timeStepInit = timeStep.data[0] - else : + else: ## Set isAdaptative to False self.isAdaptative = False ## Simulation time step fixed value @@ -74,33 +64,34 @@ class Simulation(object): def advance(self): """ Proceed to next time. - Compute last timeStep of the simulation to reach end - (with a tolerance of 1e-8). + Advance time and iteration number. + Compute a timestep for the incoming iteration (from a vairable and + to reach the end of simulation) """ - tol = 1e-10 if self._lastStep: # The timestep was adjusted to reach end in the previous call # So now the simulation is over self.isOver = True else: - # Simulation with adaptative time step - if self.isAdaptative: - if self.time >= self.end: - self._lastStep = True - if self.time>= self.timeStepInit: - self.timeStep = self.timeStep_variable.data[0] - # Simulation with fixed time step if self.currentIteration < self.iterMax: - self.currentIteration += 1 + # Advance time for the iteration just ended self.time += self.timeStep - # adjust last timestep to reach self.end - if self.end - self.time < self.timeStep and\ - abs(self.time - self.end) < tol: + self.currentIteration += 1 + + # Prepare the timestep for the following itertation + if self.isAdaptative: + self.timeStep = self.timeStep_variable.data[0] + + # Axdjust last timestep to reach self.end + if self.end - self.time < self.timeStep: self.timeStep = self.end - self.time self._lastStep = True else: + # iteration number is reached self.isOver = True - if abs(self.time - self.end) < tol: + # Time is close enough to the end to consider that the simulation + # is over. + if abs(self.time - self.end) < 1e-10: self.isOver = True def printState(self): -- GitLab