From 2f06f04d286c80bd6d10f9034148fdb853f9f379 Mon Sep 17 00:00:00 2001 From: Jean-Matthieu Etancelin <jean-matthieu.etancelin@imag.fr> Date: Tue, 21 May 2013 15:51:28 +0000 Subject: [PATCH] Fix apply method parameters. --- HySoP/hysop/operator/continuous.py | 8 +- HySoP/hysop/operator/discrete/analytic.py | 11 +- .../hysop/operator/discrete/diffusion_fft.py | 2 +- HySoP/hysop/operator/discrete/discrete.py | 2 +- HySoP/hysop/operator/discrete/penalization.py | 2 +- HySoP/hysop/operator/discrete/poisson_fft.py | 2 +- HySoP/hysop/operator/discrete/remeshing.py | 76 ----------- .../operator/discrete/synchronizeGhosts.py | 6 +- HySoP/hysop/operator/discrete/transport.py | 127 ------------------ HySoP/hysop/operator/energy_enstrophy.py | 2 +- HySoP/hysop/operator/monitors/printer.py | 2 +- 11 files changed, 21 insertions(+), 219 deletions(-) delete mode 100644 HySoP/hysop/operator/discrete/remeshing.py delete mode 100644 HySoP/hysop/operator/discrete/transport.py diff --git a/HySoP/hysop/operator/continuous.py b/HySoP/hysop/operator/continuous.py index 2a838c33e..9d0a682ad 100644 --- a/HySoP/hysop/operator/continuous.py +++ b/HySoP/hysop/operator/continuous.py @@ -85,13 +85,15 @@ class Operator(object): self.discreteOperator.finalize() @debug - def apply(self, *args): + def apply(self, t, dt, ite): """ apply the operator on its variables. - @param *args : Operator arguments. + @param t : Current simulation time. + @param dt : Time step + @param ite : Iteration number @return duration of computation. """ - return self.discreteOperator.apply(*args) + return self.discreteOperator.apply(t, dt, ite) def printComputeTime(self): """ Time monitoring.""" diff --git a/HySoP/hysop/operator/discrete/analytic.py b/HySoP/hysop/operator/discrete/analytic.py index 987499859..f931b7a9f 100644 --- a/HySoP/hysop/operator/discrete/analytic.py +++ b/HySoP/hysop/operator/discrete/analytic.py @@ -36,14 +36,15 @@ class Analytic_D(DiscreteOperator): self.vformula = np.vectorize(self.formula) @debug - def apply(self, *args): + def apply(self, t, dt, ite): self.compute_time = MPI.Wtime() for df in self.variables: datatype = df.data[0].dtype if df.isVector: if df.topology.dim == 3: df.data[0][...], df.data[1][...], df.data[2][...] = \ - self.vformula(*(df.topology.mesh.coords + args)) + self.vformula(*( + df.topology.mesh.coords + [t, dt, ite])) df.data[0][...] = np.asarray(df.data[0], dtype=datatype, order=ORDER) df.data[1][...] = np.asarray(df.data[1], @@ -52,13 +53,15 @@ class Analytic_D(DiscreteOperator): dtype=datatype, order=ORDER) elif df.topology.dim == 2: df.data[0][...], df.data[1][...] = \ - self.vformula(*(df.topology.mesh.coords + args)) + self.vformula(*( + df.topology.mesh.coords + [t, dt, ite])) df.data[0][...] = np.asarray(df.data[0], dtype=datatype, order=ORDER) df.data[1][...] = np.asarray(df.data[1], dtype=datatype, order=ORDER) else: - df.data[...] = self.vformula(*(df.topology.mesh.coords + args)) + df.data[...] = \ + self.vformula(*(df.topology.mesh.coords + [t, dt, ite])) df.data[...] = np.asarray(df.data, dtype=datatype, order=ORDER) for df in self.output: diff --git a/HySoP/hysop/operator/discrete/diffusion_fft.py b/HySoP/hysop/operator/discrete/diffusion_fft.py index 7b5738345..d43d54174 100644 --- a/HySoP/hysop/operator/discrete/diffusion_fft.py +++ b/HySoP/hysop/operator/discrete/diffusion_fft.py @@ -38,7 +38,7 @@ class DiffusionFFT(DiscreteOperator): pass @debug - def apply(self, dt, *args): + def apply(self, t, dt, ite): """ Apply operator. @param dt : current time step diff --git a/HySoP/hysop/operator/discrete/discrete.py b/HySoP/hysop/operator/discrete/discrete.py index 39df00ec2..0fb1d4d81 100644 --- a/HySoP/hysop/operator/discrete/discrete.py +++ b/HySoP/hysop/operator/discrete/discrete.py @@ -59,7 +59,7 @@ class DiscreteOperator(object): @debug @abstractmethod - def apply(self, *args): + def apply(self, t, dt, ite): """ Abstract method, apply operaton on the of discrete variables of this operator. diff --git a/HySoP/hysop/operator/discrete/penalization.py b/HySoP/hysop/operator/discrete/penalization.py index 0eb060478..c87ce5a11 100644 --- a/HySoP/hysop/operator/discrete/penalization.py +++ b/HySoP/hysop/operator/discrete/penalization.py @@ -56,7 +56,7 @@ class Penalization_d(DiscreteOperator): pass @debug - def apply(self, dt, *args): + def apply(self, t, dt, ite): self.compute_time = MPI.Wtime() diff --git a/HySoP/hysop/operator/discrete/poisson_fft.py b/HySoP/hysop/operator/discrete/poisson_fft.py index 040775862..e3b878d93 100644 --- a/HySoP/hysop/operator/discrete/poisson_fft.py +++ b/HySoP/hysop/operator/discrete/poisson_fft.py @@ -52,7 +52,7 @@ class PoissonFFT(DiscreteOperator): @debug @prof - def apply(self, *args): + def apply(self, t, dt, ite): """ Apply operator. """ diff --git a/HySoP/hysop/operator/discrete/remeshing.py b/HySoP/hysop/operator/discrete/remeshing.py deleted file mode 100644 index 5b337557d..000000000 --- a/HySoP/hysop/operator/discrete/remeshing.py +++ /dev/null @@ -1,76 +0,0 @@ -""" -@file remeshing.py - -Discrete remeshing representation -""" -from discrete import DiscreteOperator -from parmepy.gpu import PARMES_REAL_GPU - - -class Remeshing(DiscreteOperator): - """ - Remeshing operator representation. - """ - - def __init__(self, partPositions, partScalar, resscal, method=None): - """ - Create a Remeshing operator. - - @param partPositions : particles positions. - @param partScalar : particles scalar. - @param resscal : result grid scalar values. - @param method : the method to use. - """ - DiscreteOperator.__init__(self) - ## Particles positions. - self.ppos = partPositions - ## Particles scalar values. - self.pscal = partScalar - ## Result scalar - self.res_scalar = resscal - self.addVariable([self.ppos, self.pscal, self.res_scalar]) - self.input = [self.ppos, self.pscal] - self.output = [self.res_scalar] - self.method = method - ## Compute time detailed per directions - self.compute_time = [0., 0., 0.] - self.name = "remeshing" - self.call_number = [0, 0, 0] - self.gpu_precision = PARMES_REAL_GPU - - def apply(self, t, dt, splittingDirection): - """ - Apply Remeshing operator. - - @param t : current time. - @param dt : time step. - @param splittingDirection : Direction of splitting. - - Remeshing algorithm: - @li 1. Remesh particles on grid - - Use a M'6 formula - @li 2. Profile timings of OpenCL kernels. - """ - c_time = 0. - self.call_number[splittingDirection] += 1 - if self.numMethod is not None: - ## Launching kernel - evt = self.numMethod.launch(self.ppos.gpu_data, - self.pscal.gpu_data, - self.res_scalar.gpu_data, - self.gpu_precision(self.res_scalar.topology.mesh.origin[splittingDirection]), - self.gpu_precision(self.res_scalar.topology.mesh.size[splittingDirection])) - for df in self.output: - df.contains_data = False - # Get timpings from OpenCL events - self.numMethod.finish() - c_time += (evt.profile.end - evt.profile.start) * 1e-9 - self.compute_time[splittingDirection] += c_time - self.total_time += c_time - return c_time - - -if __name__ == "__main__": - print __doc__ - print "- Provided class : Remeshing" - print Remeshing.__doc__ diff --git a/HySoP/hysop/operator/discrete/synchronizeGhosts.py b/HySoP/hysop/operator/discrete/synchronizeGhosts.py index 286fff841..5556f66ae 100644 --- a/HySoP/hysop/operator/discrete/synchronizeGhosts.py +++ b/HySoP/hysop/operator/discrete/synchronizeGhosts.py @@ -115,15 +115,15 @@ class SynchronizeGhosts_d(DiscreteOperator): #self.discreteOperator.setUp() @debug - def apply(self, *args): + def apply(self, t, dt, ite): self.resolution = self.topology.localGridResolution resolution = self.topology.localGridResolution ghosts = self.topology.ghosts dim = self.topology.dim self.compute_time = time.time() # Do the send/recv as defined in setup. - if args is None: - args = self.fieldslist + #### if args is None: \todo : A verifier. + args = self.fieldslist self.fieldslist = np.asarray([self.fieldslist]) if (self.transferMethod == 'SendRecv'): for f in fieldslist: diff --git a/HySoP/hysop/operator/discrete/transport.py b/HySoP/hysop/operator/discrete/transport.py deleted file mode 100644 index f21a322d3..000000000 --- a/HySoP/hysop/operator/discrete/transport.py +++ /dev/null @@ -1,127 +0,0 @@ -""" -@file transport.py - -Discrete transport representation -""" -from discrete import DiscreteOperator -from parmepy.gpu import PARMES_REAL_GPU - - -class Transport_d(DiscreteOperator): - """ - Particle transport operator representation. - - """ - - def __init__(self, advec, idVelocityD=0, idScalarD=0, - result_position=None, result_scalar=None, method=None): - """ - Create a Advection operator. - Work on a given scalar at a given velocity to produce scalar - distribution at new positions. - - @param advec : Transport operator - @param idVelocityD : Index of velocity discretisation to use. - @param idScalarD : Index of scalar discretisation to use. - @param result_position : result position. - @param result_scalar : result scalar. - @param method : the method to use. - """ - DiscreteOperator.__init__(self) - ## Velocity. - self.velocity = advec.velocity.discreteField[idVelocityD] - ## Transported scalar. - self.scalar = advec.scalar.discreteField[idScalarD] - ## Result position - self.res_position = result_position.discreteField[0] - ## Result scalar - self.res_scalar = result_scalar.discreteField[0] - self.input = [self.velocity, self.scalar] - self.output = [self.res_position, self.res_scalar] - self.method = method - ## Previous splitting direction - self.old_splitting_direction = None - ## Compute time detailed per directions - self.compute_time = [0., 0., 0.] - ## Compute time for copy detailed per directions - self.compute_time_copy = [0., 0., 0.] - ## Compute time for transposition detailed per directions - self.compute_time_swap = [0., 0., 0.] - self.name = "advection" - self.call_number = [0, 0, 0] - self.gpu_precision = PARMES_REAL_GPU - - def apply(self, t, dt, splittingDirection): - """ - Apply advection operator. - - @param t : current time. - @param dt : time step. - @param splittingDirection : Direction of splitting. - - Advection algorithm: - @li 1. Particle initialization : \n - - by copy scalar from grid to particles if previous splitting - direction equals current splitting direction.\n - - by transposition of scalar from grid to particle. - @li 2. Particle advection :\n - - compute particle position in splitting direction as a - scalar. Performs a RK2 resolution of dx_p/dt = a_p. - @li 3. Profile timings of OpenCL kernels. - """ - c_time, c_time_init = 0., 0. - self.call_number[splittingDirection] += 1 - if self.numMethod is not None and self.init_transpose is not None and self.init_copy is not None: - # Particle init - if (self.old_splitting_direction == splittingDirection) or self.old_splitting_direction is None: - evt_init = self.init_copy.launch(self.scalar.gpu_data, - self.res_scalar.gpu_data) - else: - if self.scalar.topology.dim == 2: - evt_init = self.init_transpose.launch(self.scalar.gpu_data, - self.res_scalar.gpu_data) - else: - if min(self.old_splitting_direction, splittingDirection) == 0: - evt_init = self.init_transpose.launch(0, - self.scalar.gpu_data, - self.res_scalar.gpu_data) - else: - evt_init = self.init_transpose.launch(1, - self.scalar.gpu_data, - self.res_scalar.gpu_data) - # Advection - evt = self.numMethod.launch(self.velocity.gpu_data[splittingDirection], - self.res_position.gpu_data, - self.gpu_precision(dt), - self.gpu_precision(self.scalar.topology.mesh.origin[splittingDirection]), - self.gpu_precision(self.scalar.topology.mesh.size[splittingDirection])) - for df in self.output: - df.contains_data = False - # Get timpings from OpenCL events - self.numMethod.finish() - c_time_init = (evt_init.profile.end - evt_init.profile.start) * 1e-9 - c_time = (evt.profile.end - evt.profile.start) * 1e-9 - self.compute_time[splittingDirection] += c_time - if (self.old_splitting_direction == splittingDirection) or self.old_splitting_direction is None: - self.compute_time_copy[splittingDirection] += c_time_init - else: - self.compute_time_swap[min(self.old_splitting_direction, splittingDirection)] += c_time_init - self.total_time += (c_time + c_time_init) - self.old_splitting_direction = splittingDirection - return (c_time + c_time_init) - - def printComputeTime(self): - self.timings_info[0] = "\"Advection total\" \"copy\" \"swap xy\" \"swap xz\" \"Advection x\" \"Advection y\" \"Advection z\" " - self.timings_info[1] = str(self.total_time) + " " + str(self.compute_time_copy[0]) + " " - self.timings_info[1] += str(self.compute_time_swap[0]) + " " + str(self.compute_time_swap[1]) + " " - self.timings_info[1] += str(self.compute_time[0]) + " " + str(self.compute_time[1]) + " " + str(self.compute_time[2]) + " " - print "Advection total time : ", self.total_time, self.call_number - print "\t Advection init copy :", self.compute_time_copy, self.init_copy.call_number - print "\t Advection init swap :", self.compute_time_swap, self.init_transpose.call_number - print "\t Advection :", self.compute_time, self.numMethod.call_number - - -if __name__ == "__main__": - print __doc__ - print "- Provided class : Transport_d" - print Transport_d.__doc__ diff --git a/HySoP/hysop/operator/energy_enstrophy.py b/HySoP/hysop/operator/energy_enstrophy.py index f30dfebff..aa31a2720 100644 --- a/HySoP/hysop/operator/energy_enstrophy.py +++ b/HySoP/hysop/operator/energy_enstrophy.py @@ -60,7 +60,7 @@ class Energy_enstrophy(Monitoring): self._isUpToDate = True - def apply(self, t, dt, ite, *args): + def apply(self, t, dt, ite): """ Computation of kinetic energy, enstrophy & Checking energy and enstrophy decay diff --git a/HySoP/hysop/operator/monitors/printer.py b/HySoP/hysop/operator/monitors/printer.py index 4b1ade2d9..37e207ac7 100644 --- a/HySoP/hysop/operator/monitors/printer.py +++ b/HySoP/hysop/operator/monitors/printer.py @@ -39,7 +39,7 @@ class Printer(Monitoring): self.compute_time = 0. self.call_number = 0 - def apply(self, ite, *args): + def apply(self, t, dt, ite): self.step(ite) def _build_vtk_dict(self): -- GitLab