From fc42563488a0730cb6684564944fdd06967d58d3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Keck <Jean-Baptiste.Keck@imag.fr> Date: Sun, 2 Dec 2018 18:45:30 +0100 Subject: [PATCH] fixed some examples --- examples/shear_layer/shear_layer.py | 9 +--- hysop/backend/device/kernel_autotuner.py | 2 +- hysop/operator/adapt_timestep.py | 61 +++++++++++++++++------- hysop/operator/base/spectral_operator.py | 1 + hysop/operator/poisson_curl.py | 4 ++ 5 files changed, 53 insertions(+), 24 deletions(-) diff --git a/examples/shear_layer/shear_layer.py b/examples/shear_layer/shear_layer.py index d065729de..81dc9768b 100644 --- a/examples/shear_layer/shear_layer.py +++ b/examples/shear_layer/shear_layer.py @@ -89,15 +89,9 @@ def compute(args): velocity_cfl = args.cfl, variables = {velo: npts, vorti: npts}, dt=dt, **extra_op_kwds) - #> Directional diffusion - diffusion = DirectionalDiffusion(implementation=impl, - name='stretching_diffusion', - fields=vorti, coeffs=nu, - variables={vorti: npts}, - dt=dt, **extra_op_kwds) #> Directional splitting operator subgraph splitting = StrangSplitting(splitting_dim=dim, order=args.strang_order) - splitting.push_operators(advec, diffusion) + splitting.push_operators(advec) ### Build standard operators @@ -106,6 +100,7 @@ def compute(args): velocity=velo, vorticity=vorti, variables={velo:npts, vorti: npts}, projection=args.reprojection_frequency, + diffusion=nu, dt=dt, implementation=impl, **extra_op_kwds) #> We ask to dump the inputs and the outputs of this operator poisson.dump_outputs(fields=(vorti,), frequency=args.dump_freq) diff --git a/hysop/backend/device/kernel_autotuner.py b/hysop/backend/device/kernel_autotuner.py index bc02adc1e..fb883a101 100644 --- a/hysop/backend/device/kernel_autotuner.py +++ b/hysop/backend/device/kernel_autotuner.py @@ -708,7 +708,7 @@ class KernelAutotuner(object): def _print_footer(self, ellapsed, best_candidate): if self.verbose: (best_extra_params, best_work_load, best_global_size, best_local_size, - _, _, best_stats, _, _, _) = best_candidate + _, _, best_stats, _, _, _, _) = best_candidate if self.verbose>1: if ellapsed is not None: self._print_separator() diff --git a/hysop/operator/adapt_timestep.py b/hysop/operator/adapt_timestep.py index f54a98324..d324f267e 100755 --- a/hysop/operator/adapt_timestep.py +++ b/hysop/operator/adapt_timestep.py @@ -77,8 +77,9 @@ class TimestepCriteria(ComputationalGraphOperator): class CflTimestepCriteria(TimestepCriteria): @debug - def __init__(self, cfl, Fmin, Fmax, - parameter, dx=None, + def __init__(self, cfl, parameter, + Finf=None, Fmin=None, Fmax=None, + dx=None, name=None, pretty_name=None, relative_velocities=None, **kwds): """ @@ -92,6 +93,11 @@ class CflTimestepCriteria(TimestepCriteria): ---------- cfl: float CFL value used to compute timestep. + Finf: TensorParameter + A tensor parameter that contains Finf for every components. + Can be specified instead of Fmin and Fmax: + *Fmin will be set to -Finf + *Fmax will be set to +Finf Fmin: TensorParameter A tensor parameter that contains Fmin for every components. Fmax: TensorParameter @@ -108,53 +114,76 @@ class CflTimestepCriteria(TimestepCriteria): """ assert (cfl > 0.0), 'negative cfl condition.' check_instance(cfl, float) - check_instance(Fmin, TensorParameter) - check_instance(Fmax, TensorParameter) + if (Finf is None): + check_instance(Fmin, TensorParameter) + check_instance(Fmax, TensorParameter) + assert Fmin.shape == Fmax.shape + input_params={ Fmin.name: Fmin, Fmax.name: Fmax } + dtype = Fmin.dtype + shape = Fmin.shape + size = Fmin.size + else: + check_instance(Finf, TensorParameter) + msg='Cannot specify (Fmin,Fmax) and Finf at the same time.' + assert (Fmin is None), msg + assert (Fmax is None), msg + input_params={ Finf.name: Finf } + dtype = Finf.dtype + shape = Finf.shape + size = Finf.size + check_instance(parameter, ScalarParameter) check_instance(dx, tuple, values=float, allow_none=True) check_instance(relative_velocities, (tuple, list), allow_none=True) - assert Fmin.shape == Fmax.shape name = first_not_None(name, 'CFL') pretty_name = first_not_None(pretty_name, name) super(CflTimestepCriteria,self).__init__(name=name, pretty_name=pretty_name, - input_params={Fmin.name: Fmin, - Fmax.name: Fmax}, + input_params=input_params, output_params={parameter.name: parameter}, parameter=parameter, **kwds) if (relative_velocities is None): - relative_velocities = [(0,)*Fmin.size] + relative_velocities = [(0,)*size] assert len(relative_velocities)>=1 rv = () for Vr in relative_velocities: - Vr = npw.asarray(Vr, dtype=Fmin.dtype) - assert Vr.shape == Fmin.shape == Fmax.shape + Vr = npw.asarray(Vr, dtype=dtype) + assert Vr.shape == shape rv += (Vr,) relative_velocities = rv self.cfl = cfl self.Fmin = Fmin self.Fmax = Fmax + self.Finf = Finf self.dx = dx self.relative_velocities = relative_velocities def setup(self, **kwds): super(CflTimestepCriteria, self).setup(**kwds) if (self.dx is None): - Fmin = self.Fmin - if hasattr(Fmin, 'min_max_dfield'): - self.dx = Fmin.min_max_dfield.get_unique_attribute('mesh', '_mesh', '_space_step')[::-1] - else: + dx = None + for attr in ('Finf', 'Fmin', 'Fmax'): + attr = getattr(self, attr) + if hasattr(attr, 'min_max_dfield'): + dx = attr.min_max_dfield.get_unique_attribute('mesh', '_mesh', '_space_step')[::-1] + if (dx is None): msg='Could not extract dx from Fmin.' raise RuntimeError(msg) + self.dx = dx def compute_criteria(self, **kwds): cfl = self.cfl dx = self.dx - Fmin = self.Fmin() - Fmax = self.Fmax() + if (self.Finf is None): + Fmin = self.Fmin() + Fmax = self.Fmax() + else: + Finf = self.Finf() + Fmin = -Finf + Fmax = +Finf assert len(dx) == Fmin.size == Fmax.size assert len(self.relative_velocities)>=1 diff --git a/hysop/operator/base/spectral_operator.py b/hysop/operator/base/spectral_operator.py index 347403136..0f89b45a3 100644 --- a/hysop/operator/base/spectral_operator.py +++ b/hysop/operator/base/spectral_operator.py @@ -1225,6 +1225,7 @@ class PlannedSpectralTransform(object): buf_nbytes = compute_nbytes(buf.shape, buf.dtype) input_nbytes = compute_nbytes(input_shape, input_dtype) assert buf_nbytes >= input_nbytes, (buf_nbytes, input_nbytes) + print buf.shape, buf.strides, buf.dtype buf = buf.view(dtype=np.int8)[:input_nbytes].view(dtype=input_dtype).reshape(input_shape) if isinstance(buf, Array): buf = buf.handle diff --git a/hysop/operator/poisson_curl.py b/hysop/operator/poisson_curl.py index c7857645b..1fc61f707 100644 --- a/hysop/operator/poisson_curl.py +++ b/hysop/operator/poisson_curl.py @@ -129,6 +129,10 @@ class PoissonCurl(SpectralComputationalGraphNodeFrontend): msg='Vorticity component mistmach, got {} components but expected 3.'.format(wcomp) raise RuntimeError(msg) + if ('nu' in kwds): + msg="Diffusion is enabled with the 'diffusion' parameter, not 'nu'." + raise ValueError(msg) + super(PoissonCurl, self).__init__(velocity=velocity, vorticity=vorticity, variables=variables, base_kwds=base_kwds, implementation=implementation, **kwds) -- GitLab