diff --git a/.travis.yml b/.travis.yml index efb48cdd7279d7e684d6436440ba1107e7d67810_LnRyYXZpcy55bWw=..261aec1fbc8261fc2891e721ce4e048aac709237_LnRyYXZpcy55bWw= 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ install: - pip install -U pip setuptools wheel six colorlog - pip install -U pipenv tox-pipenv coverage fluiddevops - - pip install -U numpy cython mako mpi4py "fluidpythran>=0.1.3" # To be removed when pip==10 is out and this step can be bootstrapped + - pip install -U numpy cython mako mpi4py "fluidpythran>=0.1.4" # To be removed when pip==10 is out and this step can be bootstrapped before_script: - | diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index efb48cdd7279d7e684d6436440ba1107e7d67810_Yml0YnVja2V0LXBpcGVsaW5lcy55bWw=..261aec1fbc8261fc2891e721ce4e048aac709237_Yml0YnVja2V0LXBpcGVsaW5lcy55bWw= 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -14,5 +14,5 @@ caches: - pip script: - - pip install -U tox "fluidpythran>=0.1.3" --user + - pip install -U tox "fluidpythran>=0.1.4" --user - tox -e py36,codecov diff --git a/fluidsim/base/output/increments.py b/fluidsim/base/output/increments.py index efb48cdd7279d7e684d6436440ba1107e7d67810_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvaW5jcmVtZW50cy5weQ==..261aec1fbc8261fc2891e721ce4e048aac709237_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvaW5jcmVtZW50cy5weQ== 100644 --- a/fluidsim/base/output/increments.py +++ b/fluidsim/base/output/increments.py @@ -4,7 +4,7 @@ # pythran import numpy as np -from fluidpythran import pythran_def, Array +from fluidpythran import boost, Array from fluiddyn.util import mpi from .base import SpecificOutput @@ -14,7 +14,7 @@ # int32[], float64[][], float64[][], float, bool) -@pythran_def +@boost def strfunc_from_pdf( rxs: A, pdf: A, values: A, order: float, absolute: bool = False ): diff --git a/fluidsim/base/time_stepping/pseudo_spect.py b/fluidsim/base/time_stepping/pseudo_spect.py index efb48cdd7279d7e684d6436440ba1107e7d67810_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL3BzZXVkb19zcGVjdC5weQ==..261aec1fbc8261fc2891e721ce4e048aac709237_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL3BzZXVkb19zcGVjdC5weQ== 100644 --- a/fluidsim/base/time_stepping/pseudo_spect.py +++ b/fluidsim/base/time_stepping/pseudo_spect.py @@ -31,5 +31,4 @@ fp = FluidPythran() -T = Type(np.complex128) N = NDim(3, 4) @@ -35,5 +34,5 @@ N = NDim(3, 4) -A = Array[T, N] +A = Array[np.complex128, N] T = Type(np.float64, np.complex128) A1 = Array[T, N] diff --git a/fluidsim/operators/operators2d.py b/fluidsim/operators/operators2d.py index efb48cdd7279d7e684d6436440ba1107e7d67810_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczJkLnB5..261aec1fbc8261fc2891e721ce4e048aac709237_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczJkLnB5 100644 --- a/fluidsim/operators/operators2d.py +++ b/fluidsim/operators/operators2d.py @@ -9,8 +9,7 @@ """ -from builtins import range from warnings import warn import numpy as np @@ -13,7 +12,6 @@ from warnings import warn import numpy as np -from fluidpythran import pythran_def, Array, FluidPythran - +from fluidpythran import boost, Array, FluidPythran from fluiddyn.util import mpi @@ -19,5 +17,4 @@ from fluiddyn.util import mpi - from fluidfft.fft2d.operators import OperatorsPseudoSpectral2D as _Operators from ..base.setofvariables import SetOfVariables @@ -29,9 +26,11 @@ "operators2d.py has to be pythranized to be efficient! " "Install pythran and recompile." ) +elif fp.is_transpiling: + _Operators = object Af = Array[np.float64, "2d"] Ac = Array[np.complex128, "2d"] @@ -32,26 +31,12 @@ Af = Array[np.float64, "2d"] Ac = Array[np.complex128, "2d"] -@pythran_def -def dealiasing_setofvar( - setofvar_fft: "complex128[][][]", where: "uint8[][]", n0: int, n1: int -): - """Dealiasing of a setofvar arrays.""" - nk = setofvar_fft.shape[0] - - for i0 in range(n0): - for i1 in range(n1): - if where[i0, i1]: - for ik in range(nk): - setofvar_fft[ik, i0, i1] = 0.0 - - -@pythran_def +@boost def laplacian_fft(a_fft: Ac, Kn: Af): """Compute the n-th order Laplacian.""" return a_fft * Kn @@ -53,9 +38,9 @@ def laplacian_fft(a_fft: Ac, Kn: Af): """Compute the n-th order Laplacian.""" return a_fft * Kn -@pythran_def +@boost def invlaplacian_fft(a_fft: Ac, Kn_not0: Af, rank: int): """Compute the n-th order inverse Laplacian.""" invlap_afft = a_fft / Kn_not0 @@ -64,7 +49,7 @@ return invlap_afft -@pythran_def +@boost def compute_increments_dim1(var: Af, irx: int): """Compute the increments of var over the dim 1.""" n1 = var.shape[1] @@ -85,4 +70,5 @@ comm = mpi.comm +@boost class OperatorsPseudoSpectral2D(_Operators): @@ -88,4 +74,8 @@ class OperatorsPseudoSpectral2D(_Operators): + + _has_to_dealiase: bool + where_dealiased: "uint8[:, :]" + @staticmethod def _complete_params_with_default(params): """This static method is used to complete the *params* container. @@ -181,9 +171,7 @@ for thing in args: if isinstance(thing, SetOfVariables): - dealiasing_setofvar( - thing, self.where_dealiased, self.nK0_loc, self.nK1_loc - ) + self.dealiasing_setofvar(thing) elif isinstance(thing, np.ndarray): self.dealiasing_variable(thing) @@ -187,5 +175,7 @@ elif isinstance(thing, np.ndarray): self.dealiasing_variable(thing) - def dealiasing_setofvar(self, sov): + @boost + def dealiasing_setofvar(self, sov: "complex128[][][]"): + """Dealiasing of a setofvar arrays.""" if self._has_to_dealiase: @@ -191,7 +181,11 @@ if self._has_to_dealiase: - dealiasing_setofvar( - sov, self.where_dealiased, self.nK0_loc, self.nK1_loc - ) + nk, n0, n1 = sov.shape + + for i0 in range(n0): + for i1 in range(n1): + if self.where_dealiased[i0, i1]: + for ik in range(nk): + sov[ik, i0, i1] = 0.0 def project_fft_on_realX_seq(self, f_fft): """Project the given field in spectral space such as its diff --git a/fluidsim/operators/operators3d.py b/fluidsim/operators/operators3d.py index efb48cdd7279d7e684d6436440ba1107e7d67810_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczNkLnB5..261aec1fbc8261fc2891e721ce4e048aac709237_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczNkLnB5 100644 --- a/fluidsim/operators/operators3d.py +++ b/fluidsim/operators/operators3d.py @@ -9,12 +9,8 @@ """ -from __future__ import division - -from builtins import range - from math import pi from copy import deepcopy import numpy as np @@ -16,7 +12,7 @@ from math import pi from copy import deepcopy import numpy as np -from fluidpythran import pythran_def, Array, FluidPythran +from fluidpythran import boost, Array, FluidPythran from fluiddyn.util.mpi import nb_proc, rank @@ -22,4 +18,5 @@ from fluiddyn.util.mpi import nb_proc, rank +from fluidfft.fft3d.operators import OperatorsPseudoSpectral3D as _Operators from fluidsim.base.setofvariables import SetOfVariables @@ -23,8 +20,6 @@ from fluidsim.base.setofvariables import SetOfVariables -from fluidfft.fft3d.operators import OperatorsPseudoSpectral3D as _Operators - from .operators2d import OperatorsPseudoSpectral2D as OpPseudoSpectral2D fp = FluidPythran() @@ -35,7 +30,7 @@ Af = Array[np.float64, "3d"] -@pythran_def +@boost def dealiasing_setofvar(sov: Asov, where_dealiased: Aui8): """Dealiasing 3d setofvar object. @@ -59,7 +54,7 @@ sov[ik, i0, i1, i2] = 0.0 -@pythran_def +@boost def dealiasing_variable(ff_fft: Ac, where_dealiased: Aui8): """Dealiasing 3d array""" n0, n1, n2 = ff_fft.shape @@ -81,5 +76,6 @@ if not fp.is_transpiling and not fp.is_compiled: + # for example if Pythran is not available dealiasing_variable = dealiasing_variable_numpy dealiasing_setofvar = dealiasing_setofvar_numpy @@ -84,4 +80,6 @@ dealiasing_variable = dealiasing_variable_numpy dealiasing_setofvar = dealiasing_setofvar_numpy +elif fp.is_transpiling: + _Operators = object @@ -86,20 +84,6 @@ -@pythran_def -def urudfft_from_vxvyfft(vx_fft: Ac, vy_fft: Ac, kx: Af, ky: Af, rank: int): - k2 = kx ** 2 + ky ** 2 - k2[k2 == 0.0] = 1e-10 - - divh_fft = 1j * (kx * vx_fft + ky * vy_fft) - urx_fft = vx_fft - divh_fft * kx / k2 - ury_fft = vy_fft - divh_fft * ky / k2 - - udx_fft = vx_fft - urx_fft - udy_fft = vy_fft - ury_fft - - return urx_fft, ury_fft, udx_fft, udy_fft - - +@boost class OperatorsPseudoSpectral3D(_Operators): """Provides fast Fourier transform functions and 3D operators. @@ -120,6 +104,10 @@ """ + Kx: Af + Ky: Af + K2: Af + @staticmethod def _complete_params_with_default(params): """This static method is used to complete the *params* container. @@ -291,7 +279,8 @@ fc_fft[ikzc, ikyc, ikxc] = f_fft[ikz, iky, ikxc] return fc_fft - def urudfft_from_vxvyfft(self, vx_fft, vy_fft): + @boost + def urudfft_from_vxvyfft(self, vx_fft: Ac, vy_fft: Ac): """Compute toroidal and poloidal horizontal velocities """ @@ -295,7 +284,18 @@ """Compute toroidal and poloidal horizontal velocities """ - return urudfft_from_vxvyfft(vx_fft, vy_fft, self.Kx, self.Ky, rank) + + k2 = self.K2.copy() + k2[k2 == 0.0] = 1e-10 + + divh_fft = 1j * (self.Kx * vx_fft + self.Ky * vy_fft) + urx_fft = vx_fft - divh_fft * self.Kx / k2 + ury_fft = vy_fft - divh_fft * self.Ky / k2 + + udx_fft = vx_fft - urx_fft + udy_fft = vy_fft - ury_fft + + return urx_fft, ury_fft, udx_fft, udy_fft def _ik_from_ikc(ikc, nkc, nk): diff --git a/fluidsim/solvers/ns2d/solver.py b/fluidsim/solvers/ns2d/solver.py index efb48cdd7279d7e684d6436440ba1107e7d67810_Zmx1aWRzaW0vc29sdmVycy9uczJkL3NvbHZlci5weQ==..261aec1fbc8261fc2891e721ce4e048aac709237_Zmx1aWRzaW0vc29sdmVycy9uczJkL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/ns2d/solver.py +++ b/fluidsim/solvers/ns2d/solver.py @@ -18,7 +18,7 @@ import numpy as np -from fluidpythran import pythran_def, Array +from fluidpythran import boost, Array from fluidsim.base.setofvariables import SetOfVariables @@ -30,7 +30,7 @@ Af = Array[np.float64, "2d"] -@pythran_def +@boost def compute_Frot(ux: Af, uy: Af, px_rot: Af, py_rot: Af, beta: float = 0): if beta == 0: return -ux * px_rot - uy * py_rot diff --git a/fluidsim/solvers/plate2d/output/correlations_freq.py b/fluidsim/solvers/plate2d/output/correlations_freq.py index efb48cdd7279d7e684d6436440ba1107e7d67810_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC9jb3JyZWxhdGlvbnNfZnJlcS5weQ==..261aec1fbc8261fc2891e721ce4e048aac709237_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC9jb3JyZWxhdGlvbnNfZnJlcS5weQ== 100644 --- a/fluidsim/solvers/plate2d/output/correlations_freq.py +++ b/fluidsim/solvers/plate2d/output/correlations_freq.py @@ -11,5 +11,5 @@ """ -from __future__ import division, print_function +import os @@ -15,5 +15,2 @@ -from builtins import str -from builtins import range -import os import numpy as np @@ -19,8 +16,6 @@ import numpy as np - -# pythran import numpy as np import h5py import matplotlib.pyplot as plt from fluidpythran import cachedjit from fluiddyn.util import mpi @@ -22,7 +17,8 @@ import h5py import matplotlib.pyplot as plt from fluidpythran import cachedjit from fluiddyn.util import mpi +from fluiddyn.calcul.easypyfft import FFTW1DReal2Complex from fluidsim.base.output.base import SpecificOutput @@ -27,6 +23,7 @@ from fluidsim.base.output.base import SpecificOutput -from fluiddyn.calcul.easypyfft import FFTW1DReal2Complex + +# pythran import numpy as np @cachedjit @@ -131,5 +128,4 @@ def compute_correl4(q_fftt, iomegas1, nb_omegas, nb_xs_seq): - corr4 = compute_correl4_seq(q_fftt, iomegas1, nb_omegas, nb_xs_seq) @@ -135,5 +131,4 @@ corr4 = compute_correl4_seq(q_fftt, iomegas1, nb_omegas, nb_xs_seq) - if mpi.nb_proc > 1: # reduce SUM for mean: corr4 = mpi.comm.reduce(corr4, op=mpi.MPI.SUM, root=0) diff --git a/setup.cfg b/setup.cfg index efb48cdd7279d7e684d6436440ba1107e7d67810_c2V0dXAuY2Zn..261aec1fbc8261fc2891e721ce4e048aac709237_c2V0dXAuY2Zn 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,5 +21,5 @@ [options] setup_requires = - fluidpythran>=0.1.2 + fluidpythran>=0.1.4 numpy diff --git a/setup.py b/setup.py index efb48cdd7279d7e684d6436440ba1107e7d67810_c2V0dXAucHk=..261aec1fbc8261fc2891e721ce4e048aac709237_c2V0dXAucHk= 100644 --- a/setup.py +++ b/setup.py @@ -145,7 +145,7 @@ "future >= 0.16", "h5py", "h5netcdf", - "fluidpythran>=0.1.3", + "fluidpythran>=0.1.4", "setuptools_scm", "xarray", ] diff --git a/tox.ini b/tox.ini index efb48cdd7279d7e684d6436440ba1107e7d67810_dG94LmluaQ==..261aec1fbc8261fc2891e721ce4e048aac709237_dG94LmluaQ== 100644 --- a/tox.ini +++ b/tox.ini @@ -22,7 +22,7 @@ deps = pip==18.0 coverage - fluidpythran>=0.1.3 + fluidpythran>=0.1.4 mako numpy matplotlib