From 4a8399dee8cbf941ba0acff1c4e32bc44e898935 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Keck <Jean-Baptiste.Keck@imag.fr> Date: Sun, 16 Dec 2018 15:28:33 +0100 Subject: [PATCH] fixed examples with new syntax --- .../flow_around_sphere/flow_around_sphere.py | 18 ++++++++++-------- examples/scalar_advection/levelset.py | 8 ++++---- .../turbulent_scalar_advection.py | 13 +++++++------ .../host/python/operator/penalization.py | 2 +- hysop/operator/penalization.py | 2 +- hysop/tools/types.py | 5 +++-- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/examples/flow_around_sphere/flow_around_sphere.py b/examples/flow_around_sphere/flow_around_sphere.py index a371df7ae..827a0c568 100644 --- a/examples/flow_around_sphere/flow_around_sphere.py +++ b/examples/flow_around_sphere/flow_around_sphere.py @@ -8,7 +8,7 @@ from hysop.parameters.tensor_parameter import TensorParameter from hysop.constants import Implementation, AdvectionCriteria, HYSOP_REAL, \ StretchingFormulation, StretchingCriteria from hysop.operators import Advection, StaticDirectionalStretching, Diffusion, \ - PoissonRotational, AdaptiveTimeStep, \ + PoissonCurl, AdaptiveTimeStep, \ Enstrophy, MinMaxFieldStatistics, StrangSplitting, \ ParameterPlotter, PenalizeVorticity, FlowRateCorrection, \ VorticityAbsorption @@ -16,7 +16,7 @@ from hysop.numerics.odesolvers.runge_kutta import RK2 from hysop.methods import SpaceDiscretization, Remesh, TimeIntegrator, \ ComputeGranularity, Interpolation, StrangOrder from hysop.topology.cartesian_topology import CartesianTopology -from hysop.tools.parameters import Discretization +from hysop.tools.parameters import CartesianDiscretization pi = np.pi @@ -26,7 +26,7 @@ sin = np.sin # Define the domain dim = 3 -npts = (33,33,65) +npts = (32,32,64) box = Box(dim=dim, origin=[-2.56, -2.56, -2.56], length=[5.12, 5.12, 10.24]) @@ -124,7 +124,7 @@ method = {} # Define parameters and field (time, timestep, velocity, vorticity, enstrophy) t, dt = TimeParameters(dtype=HYSOP_REAL) velo = VelocityField(domain=box, dtype=HYSOP_REAL) -vorti = VorticityField(domain=box, dtype=HYSOP_REAL) +vorti = VorticityField(velocity=velo, dtype=HYSOP_REAL) sphere = Field(domain=box, name="Sphere", is_vector=False, dtype=HYSOP_REAL) wdotw = Field(domain=box, dtype=HYSOP_REAL, is_vector=False, name="WdotW") enstrophy = EnstrophyParameter(dtype=HYSOP_REAL) @@ -134,11 +134,13 @@ flowrate = TensorParameter(name="flowrate", dtype=HYSOP_REAL, shape=(3, ), # Topologies topo_nogh = CartesianTopology(domain=box, - discretization=Discretization(npts), + discretization=CartesianDiscretization(npts, + default_boundaries=True), mpi_params=mpi_params, cutdirs=[False, False, True]) topo_gh = CartesianTopology(domain=box, - discretization=Discretization(npts, ghosts=(4, 4, 4)), + discretization=CartesianDiscretization(npts, + ghosts=(4, 4, 4), default_boundaries=True), mpi_params=mpi_params, cutdirs=[False, False, True]) @@ -177,7 +179,7 @@ penal = PenalizeVorticity( diffuse = Diffusion( implementation=Implementation.FORTRAN, name='diffuse', - viscosity=viscosity, + nu=viscosity, Fin=vorti, variables={vorti: topo_nogh}, dt=dt, **extra_op_kwds) @@ -191,7 +193,7 @@ absorption = VorticityAbsorption( variables={velo: topo_nogh, vorti: topo_nogh}, dt=dt, **extra_op_kwds) #> Poisson operator to recover the velocity from the vorticity -poisson = PoissonRotational( +poisson = PoissonCurl( implementation=Implementation.FORTRAN, name='poisson', velocity=velo, diff --git a/examples/scalar_advection/levelset.py b/examples/scalar_advection/levelset.py index 5b5381319..963947427 100644 --- a/examples/scalar_advection/levelset.py +++ b/examples/scalar_advection/levelset.py @@ -5,7 +5,7 @@ import sympy as sm from hysop import Field, Box, Simulation, Problem, \ - ScalarParameter, MPIParams, Discretization, CartesianTopology + ScalarParameter, MPIParams, CartesianDiscretization, CartesianTopology from hysop.constants import Implementation, Backend from hysop.operators import DirectionalAdvection, StrangSplitting, Integrate, \ AnalyticField, Advection @@ -31,8 +31,8 @@ def init_scalar(data, coords): data[0][rr < 0.1] += 1. # Define domain -npts = (65,)*dim -npts_s = (65, )*dim +npts = (64,)*dim +npts_s = (64, )*dim box = Box(origin=(0.,)*dim, length=(1.,)*dim, dim=dim) if dim == 3: dt0 = 0.35 / (4. * pi) @@ -68,7 +68,7 @@ simu.write_parameters(simu.t, vol, filename='volume.txt', precision=8) # ghosts = (2,)*dim -# d3d = Discretization(npts, ghosts) +# d3d = CartesianDiscretization(npts, ghosts, default_boundaries=True) # topo = CartesianTopology(domain=box, discretization=d3d, backend=Backend.OPENCL) # Setup implementation specific variables diff --git a/examples/scalar_advection/turbulent_scalar_advection.py b/examples/scalar_advection/turbulent_scalar_advection.py index 8a887f383..1c8664a81 100644 --- a/examples/scalar_advection/turbulent_scalar_advection.py +++ b/examples/scalar_advection/turbulent_scalar_advection.py @@ -60,13 +60,13 @@ from hysop.constants import Implementation, AdvectionCriteria, HYSOP_REAL, \ StretchingFormulation from hysop.topology.cartesian_topology import CartesianTopology from hysop.operators import Advection, StaticDirectionalStretching, Diffusion, \ - PoissonRotational, AdaptiveTimeStep, DirectionalDiffusion, \ + PoissonCurl, AdaptiveTimeStep, DirectionalDiffusion, \ Enstrophy, MinMaxFieldStatistics, StrangSplitting, \ ParameterPlotter, DirectionalAdvection from hysop.numerics.odesolvers.runge_kutta import RK2 from hysop.methods import SpaceDiscretization, Remesh, TimeIntegrator, \ ComputeGranularity, Interpolation, StrangOrder -from hysop.tools.parameters import Discretization +from hysop.tools.parameters import CartesianDiscretization # Define the domain dim = 3 @@ -98,14 +98,15 @@ method = {} # Define parameters and field (time, timestep, velocity, vorticity, enstrophy) t, dt = TimeParameters(dtype=HYSOP_REAL) velo = VelocityField(domain=box, dtype=HYSOP_REAL) -vorti = VorticityField(domain=box, dtype=HYSOP_REAL) +vorti = VorticityField(velocity=velo, dtype=HYSOP_REAL) enstrophy = EnstrophyParameter(dtype=HYSOP_REAL) wdotw = Field(domain=box, dtype=HYSOP_REAL, is_vector=False, name="WdotW") scal = Field(domain=box, name='Scalar', is_vector=False) # Topologies topo_nogh = CartesianTopology(domain=box, - discretization=Discretization(npts_uw), + discretization=CartesianDiscretization(npts_uw, + default_boundaries=True), mpi_params=mpi_params, cutdirs=[False, False, True]) @@ -155,12 +156,12 @@ splitting.push_operators(stretch) diffuse = Diffusion( implementation=Implementation.FORTRAN, name='diffuse', - viscosity=VISCOSITY, + nu=VISCOSITY, Fin=vorti, variables={vorti: topo_nogh}, dt=dt, **extra_op_kwds) #> Poisson operator to recover the velocity from the vorticity -poisson = PoissonRotational( +poisson = PoissonCurl( implementation=Implementation.FORTRAN, name='poisson', velocity=velo, diff --git a/hysop/backend/host/python/operator/penalization.py b/hysop/backend/host/python/operator/penalization.py index ba84eb882..6f3d0d58a 100755 --- a/hysop/backend/host/python/operator/penalization.py +++ b/hysop/backend/host/python/operator/penalization.py @@ -45,7 +45,7 @@ class PythonPenalizeVorticity(HostOperator): check_instance(dt, ScalarParameter) check_instance(coeff, (ScalarParameter, float)) check_instance(obstacles, (tuple, dict), values=Field, - keys=(ScalarParameter, float)) + keys=(ScalarParameter, float), check_kwds=False) input_fields = {velocity: variables[velocity], vorticity: variables[vorticity]} diff --git a/hysop/operator/penalization.py b/hysop/operator/penalization.py index d43442294..6907e1093 100755 --- a/hysop/operator/penalization.py +++ b/hysop/operator/penalization.py @@ -93,7 +93,7 @@ class PenalizeVorticity(ComputationalGraphNodeFrontend): check_instance(dt, ScalarParameter) check_instance(coeff, (ScalarParameter, float), allow_none=True) check_instance(obstacles, (tuple, dict), values=Field, - keys=(ScalarParameter, float)) + keys=(ScalarParameter, float), check_kwds=False) super(PenalizeVorticity, self).__init__( velocity=velocity, vorticity=vorticity, diff --git a/hysop/tools/types.py b/hysop/tools/types.py index 2d1a06899..3f127f440 100644 --- a/hysop/tools/types.py +++ b/hysop/tools/types.py @@ -14,7 +14,8 @@ class InstanceOf(object): return 'InstanceOf({})'.format(self.cls.__name__) -def check_instance(val, cls, allow_none=False, **kargs): +def check_instance(val, cls, allow_none=False, + check_kwds=True, **kargs): """ Raise a TypeError if val is not an instance of cls. cls can be a tuple of types like isinstance(...) capabilities. @@ -240,7 +241,7 @@ def check_instance(val, cls, allow_none=False, **kargs): msg=msg.format(val, maxval) raise ValueError(msg) - if kargs: + if check_kwds and kargs: raise RuntimeError('Some arguments were not used ({}).'.format(kargs)) -- GitLab