diff --git a/.hgignore b/.hgignore index 9bccb25fe016aed4b58d7978626bbeb12912e6db_LmhnaWdub3Jl..d518cba80100a7dda4c0ac799c06b46c6fee5871_LmhnaWdub3Jl 100644 --- a/.hgignore +++ b/.hgignore @@ -51,6 +51,8 @@ */*.png */*_pythran.cpp +**/_pythran/_*.py +**/_pythran/_*.cpp bench/results_bench/*.json bench/oar_launcher_* diff --git a/.travis.yml b/.travis.yml index 9bccb25fe016aed4b58d7978626bbeb12912e6db_LnRyYXZpcy55bWw=..d518cba80100a7dda4c0ac799c06b46c6fee5871_LnRyYXZpcy55bWw= 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ python: - 3.6 - - 2.7 - - 3.5 env: - TOXENV=py,codecov-travis OMPI_CC=/usr/bin/gcc-6 OMPI_CXX=/usr/bin/g++-6 @@ -35,10 +33,6 @@ - python: 3.6 env: TOXENV=lint - exclude: - - python: 3.5 - env: TOXENV=py,codecov-travis OMPI_CC=/usr/bin/gcc-6 OMPI_CXX=/usr/bin/g++-6 - before_cache: - | coverage erase @@ -50,9 +44,9 @@ # - $TRAVIS_BUILD_DIR/.tox install: - - pip install -U pip setuptools wheel six colorlog - - pip install -U tox-pipenv coverage fluiddevops - - pip install -U numpy cython mako mpi4py # To be removed when pip==10 is out and this step can be bootstrapped + - pip install -U pip==18.0 setuptools wheel six colorlog + - pip install -U pipenv==2018.7.1 tox-pipenv coverage fluiddevops + - pip install -U numpy cython mako mpi4py fluidpythran # To be removed when pip==10 is out and this step can be bootstrapped before_script: - | diff --git a/Makefile b/Makefile index 9bccb25fe016aed4b58d7978626bbeb12912e6db_TWFrZWZpbGU=..d518cba80100a7dda4c0ac799c06b46c6fee5871_TWFrZWZpbGU= 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ coverage: _tests_coverage _report_coverage lint: - pylint -rn --rcfile=pylintrc --jobs=$(shell nproc) fluidsim + pylint -rn --rcfile=pylintrc --jobs=$(shell nproc) fluidsim --exit-zero install: python setup.py install diff --git a/bench/profile_time_stepping/init.py b/bench/profile_time_stepping/init.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_YmVuY2gvcHJvZmlsZV90aW1lX3N0ZXBwaW5nL2luaXQucHk= --- /dev/null +++ b/bench/profile_time_stepping/init.py @@ -0,0 +1,55 @@ + +from fluidsim.solvers.ns2d.solver import Simul +from fluidsim.solvers.sw1l.solver import Simul + +params = Simul.create_default_params() + +params.output.sub_directory = 'bench_time_stepping' + +params.oper.nx = params.oper.ny = nh = 1024 + +params.nu_8 = 1. + +params.time_stepping.it_end = 10 +params.time_stepping.USE_T_END = False +params.time_stepping.USE_CFL = False +params.time_stepping.deltat0 = 1e-16 +params.time_stepping.type_time_scheme = "RK2" + +params.init_fields.type = 'dipole' + +params.forcing.enable = True +params.forcing.type = 'proportional' + +params.output.periods_print.print_stdout = 0.25 + +sim = Simul(params) + +print("used time stepping func:\n", sim.time_stepping._time_step_RK) + +""" +# cython +%timeit sim.time_stepping._time_step_RK() +# numpy +%timeit sim.time_stepping._time_step_RK2() +# pythran +%timeit sim.time_stepping._time_step_RK2_pythran() +# fluidpythran +%timeit sim.time_stepping._time_step_RK2_fluidpythran() + +108 ms ± 292 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) +94.1 ms ± 449 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) +94.1 ms ± 441 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) + +# cython +%timeit sim.time_stepping._time_step_RK() +# numpy +%timeit sim.time_stepping._time_step_RK4() +# fluidpythran +%timeit sim.time_stepping._time_step_RK4_fluidpythran() + +243 ms ± 6.93 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) +263 ms ± 5.38 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) +227 ms ± 9.36 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) + +""" diff --git a/bench/profiling/util_bench.py b/bench/profiling/util_bench.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_YmVuY2gvcHJvZmlsaW5nL3V0aWxfYmVuY2gucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_YmVuY2gvcHJvZmlsaW5nL3V0aWxfYmVuY2gucHk= 100644 --- a/bench/profiling/util_bench.py +++ b/bench/profiling/util_bench.py @@ -17,7 +17,7 @@ params.oper.ny = nh # params.oper.type_fft = 'fft2d.mpi_with_fftw1d' - params.oper.type_fft = 'fft2d.with_cufft' + # params.oper.type_fft = 'fft2d.with_cufft' params.forcing.enable = True params.forcing.type = 'tcrandom' diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Yml0YnVja2V0LXBpcGVsaW5lcy55bWw=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Yml0YnVja2V0LXBpcGVsaW5lcy55bWw= 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -14,5 +14,5 @@ caches: - pip script: - - pip install -U tox --user + - pip install -U tox fluidpythran --user - tox -e py36,codecov @@ -18,11 +18,4 @@ - tox -e py36,codecov - - step: - image: fluiddyn/python2-stable - caches: - - pip - script: - - pip install -U tox --user - - tox -e py27,codecov dev: - parallel: - step: @@ -30,5 +23,5 @@ caches: - pip script: - - pip install -U tox --user + - pip install -U tox fluidpythran --user - tox -e py36,codecov @@ -34,8 +27,1 @@ - tox -e py36,codecov - - step: - image: fluiddyn/python2-stable - caches: - - pip - script: - - pip install -U tox --user - - tox -e py27,codecov diff --git a/config.py b/config.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Y29uZmlnLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Y29uZmlnLnB5 100644 --- a/config.py +++ b/config.py @@ -58,7 +58,6 @@ # To ensure the with statement works. Required for some older 2.7.x releases class Pool(LegacyPool): - def __enter__(self): return self @@ -72,7 +71,7 @@ "to use concurrent.futures Python 2.7 backport.\n" ) -DEBUG = os.environ.get('FLUIDDYN_DEBUG', False) +DEBUG = os.environ.get("FLUIDDYN_DEBUG", False) PARALLEL_COMPILE = not DEBUG @@ -136,10 +135,16 @@ """ self.check_extensions_list(self.extensions) - try: - self.compiler.compiler_so.remove("-Wstrict-prototypes") - except (AttributeError, ValueError): - pass + + to_be_removed = ["-Wstrict-prototypes"] + starts_forbiden = ["-axMIC_", "-diag-disable:"] + + self.compiler.compiler_so = [ + key + for key in self.compiler.compiler_so + if key not in to_be_removed + and all([not key.startswith(s) for s in starts_forbiden]) + ] for ext in self.extensions: try: diff --git a/doc/environment.yml b/doc/environment.yml index 9bccb25fe016aed4b58d7978626bbeb12912e6db_ZG9jL2Vudmlyb25tZW50LnltbA==..d518cba80100a7dda4c0ac799c06b46c6fee5871_ZG9jL2Vudmlyb25tZW50LnltbA== 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -7,11 +7,9 @@ - pandas - cython - h5py - - sphinx>=1.7.7 - - numpydoc - jupyter - matplotlib - fftw - pyfftw - mako - pip: @@ -12,9 +10,11 @@ - jupyter - matplotlib - fftw - pyfftw - mako - pip: + - sphinx + - numpydoc - sphinx_rtd_theme - hg+https://bitbucket.org/fluiddyn/fluiddyn#egg=fluiddyn - hg+https://bitbucket.org/fluiddyn/fluidfft#egg=fluidfft diff --git a/doc/examples/simul_ns2d.py b/doc/examples/simul_ns2d.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_ZG9jL2V4YW1wbGVzL3NpbXVsX25zMmQucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_ZG9jL2V4YW1wbGVzL3NpbXVsX25zMmQucHk= 100644 --- a/doc/examples/simul_ns2d.py +++ b/doc/examples/simul_ns2d.py @@ -4,8 +4,6 @@ params = Simul.create_default_params() -params.output.sub_directory = 'examples' - params.oper.nx = params.oper.ny = nh = 32 params.oper.Lx = params.oper.Ly = Lh = 2 * pi diff --git a/fluidsim/_version.py b/fluidsim/_version.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vX3ZlcnNpb24ucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vX3ZlcnNpb24ucHk= 100644 --- a/fluidsim/_version.py +++ b/fluidsim/_version.py @@ -20,15 +20,8 @@ """ - -try: - from setuptools_scm import get_version - - __version__ = get_version() -except: - __version__ = "0.2.2.post0" - +__version__ = "0.2.3" try: from pyfiglet import figlet_format @@ -31,9 +24,9 @@ try: from pyfiglet import figlet_format - __about__ = figlet_format("fluidsim v" + __version__, font="big") -except: + __about__ = figlet_format("fluidsim", font="big") +except ImportError: __about__ = r""" __ _ _ _ _ / _| | (_) | | (_) @@ -41,4 +34,5 @@ | _| | | | | |/ _` / __| | '_ ` _ \ | | | | |_| | | (_| \__ \ | | | | | | |_| |_|\__,_|_|\__,_|___/_|_| |_| |_| +""" @@ -44,2 +38,2 @@ -""" +__about__ = __about__.rstrip() + f"\n\n{28 * ' '} v. {__version__}\n" diff --git a/fluidsim/base/basilisk/operators.py b/fluidsim/base/basilisk/operators.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9vcGVyYXRvcnMucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9vcGVyYXRvcnMucHk= 100644 --- a/fluidsim/base/basilisk/operators.py +++ b/fluidsim/base/basilisk/operators.py @@ -1,5 +1,3 @@ - - from __future__ import division from builtins import object diff --git a/fluidsim/base/basilisk/output/__init__.py b/fluidsim/base/basilisk/output/__init__.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9vdXRwdXQvX19pbml0X18ucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9vdXRwdXQvX19pbml0X18ucHk= 100644 --- a/fluidsim/base/basilisk/output/__init__.py +++ b/fluidsim/base/basilisk/output/__init__.py @@ -1,5 +1,3 @@ - - from ...output.base import OutputBase # , SpecificOutput diff --git a/fluidsim/base/basilisk/run_example.py b/fluidsim/base/basilisk/run_example.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9ydW5fZXhhbXBsZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9ydW5fZXhhbXBsZS5weQ== 100644 --- a/fluidsim/base/basilisk/run_example.py +++ b/fluidsim/base/basilisk/run_example.py @@ -1,4 +1,3 @@ - import matplotlib.pyplot as plt from fluidsim.base.basilisk.solver import Simul diff --git a/fluidsim/base/basilisk/solver.py b/fluidsim/base/basilisk/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9zb2x2ZXIucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9zb2x2ZXIucHk= 100644 --- a/fluidsim/base/basilisk/solver.py +++ b/fluidsim/base/basilisk/solver.py @@ -1,4 +1,3 @@ - from __future__ import print_function from fluidsim.base.solvers.base import SimulBase @@ -43,7 +42,7 @@ def init(i, t): bas.omega.f = bas.noise - bas.event(init, t=0.) + bas.event(init, t=0.0) Simul = SimulBasilisk diff --git a/fluidsim/base/basilisk/state.py b/fluidsim/base/basilisk/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9zdGF0ZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay9zdGF0ZS5weQ== 100644 --- a/fluidsim/base/basilisk/state.py +++ b/fluidsim/base/basilisk/state.py @@ -1,5 +1,3 @@ - - from ..state import StateBase diff --git a/fluidsim/base/basilisk/time_stepping.py b/fluidsim/base/basilisk/time_stepping.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay90aW1lX3N0ZXBwaW5nLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9iYXNpbGlzay90aW1lX3N0ZXBwaW5nLnB5 100644 --- a/fluidsim/base/basilisk/time_stepping.py +++ b/fluidsim/base/basilisk/time_stepping.py @@ -1,4 +1,3 @@ - from __future__ import print_function from time import time @@ -12,7 +11,7 @@ def _complete_params_with_default(params): """This static method is used to complete the *params* container. """ - attribs = {"USE_T_END": True, "t_end": 10., "it_end": 10, "deltat0": 0.5} + attribs = {"USE_T_END": True, "t_end": 10.0, "it_end": 10, "deltat0": 0.5} params._set_child("time_stepping", attribs=attribs) def __init__(self, sim): @@ -66,7 +65,7 @@ print("t_end, nb_time_steps", t_end, nb_time_steps) self.sim.basilisk.event( - one_time_step, t=np.linspace(0., t_end, nb_time_steps + 1) + one_time_step, t=np.linspace(0.0, t_end, nb_time_steps + 1) ) time_begining_simul = time() diff --git a/fluidsim/base/forcing/anisotropic.py b/fluidsim/base/forcing/anisotropic.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9mb3JjaW5nL2FuaXNvdHJvcGljLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9mb3JjaW5nL2FuaXNvdHJvcGljLnB5 100644 --- a/fluidsim/base/forcing/anisotropic.py +++ b/fluidsim/base/forcing/anisotropic.py @@ -129,8 +129,8 @@ width = kxmax_forcing - kxmin_forcing height = kymax_forcing - kymin_forcing - theta1 = 90. - degrees(self.angle) - theta2 = 90. + theta1 = 90.0 - degrees(self.angle) + theta2 = 90.0 KX = self.oper_coarse.KX KY = self.oper_coarse.KY diff --git a/fluidsim/base/forcing/base.py b/fluidsim/base/forcing/base.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9mb3JjaW5nL2Jhc2UucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9mb3JjaW5nL2Jhc2UucHk= 100644 --- a/fluidsim/base/forcing/base.py +++ b/fluidsim/base/forcing/base.py @@ -58,7 +58,7 @@ "enable": False, "type": "", "available_types": [], - "forcing_rate": 1., + "forcing_rate": 1.0, "key_forced": None, }, ) diff --git a/fluidsim/base/forcing/specific.py b/fluidsim/base/forcing/specific.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9mb3JjaW5nL3NwZWNpZmljLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9mb3JjaW5nL3NwZWNpZmljLnB5 100644 --- a/fluidsim/base/forcing/specific.py +++ b/fluidsim/base/forcing/specific.py @@ -16,7 +16,7 @@ :members: :private-members: -.. autoclass:: SpecificForcingPseudoSpectral +.. autoclass:: SpecificForcingPseudoSpectralCoarse :members: :private-members: @@ -79,7 +79,7 @@ tag = "pseudo_spectral" def __init__(self, sim): - super(SpecificForcingPseudoSpectralSimple, self).__init__(sim) + super().__init__(sim) self.fstate = sim.state.__class__(sim, oper=self.sim.oper) self.forcing_fft = self.fstate.state_spect @@ -83,6 +83,18 @@ self.fstate = sim.state.__class__(sim, oper=self.sim.oper) self.forcing_fft = self.fstate.state_spect + def compute(self): + """compute a forcing normalize with a 2nd degree eq.""" + obj = self.compute_forcing_fft_each_time() + if isinstance(obj, dict): + kwargs = obj + else: + kwargs = {self.sim.params.forcing.key_forced: obj} + self.fstate.init_statespect_from(**kwargs) + + def compute_forcing_fft_each_time(self): + raise NotImplementedError + class InScriptForcingPseudoSpectral(SpecificForcingPseudoSpectralSimple): """Forcing maker for forcing defined by the user in the launching script @@ -94,6 +106,6 @@ tag = "in_script" def __init__(self, sim): - super(InScriptForcingPseudoSpectral, self).__init__(sim) + super().__init__(sim) self.is_initialized = False @@ -98,14 +110,5 @@ self.is_initialized = False - def compute(self): - """compute a forcing normalize with a 2nd degree eq.""" - obj = self.compute_forcing_fft_each_time() - if isinstance(obj, dict): - kwargs = obj - else: - kwargs = {self.sim.params.forcing.key_forced: obj} - self.fstate.init_statespect_from(**kwargs) - def compute_forcing_fft_each_time(self): """Compute the coarse forcing in Fourier space""" obj = self.compute_forcing_each_time() @@ -130,7 +133,7 @@ self.is_initialized = True -class SpecificForcingPseudoSpectral(SpecificForcing): +class SpecificForcingPseudoSpectralCoarse(SpecificForcing): """Specific forcing for pseudo-spectra solvers""" tag = "pseudo_spectral" @@ -159,8 +162,8 @@ def __init__(self, sim): - super(SpecificForcingPseudoSpectral, self).__init__(sim) + super().__init__(sim) params = sim.params self.forcing_fft = SetOfVariables( @@ -163,8 +166,8 @@ params = sim.params self.forcing_fft = SetOfVariables( - like=sim.state.state_spect, info="forcing_fft", value=0. + like=sim.state.state_spect, info="forcing_fft", value=0.0 ) if params.forcing.nkmax_forcing < params.forcing.nkmin_forcing: @@ -241,7 +244,7 @@ pass params_coarse.oper.type_fft = "sequential" - params_coarse.oper.coef_dealiasing = 1. + params_coarse.oper.coef_dealiasing = 1.0 self.oper_coarse = sim.oper.__class__(params=params_coarse) self.shapeK_loc_coarse = self.oper_coarse.shapeK_loc @@ -335,20 +338,6 @@ ) ) - -class InScriptForcingPseudoSpectralCoarse(SpecificForcingPseudoSpectral): - """Forcing maker for forcing defined by the user in the launching script - - .. inheritance-diagram:: InScriptForcingPseudoSpectralCoarse - - """ - - tag = "in_script_coarse" - - def __init__(self, sim): - super(InScriptForcingPseudoSpectralCoarse, self).__init__(sim) - self.is_initialized = False - def compute(self): """compute a forcing normalize with a 2nd degree eq.""" @@ -364,6 +353,23 @@ self.put_forcingc_in_forcing() def compute_forcingc_fft_each_time(self): + raise NotImplementedError + + +class InScriptForcingPseudoSpectralCoarse(SpecificForcingPseudoSpectralCoarse): + """Forcing maker for forcing defined by the user in the launching script + + .. inheritance-diagram:: InScriptForcingPseudoSpectralCoarse + + """ + + tag = "in_script_coarse" + + def __init__(self, sim): + super().__init__(sim) + self.is_initialized = False + + def compute_forcingc_fft_each_time(self): """Compute the coarse forcing in Fourier space""" return self.oper_coarse.fft(self.compute_forcingc_each_time()) @@ -382,7 +388,7 @@ self.is_initialized = True -class Proportional(SpecificForcingPseudoSpectral): +class Proportional(SpecificForcingPseudoSpectralCoarse): """Specific forcing proportional to the forced variable .. inheritance-diagram:: Proportional @@ -417,5 +423,5 @@ To be called only with proc 0. """ fvc_fft = vc_fft.copy() - fvc_fft[self.COND_NO_F] = 0. + fvc_fft[self.COND_NO_F] = 0.0 @@ -421,5 +427,5 @@ - Z_fft = abs(fvc_fft) ** 2 / 2. + Z_fft = abs(fvc_fft) ** 2 / 2.0 # # possibly "kill" the largest mode # nb_kill = 0 @@ -437,9 +443,9 @@ Z = self.oper_coarse.sum_wavenumbers(Z_fft) deltat = self.sim.time_stepping.deltat - alpha = (np.sqrt(1 + deltat * self.forcing_rate / Z) - 1.) / deltat + alpha = (np.sqrt(1 + deltat * self.forcing_rate / Z) - 1.0) / deltat fvc_fft = alpha * fvc_fft return fvc_fft @@ -441,9 +447,9 @@ fvc_fft = alpha * fvc_fft return fvc_fft -class NormalizedForcing(SpecificForcingPseudoSpectral): +class NormalizedForcing(SpecificForcingPseudoSpectralCoarse): """Specific forcing normalized to keep constant injection .. inheritance-diagram:: NormalizedForcing @@ -465,7 +471,7 @@ ) def __init__(self, sim): - super(NormalizedForcing, self).__init__(sim) + super().__init__(sim) if self.params.forcing.normalized.type == "particular_k": raise NotImplementedError @@ -575,10 +581,10 @@ ) if ikx_part == 0: - P_forcing2_part = P_forcing2_part / 2. + P_forcing2_part = P_forcing2_part / 2.0 P_forcing2_other = P_forcing2 - P_forcing2_part fvc_fft[ik0_part, ik1_part] = ( -P_forcing2_other / vc_fft[ik0_part, ik1_part].real ) if ikx_part != 0: @@ -579,10 +585,10 @@ P_forcing2_other = P_forcing2 - P_forcing2_part fvc_fft[ik0_part, ik1_part] = ( -P_forcing2_other / vc_fft[ik0_part, ik1_part].real ) if ikx_part != 0: - fvc_fft[ik0_part, ik1_part] = fvc_fft[ik0_part, ik1_part] / 2. + fvc_fft[ik0_part, ik1_part] = fvc_fft[ik0_part, ik1_part] / 2.0 oper_c.project_fft_on_realX(fvc_fft) @@ -648,7 +654,7 @@ try: alpha1, alpha2 = np.roots([a, b, c]) except ValueError: - return 0. + return 0.0 which_root = self.params.forcing.normalized.which_root @@ -666,7 +672,7 @@ return alpha2 elif which_root == "positive": - if alpha2 > 0.: + if alpha2 > 0.0: return alpha2 else: @@ -701,7 +707,7 @@ def __init__(self, sim): - super(RandomSimplePseudoSpectral, self).__init__(sim) + super().__init__(sim) if self.params.forcing.random.only_positive: self._min_val = None @@ -715,6 +721,6 @@ """ f_fft = self.oper_coarse.create_arrayK_random(min_val=self._min_val) # fftwpy/easypyfft returns f_fft - f_fft[self.oper_coarse.shapeK_loc[0] // 2] = 0. - f_fft[:, self.oper_coarse.shapeK_loc[1] - 1] = 0. + f_fft[self.oper_coarse.shapeK_loc[0] // 2] = 0.0 + f_fft[:, self.oper_coarse.shapeK_loc[1] - 1] = 0.0 f_fft = self.oper_coarse.project_fft_on_realX(f_fft) @@ -720,5 +726,5 @@ f_fft = self.oper_coarse.project_fft_on_realX(f_fft) - f_fft[self.COND_NO_F] = 0. + f_fft[self.COND_NO_F] = 0.0 return f_fft def forcingc_raw_each_time(self, a_fft): @@ -750,7 +756,7 @@ def __init__(self, sim): - super(TimeCorrelatedRandomPseudoSpectral, self).__init__(sim) + super().__init__(sim) if mpi.rank == 0: self.forcing0 = self.compute_forcingc_raw() @@ -763,7 +769,7 @@ time_correlation = pforcing.tcrandom.time_correlation if time_correlation == "based_on_forcing_rate": - self.period_change_f0f1 = self.forcing_rate ** (-1. / 3) + self.period_change_f0f1 = self.forcing_rate ** (-1.0 / 3) else: self.period_change_f0f1 = time_correlation self.t_last_change = self.sim.time_stepping.t diff --git a/fluidsim/base/init_fields.py b/fluidsim/base/init_fields.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9pbml0X2ZpZWxkcy5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9pbml0X2ZpZWxkcy5weQ== 100644 --- a/fluidsim/base/init_fields.py +++ b/fluidsim/base/init_fields.py @@ -288,7 +288,7 @@ field_loc = field_seq state_phys.set_var(k, field_loc) else: - state_phys.set_var(k, self.sim.oper.create_arrayX(value=0.)) + state_phys.set_var(k, self.sim.oper.create_arrayX(value=0.0)) if mpi.rank == 0: time = group_state_phys.attrs["time"] try: @@ -298,7 +298,7 @@ it = 0 h5file.close() else: - time = 0. + time = 0.0 it = 0 if mpi.nb_proc > 1: @@ -347,7 +347,7 @@ for index_key in range(len(keys_state_spect)): field_fft_seq_in = sim_in.state.state_spect[index_key] - field_fft_seq_new_res = sim.oper.create_arrayK(value=0.) + field_fft_seq_new_res = sim.oper.create_arrayK(value=0.0) [nk0_seq, nk1_seq] = field_fft_seq_new_res.shape [nk0_seq_in, nk1_seq_in] = field_fft_seq_in.shape @@ -381,7 +381,7 @@ if k in sim_in.info.solver.classes.State["keys_state_spect"]: sim.state.state_spect[k] = state_spect[k] else: - sim.state.state_spect[k] = self.oper.create_arrayK(value=0.) + sim.state.state_spect[k] = self.oper.create_arrayK(value=0.0) sim.state.statephys_from_statespect() @@ -405,7 +405,7 @@ @classmethod def _complete_params_with_default(cls, params): super(InitFieldsConstant, cls)._complete_params_with_default(params) - params.init_fields._set_child(cls.tag, attribs={"value": 1.}) + params.init_fields._set_child(cls.tag, attribs={"value": 1.0}) params.init_fields.constant._set_doc( """ value: float (default 1.) @@ -429,7 +429,7 @@ def _complete_params_with_default(cls, params): """Complete the `params` container (class method).""" super(InitFieldsNoise, cls)._complete_params_with_default(params) - params.init_fields._set_child(cls.tag, attribs={"max": 1.}) + params.init_fields._set_child(cls.tag, attribs={"max": 1.0}) params.init_fields.noise._set_doc( """ max: float (default 1.) diff --git a/fluidsim/base/output/base.py b/fluidsim/base/output/base.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvYmFzZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvYmFzZS5weQ== 100644 --- a/fluidsim/base/output/base.py +++ b/fluidsim/base/output/base.py @@ -251,7 +251,7 @@ if not self.params.ONLINE_PLOT_OK: for k in self.params.periods_plot._get_key_attribs(): - self.params.periods_plot[k] = 0. + self.params.periods_plot[k] = 0.0 if not self._has_to_save: for k in self.params.periods_save._get_key_attribs(): @@ -255,7 +255,7 @@ if not self._has_to_save: for k in self.params.periods_save._get_key_attribs(): - self.params.periods_save[k] = 0. + self.params.periods_save[k] = 0.0 def _init_name_run(self): """Initialize the run name""" @@ -498,10 +498,10 @@ pass def compute_energy(self): - return 0. + return 0.0 def print_size_in_Mo(self, arr, string=None): if string is None: string = "Size of ndarray (equiv. seq.)" else: string = "Size of " + string + " (equiv. seq.)" @@ -502,10 +502,10 @@ def print_size_in_Mo(self, arr, string=None): if string is None: string = "Size of ndarray (equiv. seq.)" else: string = "Size of " + string + " (equiv. seq.)" - mem = arr.nbytes * 1.e-6 + mem = arr.nbytes * 1.0e-6 if mpi.nb_proc > 1: mem = mpi.comm.allreduce(mem, op=mpi.MPI.SUM) self.print_stdout(string.ljust(30) + ": {0} Mo".format(mem)) @@ -520,7 +520,7 @@ def compute_energy_fft(self): """Compute energy(k)""" - energy_fft = 0. + energy_fft = 0.0 for k in self.sim.state.keys_state_spect: energy_fft += ( np.abs(self.sim.state.state_spect.get_var(k)) ** 2 @@ -524,7 +524,7 @@ for k in self.sim.state.keys_state_spect: energy_fft += ( np.abs(self.sim.state.state_spect.get_var(k)) ** 2 - ) / 2. + ) / 2.0 return energy_fft @@ -569,7 +569,7 @@ self.has_to_plot = False self.period_show = params.output.period_refresh_plots - self.t_last_show = 0. + self.t_last_show = 0.0 self._init_path_files() @@ -577,5 +577,5 @@ self._init_online_plot() if not output._has_to_save: - self.period_save = 0. + self.period_save = 0.0 @@ -581,5 +581,5 @@ - if self.period_save != 0.: + if self.period_save != 0.0: self._init_files(dict_arrays_1time) def _init_path_files(self): diff --git a/fluidsim/base/output/increments.py b/fluidsim/base/output/increments.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvaW5jcmVtZW50cy5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvaW5jcmVtZW50cy5weQ== 100644 --- a/fluidsim/base/output/increments.py +++ b/fluidsim/base/output/increments.py @@ -1,5 +1,3 @@ - - from __future__ import division, print_function from builtins import range @@ -60,7 +58,7 @@ self.nrx = self.rxs.size dict_arrays_1time = {"rxs": self.rxs, "nbins": self.nbins} - + self._bins = np.arange(0.5, self.nbins, dtype=float) / self.nbins self.keys_vars_to_compute = list(output.sim.state.state_phys.keys) super(Increments, self).__init__( @@ -118,9 +116,7 @@ return dict_results def compute_values_inc(self, valmin, valmax): - return valmin + (valmax - valmin) / self.nbins * np.arange( - 0.5, self.nbins - ) + return valmin + (valmax - valmin) * self._bins def load(self): """load the saved pdf and return a dictionary.""" @@ -166,7 +162,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -263,7 +259,7 @@ cond = rxs < 6 * deltax ax1.plot( - rxs[cond], 1.e4 * rxs[cond] ** (order) / norm[cond], "k", linewidth=2 + rxs[cond], 1.0e4 * rxs[cond] ** (order) / norm[cond], "k", linewidth=2 ) ax1.plot(rxs, rxs ** (order / 3) / norm, "--k", linewidth=2) @@ -267,7 +263,7 @@ ) ax1.plot(rxs, rxs ** (order / 3) / norm, "--k", linewidth=2) - ax1.plot(rxs, 1.e0 * rxs ** (1) / norm, ":k", linewidth=2) + ax1.plot(rxs, 1.0e0 * rxs ** (1) / norm, ":k", linewidth=2) z_bottom_axe = 0.09 size_axe[1] = z_bottom_axe @@ -561,7 +557,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -663,7 +659,7 @@ cond = rxs < 6 * deltax ax1.plot( - rxs[cond], 1.e4 * rxs[cond] ** (order) / norm[cond], "k", linewidth=2 + rxs[cond], 1.0e4 * rxs[cond] ** (order) / norm[cond], "k", linewidth=2 ) ax1.plot(rxs, rxs ** (order / 3) / norm, "--k", linewidth=2) @@ -667,7 +663,7 @@ ) ax1.plot(rxs, rxs ** (order / 3) / norm, "--k", linewidth=2) - ax1.plot(rxs, 1.e0 * rxs ** (1) / norm, ":k", linewidth=2) + ax1.plot(rxs, 1.0e0 * rxs ** (1) / norm, ":k", linewidth=2) z_bottom_axe = 0.09 size_axe[1] = z_bottom_axe @@ -819,7 +815,7 @@ cond = rxs < 6 * deltax ax1.plot( rxs[cond], - 1.e0 * rxs[cond] ** 3 / S_Kolmo_theo[cond], + 1.0e0 * rxs[cond] ** 3 / S_Kolmo_theo[cond], "k", linewidth=2, ) diff --git a/fluidsim/base/output/movies.py b/fluidsim/base/output/movies.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvbW92aWVzLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvbW92aWVzLnB5 100644 --- a/fluidsim/base/output/movies.py +++ b/fluidsim/base/output/movies.py @@ -363,7 +363,7 @@ print("Saving movie to ", path_file, "...") writer = Writer( - fps=1. / dt_frame_in_sec, metadata=dict(artist="FluidSim") + fps=1.0 / dt_frame_in_sec, metadata=dict(artist="FluidSim") ) # _animation is a FuncAnimation object self._animation.save(path_file, writer=writer, dpi=150) diff --git a/fluidsim/base/output/print_stdout.py b/fluidsim/base/output/print_stdout.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvcHJpbnRfc3Rkb3V0LnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvcHJpbnRfc3Rkb3V0LnB5 100644 --- a/fluidsim/base/output/print_stdout.py +++ b/fluidsim/base/output/print_stdout.py @@ -1,4 +1,3 @@ - from __future__ import print_function from builtins import object @@ -18,7 +17,7 @@ @staticmethod def _complete_params_with_default(params): - params.output.periods_print._set_attrib("print_stdout", 1.) + params.output.periods_print._set_attrib("print_stdout", 1.0) def __init__(self, output): sim = output.sim @@ -53,7 +52,7 @@ if self.period_print == 0: return - self.energy_temp = self.energy0 + 0. + self.energy_temp = self.energy0 + 0.0 self.t_last_print_info = -self.period_print self.print_stdout = self.__call__ diff --git a/fluidsim/base/output/spatial_means.py b/fluidsim/base/output/spatial_means.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvc3BhdGlhbF9tZWFucy5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvc3BhdGlhbF9tZWFucy5weQ== 100644 --- a/fluidsim/base/output/spatial_means.py +++ b/fluidsim/base/output/spatial_means.py @@ -1,4 +1,3 @@ - from __future__ import division, print_function import os @@ -107,7 +106,7 @@ def plot(self): pass - def compute_time_means(self, tstatio=0., tmax=None): + def compute_time_means(self, tstatio=0.0, tmax=None): """compute the temporal means.""" dict_results = self.load() if tmax is None: diff --git a/fluidsim/base/output/spect_energy_budget.py b/fluidsim/base/output/spect_energy_budget.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvc3BlY3RfZW5lcmd5X2J1ZGdldC5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvc3BlY3RfZW5lcmd5X2J1ZGdldC5weQ== 100644 --- a/fluidsim/base/output/spect_energy_budget.py +++ b/fluidsim/base/output/spect_energy_budget.py @@ -1,4 +1,3 @@ - import numpy as np from fluiddyn.util import mpi diff --git a/fluidsim/base/output/time_signals_fft.py b/fluidsim/base/output/time_signals_fft.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvdGltZV9zaWduYWxzX2ZmdC5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9vdXRwdXQvdGltZV9zaWduYWxzX2ZmdC5weQ== 100644 --- a/fluidsim/base/output/time_signals_fft.py +++ b/fluidsim/base/output/time_signals_fft.py @@ -163,7 +163,7 @@ self.period_save = np.pi / (8 * self.omega_array_ik.max()) else: - self.period_save = 0. + self.period_save = 0.0 if mpi.nb_proc > 1: self.period_save = mpi.comm.bcast(self.period_save) @@ -358,7 +358,7 @@ def time_spectrum(self, sig_long): Nt = sig_long.size - stepit0 = int(np.fix(self.nt / 2.)) + stepit0 = int(np.fix(self.nt / 2.0)) nb_spectra = 0 it0 = 0 diff --git a/fluidsim/base/params.py b/fluidsim/base/params.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9wYXJhbXMucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9wYXJhbXMucHk= 100644 --- a/fluidsim/base/params.py +++ b/fluidsim/base/params.py @@ -64,7 +64,7 @@ for attrib in diff_attribs: params1._set_attrib(attrib, params2[attrib]) - # Merge childrean + # Merge children diff_children = set(params2._tag_children) - set(params1._tag_children) internal_attribs = [ "attribs", @@ -79,8 +79,8 @@ for child in diff_children: child_attribs = params2[child]._make_dict() - # Clean up intenal attributes from dictionary + # Clean up internal attributes from dictionary list(map(child_attribs.__delitem__, internal_attribs)) params1._set_child(child, child_attribs) @@ -83,8 +83,8 @@ list(map(child_attribs.__delitem__, internal_attribs)) params1._set_child(child, child_attribs) - # Recurse + # Recursive for child in params2._tag_children: params1[child] |= params2[child] @@ -123,25 +123,6 @@ for other in other_params: to_params |= other - def find_available_fluidfft(dim): - """Find available FluidFFT implementations.""" - use_mpi = mpi.nb_proc > 1 - fluidfft = import_module("fluidfft.fft{}d".format(dim)) - fluidfft_classes = ( - fluidfft.get_classes_mpi() if use_mpi else fluidfft.get_classes_seq() - ) - for k, v in fluidfft_classes.items(): - if v is not None: - break - - else: - raise ValueError( - "No compatible fluidfft FFT types found for" - "{}D, mpi={}".format(dim, use_mpi) - ) - - return k - # Substitute old FFT types with newer FluidFFT implementations if hasattr(to_params, "oper") and hasattr(to_params.oper, "type_fft"): method = to_params.oper.type_fft @@ -151,8 +132,7 @@ for prefix in ("fft2d.", "fft3d.", "fluidfft.") ] ): - dim = 3 if hasattr(to_params.oper, "nz") else 2 - type_fft = find_available_fluidfft(dim) + type_fft = "default" print("params.oper.type_fft", to_params.oper.type_fft, "->", type_fft) to_params.oper.type_fft = type_fft @@ -201,6 +181,7 @@ elif path.endswith(".xml"): if not os.path.exists(path): raise ValueError("The file " + path + "does not exists.") + path_xml = path if path_xml is not None and os.path.exists(path_xml): @@ -218,7 +199,7 @@ else: str_path = path - print("load params from file\n" + str_path) + print("Loading params from file\n" + str_path) with h5py.File(path) as h5file: params = Parameters(hdf5_object=h5file["/info_simul/params"]) else: @@ -252,6 +233,7 @@ print("load params from file\n" + str_path) with h5py.File(path) as h5file: return Parameters(hdf5_object=h5file["/info_simul/solver"]) + else: return ValueError diff --git a/fluidsim/base/preprocess/base.py b/fluidsim/base/preprocess/base.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9wcmVwcm9jZXNzL2Jhc2UucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9wcmVwcm9jZXNzL2Jhc2UucHk= 100644 --- a/fluidsim/base/preprocess/base.py +++ b/fluidsim/base/preprocess/base.py @@ -38,6 +38,6 @@ attribs = { "enable": False, "init_field_scale": "unity", - "init_field_const": 1., + "init_field_const": 1.0, "viscosity_type": "laplacian", "viscosity_scale": "enstrophy_forcing", @@ -42,4 +42,4 @@ "viscosity_type": "laplacian", "viscosity_scale": "enstrophy_forcing", - "viscosity_const": 1., + "viscosity_const": 1.0, "forcing_scale": "unity", @@ -45,5 +45,5 @@ "forcing_scale": "unity", - "forcing_const": 1., + "forcing_const": 1.0, } params._set_child("preprocess", attribs=attribs) diff --git a/fluidsim/base/preprocess/pseudo_spect.py b/fluidsim/base/preprocess/pseudo_spect.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9wcmVwcm9jZXNzL3BzZXVkb19zcGVjdC5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9wcmVwcm9jZXNzL3BzZXVkb19zcGVjdC5weQ== 100644 --- a/fluidsim/base/preprocess/pseudo_spect.py +++ b/fluidsim/base/preprocess/pseudo_spect.py @@ -59,7 +59,7 @@ ux_fft = state.get_var("ux_fft") uy_fft = state.get_var("uy_fft") - if Ek != 0.: + if Ek != 0.0: ux_fft = (C / Ek) ** 0.5 * ux_fft uy_fft = (C / Ek) ** 0.5 * uy_fft @@ -72,7 +72,7 @@ omega_0 = self.output.compute_enstrophy() rot_fft = state.get_var("rot_fft") - if omega_0 != 0.: + if omega_0 != 0.0: rot_fft = (C / omega_0) ** 0.5 * rot_fft state.init_from_rotfft(rot_fft) @@ -88,8 +88,8 @@ omega_0 = self.output.compute_enstrophy() rot_fft = state.get_var("rot_fft") - if omega_0 != 0.: - C_0 = omega_0 / (P ** (2. / 3) * k_f ** (4. / 3)) + if omega_0 != 0.0: + C_0 = omega_0 / (P ** (2.0 / 3) * k_f ** (4.0 / 3)) rot_fft = (C / C_0) ** 0.5 * rot_fft state.init_from_rotfft(rot_fft) @@ -305,7 +305,7 @@ if viscosity_scale == "enstrophy": omega_0 = args[0] eta = omega_0 ** 1.5 - time_scale = eta ** (-1. / 3) + time_scale = eta ** (-1.0 / 3) elif viscosity_scale == "energy": energy_0 = args[0] epsilon = energy_0 * (1.5) / large_scale @@ -309,7 +309,7 @@ elif viscosity_scale == "energy": energy_0 = args[0] epsilon = energy_0 * (1.5) / large_scale - time_scale = epsilon ** (-1. / 3) * length_scale ** (2. / 3) + time_scale = epsilon ** (-1.0 / 3) * length_scale ** (2.0 / 3) elif viscosity_scale == "enstrophy_forcing": omega_0 = args[0] eta = omega_0 ** 1.5 @@ -313,6 +313,6 @@ elif viscosity_scale == "enstrophy_forcing": omega_0 = args[0] eta = omega_0 ** 1.5 - t1 = eta ** (-1. / 3) + t1 = eta ** (-1.0 / 3) # Energy dissipation rate epsilon = args[1] @@ -317,6 +317,6 @@ # Energy dissipation rate epsilon = args[1] - t2 = epsilon ** (-1. / 3) * length_scale ** (2. / 3) + t2 = epsilon ** (-1.0 / 3) * length_scale ** (2.0 / 3) time_scale = min(t1, t2) elif viscosity_scale == "forcing": epsilon = args[0] @@ -320,7 +320,7 @@ time_scale = min(t1, t2) elif viscosity_scale == "forcing": epsilon = args[0] - time_scale = epsilon ** (-1. / 3) * length_scale ** (2. / 3) + time_scale = epsilon ** (-1.0 / 3) * length_scale ** (2.0 / 3) else: raise ValueError("Unknown viscosity scale: %s" % viscosity_scale) @@ -337,7 +337,7 @@ elif "eps" in kwargs: epsilon = kwargs["eps"] else: - epsilon = 1. + epsilon = 1.0 print("Dissipation, epsilon =", epsilon) kolmo_len = [] @@ -353,6 +353,6 @@ v.append(nu) if verbose: kolmo_len.append( - (nu ** 3 / epsilon) ** (1. / (3 * order - 2)) + (nu ** 3 / epsilon) ** (1.0 / (3 * order - 2)) ) else: @@ -357,6 +357,6 @@ ) else: - v.append(0.) + v.append(0.0) if verbose: kolmo_len = np.mean(kolmo_len) diff --git a/fluidsim/base/solvers/base.py b/fluidsim/base/solvers/base.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9zb2x2ZXJzL2Jhc2UucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9zb2x2ZXJzL2Jhc2UucHk= 100644 --- a/fluidsim/base/solvers/base.py +++ b/fluidsim/base/solvers/base.py @@ -61,7 +61,7 @@ "NEW_DIR_RESULTS": True, "ONLY_COARSE_OPER": False, # Physical parameters: - "nu_2": 0., + "nu_2": 0.0, } params._set_attribs(attribs) params._set_doc( @@ -131,7 +131,9 @@ dict_classes = self.info_solver.import_classes() if not isinstance(params, Parameters): - raise TypeError("params should be a Parameters instance.") + raise TypeError( + "params should be a Parameters instance, not %s" % type(params) + ) self.params = params self.info = create_info_simul(self.info_solver, params) @@ -196,7 +198,7 @@ ) else: tendencies = old - tendencies.initialize(value=0.) + tendencies.initialize(value=0.0) return tendencies @@ -209,7 +211,7 @@ params.short_name_type_run = "test" params.time_stepping.USE_CFL = False - params.time_stepping.t_end = 2. + params.time_stepping.t_end = 2.0 params.time_stepping.deltat0 = 0.1 sim = Simul(params) diff --git a/fluidsim/base/solvers/finite_diff.py b/fluidsim/base/solvers/finite_diff.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9zb2x2ZXJzL2Zpbml0ZV9kaWZmLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9zb2x2ZXJzL2Zpbml0ZV9kaWZmLnB5 100644 --- a/fluidsim/base/solvers/finite_diff.py +++ b/fluidsim/base/solvers/finite_diff.py @@ -1,4 +1,3 @@ - from fluidsim.base.solvers.base import InfoSolverBase diff --git a/fluidsim/base/solvers/info_base.py b/fluidsim/base/solvers/info_base.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9zb2x2ZXJzL2luZm9fYmFzZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9zb2x2ZXJzL2luZm9fYmFzZS5weQ== 100644 --- a/fluidsim/base/solvers/info_base.py +++ b/fluidsim/base/solvers/info_base.py @@ -1,4 +1,3 @@ - from copy import deepcopy from fluiddyn.util.paramcontainer import ParamContainer diff --git a/fluidsim/base/solvers/pseudo_spect.py b/fluidsim/base/solvers/pseudo_spect.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9zb2x2ZXJzL3BzZXVkb19zcGVjdC5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9zb2x2ZXJzL3BzZXVkb19zcGVjdC5weQ== 100644 --- a/fluidsim/base/solvers/pseudo_spect.py +++ b/fluidsim/base/solvers/pseudo_spect.py @@ -109,7 +109,7 @@ """Complete the `params` container (static method).""" SimulBase._complete_params_with_default(params) - attribs = {"nu_8": 0., "nu_4": 0., "nu_m4": 0.} + attribs = {"nu_8": 0.0, "nu_4": 0.0, "nu_m4": 0.0} params._set_attribs(attribs) params._set_doc( @@ -171,6 +171,6 @@ else: f_d = np.zeros_like(self.oper.K2) - if self.params.nu_4 > 0.: + if self.params.nu_4 > 0.0: f_d += self.params.nu_4 * self.oper.K4 @@ -175,5 +175,5 @@ f_d += self.params.nu_4 * self.oper.K4 - if self.params.nu_8 > 0.: + if self.params.nu_8 > 0.0: f_d += self.params.nu_8 * self.oper.K8 @@ -178,8 +178,8 @@ f_d += self.params.nu_8 * self.oper.K8 - if self.params.nu_m4 != 0.: + if self.params.nu_m4 != 0.0: f_d_hypo = self.params.nu_m4 / self.oper.K2_not0 ** 2 # mode K2 = 0 ! if mpi.rank == 0: f_d_hypo[0, 0] = f_d_hypo[0, 1] @@ -181,9 +181,9 @@ f_d_hypo = self.params.nu_m4 / self.oper.K2_not0 ** 2 # mode K2 = 0 ! if mpi.rank == 0: f_d_hypo[0, 0] = f_d_hypo[0, 1] - f_d_hypo[self.oper.K <= 20] = 0. + f_d_hypo[self.oper.K <= 20] = 0.0 else: f_d_hypo = np.zeros_like(f_d) @@ -207,7 +207,7 @@ else: tendencies = old - tendencies.initialize(value=0.) + tendencies.initialize(value=0.0) return tendencies @@ -231,6 +231,6 @@ delta_x = params.oper.Lx / params.oper.nx params.nu_8 = ( - 2. * 10e-1 * params.forcing.forcing_rate ** (1. / 3) * delta_x ** 8 + 2.0 * 10e-1 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x ** 8 ) @@ -235,6 +235,6 @@ ) - params.time_stepping.t_end = 5. + params.time_stepping.t_end = 5.0 params.init_fields.type = "noise" @@ -238,6 +238,6 @@ params.init_fields.type = "noise" - params.output.periods_plot.phys_fields = 0. + params.output.periods_plot.phys_fields = 0.0 params.output.periods_print.print_stdout = 0.25 @@ -242,6 +242,6 @@ params.output.periods_print.print_stdout = 0.25 - params.output.periods_save.phys_fields = 2. + params.output.periods_save.phys_fields = 2.0 sim = Simul(params) diff --git a/fluidsim/base/sphericalharmo/output.py b/fluidsim/base/sphericalharmo/output.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9zcGhlcmljYWxoYXJtby9vdXRwdXQucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9zcGhlcmljYWxoYXJtby9vdXRwdXQucHk= 100644 --- a/fluidsim/base/sphericalharmo/output.py +++ b/fluidsim/base/sphericalharmo/output.py @@ -1,5 +1,3 @@ - - from fluidsim.base.output import OutputBasePseudoSpectral diff --git a/fluidsim/base/sphericalharmo/phys_fields.py b/fluidsim/base/sphericalharmo/phys_fields.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9zcGhlcmljYWxoYXJtby9waHlzX2ZpZWxkcy5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9zcGhlcmljYWxoYXJtby9waHlzX2ZpZWxkcy5weQ== 100644 --- a/fluidsim/base/sphericalharmo/phys_fields.py +++ b/fluidsim/base/sphericalharmo/phys_fields.py @@ -1,5 +1,3 @@ - - from ..output.phys_fields2d import PhysFieldsBase2D diff --git a/fluidsim/base/sphericalharmo/solver.py b/fluidsim/base/sphericalharmo/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9zcGhlcmljYWxoYXJtby9zb2x2ZXIucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9zcGhlcmljYWxoYXJtby9zb2x2ZXIucHk= 100644 --- a/fluidsim/base/sphericalharmo/solver.py +++ b/fluidsim/base/sphericalharmo/solver.py @@ -63,7 +63,7 @@ params.short_name_type_run = "test" params.time_stepping.USE_CFL = False - params.time_stepping.t_end = 2. + params.time_stepping.t_end = 2.0 params.time_stepping.deltat0 = 0.1 sim = Simul(params) diff --git a/fluidsim/base/sphericalharmo/state.py b/fluidsim/base/sphericalharmo/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9zcGhlcmljYWxoYXJtby9zdGF0ZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9zcGhlcmljYWxoYXJtby9zdGF0ZS5weQ== 100644 --- a/fluidsim/base/sphericalharmo/state.py +++ b/fluidsim/base/sphericalharmo/state.py @@ -54,5 +54,5 @@ elif key == "uy_sh": result = self.oper.sht(self.state_phys.get_var("uy")) elif key == "div_sh": - result = self.oper.create_array_sh(0.) + result = self.oper.create_array_sh(0.0) elif key == "div": @@ -58,5 +58,5 @@ elif key == "div": - result = self.oper.create_array_spat(0.) + result = self.oper.create_array_spat(0.0) elif key == "q": rot = self.state_phys.get_var("rot") result = rot @@ -68,7 +68,7 @@ else: print(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result diff --git a/fluidsim/base/state.py b/fluidsim/base/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS9zdGF0ZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS9zdGF0ZS5weQ== 100644 --- a/fluidsim/base/state.py +++ b/fluidsim/base/state.py @@ -197,7 +197,7 @@ init_statespect_from(ux=ux, uy=uy, eta=eta) """ - self.state_phys[:] = 0. + self.state_phys[:] = 0.0 for key, value in list(kwargs.items()): if key not in self.keys_state_phys: @@ -375,7 +375,7 @@ init_statespect_from(ux_fft=ux_fft, uy_fft=uy_fft, eta_fft=eta_fft) """ - self.state_spect[:] = 0. + self.state_spect[:] = 0.0 for key, value in list(kwargs.items()): if key not in self.keys_state_spect: diff --git a/fluidsim/base/test/test_base_solver.py b/fluidsim/base/test/test_base_solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS90ZXN0L3Rlc3RfYmFzZV9zb2x2ZXIucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS90ZXN0L3Rlc3RfYmFzZV9zb2x2ZXIucHk= 100644 --- a/fluidsim/base/test/test_base_solver.py +++ b/fluidsim/base/test/test_base_solver.py @@ -1,5 +1,3 @@ - - import unittest import shutil diff --git a/fluidsim/base/test/test_base_solver_ps.py b/fluidsim/base/test/test_base_solver_ps.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS90ZXN0L3Rlc3RfYmFzZV9zb2x2ZXJfcHMucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS90ZXN0L3Rlc3RfYmFzZV9zb2x2ZXJfcHMucHk= 100644 --- a/fluidsim/base/test/test_base_solver_ps.py +++ b/fluidsim/base/test/test_base_solver_ps.py @@ -1,5 +1,3 @@ - - import unittest import shutil from glob import glob @@ -33,8 +31,8 @@ if params is None: params = SimulBasePseudoSpectral.create_default_params() - params.output.periods_plot.phys_fields = 0. - params.output.periods_print.print_stdout = 0. + params.output.periods_plot.phys_fields = 0.0 + params.output.periods_print.print_stdout = 0.0 params.short_name_type_run = "test_base_solver_ps" nh = 8 @@ -44,7 +42,7 @@ params.oper.Lx = Lh params.oper.Ly = Lh - params.nu_2 = 1. + params.nu_2 = 1.0 params.time_stepping.t_end = 0.4 @@ -76,7 +74,7 @@ with stdout_redirected(): modif_resolution_from_dir( - self.sim.output.path_run, coef_modif_resol=3. / 2, PLOT=False + self.sim.output.path_run, coef_modif_resol=3.0 / 2, PLOT=False ) path_new = os.path.join(self.sim.output.path_run, "State_phys_12x12") os.chdir(path_new) diff --git a/fluidsim/base/time_stepping/base.py b/fluidsim/base/time_stepping/base.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL2Jhc2UucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL2Jhc2UucHk= 100644 --- a/fluidsim/base/time_stepping/base.py +++ b/fluidsim/base/time_stepping/base.py @@ -32,7 +32,7 @@ """ attribs = { "USE_T_END": True, - "t_end": 10., + "t_end": 10.0, "it_end": 10, "USE_CFL": False, "type_time_scheme": "RK4", @@ -247,7 +247,7 @@ + max_uz / self.sim.oper.deltaz ) else: - tmp = 0. + tmp = 0.0 self._compute_time_increment_CLF_from_tmp(tmp) diff --git a/fluidsim/base/time_stepping/pseudo_spect.py b/fluidsim/base/time_stepping/pseudo_spect.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL3BzZXVkb19zcGVjdC5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL3BzZXVkb19zcGVjdC5weQ== 100644 --- a/fluidsim/base/time_stepping/pseudo_spect.py +++ b/fluidsim/base/time_stepping/pseudo_spect.py @@ -20,6 +20,4 @@ """ -from builtins import object - from warnings import warn @@ -25,4 +23,5 @@ from warnings import warn +import os import numpy as np @@ -26,5 +25,7 @@ import numpy as np +from fluidpythran import FluidPythran + from .base import TimeSteppingBase @@ -29,5 +30,9 @@ from .base import TimeSteppingBase +from .rk_pythran import step0_RK2_pythran, step1_RK2_pythran + +fp = FluidPythran() + class ExactLinearCoefs(object): """Handle the computation of the exact coefficient for the RK4.""" @@ -43,7 +48,7 @@ if sim.params.time_stepping.USE_CFL: self.get_updated_coefs = self.get_updated_coefs_CLF - self.dt_old = 0. + self.dt_old = 0.0 else: self.compute(time_stepping.deltat) self.get_updated_coefs = self.get_coefs @@ -106,6 +111,19 @@ if params_ts.type_time_scheme not in ["RK2", "RK4"]: raise ValueError("Problem name time_scheme") + self._state_spect_tmp = np.empty_like(self.sim.state.state_spect) + + if params_ts.type_time_scheme == "RK4": + self._state_spect_tmp1 = np.empty_like(self.sim.state.state_spect) + + if os.environ.get("FLUIDSIM_USE_FLUIDPYTHRAN", False): + if params_ts.type_time_scheme == "RK2": + time_step_RK = self._time_step_RK2_fluidpythran + else: + time_step_RK = self._time_step_RK4_fluidpythran + self._time_step_RK = time_step_RK + return + dtype = self.freq_lin.dtype if dtype == np.float64: str_type = "float" @@ -206,6 +224,37 @@ dt = self.deltat diss, diss2 = self.exact_linear_coefs.get_updated_coefs() - tendencies_nonlin = self.sim.tendencies_nonlin + compute_tendencies = self.sim.tendencies_nonlin + state_spect = self.sim.state.state_spect + + tendencies_n = compute_tendencies() + state_spect_n12 = (state_spect + dt / 2 * tendencies_n) * diss2 + tendencies_n12 = compute_tendencies(state_spect_n12, old=tendencies_n) + self.sim.state.state_spect = ( + state_spect * diss + dt * diss2 * tendencies_n12 + ) + + def _time_step_RK2_pythran(self): + dt = self.deltat + diss, diss2 = self.exact_linear_coefs.get_updated_coefs() + + compute_tendencies = self.sim.tendencies_nonlin + state_spect = self.sim.state.state_spect + + tendencies_n = compute_tendencies() + + state_spect_n12 = self._state_spect_tmp + # state_spect_n12[:] = (state_spect + dt / 2 * tendencies_n) * diss2 + step0_RK2_pythran(state_spect_n12, state_spect, tendencies_n, diss2, dt) + + tendencies_n12 = compute_tendencies(state_spect_n12, old=tendencies_n) + # state_spect[:] = state_spect * diss + dt * diss2 * tendencies_n12 + step1_RK2_pythran(state_spect, tendencies_n12, diss, diss2, dt) + + def _time_step_RK2_fluidpythran(self): + dt = self.deltat + diss, diss2 = self.exact_linear_coefs.get_updated_coefs() + + compute_tendencies = self.sim.tendencies_nonlin state_spect = self.sim.state.state_spect @@ -210,13 +259,66 @@ state_spect = self.sim.state.state_spect - tendencies_fft_n = tendencies_nonlin() - state_spect_n12 = (state_spect + dt / 2 * tendencies_fft_n) * diss2 - tendencies_fft_n12 = tendencies_nonlin( - state_spect_n12, old=tendencies_fft_n - ) - self.sim.state.state_spect = ( - state_spect * diss + dt * diss2 * tendencies_fft_n12 - ) + tendencies_n = compute_tendencies() + + state_spect_n12 = self._state_spect_tmp + + if fp.is_pythranized: + fp.use_pythranized_block("rk2_step0") + else: + # pythran block ( + # complex128[][][] state_spect_n12, state_spect, tendencies_n; + # float64[][] diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect_n12, state_spect, tendencies_n; + # complex128[][][] diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect_n12, state_spect, tendencies_n; + # float64[][][] diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][][] state_spect_n12, state_spect, tendencies_n; + # float64[][][] diss2; + # float dt + # ) + state_spect_n12[:] = (state_spect + dt / 2 * tendencies_n) * diss2 + + tendencies_n12 = compute_tendencies(state_spect_n12, old=tendencies_n) + + if fp.is_pythranized: + fp.use_pythranized_block("rk2_step1") + else: + # pythran block ( + # complex128[][][] state_spect, tendencies_n12; + # float64[][] diss, diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect, tendencies_n12; + # complex128[][][] diss, diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect, tendencies_n12; + # float64[][][] diss, diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][][] state_spect, tendencies_n12; + # float64[][][] diss, diss2; + # float dt + # ) + state_spect[:] = state_spect * diss + dt * diss2 * tendencies_n12 def _time_step_RK4(self): r"""Advance in time with the Runge-Kutta 4 method. @@ -315,6 +417,6 @@ dt = self.deltat diss, diss2 = self.exact_linear_coefs.get_updated_coefs() - tendencies_nonlin = self.sim.tendencies_nonlin + compute_tendencies = self.sim.tendencies_nonlin state_spect = self.sim.state.state_spect @@ -319,5 +421,5 @@ state_spect = self.sim.state.state_spect - tendencies_fft_0 = tendencies_nonlin() + tendencies_0 = compute_tendencies() # based on approximation 1 @@ -322,7 +424,5 @@ # based on approximation 1 - state_spect_temp = (state_spect + dt / 6 * tendencies_fft_0) * diss - state_spect_np12_approx1 = ( - state_spect + dt / 2 * tendencies_fft_0 - ) * diss2 + state_spec_tmp = (state_spect + dt / 6 * tendencies_0) * diss + state_spect_np12_approx1 = (state_spect + dt / 2 * tendencies_0) * diss2 @@ -328,4 +428,4 @@ - tendencies_fft_1 = tendencies_nonlin( - state_spect_np12_approx1, old=tendencies_fft_0 + tendencies_1 = compute_tendencies( + state_spect_np12_approx1, old=tendencies_0 ) @@ -331,4 +431,4 @@ ) - del (state_spect_np12_approx1) + del state_spect_np12_approx1 # based on approximation 2 @@ -333,5 +433,5 @@ # based on approximation 2 - state_spect_temp += dt / 3 * diss2 * tendencies_fft_1 - state_spect_np12_approx2 = state_spect * diss2 + dt / 2 * tendencies_fft_1 + state_spec_tmp += dt / 3 * diss2 * tendencies_1 + state_spect_np12_approx2 = state_spect * diss2 + dt / 2 * tendencies_1 @@ -337,4 +437,4 @@ - tendencies_fft_2 = tendencies_nonlin( - state_spect_np12_approx2, old=tendencies_fft_1 + tendencies_2 = compute_tendencies( + state_spect_np12_approx2, old=tendencies_1 ) @@ -340,4 +440,4 @@ ) - del (state_spect_np12_approx2) + del state_spect_np12_approx2 # based on approximation 3 @@ -342,7 +442,5 @@ # based on approximation 3 - state_spect_temp += dt / 3 * diss2 * tendencies_fft_2 - state_spect_np1_approx = ( - state_spect * diss + dt * diss2 * tendencies_fft_2 - ) + state_spec_tmp += dt / 3 * diss2 * tendencies_2 + state_spect_np1_approx = state_spect * diss + dt * diss2 * tendencies_2 @@ -348,4 +446,4 @@ - tendencies_fft_3 = tendencies_nonlin( - state_spect_np1_approx, old=tendencies_fft_2 + tendencies_3 = compute_tendencies( + state_spect_np1_approx, old=tendencies_2 ) @@ -351,4 +449,4 @@ ) - del (state_spect_np1_approx) + del state_spect_np1_approx # result using the 4 approximations @@ -353,3 +451,156 @@ # result using the 4 approximations - self.sim.state.state_spect = state_spect_temp + dt / 6 * tendencies_fft_3 + self.sim.state.state_spect = state_spec_tmp + dt / 6 * tendencies_3 + + def _time_step_RK4_fluidpythran(self): + dt = self.deltat + diss, diss2 = self.exact_linear_coefs.get_updated_coefs() + + compute_tendencies = self.sim.tendencies_nonlin + state_spect = self.sim.state.state_spect + + tendencies_0 = compute_tendencies() + state_spect_tmp = self._state_spect_tmp + state_spect_tmp1 = self._state_spect_tmp1 + state_spect_np12_approx1 = state_spect_tmp1 + + if fp.is_pythranized: + fp.use_pythranized_block("rk4_step0") + else: + # based on approximation 0 + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, + # tendencies_0, state_spect_np12_approx1; + # float64[][] diss, diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, + # tendencies_0, state_spect_np12_approx1; + # complex128[][][] diss, diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, + # tendencies_0, state_spect_np12_approx1; + # float64[][][] diss, diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][][] state_spect, state_spect_tmp, + # tendencies_0, state_spect_np12_approx1; + # float64[][][] diss, diss2; + # float dt + # ) + state_spect_tmp[:] = (state_spect + dt / 6 * tendencies_0) * diss + state_spect_np12_approx1[:] = ( + state_spect + dt / 2 * tendencies_0 + ) * diss2 + + tendencies_1 = compute_tendencies( + state_spect_np12_approx1, old=tendencies_0 + ) + del state_spect_np12_approx1 + + state_spect_np12_approx2 = state_spect_tmp1 + + if fp.is_pythranized: + fp.use_pythranized_block("rk4_step1") + else: + # based on approximation 1 + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, + # state_spect_np12_approx2, tendencies_1; + # float64[][] diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, + # state_spect_np12_approx2, tendencies_1; + # complex128[][][] diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, + # state_spect_np12_approx2, tendencies_1; + # float64[][][] diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][][] state_spect, state_spect_tmp, + # state_spect_np12_approx2, tendencies_1; + # float64[][][] diss2; + # float dt + # ) + state_spect_tmp[:] += dt / 3 * diss2 * tendencies_1 + state_spect_np12_approx2[:] = ( + state_spect * diss2 + dt / 2 * tendencies_1 + ) + + tendencies_2 = compute_tendencies( + state_spect_np12_approx2, old=tendencies_1 + ) + del state_spect_np12_approx2 + + state_spect_np1_approx = state_spect_tmp1 + + if fp.is_pythranized: + fp.use_pythranized_block("rk4_step2") + else: + # based on approximation 2 + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, + # state_spect_np1_approx, tendencies_2; + # float64[][] diss, diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, + # state_spect_np1_approx, tendencies_2; + # complex128[][][] diss, diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, + # state_spect_np1_approx, tendencies_2; + # float64[][][] diss, diss2; + # float dt + # ) + + # pythran block ( + # complex128[][][][] state_spect, state_spect_tmp, + # state_spect_np1_approx, tendencies_2; + # float64[][][] diss, diss2; + # float dt + # ) + state_spect_tmp[:] += dt / 3 * diss2 * tendencies_2 + state_spect_np1_approx[:] = ( + state_spect * diss + dt * diss2 * tendencies_2 + ) + + tendencies_3 = compute_tendencies( + state_spect_np1_approx, old=tendencies_2 + ) + del state_spect_np1_approx + + if fp.is_pythranized: + fp.use_pythranized_block("rk4_step3") + else: + # result using the 4 approximations + # pythran block ( + # complex128[][][] state_spect, state_spect_tmp, tendencies_3; + # float dt + # ) + # pythran block ( + # complex128[][][][] state_spect, state_spect_tmp, tendencies_3; + # float dt + # ) + state_spect[:] = state_spect_tmp + dt / 6 * tendencies_3 diff --git a/fluidsim/base/time_stepping/pseudo_spect_cy.pyx b/fluidsim/base/time_stepping/pseudo_spect_cy.pyx index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL3BzZXVkb19zcGVjdF9jeS5weXg=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL3BzZXVkb19zcGVjdF9jeS5weXg= 100644 --- a/fluidsim/base/time_stepping/pseudo_spect_cy.pyx +++ b/fluidsim/base/time_stepping/pseudo_spect_cy.pyx @@ -1,3 +1,4 @@ +# cython: language_level=3 """ Time stepping Cython (:mod:`fluidsim.base.time_stepping.pseudo_spect_cy`) ========================================================================= @@ -14,8 +15,6 @@ """ -from __future__ import absolute_import - cimport numpy as np import numpy as np np.import_array() @@ -85,8 +84,8 @@ n0 = exact.shape[0] n1 = exact.shape[1] - for i0 in xrange(n0): - for i1 in xrange(n1): + for i0 in range(n0): + for i1 in range(n1): exact[i0, i1] = exp(-dt*f_lin[i0, i1]) exact2[i0, i1] = exp(-dt/2*f_lin[i0, i1]) self.dt_old = dt @@ -104,9 +103,9 @@ exact2 = self.exact2 f_lin = self.freq_lin - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): exact[ik, i0, i1] = cexp(-dt*f_lin[ik, i0, i1]) exact2[ik, i0, i1] = cexp(-dt/2*f_lin[ik, i0, i1]) @@ -140,7 +139,7 @@ cdef np.ndarray[DTYPEc_t, ndim=3] datas, datat cdef np.ndarray[DTYPEc_t, ndim=3] datatemp, datatemp2 - tendencies_nonlin = self.sim.tendencies_nonlin + compute_tendencies = self.sim.tendencies_nonlin state_spect = self.sim.state.state_spect nk = state_spect.shape[0] @@ -149,6 +148,6 @@ exact, exact2 = self.exact_linear_coefs.get_updated_coefs() - tendencies_fft_1 = tendencies_nonlin() + tendencies_1 = compute_tendencies() # # alternativelly, this @@ -153,4 +152,4 @@ # # alternativelly, this - # state_spect_temp = (self.state_spect + dt/6*tendencies_fft_1)*exact + # state_spect_temp = (self.state_spect + dt/6*tendencies_1)*exact # state_spect_np12_approx1 = ( @@ -156,5 +155,5 @@ # state_spect_np12_approx1 = ( - # self.state_spect + dt/2*tendencies_fft_1)*exact2 + # self.state_spect + dt/2*tendencies_1)*exact2 # # or this (slightly faster...) datas = state_spect @@ -158,7 +157,7 @@ # # or this (slightly faster...) datas = state_spect - datat = tendencies_fft_1 + datat = tendencies_1 state_spect_temp = SetOfVariables(like=state_spect) datatemp = state_spect_temp @@ -166,9 +165,9 @@ state_spect_np12_approx1 = SetOfVariables(like=state_spect) datatemp2 = state_spect_np12_approx1 - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datatemp[ik, i0, i1] = ( datas[ik, i0, i1] + dt/6*datat[ik, i0, i1])*exact[i0, i1] @@ -176,7 +175,7 @@ datas[ik, i0, i1] + dt/2*datat[ik, i0, i1])*exact2[i0, i1] - tendencies_fft_2 = tendencies_nonlin( - state_spect_np12_approx1, old=tendencies_fft_1) + tendencies_2 = compute_tendencies( + state_spect_np12_approx1, old=tendencies_1) # # alternativelly, this @@ -181,4 +180,4 @@ # # alternativelly, this - # state_spect_temp += dt/3*exact2*tendencies_fft_2 + # state_spect_temp += dt/3*exact2*tendencies_2 # state_spect_np12_approx2 = (exact2*self.state_spect @@ -184,4 +183,4 @@ # state_spect_np12_approx2 = (exact2*self.state_spect - # + dt/2*tendencies_fft_2) + # + dt/2*tendencies_2) # # or this (slightly faster...) @@ -186,6 +185,6 @@ # # or this (slightly faster...) - datat = tendencies_fft_2 + datat = tendencies_2 state_spect_np12_approx2 = state_spect_np12_approx1 del(state_spect_np12_approx1) @@ -189,6 +188,6 @@ state_spect_np12_approx2 = state_spect_np12_approx1 del(state_spect_np12_approx1) - + datatemp2 = state_spect_np12_approx2 @@ -193,8 +192,8 @@ datatemp2 = state_spect_np12_approx2 - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datatemp[ik, i0, i1] = ( datatemp[ik, i0, i1] + dt/3*exact2[i0, i1]*datat[ik, i0, i1]) @@ -202,7 +201,7 @@ exact2[i0, i1]*datas[ik, i0, i1] + dt/2*datat[ik, i0, i1]) - tendencies_fft_3 = tendencies_nonlin( - state_spect_np12_approx2, old=tendencies_fft_2) + tendencies_3 = compute_tendencies( + state_spect_np12_approx2, old=tendencies_2) # # alternativelly, this @@ -207,4 +206,4 @@ # # alternativelly, this - # state_spect_temp += dt/3*exact2*tendencies_fft_3 + # state_spect_temp += dt/3*exact2*tendencies_3 # state_spect_np1_approx = (exact*self.state_spect @@ -210,4 +209,4 @@ # state_spect_np1_approx = (exact*self.state_spect - # + dt*exact2*tendencies_fft_3) + # + dt*exact2*tendencies_3) # # or this (slightly faster...) @@ -212,8 +211,8 @@ # # or this (slightly faster...) - datat = tendencies_fft_3 + datat = tendencies_3 state_spect_np1_approx = state_spect_np12_approx2 del(state_spect_np12_approx2) datatemp2 = state_spect_np1_approx @@ -215,11 +214,11 @@ state_spect_np1_approx = state_spect_np12_approx2 del(state_spect_np12_approx2) datatemp2 = state_spect_np1_approx - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datatemp[ik, i0, i1] = ( datatemp[ik, i0, i1] + dt/3*exact2[i0, i1]*datat[ik, i0, i1]) @@ -227,8 +226,8 @@ exact[i0, i1]*datas[ik, i0, i1] + dt*exact2[i0, i1]*datat[ik, i0, i1]) - tendencies_fft_4 = tendencies_nonlin( - state_spect_np1_approx, old=tendencies_fft_3) + tendencies_4 = compute_tendencies( + state_spect_np1_approx, old=tendencies_3) del(state_spect_np1_approx) # # alternativelly, this @@ -232,6 +231,6 @@ del(state_spect_np1_approx) # # alternativelly, this - # self.state_spect = state_spect_temp + dt/6*tendencies_fft_4 + # self.state_spect = state_spect_temp + dt/6*tendencies_4 # # or this (slightly faster... may be not...) @@ -236,4 +235,4 @@ # # or this (slightly faster... may be not...) - datat = tendencies_fft_4 + datat = tendencies_4 @@ -239,7 +238,7 @@ - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datas[ik, i0, i1] = ( datatemp[ik, i0, i1] + dt/6*datat[ik, i0, i1]) @@ -247,6 +246,68 @@ @cython.embedsignature(True) @cython.boundscheck(False) @cython.wraparound(False) + def _time_step_RK2_state_ndim3_freqlin_ndim2_float(self): + """Advance in time *sim.state.state_spect* with the Runge-Kutta 2 method. + + See :ref:`the pure python RK2 function <rk2timescheme>` for the + presentation of the time scheme. + + For this function, the coefficient :math:`\sigma` is real and + represents the dissipation. + + """ + cdef double dt = self.deltat + + cdef Py_ssize_t i0, i1, ik, nk, n0, n1 + cdef np.ndarray[double, ndim=2] diss, diss2 + + cdef np.ndarray[DTYPEc_t, ndim=3] state_spect, datat, datatemp + + compute_tendencies = self.sim.tendencies_nonlin + state_spect = self.sim.state.state_spect + + nk = state_spect.shape[0] + n0 = state_spect.shape[1] + n1 = state_spect.shape[2] + + diss, diss2 = self.exact_linear_coefs.get_updated_coefs() + + tendencies_n = compute_tendencies() + + # # alternativelly, this + # state_spect_n12 = (state_spect + dt / 2 * tendencies_n) * diss2 + # # or this (slightly faster...) + + datat = tendencies_n + datatemp = state_spect_n12 = SetOfVariables(like=state_spect) + + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): + datatemp[ik, i0, i1] = ( + state_spect[ik, i0, i1] + dt / 2 * datat[ik, i0, i1] + ) * diss2[i0, i1] + + datat = tendencies_n12 = compute_tendencies( + state_spect_n12, old=tendencies_n + ) + + # # alternativelly, this + # self.sim.state.state_spect = ( + # state_spect * diss + dt * diss2 * tendencies_n12 + # ) + # # or this (slightly faster...) + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): + state_spect[ik, i0, i1] = ( + state_spect[ik, i0, i1] * diss[i0, i1] + + dt * diss2[i0, i1] * datat[ik, i0, i1] + ) + + @cython.embedsignature(True) + @cython.boundscheck(False) + @cython.wraparound(False) def _time_step_RK4_state_ndim3_freqlin_ndim3_float(self): """Advance in time *sim.state.state_spect* with the Runge-Kutta 4 method. @@ -262,7 +323,7 @@ cdef np.ndarray[DTYPEc_t, ndim=3] datas, datat cdef np.ndarray[DTYPEc_t, ndim=3] datatemp, datatemp2 - tendencies_nonlin = self.sim.tendencies_nonlin + compute_tendencies = self.sim.tendencies_nonlin state_spect = self.sim.state.state_spect datas = state_spect @@ -272,6 +333,6 @@ exact, exact2 = self.exact_linear_coefs.get_updated_coefs() - tendencies_fft_1 = tendencies_nonlin() + tendencies_1 = compute_tendencies() # # alternativelly, this @@ -276,4 +337,4 @@ # # alternativelly, this - # state_spect_temp = (self.state_spect + dt/6*tendencies_fft_1)*exact + # state_spect_temp = (self.state_spect + dt/6*tendencies_1)*exact # state_spect_np12_approx1 = (self.state_spect @@ -279,4 +340,4 @@ # state_spect_np12_approx1 = (self.state_spect - # + dt/2*tendencies_fft_1)*exact2 + # + dt/2*tendencies_1)*exact2 # # or this (slightly faster...) @@ -281,6 +342,6 @@ # # or this (slightly faster...) - datat = tendencies_fft_1 + datat = tendencies_1 state_spect_temp = SetOfVariables(like=state_spect) datatemp = state_spect_temp @@ -288,9 +349,9 @@ state_spect_np12_approx1 = SetOfVariables(like=state_spect) datatemp2 = state_spect_np12_approx1 - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datatemp[ik, i0, i1] = ( datas[ik, i0, i1] + dt/6*datat[ik, i0, i1])*exact[ik, i0, i1] @@ -298,7 +359,7 @@ datas[ik, i0, i1] + dt/2*datat[ik, i0, i1])*exact2[ik, i0, i1] - tendencies_fft_2 = tendencies_nonlin( - state_spect_np12_approx1, old=tendencies_fft_1) + tendencies_2 = compute_tendencies( + state_spect_np12_approx1, old=tendencies_1) # # alternativelly, this @@ -303,4 +364,4 @@ # # alternativelly, this - # state_spect_temp += dt/3*exact2*tendencies_fft_2 + # state_spect_temp += dt/3*exact2*tendencies_2 # state_spect_np12_approx2 = (exact2*self.state_spect @@ -306,4 +367,4 @@ # state_spect_np12_approx2 = (exact2*self.state_spect - # + dt/2*tendencies_fft_2) + # + dt/2*tendencies_2) # # or this (slightly faster...) @@ -308,8 +369,8 @@ # # or this (slightly faster...) - datat = tendencies_fft_2 + datat = tendencies_2 state_spect_np12_approx2 = state_spect_np12_approx1 del(state_spect_np12_approx1) datatemp2 = state_spect_np12_approx2 @@ -311,11 +372,11 @@ state_spect_np12_approx2 = state_spect_np12_approx1 del(state_spect_np12_approx1) datatemp2 = state_spect_np12_approx2 - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datatemp[ik, i0, i1] = ( datatemp[ik, i0, i1] + dt/3*exact2[ik, i0, i1]*datat[ik, i0, i1]) @@ -323,7 +384,7 @@ exact2[ik, i0, i1]*datas[ik, i0, i1] + dt/2*datat[ik, i0, i1]) - tendencies_fft_3 = tendencies_nonlin( - state_spect_np12_approx2, old=tendencies_fft_2) + tendencies_3 = compute_tendencies( + state_spect_np12_approx2, old=tendencies_2) # # alternativelly, this @@ -328,4 +389,4 @@ # # alternativelly, this - # state_spect_temp += dt/3*exact2*tendencies_fft_3 + # state_spect_temp += dt/3*exact2*tendencies_3 # state_spect_np1_approx = (exact*self.state_spect @@ -331,4 +392,4 @@ # state_spect_np1_approx = (exact*self.state_spect - # + dt*exact2*tendencies_fft_3) + # + dt*exact2*tendencies_3) # # or this (slightly faster...) @@ -333,8 +394,8 @@ # # or this (slightly faster...) - datat = tendencies_fft_3 + datat = tendencies_3 state_spect_np1_approx = state_spect_np12_approx2 del(state_spect_np12_approx2) datatemp2 = state_spect_np1_approx @@ -336,11 +397,11 @@ state_spect_np1_approx = state_spect_np12_approx2 del(state_spect_np12_approx2) datatemp2 = state_spect_np1_approx - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datatemp[ik, i0, i1] = ( datatemp[ik, i0, i1] + dt/3*exact2[ik, i0, i1]*datat[ik, i0, i1]) @@ -348,8 +409,8 @@ exact[ik, i0, i1]*datas[ik, i0, i1] + dt*exact2[ik, i0, i1]*datat[ik, i0, i1]) - tendencies_fft_4 = tendencies_nonlin( - state_spect_np1_approx, old=tendencies_fft_3) + tendencies_4 = compute_tendencies( + state_spect_np1_approx, old=tendencies_3) del(state_spect_np1_approx) # # alternativelly, this @@ -353,6 +414,6 @@ del(state_spect_np1_approx) # # alternativelly, this - # self.state_spect = state_spect_temp + dt/6*tendencies_fft_4 + # self.state_spect = state_spect_temp + dt/6*tendencies_4 # # or this (slightly faster... may be not...) @@ -357,4 +418,4 @@ # # or this (slightly faster... may be not...) - datat = tendencies_fft_4 + datat = tendencies_4 @@ -360,7 +421,7 @@ - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datas[ik, i0, i1] = ( datatemp[ik, i0, i1] + dt/6*datat[ik, i0, i1]) @@ -386,7 +447,7 @@ cdef np.ndarray[DTYPEc_t, ndim=3] datas, datat cdef np.ndarray[DTYPEc_t, ndim=3] datatemp, datatemp2 - tendencies_nonlin = self.sim.tendencies_nonlin + compute_tendencies = self.sim.tendencies_nonlin state_spect = self.sim.state.state_spect datas = state_spect @@ -396,6 +457,6 @@ exact, exact2 = self.exact_linear_coefs.get_updated_coefs() - tendencies_fft_1 = tendencies_nonlin() + tendencies_1 = compute_tendencies() # # alternativelly, this @@ -400,4 +461,4 @@ # # alternativelly, this - # state_spect_temp = (self.state_spect + dt/6*tendencies_fft_1)*exact + # state_spect_temp = (self.state_spect + dt/6*tendencies_1)*exact # state_spect_np12_approx1 = (self.state_spect @@ -403,4 +464,4 @@ # state_spect_np12_approx1 = (self.state_spect - # + dt/2*tendencies_fft_1)*exact2 + # + dt/2*tendencies_1)*exact2 # # or this (slightly faster...) @@ -405,6 +466,6 @@ # # or this (slightly faster...) - datat = tendencies_fft_1 + datat = tendencies_1 state_spect_temp = SetOfVariables(like=state_spect) datatemp = state_spect_temp @@ -412,9 +473,9 @@ state_spect_np12_approx1 = SetOfVariables(like=state_spect) datatemp2 = state_spect_np12_approx1 - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datatemp[ik, i0, i1] = ( datas[ik, i0, i1] + dt/6*datat[ik, i0, i1])*exact[ik, i0, i1] @@ -422,7 +483,7 @@ datas[ik, i0, i1] + dt/2*datat[ik, i0, i1])*exact2[ik, i0, i1] - tendencies_fft_2 = tendencies_nonlin( - state_spect_np12_approx1, old=tendencies_fft_1) + tendencies_2 = compute_tendencies( + state_spect_np12_approx1, old=tendencies_1) # # alternativelly, this @@ -427,4 +488,4 @@ # # alternativelly, this - # state_spect_temp += dt/3*exact2*tendencies_fft_2 + # state_spect_temp += dt/3*exact2*tendencies_2 # state_spect_np12_approx2 = (exact2*self.state_spect @@ -430,4 +491,4 @@ # state_spect_np12_approx2 = (exact2*self.state_spect - # + dt/2*tendencies_fft_2) + # + dt/2*tendencies_2) # # or this (slightly faster...) @@ -432,8 +493,8 @@ # # or this (slightly faster...) - datat = tendencies_fft_2 + datat = tendencies_2 state_spect_np12_approx2 = state_spect_np12_approx1 del(state_spect_np12_approx1) datatemp2 = state_spect_np12_approx2 @@ -435,11 +496,11 @@ state_spect_np12_approx2 = state_spect_np12_approx1 del(state_spect_np12_approx1) datatemp2 = state_spect_np12_approx2 - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datatemp[ik, i0, i1] = ( datatemp[ik, i0, i1] + dt/3*exact2[ik, i0, i1]*datat[ik, i0, i1]) @@ -447,7 +508,7 @@ exact2[ik, i0, i1]*datas[ik, i0, i1] + dt/2*datat[ik, i0, i1]) - tendencies_fft_3 = tendencies_nonlin( - state_spect_np12_approx2, old=tendencies_fft_2) + tendencies_3 = compute_tendencies( + state_spect_np12_approx2, old=tendencies_2) # # alternativelly, this @@ -452,4 +513,4 @@ # # alternativelly, this - # state_spect_temp += dt/3*exact2*tendencies_fft_3 + # state_spect_temp += dt/3*exact2*tendencies_3 # state_spect_np1_approx = (exact*self.state_spect @@ -455,4 +516,4 @@ # state_spect_np1_approx = (exact*self.state_spect - # + dt*exact2*tendencies_fft_3) + # + dt*exact2*tendencies_3) # # or this (slightly faster...) @@ -457,8 +518,8 @@ # # or this (slightly faster...) - datat = tendencies_fft_3 + datat = tendencies_3 state_spect_np1_approx = state_spect_np12_approx2 del(state_spect_np12_approx2) datatemp2 = state_spect_np1_approx @@ -460,11 +521,11 @@ state_spect_np1_approx = state_spect_np12_approx2 del(state_spect_np12_approx2) datatemp2 = state_spect_np1_approx - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datatemp[ik, i0, i1] = ( datatemp[ik, i0, i1] + dt/3*exact2[ik, i0, i1]*datat[ik, i0, i1]) @@ -472,8 +533,8 @@ exact[ik, i0, i1]*datas[ik, i0, i1] + dt*exact2[ik, i0, i1]*datat[ik, i0, i1]) - tendencies_fft_4 = tendencies_nonlin( - state_spect_np1_approx, old=tendencies_fft_3) + tendencies_4 = compute_tendencies( + state_spect_np1_approx, old=tendencies_3) del(state_spect_np1_approx) # # alternativelly, this @@ -477,6 +538,6 @@ del(state_spect_np1_approx) # # alternativelly, this - # self.state_spect = state_spect_temp + dt/6*tendencies_fft_4 + # self.state_spect = state_spect_temp + dt/6*tendencies_4 # # or this (slightly faster... may be not...) @@ -481,4 +542,4 @@ # # or this (slightly faster... may be not...) - datat = tendencies_fft_4 + datat = tendencies_4 @@ -484,7 +545,7 @@ - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): datas[ik, i0, i1] = ( datatemp[ik, i0, i1] + dt/6*datat[ik, i0, i1]) @@ -514,7 +575,7 @@ cdef np.ndarray[DTYPEc_t, ndim=4] datas, datat cdef np.ndarray[DTYPEc_t, ndim=4] datatemp, datatemp2 - tendencies_nonlin = self.sim.tendencies_nonlin + compute_tendencies = self.sim.tendencies_nonlin state_spect = self.sim.state.state_spect nk = state_spect.shape[0] @@ -524,6 +585,6 @@ exact, exact2 = self.exact_linear_coefs.get_updated_coefs() - tendencies_fft_1 = tendencies_nonlin() + tendencies_1 = compute_tendencies() # # alternativelly, this @@ -528,4 +589,4 @@ # # alternativelly, this - # state_spect_temp = (self.state_spect + dt/6*tendencies_fft_1)*exact + # state_spect_temp = (self.state_spect + dt/6*tendencies_1)*exact # state_spect_np12_approx1 = ( @@ -531,5 +592,5 @@ # state_spect_np12_approx1 = ( - # self.state_spect + dt/2*tendencies_fft_1)*exact2 + # self.state_spect + dt/2*tendencies_1)*exact2 # # or this (slightly faster...) datas = state_spect @@ -533,7 +594,7 @@ # # or this (slightly faster...) datas = state_spect - datat = tendencies_fft_1 + datat = tendencies_1 state_spect_temp = SetOfVariables(like=state_spect) datatemp = state_spect_temp @@ -541,10 +602,10 @@ state_spect_np12_approx1 = SetOfVariables(like=state_spect) datatemp2 = state_spect_np12_approx1 - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): - for i2 in xrange(n2): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): + for i2 in range(n2): datatemp[ik, i0, i1, i2] = ( datas[ik, i0, i1, i2] + dt/6*datat[ik, i0, i1, i2])*exact[i0, i1, i2] @@ -552,7 +613,7 @@ datas[ik, i0, i1, i2] + dt/2*datat[ik, i0, i1, i2])*exact2[i0, i1, i2] - tendencies_fft_2 = tendencies_nonlin( - state_spect_np12_approx1, old=tendencies_fft_1) + tendencies_2 = compute_tendencies( + state_spect_np12_approx1, old=tendencies_1) # # alternativelly, this @@ -557,4 +618,4 @@ # # alternativelly, this - # state_spect_temp += dt/3*exact2*tendencies_fft_2 + # state_spect_temp += dt/3*exact2*tendencies_2 # state_spect_np12_approx2 = (exact2*self.state_spect @@ -560,4 +621,4 @@ # state_spect_np12_approx2 = (exact2*self.state_spect - # + dt/2*tendencies_fft_2) + # + dt/2*tendencies_2) # # or this (slightly faster...) @@ -562,8 +623,8 @@ # # or this (slightly faster...) - datat = tendencies_fft_2 + datat = tendencies_2 state_spect_np12_approx2 = state_spect_np12_approx1 del(state_spect_np12_approx1) datatemp2 = state_spect_np12_approx2 @@ -565,12 +626,12 @@ state_spect_np12_approx2 = state_spect_np12_approx1 del(state_spect_np12_approx1) datatemp2 = state_spect_np12_approx2 - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): - for i2 in xrange(n2): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): + for i2 in range(n2): datatemp[ik, i0, i1, i2] = ( datatemp[ik, i0, i1, i2] + dt/3*exact2[i0, i1, i2]*datat[ik, i0, i1, i2]) @@ -578,7 +639,7 @@ exact2[i0, i1, i2]*datas[ik, i0, i1, i2] + dt/2*datat[ik, i0, i1, i2]) - tendencies_fft_3 = tendencies_nonlin( - state_spect_np12_approx2, old=tendencies_fft_2) + tendencies_3 = compute_tendencies( + state_spect_np12_approx2, old=tendencies_2) # # alternativelly, this @@ -583,4 +644,4 @@ # # alternativelly, this - # state_spect_temp += dt/3*exact2*tendencies_fft_3 + # state_spect_temp += dt/3*exact2*tendencies_3 # state_spect_np1_approx = (exact*self.state_spect @@ -586,4 +647,4 @@ # state_spect_np1_approx = (exact*self.state_spect - # + dt*exact2*tendencies_fft_3) + # + dt*exact2*tendencies_3) # # or this (slightly faster...) @@ -588,8 +649,8 @@ # # or this (slightly faster...) - datat = tendencies_fft_3 + datat = tendencies_3 state_spect_np1_approx = state_spect_np12_approx2 del(state_spect_np12_approx2) datatemp2 = state_spect_np1_approx @@ -591,12 +652,12 @@ state_spect_np1_approx = state_spect_np12_approx2 del(state_spect_np12_approx2) datatemp2 = state_spect_np1_approx - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): - for i2 in xrange(n2): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): + for i2 in range(n2): datatemp[ik, i0, i1, i2] = ( datatemp[ik, i0, i1, i2] + dt/3*exact2[i0, i1, i2]*datat[ik, i0, i1, i2]) @@ -604,8 +665,8 @@ exact[i0, i1, i2]*datas[ik, i0, i1, i2] + dt*exact2[i0, i1, i2]*datat[ik, i0, i1, i2]) - tendencies_fft_4 = tendencies_nonlin( - state_spect_np1_approx, old=tendencies_fft_3) + tendencies_4 = compute_tendencies( + state_spect_np1_approx, old=tendencies_3) del(state_spect_np1_approx) # # alternativelly, this @@ -609,6 +670,6 @@ del(state_spect_np1_approx) # # alternativelly, this - # self.state_spect = state_spect_temp + dt/6*tendencies_fft_4 + # self.state_spect = state_spect_temp + dt/6*tendencies_4 # # or this (slightly faster... may be not...) @@ -613,4 +674,4 @@ # # or this (slightly faster... may be not...) - datat = tendencies_fft_4 + datat = tendencies_4 @@ -616,8 +677,8 @@ - for ik in xrange(nk): - for i0 in xrange(n0): - for i1 in xrange(n1): - for i2 in xrange(n2): + for ik in range(nk): + for i0 in range(n0): + for i1 in range(n1): + for i2 in range(n2): datas[ik, i0, i1, i2] = ( datatemp[ik, i0, i1, i2] + dt/6*datat[ik, i0, i1, i2]) diff --git a/fluidsim/base/time_stepping/rk_pythran.py b/fluidsim/base/time_stepping/rk_pythran.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL3JrX3B5dGhyYW4ucHk= --- /dev/null +++ b/fluidsim/base/time_stepping/rk_pythran.py @@ -0,0 +1,40 @@ +# pythran export step0_RK2_pythran( +# complex128[][][], +# complex128[][][], +# complex128[][][], +# float64[][] or complex128[][], +# float +# ) + +# pythran export step0_RK2_pythran( +# complex128[][][][], +# complex128[][][][], +# complex128[][][][], +# float64[][][] or complex128[][][], +# float +# ) + + +def step0_RK2_pythran(state_spect_n12, state_spect, tendencies_n, diss2, dt): + state_spect_n12[:] = (state_spect + dt / 2 * tendencies_n) * diss2 + + +# pythran export step1_RK2_pythran( +# complex128[][][], +# complex128[][][], +# float64[][] or complex128[][], +# float64[][] or complex128[][], +# float +# ) + +# pythran export step1_RK2_pythran( +# complex128[][][][], +# complex128[][][][], +# float64[][][] or complex128[][][], +# float64[][][] or complex128[][][], +# float +# ) + + +def step1_RK2_pythran(state_spect, tendencies_n12, diss, diss2, dt): + state_spect[:] = state_spect * diss + dt * diss2 * tendencies_n12 diff --git a/fluidsim/base/time_stepping/simple.py b/fluidsim/base/time_stepping/simple.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL3NpbXBsZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vYmFzZS90aW1lX3N0ZXBwaW5nL3NpbXBsZS5weQ== 100644 --- a/fluidsim/base/time_stepping/simple.py +++ b/fluidsim/base/time_stepping/simple.py @@ -29,7 +29,7 @@ if sim.params.time_stepping.USE_CFL: self.get_updated_coefs = self.get_updated_coefs_CLF - self.dt_old = 0. + self.dt_old = 0.0 else: self.compute(time_stepping.deltat) self.get_updated_coefs = self.get_coefs @@ -67,7 +67,7 @@ self._init_time_scheme() def _init_freq_lin(self): - self.freq_lin = 0. + self.freq_lin = 0.0 def _init_exact_linear_coef(self): self.exact_linear_coefs = ExactLinearCoefs(self) diff --git a/fluidsim/operators/_bench_util2d.py b/fluidsim/operators/_bench_util2d.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vb3BlcmF0b3JzL19iZW5jaF91dGlsMmQucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vb3BlcmF0b3JzL19iZW5jaF91dGlsMmQucHk= 100644 --- a/fluidsim/operators/_bench_util2d.py +++ b/fluidsim/operators/_bench_util2d.py @@ -1,4 +1,3 @@ - import perf name_modules = ("native_openmp", "native", "openmp", "simd", "simple") diff --git a/fluidsim/operators/base.py b/fluidsim/operators/base.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vb3BlcmF0b3JzL2Jhc2UucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vb3BlcmF0b3JzL2Jhc2UucHk= 100644 --- a/fluidsim/operators/base.py +++ b/fluidsim/operators/base.py @@ -21,7 +21,7 @@ def _complete_params_with_default(params): """This static method is used to complete the *params* container. """ - attribs = {"nx": 48, "Lx": 8.} + attribs = {"nx": 48, "Lx": 8.0} params._set_child("oper", attribs=attribs) return params diff --git a/fluidsim/operators/op_finitediff.py b/fluidsim/operators/op_finitediff.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vb3BlcmF0b3JzL29wX2Zpbml0ZWRpZmYucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vb3BlcmF0b3JzL29wX2Zpbml0ZWRpZmYucHk= 100644 --- a/fluidsim/operators/op_finitediff.py +++ b/fluidsim/operators/op_finitediff.py @@ -216,6 +216,6 @@ nx = 3 ny = 3 oper = OperatorFiniteDiff2DPeriodic( - [ny, nx], [old_div(nx, 2.), old_div(ny, 2.)] + [ny, nx], [old_div(nx, 2.0), old_div(ny, 2.0)] ) a = np.arange(nx * ny).reshape([ny, nx]) diff --git a/fluidsim/operators/operators1d.py b/fluidsim/operators/operators1d.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczFkLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczFkLnB5 100644 --- a/fluidsim/operators/operators1d.py +++ b/fluidsim/operators/operators1d.py @@ -28,7 +28,7 @@ """ params = OperatorsBase1D._complete_params_with_default(params) params.oper._set_attribs( - {"type_fft": "sequential", "coef_dealiasing": 2. / 3} + {"type_fft": "sequential", "coef_dealiasing": 2.0 / 3} ) return params @@ -87,7 +87,7 @@ self.dealiasing_variable(thing) def dealiasing_variable(self, f_fft): - f_fft[self.where_dealiased] = 0. + f_fft[self.where_dealiased] = 0.0 def dealiasing_setofvar(self, sov): for ik in range(sov.nvar): diff --git a/fluidsim/operators/operators2d.py b/fluidsim/operators/operators2d.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczJkLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczJkLnB5 100644 --- a/fluidsim/operators/operators2d.py +++ b/fluidsim/operators/operators2d.py @@ -47,7 +47,7 @@ """ attribs = { "type_fft": "default", - "coef_dealiasing": 2. / 3, + "coef_dealiasing": 2.0 / 3, "nx": 48, "ny": 48, "Lx": 8, @@ -78,4 +78,7 @@ params.oper.nx = nx params.oper.ny = ny + if params.ONLY_COARSE_OPER: + nx = ny = 4 + super(OperatorsPseudoSpectral2D, self).__init__( @@ -81,6 +84,6 @@ super(OperatorsPseudoSpectral2D, self).__init__( - params.oper.nx, - params.oper.ny, + nx, + ny, params.oper.Lx, params.oper.Ly, fft=params.oper.type_fft, @@ -110,7 +113,7 @@ # for shallow water models Kappa2 = self.K2 + self.params.kd2 self.Kappa2_not0 = self.K2_not0 + self.params.kd2 - self.Kappa_over_ic = -1.j * np.sqrt(Kappa2 / self.params.c2) + self.Kappa_over_ic = -1.0j * np.sqrt(Kappa2 / self.params.c2) except AttributeError: pass @@ -121,7 +124,7 @@ pass else: if NO_SHEAR_MODES: - COND_NOSHEAR = abs(self.KX) == 0. + COND_NOSHEAR = abs(self.KX) == 0.0 where_dealiased = np.logical_or( COND_NOSHEAR, self.where_dealiased ) @@ -202,7 +205,7 @@ for ikxc in range(nkxc): kx = self.deltakx * ikxc - rank_ikx, ikxloc, ikyloc = self.where_is_wavenumber(kx, 0.) + rank_ikx, ikxloc, ikyloc = self.where_is_wavenumber(kx, 0.0) if rank == rank_ikx: # create f1d_temp for ikyc in range(nkyc): @@ -327,7 +330,7 @@ if nb_proc == 1: pdf, bin_edges = np.histogram( - field, bins=nb_bins, normed=True, range=(range_min, range_max) + field, bins=nb_bins, density=True, range=(range_min, range_max) ) else: hist, bin_edges = np.histogram( @@ -532,7 +535,7 @@ for i0 in range(n0): for i1 in range(n1): if i0 == 0 and i1 == 0 and rank == 0: - d_fft[i0, i1] = 0. + d_fft[i0, i1] = 0.0 else: d_fft[i0, i1] = Delta_a_fft[i0, i1] / Kappa_over_ic[i0, i1] return d_fft @@ -597,7 +600,7 @@ """q, ap, am (fft) ---> ux, uy, eta (fft)""" a_fft = ap_fft + am_fft if rank == 0: - a_fft[0, 0] = 0. + a_fft[0, 0] = 0.0 div_fft = self.divfft_from_apamfft(ap_fft, am_fft) (uxa_fft, uya_fft, etaa_fft) = self.uxuyetafft_from_afft(a_fft) (uxq_fft, uyq_fft, etaq_fft) = self.uxuyetafft_from_qfft(q_fft) @@ -660,7 +663,7 @@ Negative of the result. """ - sign = 1. / 1j ** order + sign = 1.0 / 1j ** order if sign.imag != 0: raise ValueError("Order={} should be even!".format(order)) @@ -710,7 +713,7 @@ for ikxc in range(nKxc): kx = self.deltakx * ikxc - rank_ikx, ikxloc, ikyloc = self.where_is_wavenumber(kx, 0.) + rank_ikx, ikxloc, ikyloc = self.where_is_wavenumber(kx, 0.0) if mpi.rank == 0: fc1D = fck_fft[ikxc] @@ -730,7 +733,7 @@ if mpi.rank == rank_ikx: # copy for ikyc in range(nKyc): - if ikyc <= nKyc / 2.: + if ikyc <= nKyc / 2.0: iky = ikyc else: kynodim = ikyc - nKyc @@ -746,7 +749,7 @@ raise ValueError("any(arr_coarse[:, nKxc-1] != 0)") for ikyc in range(nKyc): - if ikyc <= nKyc / 2.: + if ikyc <= nKyc / 2.0: iky = ikyc else: kynodim = ikyc - nKyc diff --git a/fluidsim/operators/operators3d.py b/fluidsim/operators/operators3d.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczNkLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vb3BlcmF0b3JzL29wZXJhdG9yczNkLnB5 100644 --- a/fluidsim/operators/operators3d.py +++ b/fluidsim/operators/operators3d.py @@ -124,4 +124,15 @@ self.params = params self.axes = ("z", "y", "x") + if params.ONLY_COARSE_OPER: + nx = ny = nz = 4 + # Unchanged, but type cast into integers + params.oper.nx = int(params.oper.nx) + params.oper.ny = int(params.oper.ny) + params.oper.nz = int(params.oper.nz) + else: + nx = params.oper.nx = int(params.oper.nx) + ny = params.oper.ny = int(params.oper.ny) + nz = params.oper.nz = int(params.oper.nz) + super(OperatorsPseudoSpectral3D, self).__init__( @@ -127,7 +138,7 @@ super(OperatorsPseudoSpectral3D, self).__init__( - params.oper.nx, - params.oper.ny, - params.oper.nz, + nx, + ny, + nz, params.oper.Lx, params.oper.Ly, params.oper.Lz, @@ -236,7 +247,7 @@ def _ik_from_ikc(ikc, nkc, nk): - if ikc <= nkc / 2.: + if ikc <= nkc / 2.0: ik = ikc else: knodim = ikc - nkc diff --git a/fluidsim/operators/test/test_operators2d.py b/fluidsim/operators/test/test_operators2d.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vb3BlcmF0b3JzL3Rlc3QvdGVzdF9vcGVyYXRvcnMyZC5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vb3BlcmF0b3JzL3Rlc3QvdGVzdF9vcGVyYXRvcnMyZC5weQ== 100644 --- a/fluidsim/operators/test/test_operators2d.py +++ b/fluidsim/operators/test/test_operators2d.py @@ -16,7 +16,7 @@ NO_PYTHRAN = False -def create_oper(type_fft=None, coef_dealiasing=2. / 3): +def create_oper(type_fft=None, coef_dealiasing=2.0 / 3, **kwargs): params = ParamContainer(tag="params") @@ -20,10 +20,10 @@ params = ParamContainer(tag="params") - params._set_attrib("ONLY_COARSE_OPER", False) + params._set_attrib("ONLY_COARSE_OPER", kwargs.get("ONLY_COARSE_OPER", False)) params._set_attrib("f", 0) params._set_attrib("c2", 100) params._set_attrib("kd2", 0) OperatorsPseudoSpectral2D._complete_params_with_default(params) @@ -24,13 +24,15 @@ params._set_attrib("f", 0) params._set_attrib("c2", 100) params._set_attrib("kd2", 0) OperatorsPseudoSpectral2D._complete_params_with_default(params) - if mpi.nb_proc == 1: + if "nh" in kwargs: + nh = kwargs["nh"] + elif mpi.nb_proc == 1: nh = 9 else: nh = 8 params.oper.nx = nh params.oper.ny = nh @@ -31,10 +33,10 @@ nh = 9 else: nh = 8 params.oper.nx = nh params.oper.ny = nh - Lh = 6. + Lh = 6.0 params.oper.Lx = Lh params.oper.Ly = Lh @@ -78,7 +80,7 @@ rot = oper.create_arrayX_random() rot_fft = oper.fft2(rot) if mpi.rank == 0: - rot_fft[0, 0] = 0. + rot_fft[0, 0] = 0.0 ux_fft, uy_fft = oper.vecfft_from_rotfft(rot_fft) rot2_fft = oper.rotfft_from_vecfft(ux_fft, uy_fft) @@ -90,7 +92,7 @@ ff = oper.create_arrayX_random() ff_fft = oper.fft2(ff) if mpi.rank == 0: - ff_fft[0, 0] = 0. + ff_fft[0, 0] = 0.0 lap_fft = oper.laplacian_fft(ff_fft, order=4) ff_fft_back = oper.invlaplacian_fft(lap_fft, order=4) @@ -120,6 +122,26 @@ assert_increments_equal(irx) +class TestOperatorCoarse(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.nh = 12 + cls.oper = create_oper(ONLY_COARSE_OPER=True, nh=cls.nh) + + def test_oper_coarse(self): + """Test coarse operator parameters which, by default, initializes + `nh=4`. + + """ + oper = self.oper + + # Assert params are intact but the operator is initialized coarse + self.assertEqual(oper.params.oper.nx, self.nh) + self.assertEqual(oper.params.oper.ny, self.nh) + self.assertNotEqual(oper.nx, self.nh) + self.assertNotEqual(oper.ny, self.nh) + + class TestOperatorsDealiasing(unittest.TestCase): @classmethod def setUpClass(cls): @@ -131,7 +153,7 @@ """ oper = self.oper - var_fft = oper.create_arrayK(1.) + var_fft = oper.create_arrayK(1.0) sum_var = var_fft.sum() oper.dealiasing(var_fft) sum_var_dealiased = var_fft.sum() diff --git a/fluidsim/operators/util2d_pythran.py b/fluidsim/operators/util2d_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vb3BlcmF0b3JzL3V0aWwyZF9weXRocmFuLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vb3BlcmF0b3JzL3V0aWwyZF9weXRocmFuLnB5 100644 --- a/fluidsim/operators/util2d_pythran.py +++ b/fluidsim/operators/util2d_pythran.py @@ -25,7 +25,7 @@ for i1 in range(n1): if where[i0, i1]: for ik in range(nk): - setofvar_fft[ik, i0, i1] = 0. + setofvar_fft[ik, i0, i1] = 0.0 # pythran export laplacian_fft(complex128[][], float64[][]) @@ -43,7 +43,7 @@ """Compute the n-th order inverse Laplacian.""" invlap_afft = a_fft / Kn_not0 if rank == 0: - invlap_afft[0, 0] = 0. + invlap_afft[0, 0] = 0.0 return invlap_afft diff --git a/fluidsim/operators/util3d_pythran.py b/fluidsim/operators/util3d_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vb3BlcmF0b3JzL3V0aWwzZF9weXRocmFuLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vb3BlcmF0b3JzL3V0aWwzZF9weXRocmFuLnB5 100644 --- a/fluidsim/operators/util3d_pythran.py +++ b/fluidsim/operators/util3d_pythran.py @@ -33,7 +33,7 @@ for i2 in range(n2): if where_dealiased[i0, i1, i2]: for ik in range(nk): - sov[ik, i0, i1, i2] = 0. + sov[ik, i0, i1, i2] = 0.0 # pythran export dealiasing_variable(complex128[][][], uint8[][][]) @@ -47,7 +47,7 @@ for i1 in range(n1): for i2 in range(n2): if where_dealiased[i0, i1, i2]: - ff_fft[i0, i1, i2] = 0. + ff_fft[i0, i1, i2] = 0.0 # pythran export urudfft_from_vxvyfft( @@ -56,7 +56,7 @@ def urudfft_from_vxvyfft(vx_fft, vy_fft, kx, ky, rank): k2 = kx ** 2 + ky ** 2 - k2[k2 == 0.] = 1e-10 + k2[k2 == 0.0] = 1e-10 divh_fft = 1j * (kx * vx_fft + ky * vy_fft) urx_fft = vx_fft - divh_fft * kx / k2 diff --git a/fluidsim/solvers/ad1d/output/__init__.py b/fluidsim/solvers/ad1d/output/__init__.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9hZDFkL291dHB1dC9fX2luaXRfXy5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9hZDFkL291dHB1dC9fX2luaXRfXy5weQ== 100644 --- a/fluidsim/solvers/ad1d/output/__init__.py +++ b/fluidsim/solvers/ad1d/output/__init__.py @@ -1,5 +1,3 @@ - - import numpy as np from fluidsim.base.output import OutputBase diff --git a/fluidsim/solvers/ad1d/output/print_stdout.py b/fluidsim/solvers/ad1d/output/print_stdout.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9hZDFkL291dHB1dC9wcmludF9zdGRvdXQucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9hZDFkL291dHB1dC9wcmludF9zdGRvdXQucHk= 100644 --- a/fluidsim/solvers/ad1d/output/print_stdout.py +++ b/fluidsim/solvers/ad1d/output/print_stdout.py @@ -1,4 +1,3 @@ - from fluidsim.solvers.ns2d.output.print_stdout import PrintStdOutNS2D diff --git a/fluidsim/solvers/ad1d/pseudo_spect/solver.py b/fluidsim/solvers/ad1d/pseudo_spect/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3BzZXVkb19zcGVjdC9zb2x2ZXIucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3BzZXVkb19zcGVjdC9zb2x2ZXIucHk= 100644 --- a/fluidsim/solvers/ad1d/pseudo_spect/solver.py +++ b/fluidsim/solvers/ad1d/pseudo_spect/solver.py @@ -47,7 +47,7 @@ @staticmethod def _complete_params_with_default(params): SimulBasePseudoSpectral._complete_params_with_default(params) - params._set_attrib("U", 1.) + params._set_attrib("U", 1.0) def tendencies_nonlin(self, state_spect=None, old=None): @@ -58,9 +58,9 @@ else: tendencies_fft = old - tendencies_fft[:] = 0. + tendencies_fft[:] = 0.0 return tendencies_fft def compute_freq_complex(self, key): assert key == "s_fft" @@ -62,9 +62,9 @@ return tendencies_fft def compute_freq_complex(self, key): assert key == "s_fft" - omega = 1.j * self.params.U * self.oper.KX + omega = 1.0j * self.params.U * self.oper.KX return omega @@ -74,10 +74,10 @@ params = Simul.create_default_params() params.output.sub_directory = "examples" - params.output.periods_save.phys_fields = 1. + params.output.periods_save.phys_fields = 1.0 params.short_name_type_run = "test" params.oper.Lx = 10 params.oper.nx = 256 params.nu_2 = 1e-3 params.time_stepping.USE_CFL = False params.time_stepping.deltat0 = 1e-3 @@ -78,10 +78,10 @@ params.short_name_type_run = "test" params.oper.Lx = 10 params.oper.nx = 256 params.nu_2 = 1e-3 params.time_stepping.USE_CFL = False params.time_stepping.deltat0 = 1e-3 - params.time_stepping.t_end = 1. + params.time_stepping.t_end = 1.0 params.time_stepping.type_time_scheme = "RK2" params.init_fields.type = "in_script" diff --git a/fluidsim/solvers/ad1d/pseudo_spect/state.py b/fluidsim/solvers/ad1d/pseudo_spect/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3BzZXVkb19zcGVjdC9zdGF0ZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3BzZXVkb19zcGVjdC9zdGF0ZS5weQ== 100644 --- a/fluidsim/solvers/ad1d/pseudo_spect/state.py +++ b/fluidsim/solvers/ad1d/pseudo_spect/state.py @@ -49,7 +49,7 @@ if mpi.rank == 0: print(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result diff --git a/fluidsim/solvers/ad1d/solver.py b/fluidsim/solvers/ad1d/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/ad1d/solver.py +++ b/fluidsim/solvers/ad1d/solver.py @@ -65,10 +65,10 @@ """This static method is used to complete the *params* container. """ SimulBase._complete_params_with_default(params) - attribs = {"U": 1.} + attribs = {"U": 1.0} params._set_attribs(attribs) def tendencies_nonlin(self, state_phys=None, old=None): """Compute the "nonlinear" tendencies.""" if old is None: tendencies = SetOfVariables( @@ -69,10 +69,10 @@ params._set_attribs(attribs) def tendencies_nonlin(self, state_phys=None, old=None): """Compute the "nonlinear" tendencies.""" if old is None: tendencies = SetOfVariables( - like=self.state.state_phys, info="tendencies", value=0. + like=self.state.state_phys, info="tendencies", value=0.0 ) else: tendencies = old @@ -97,8 +97,8 @@ params = Simul.create_default_params() - params.U = 1. + params.U = 1.0 params.short_name_type_run = "test" params.oper.nx = 200 @@ -101,8 +101,8 @@ params.short_name_type_run = "test" params.oper.nx = 200 - params.oper.Lx = 1. + params.oper.Lx = 1.0 # params.oper.type_fft = 'FFTWPY' @@ -121,7 +121,7 @@ params.output.periods_save.phys_fields = 0.5 - params.output.periods_plot.phys_fields = 0. + params.output.periods_plot.phys_fields = 0.0 params.output.phys_fields.field_to_plot = "s" diff --git a/fluidsim/solvers/ad1d/state.py b/fluidsim/solvers/ad1d/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3N0YXRlLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3N0YXRlLnB5 100644 --- a/fluidsim/solvers/ad1d/state.py +++ b/fluidsim/solvers/ad1d/state.py @@ -47,7 +47,7 @@ if mpi.rank == 0: print(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result diff --git a/fluidsim/solvers/ad1d/test_solver.py b/fluidsim/solvers/ad1d/test_solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3Rlc3Rfc29sdmVyLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9hZDFkL3Rlc3Rfc29sdmVyLnB5 100644 --- a/fluidsim/solvers/ad1d/test_solver.py +++ b/fluidsim/solvers/ad1d/test_solver.py @@ -1,4 +1,3 @@ - import unittest import shutil import warnings @@ -33,8 +32,8 @@ ) params = Simul.create_default_params() - params.U = 1. + params.U = 1.0 params.short_name_type_run = "test" params.oper.nx = 40 @@ -37,8 +36,8 @@ params.short_name_type_run = "test" params.oper.nx = 40 - params.oper.Lx = 1. + params.oper.Lx = 1.0 params.time_stepping.type_time_scheme = "RK2" @@ -53,7 +52,7 @@ params.output.periods_save.phys_fields = 0.5 - params.output.periods_plot.phys_fields = 0. + params.output.periods_plot.phys_fields = 0.0 params.output.phys_fields.field_to_plot = "s" diff --git a/fluidsim/solvers/models0d/lorenz/solver.py b/fluidsim/solvers/models0d/lorenz/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9tb2RlbHMwZC9sb3Jlbnovc29sdmVyLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9tb2RlbHMwZC9sb3Jlbnovc29sdmVyLnB5 100644 --- a/fluidsim/solvers/models0d/lorenz/solver.py +++ b/fluidsim/solvers/models0d/lorenz/solver.py @@ -73,7 +73,7 @@ def _complete_params_with_default(params): """Complete the `params` container (static method).""" SimulBase._complete_params_with_default(params) - attribs = {"sigma": 10., "beta": 8. / 3, "rho": 28.} + attribs = {"sigma": 10.0, "beta": 8.0 / 3, "rho": 28.0} params._set_attribs(attribs) def __init__(self, *args, **kargs): @@ -151,7 +151,7 @@ sim = Simul(params) - sim.state.state_phys.set_var("X", sim.Xs0 + 2.) + sim.state.state_phys.set_var("X", sim.Xs0 + 2.0) sim.state.state_phys.set_var("Y", sim.Ys0) sim.state.state_phys.set_var("Z", sim.Zs0) diff --git a/fluidsim/solvers/models0d/predaprey/solver.py b/fluidsim/solvers/models0d/predaprey/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9tb2RlbHMwZC9wcmVkYXByZXkvc29sdmVyLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9tb2RlbHMwZC9wcmVkYXByZXkvc29sdmVyLnB5 100644 --- a/fluidsim/solvers/models0d/predaprey/solver.py +++ b/fluidsim/solvers/models0d/predaprey/solver.py @@ -70,7 +70,7 @@ def _complete_params_with_default(params): """Complete the `params` container (static method).""" SimulBase._complete_params_with_default(params) - attribs = {"A": 1., "B": 1., "C": 1., "D": 0.5} + attribs = {"A": 1.0, "B": 1.0, "C": 1.0, "D": 0.5} params._set_attribs(attribs) def __init__(self, *args, **kargs): diff --git a/fluidsim/solvers/models0d/test_lorenz.py b/fluidsim/solvers/models0d/test_lorenz.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9tb2RlbHMwZC90ZXN0X2xvcmVuei5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9tb2RlbHMwZC90ZXN0X2xvcmVuei5weQ== 100644 --- a/fluidsim/solvers/models0d/test_lorenz.py +++ b/fluidsim/solvers/models0d/test_lorenz.py @@ -1,4 +1,3 @@ - import unittest import shutil @@ -33,7 +32,7 @@ with stdout_redirected(): sim = Simul(params) - sim.state.state_phys.set_var("X", sim.Xs0 + 2.) + sim.state.state_phys.set_var("X", sim.Xs0 + 2.0) sim.state.state_phys.set_var("Y", sim.Ys0) sim.state.state_phys.set_var("Z", sim.Zs0) diff --git a/fluidsim/solvers/models0d/test_predaprey.py b/fluidsim/solvers/models0d/test_predaprey.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9tb2RlbHMwZC90ZXN0X3ByZWRhcHJleS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9tb2RlbHMwZC90ZXN0X3ByZWRhcHJleS5weQ== 100644 --- a/fluidsim/solvers/models0d/test_predaprey.py +++ b/fluidsim/solvers/models0d/test_predaprey.py @@ -1,4 +1,3 @@ - import unittest import shutil @@ -33,8 +32,8 @@ with stdout_redirected(): sim = Simul(params) - sim.state.state_phys.set_var("X", sim.Xs + 2.) - sim.state.state_phys.set_var("Y", sim.Ys + 1.) + sim.state.state_phys.set_var("X", sim.Xs + 2.0) + sim.state.state_phys.set_var("Y", sim.Ys + 1.0) with stdout_redirected(): sim.time_stepping.start() diff --git a/fluidsim/solvers/ns2d/bouss/solver.py b/fluidsim/solvers/ns2d/bouss/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL2JvdXNzL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL2JvdXNzL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/ns2d/bouss/solver.py +++ b/fluidsim/solvers/ns2d/bouss/solver.py @@ -233,9 +233,9 @@ delta_x = Lx / nx - params.nu_2 = 1. * 10e-6 + params.nu_2 = 1.0 * 10e-6 # params.nu_8 = 2.*10e-1*params.forcing.forcing_rate**(1./3)*delta_x**8 params.time_stepping.USE_CFL = True params.time_stepping.USE_T_END = True # params.time_stepping.deltat0 = 0.1 # Period of time of the simulation @@ -237,9 +237,9 @@ # params.nu_8 = 2.*10e-1*params.forcing.forcing_rate**(1./3)*delta_x**8 params.time_stepping.USE_CFL = True params.time_stepping.USE_T_END = True # params.time_stepping.deltat0 = 0.1 # Period of time of the simulation - params.time_stepping.t_end = 5. + params.time_stepping.t_end = 5.0 # params.time_stepping.it_end = 50 params.init_fields.type = "noise" @@ -259,6 +259,6 @@ params.output.periods_print.print_stdout = 0.01 - params.output.periods_save.phys_fields = 2. + params.output.periods_save.phys_fields = 2.0 params.output.periods_save.spectra = 0.5 params.output.periods_save.spatial_means = 0.05 @@ -263,5 +263,5 @@ params.output.periods_save.spectra = 0.5 params.output.periods_save.spatial_means = 0.05 - params.output.periods_save.spect_energy_budg = 1. - params.output.periods_save.increments = 1. + params.output.periods_save.spect_energy_budg = 1.0 + params.output.periods_save.increments = 1.0 @@ -267,5 +267,5 @@ - params.output.periods_plot.phys_fields = 5. + params.output.periods_plot.phys_fields = 5.0 params.output.ONLINE_PLOT_OK = True diff --git a/fluidsim/solvers/ns2d/bouss/state.py b/fluidsim/solvers/ns2d/bouss/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL2JvdXNzL3N0YXRlLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL2JvdXNzL3N0YXRlLnB5 100644 --- a/fluidsim/solvers/ns2d/bouss/state.py +++ b/fluidsim/solvers/ns2d/bouss/state.py @@ -86,7 +86,7 @@ if mpi.rank == 0: print(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result diff --git a/fluidsim/solvers/ns2d/bouss/util_pythran.py b/fluidsim/solvers/ns2d/bouss/util_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL2JvdXNzL3V0aWxfcHl0aHJhbi5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL2JvdXNzL3V0aWxfcHl0aHJhbi5weQ== 100644 --- a/fluidsim/solvers/ns2d/bouss/util_pythran.py +++ b/fluidsim/solvers/ns2d/bouss/util_pythran.py @@ -1,5 +1,3 @@ - - # pythran export tendencies_nonlin_ns2dbouss( # float64[][], float64[][], float64[][], float64[][], # float64[][], float64[][]) diff --git a/fluidsim/solvers/ns2d/forcing.py b/fluidsim/solvers/ns2d/forcing.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL2ZvcmNpbmcucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL2ZvcmNpbmcucHk= 100644 --- a/fluidsim/solvers/ns2d/forcing.py +++ b/fluidsim/solvers/ns2d/forcing.py @@ -10,7 +10,7 @@ from fluidsim.base.forcing import ForcingBasePseudoSpectral from fluidsim.base.forcing.anisotropic import ( - TimeCorrelatedRandomPseudoSpectralAnisotropic + TimeCorrelatedRandomPseudoSpectralAnisotropic, ) diff --git a/fluidsim/solvers/ns2d/init_fields.py b/fluidsim/solvers/ns2d/init_fields.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL2luaXRfZmllbGRzLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL2luaXRfZmllbGRzLnB5 100644 --- a/fluidsim/solvers/ns2d/init_fields.py +++ b/fluidsim/solvers/ns2d/init_fields.py @@ -35,7 +35,7 @@ super(InitFieldsNoise, cls)._complete_params_with_default(params) params.init_fields._set_child( - cls.tag, attribs={"velo_max": 1., "length": 0.} + cls.tag, attribs={"velo_max": 1.0, "length": 0.0} ) params.init_fields.noise._set_doc( @@ -63,6 +63,6 @@ lambda0 = params.init_fields.noise.length if lambda0 == 0: - lambda0 = min(oper.Lx, oper.Ly) / 4. + lambda0 = min(oper.Lx, oper.Ly) / 4.0 def H_smooth(x, delta): @@ -67,6 +67,6 @@ def H_smooth(x, delta): - return (1. + np.tanh(2 * np.pi * x / delta)) / 2. + return (1.0 + np.tanh(2 * np.pi * x / delta)) / 2.0 # to compute always the same field... (for 1 resolution...) np.random.seed(42 + mpi.rank) @@ -85,10 +85,10 @@ ) if mpi.rank == 0: - ux_fft[0, 0] = 0. - uy_fft[0, 0] = 0. + ux_fft[0, 0] = 0.0 + uy_fft[0, 0] = 0.0 oper.projection_perp(ux_fft, uy_fft) oper.dealiasing(ux_fft, uy_fft) k0 = 2 * np.pi / lambda0 @@ -90,9 +90,9 @@ oper.projection_perp(ux_fft, uy_fft) oper.dealiasing(ux_fft, uy_fft) k0 = 2 * np.pi / lambda0 - delta_k0 = 1. * k0 + delta_k0 = 1.0 * k0 ux_fft = ux_fft * H_smooth(k0 - oper.K, delta_k0) uy_fft = uy_fft * H_smooth(k0 - oper.K, delta_k0) @@ -127,10 +127,10 @@ oper = self.sim.oper rot = self.vorticity_jet() rot_fft = oper.fft2(rot) - rot_fft[oper.K == 0] = 0. + rot_fft[oper.K == 0] = 0.0 self.sim.state.init_from_rotfft(rot_fft) def vorticity_jet(self): oper = self.sim.oper Ly = oper.Ly a = 0.5 @@ -131,9 +131,9 @@ self.sim.state.init_from_rotfft(rot_fft) def vorticity_jet(self): oper = self.sim.oper Ly = oper.Ly a = 0.5 - b = Ly / 2. - omega0 = 2. + b = Ly / 2.0 + omega0 = 2.0 omega = omega0 * ( @@ -139,10 +139,10 @@ omega = omega0 * ( - np.exp(-((oper.YY - Ly / 2. + b / 2.) / a) ** 2) - - np.exp(-((oper.YY - Ly / 2. - b / 2.) / a) ** 2) - + np.exp(-((oper.YY - Ly / 2. + b / 2. + Ly) / a) ** 2) - - np.exp(-((oper.YY - Ly / 2. - b / 2. + Ly) / a) ** 2) - + np.exp(-((oper.YY - Ly / 2. + b / 2. - Ly) / a) ** 2) - - np.exp(-((oper.YY - Ly / 2. - b / 2. - Ly) / a) ** 2) + np.exp(-((oper.YY - Ly / 2.0 + b / 2.0) / a) ** 2) + - np.exp(-((oper.YY - Ly / 2.0 - b / 2.0) / a) ** 2) + + np.exp(-((oper.YY - Ly / 2.0 + b / 2.0 + Ly) / a) ** 2) + - np.exp(-((oper.YY - Ly / 2.0 - b / 2.0 + Ly) / a) ** 2) + + np.exp(-((oper.YY - Ly / 2.0 + b / 2.0 - Ly) / a) ** 2) + - np.exp(-((oper.YY - Ly / 2.0 - b / 2.0 - Ly) / a) ** 2) ) return omega @@ -166,10 +166,10 @@ def vorticity_shape_1dipole(self): oper = self.sim.oper - xs = oper.Lx / 2. - ys = oper.Ly / 2. + xs = oper.Lx / 2.0 + ys = oper.Ly / 2.0 theta = np.pi / 2.3 b = 2.5 omega = np.zeros(oper.shapeX_loc) def wz_2LO(XX, YY, b): @@ -171,10 +171,10 @@ theta = np.pi / 2.3 b = 2.5 omega = np.zeros(oper.shapeX_loc) def wz_2LO(XX, YY, b): - return 2 * np.exp(-(XX ** 2 + (YY - b / 2.) ** 2)) - 2 * np.exp( - -(XX ** 2 + (YY + b / 2.) ** 2) + return 2 * np.exp(-(XX ** 2 + (YY - b / 2.0) ** 2)) - 2 * np.exp( + -(XX ** 2 + (YY + b / 2.0) ** 2) ) for ip in range(-1, 2): diff --git a/fluidsim/solvers/ns2d/output/__init__.py b/fluidsim/solvers/ns2d/output/__init__.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL291dHB1dC9fX2luaXRfXy5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL291dHB1dC9fX2luaXRfXy5weQ== 100644 --- a/fluidsim/solvers/ns2d/output/__init__.py +++ b/fluidsim/solvers/ns2d/output/__init__.py @@ -92,8 +92,8 @@ """Compute energy(k)""" rot_fft = self.sim.state.state_spect.get_var("rot_fft") ux_fft, uy_fft = self.oper.vecfft_from_rotfft(rot_fft) - return (np.abs(ux_fft) ** 2 + np.abs(uy_fft) ** 2) / 2. + return (np.abs(ux_fft) ** 2 + np.abs(uy_fft) ** 2) / 2.0 def compute_enstrophy_fft(self): """Compute enstrophy(k)""" rot_fft = self.sim.state.state_spect.get_var("rot_fft") @@ -96,8 +96,8 @@ def compute_enstrophy_fft(self): """Compute enstrophy(k)""" rot_fft = self.sim.state.state_spect.get_var("rot_fft") - return np.abs(rot_fft) ** 2 / 2. + return np.abs(rot_fft) ** 2 / 2.0 def compute_energy(self): """Compute the spatially averaged energy.""" diff --git a/fluidsim/solvers/ns2d/output/print_stdout.py b/fluidsim/solvers/ns2d/output/print_stdout.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL291dHB1dC9wcmludF9zdGRvdXQucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL291dHB1dC9wcmludF9zdGRvdXQucHk= 100644 --- a/fluidsim/solvers/ns2d/output/print_stdout.py +++ b/fluidsim/solvers/ns2d/output/print_stdout.py @@ -33,7 +33,7 @@ if hasattr(self, "energy_tmp"): delta_energy = energy - self.energy_tmp else: - delta_energy = 0. + delta_energy = 0.0 if mpi.rank == 0: to_print += ( diff --git a/fluidsim/solvers/ns2d/output/spect_energy_budget.py b/fluidsim/solvers/ns2d/output/spect_energy_budget.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL291dHB1dC9zcGVjdF9lbmVyZ3lfYnVkZ2V0LnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL291dHB1dC9zcGVjdF9lbmVyZ3lfYnVkZ2V0LnB5 100644 --- a/fluidsim/solvers/ns2d/output/spect_energy_budget.py +++ b/fluidsim/solvers/ns2d/output/spect_energy_budget.py @@ -58,7 +58,7 @@ oper.dealiasing(Fy_fft) transferZ_fft = ( - np.real(rot_fft.conj() * Frot_fft + rot_fft * Frot_fft.conj()) / 2. + np.real(rot_fft.conj() * Frot_fft + rot_fft * Frot_fft.conj()) / 2.0 ) # print ('sum(transferZ) = {0:9.4e} ; sum(abs(transferZ)) = {1:9.4e}' # ).format(self.sum_wavenumbers(transferZ_fft), @@ -71,7 +71,7 @@ + uy_fft.conj() * Fy_fft + uy_fft * Fy_fft.conj() ) - / 2. + / 2.0 ) # print ('sum(transferE) = {0:9.4e} ; sum(abs(transferE)) = {1:9.4e}' # ).format(self.sum_wavenumbers(transferE_fft), @@ -113,7 +113,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -146,7 +146,7 @@ ax1.set_xscale("log") ax1.set_yscale("linear") - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot, delta_i_plot): transferE = dset_transferE[it] diff --git a/fluidsim/solvers/ns2d/output/spectra.py b/fluidsim/solvers/ns2d/output/spectra.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL291dHB1dC9zcGVjdHJhLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL291dHB1dC9zcGVjdHJhLnB5 100644 --- a/fluidsim/solvers/ns2d/output/spectra.py +++ b/fluidsim/solvers/ns2d/output/spectra.py @@ -41,7 +41,7 @@ ): spectrum2D = dict_spectra2D["spectrum2D_E"] khE = self.oper.khE - coef_norm = khE ** (3.) + coef_norm = khE ** (3.0) self.axe.loglog(khE, spectrum2D * coef_norm, "k") lin_inf, lin_sup = self.axe.get_ylim() if lin_inf < 10e-6: @@ -116,9 +116,9 @@ is_asym = len(EKx) == len(EKy) coef_norm = kh2 ** (coef_compensate) - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum1Dkx[it] if is_asym: EK += dset_spectrum1Dky[it] @@ -120,9 +120,9 @@ for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum1Dkx[it] if is_asym: EK += dset_spectrum1Dky[it] - EK[EK < 10e-16] = 0. + EK[EK < 10e-16] = 0.0 ax1.plot(kh, EK * coef_norm, "k", linewidth=2) EK = dset_spectrum1Dkx[imin_plot : imax_plot + 1] @@ -149,7 +149,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -192,6 +192,6 @@ coef_norm = kh2 ** coef_compensate - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum[it] @@ -196,6 +196,6 @@ for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum[it] - EK[EK < 10e-16] = 0. + EK[EK < 10e-16] = 0.0 ax1.plot(kh, EK * coef_norm, "k", linewidth=1) EK = dset_spectrum[imin_plot : imax_plot + 1].mean(0) @@ -199,7 +199,7 @@ ax1.plot(kh, EK * coef_norm, "k", linewidth=1) EK = dset_spectrum[imin_plot : imax_plot + 1].mean(0) - EK[EK < 10e-16] = 0. + EK[EK < 10e-16] = 0.0 ax1.plot(kh, EK * coef_norm, "k", linewidth=2) ax1.plot(kh, kh2 ** (-3) * coef_norm, "k--", linewidth=1) @@ -203,4 +203,4 @@ ax1.plot(kh, EK * coef_norm, "k", linewidth=2) ax1.plot(kh, kh2 ** (-3) * coef_norm, "k--", linewidth=1) - ax1.plot(kh, 0.01 * kh2 ** (-5. / 3) * coef_norm, "k-.", linewidth=1) + ax1.plot(kh, 0.01 * kh2 ** (-5.0 / 3) * coef_norm, "k-.", linewidth=1) diff --git a/fluidsim/solvers/ns2d/solver.py b/fluidsim/solvers/ns2d/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/ns2d/solver.py +++ b/fluidsim/solvers/ns2d/solver.py @@ -93,7 +93,7 @@ def _complete_params_with_default(params): """Complete the `params` container (static method).""" SimulBasePseudoSpectral._complete_params_with_default(params) - attribs = {"beta": 0.} + attribs = {"beta": 0.0} params._set_attribs(attribs) def tendencies_nonlin(self, state_spect=None, old=None): @@ -212,6 +212,6 @@ delta_x = Lh / nh params.nu_8 = ( - 2. * 10e-1 * params.forcing.forcing_rate ** (1. / 3) * delta_x ** 8 + 2.0 * 10e-1 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x ** 8 ) @@ -216,6 +216,6 @@ ) - params.time_stepping.t_end = 10. + params.time_stepping.t_end = 10.0 params.init_fields.type = "dipole" @@ -228,7 +228,7 @@ # params.output.periods_print.print_stdout = 0.25 - params.output.periods_save.phys_fields = 1. + params.output.periods_save.phys_fields = 1.0 params.output.periods_save.spectra = 0.5 params.output.periods_save.spatial_means = 0.05 # params.output.periods_save.spect_energy_budg = 0.5 diff --git a/fluidsim/solvers/ns2d/state.py b/fluidsim/solvers/ns2d/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0YXRlLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0YXRlLnB5 100644 --- a/fluidsim/solvers/ns2d/state.py +++ b/fluidsim/solvers/ns2d/state.py @@ -82,7 +82,7 @@ if mpi.rank == 0: print(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result @@ -118,9 +118,9 @@ def init_from_uxfft(self, ux_fft): """Initialize the state from the variable `ux_fft`""" - uy_fft = self.oper.create_arrayK(value=0.) + uy_fft = self.oper.create_arrayK(value=0.0) rot_fft = self.oper.rotfft_from_vecfft(ux_fft, uy_fft) self.init_from_rotfft(rot_fft) def init_from_uyfft(self, uy_fft): """Initialize the state from the variable `uy_fft`""" @@ -122,9 +122,9 @@ rot_fft = self.oper.rotfft_from_vecfft(ux_fft, uy_fft) self.init_from_rotfft(rot_fft) def init_from_uyfft(self, uy_fft): """Initialize the state from the variable `uy_fft`""" - ux_fft = self.oper.create_arrayK(value=0.) + ux_fft = self.oper.create_arrayK(value=0.0) rot_fft = self.oper.rotfft_from_vecfft(ux_fft, uy_fft) self.init_from_rotfft(rot_fft) diff --git a/fluidsim/solvers/ns2d/strat/diag/solver.py b/fluidsim/solvers/ns2d/strat/diag/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L2RpYWcvc29sdmVyLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L2RpYWcvc29sdmVyLnB5 100644 --- a/fluidsim/solvers/ns2d/strat/diag/solver.py +++ b/fluidsim/solvers/ns2d/strat/diag/solver.py @@ -54,7 +54,7 @@ """This static method is used to complete the *params* container. """ SimulBasePseudoSpectral._complete_params_with_default(params) - attribs = {"beta": 0.} + attribs = {"beta": 0.0} params._set_attribs(attribs) def tendencies_nonlin(self, state_spect=None, old=None): @@ -126,5 +126,5 @@ delta_x = old_div(params.oper.Lx, params.oper.nx) params.nu_8 = ( - 2. + 2.0 * 10e-1 @@ -130,5 +130,5 @@ * 10e-1 - * params.forcing.forcing_rate ** (old_div(1., 3)) + * params.forcing.forcing_rate ** (old_div(1.0, 3)) * delta_x ** 8 ) @@ -132,7 +132,7 @@ * delta_x ** 8 ) - params.time_stepping.t_end = 1. + params.time_stepping.t_end = 1.0 params.init_fields.type = "noise" diff --git a/fluidsim/solvers/ns2d/strat/output/__init__.py b/fluidsim/solvers/ns2d/strat/output/__init__.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9fX2luaXRfXy5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9fX2luaXRfXy5weQ== 100644 --- a/fluidsim/solvers/ns2d/strat/output/__init__.py +++ b/fluidsim/solvers/ns2d/strat/output/__init__.py @@ -150,6 +150,7 @@ + "the degree symbol or a float in radians" ) - self.froude_number = round(np.sin(angle), 1) + # self.froude_number = round(np.sin(angle), 1) + self.froude_number = np.sin(angle) def _compute_ratio_omegas(self): @@ -154,12 +155,32 @@ def _compute_ratio_omegas(self): - """Compute ratio omegas; R = N * sin(angle)/P**(1/3.)""" - P = self.sim.params.forcing.forcing_rate - N = self.sim.params.N - return round(N * self.froude_number / P ** (1. / 3), 1) + """Compute ratio omegas; gamma = \omega_l / \omega_{af}""" + params = self.sim.params + + omega_l = params.N * self.froude_number + if ( + params.forcing.key_forced is None + or params.forcing.key_forced == "rot_fft" + ): + omega_af = (2 * np.pi) * params.forcing.forcing_rate ** (1.0 / 3) + elif params.forcing.key_forced == "ap_fft": + nkmax_forcing = params.forcing.nkmax_forcing + nkmin_forcing = params.forcing.nkmin_forcing + + deltak = max(2 * np.pi / params.oper.Lx, 2 * np.pi / params.oper.Ly) + k_f = ((nkmax_forcing + nkmin_forcing) / 2) * deltak + omega_af = ( + 2 + * np.pi + / params.forcing.forcing_rate ** (1.0 / 7) + * ((2 * np.pi / k_f) ** (2.0 / 7)) + ) + else: + raise ValueError("params.forcing.key_forced is not known.") + return omega_l / omega_af def _produce_str_describing_attribs_strat(self): """ Produce string describing the parameters froude_number and ratio_omegas. #TODO: not the best way to produce string. """ @@ -160,11 +181,11 @@ def _produce_str_describing_attribs_strat(self): """ Produce string describing the parameters froude_number and ratio_omegas. #TODO: not the best way to produce string. """ - str_froude_number = str(self.froude_number) - str_ratio_omegas = str(self._compute_ratio_omegas()) + str_froude_number = str(round(self.froude_number, 1)) + str_ratio_omegas = str(round(self._compute_ratio_omegas(), 1)) if "." in str_froude_number: str_froude_number = ( diff --git a/fluidsim/solvers/ns2d/strat/output/spatial_means.py b/fluidsim/solvers/ns2d/strat/output/spatial_means.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9zcGF0aWFsX21lYW5zLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9zcGF0aWFsX21lYW5zLnB5 100644 --- a/fluidsim/solvers/ns2d/strat/output/spatial_means.py +++ b/fluidsim/solvers/ns2d/strat/output/spatial_means.py @@ -37,7 +37,7 @@ enstrophy = self.sum_wavenumbers(enstrophy_fft) # Compute energy shear modes - COND_SHEAR_MODES = abs(self.sim.oper.KX) == 0. + COND_SHEAR_MODES = abs(self.sim.oper.KX) == 0.0 energy_shear_modes = np.sum(energy_fft[COND_SHEAR_MODES]) if mpi.nb_proc > 1: energy_shear_modes = mpi.comm.reduce( @@ -47,6 +47,6 @@ # Dissipation rate kinetic and potential energy (kappa = viscosity) f_d, f_d_hypo = self.sim.compute_freq_diss() - epsK = self.sum_wavenumbers(f_d * 2. * energyK_fft) - epsK_hypo = self.sum_wavenumbers(f_d_hypo * 2. * energyK_fft) + epsK = self.sum_wavenumbers(f_d * 2.0 * energyK_fft) + epsK_hypo = self.sum_wavenumbers(f_d_hypo * 2.0 * energyK_fft) @@ -52,4 +52,4 @@ - epsA = self.sum_wavenumbers(f_d * 2. * energyA_fft) - epsA_hypo = self.sum_wavenumbers(f_d_hypo * 2. * energyA_fft) + epsA = self.sum_wavenumbers(f_d * 2.0 * energyA_fft) + epsA_hypo = self.sum_wavenumbers(f_d_hypo * 2.0 * energyA_fft) @@ -55,6 +55,6 @@ - epsZ = self.sum_wavenumbers(f_d * 2. * enstrophy_fft) - epsZ_hypo = self.sum_wavenumbers(f_d_hypo * 2. * enstrophy_fft) + epsZ = self.sum_wavenumbers(f_d * 2.0 * enstrophy_fft) + epsZ_hypo = self.sum_wavenumbers(f_d_hypo * 2.0 * enstrophy_fft) # Injection energy if forcing is True if self.sim.params.forcing.enable: @@ -384,6 +384,7 @@ """Plots the energy.""" if mpi.rank != 0: return + pforcing = self.params.forcing dict_results = self.load() @@ -401,7 +402,9 @@ # Normalization by E_f if pforcing.key_forced == "ap_fft": - E_f = pforcing.forcing_rate ** (2. / 7) * (2 * pi / k_f) ** (10. / 7) + E_f = pforcing.forcing_rate ** (2.0 / 7) * (2 * pi / k_f) ** ( + 10.0 / 7 + ) else: raise NotImplementedError("Computation E_f not implemented.") diff --git a/fluidsim/solvers/ns2d/strat/output/spatio_temporal_spectra.py b/fluidsim/solvers/ns2d/strat/output/spatio_temporal_spectra.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9zcGF0aW9fdGVtcG9yYWxfc3BlY3RyYS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9zcGF0aW9fdGVtcG9yYWxfc3BlY3RyYS5weQ== 100644 --- a/fluidsim/solvers/ns2d/strat/output/spatio_temporal_spectra.py +++ b/fluidsim/solvers/ns2d/strat/output/spatio_temporal_spectra.py @@ -11,10 +11,6 @@ """ -from __future__ import division, print_function - -from builtins import range - import os import sys import time @@ -124,6 +120,7 @@ # Check: self.nb_arr_in_file should be > 0 if self.nb_arr_in_file <= 0 and self.periods_save > 0: raise ValueError("The size of the file should be larger.") + else: self.spatio_temp = np.empty( [self.nb_arr_in_file, n0, n1 // 2], dtype=complex @@ -134,6 +131,6 @@ [2, self.nb_arr_in_file, n0, n1 // 2], dtype=complex ) - # self.spatio_temp_ap = np.empty( - # [self.nb_arr_in_file, n0, n1 // 2], dtype=complex) + # self.spatio_temp_ap = np.empty( + # [self.nb_arr_in_file, n0, n1 // 2], dtype=complex) @@ -139,6 +136,6 @@ - # self.spatio_temp_am = np.empty( - # [self.nb_arr_in_file, n0, n1 // 2], dtype=complex) + # self.spatio_temp_am = np.empty( + # [self.nb_arr_in_file, n0, n1 // 2], dtype=complex) # Convert time_start to it_start self.it_start = int(self.time_start / self.params.time_stepping.deltat0) @@ -230,7 +227,7 @@ dtype=complex, ) - # print("field_seq shape", field_seq.shape) + # print("field_seq shape", field_seq.shape) if mpi.nb_proc > 1: mpi.comm.Gather(field, field_seq, root=0) @@ -318,7 +315,7 @@ list_files = glob(os.path.join(self.path_dir, "spatio_temp_it=*")) # Compute sampling frequency - freq_sampling = 1. / ( + freq_sampling = 1.0 / ( self.time_decimate * self.params.time_stepping.deltat0 ) @@ -375,3 +372,140 @@ / self.duration_file ), ) + + def plot_frequency_spectra_individual_mode(self, mode): + """ + Plot frequency spectra from individual Fourier mode. + + It plots the frequency spectra of the last file. + + Parameters + ---------- + mode : tuple + Mode to plot (kx , kz) + """ + # Define path file. It is the last file. + path_file = glob(os.path.join(self.path_dir, "spatio_temp_it=*"))[0] + print("File to plot is {} ...".format(os.path.basename(path_file))) + print("kx_user = {:.3f} ; kz_user = {:.3f}".format(mode[0], mode[1])) + + # Load frequency spectra + with h5py.File(path_file, "r") as f: + if "temp_spectrum" in f.keys(): + temp_spectrum = f["temp_spectrum"].value + omegas = f["omegas"].value + else: + raise ValueError( + "temp_spectrum not in f.keys(). " "It needs to be computed." + ) + + # Define index with spatial decimation + idx_mode = np.argmin( + abs(self.sim.oper.kx[:: self.spatial_decimate] - mode[0]) + ) + idz_mode = np.argmin( + abs(self.sim.oper.ky[:: self.spatial_decimate] - mode[1]) + ) + print( + "kx_plot = {:.3f} ; kz_plot = {:.3f}".format( + self.sim.oper.kx[:: self.spatial_decimate][idx_mode], + self.sim.oper.ky[:: self.spatial_decimate][idz_mode], + ) + ) + print("ikx_mode = {} ; idz_mode = {}".format(idx_mode, idz_mode)) + + # Compute omega dispersion relation mode + kx_mode = self.sim.oper.kx[:: self.spatial_decimate][idx_mode] + kz_mode = self.sim.oper.ky[:: self.spatial_decimate][idz_mode] + f_iw = ( + (1 / (2 * pi)) + * self.sim.params.N + * (kx_mode / np.sqrt(kx_mode ** 2 + kz_mode ** 2)) + ) + + # Plot omega + + fig1, ax1 = plt.subplots() + ax1.set_xlabel(r"$\omega / \omega_{i\omega}$") + ax1.set_ylabel(r"$F(\omega)$") + ax1.set_title( + r"$\omega_+ ; (k_x, k_z) = ({:.2f}, {:.2f})$".format( + self.sim.oper.kx[:: self.spatial_decimate][idx_mode], + self.sim.oper.ky[:: self.spatial_decimate][idz_mode], + ) + ) + + ax1.loglog( + omegas[0 : len(omegas) // 2] / f_iw, + temp_spectrum[0, 0 : len(omegas) // 2, idz_mode, idx_mode], + ) + ax1.axvline(x=f_iw / f_iw, color="k", linestyle="--") + + # Plot omega - + fig2, ax2 = plt.subplots() + ax2.set_xlabel(r"$\omega / \omega_{i\omega}$") + ax2.set_ylabel(r"$F(\omega)$") + ax2.set_title( + r"$\omega_- ; (k_x, k_z) = ({:.2f}, {:.2f})$".format( + self.sim.oper.kx[:: self.spatial_decimate][idx_mode], + self.sim.oper.ky[:: self.spatial_decimate][idz_mode], + ) + ) + + ax2.loglog( + -1 * omegas[len(omegas) // 2 + 1 :] / f_iw, + temp_spectrum[0, len(omegas) // 2 + 1 :, idz_mode, idx_mode], + ) + ax2.axvline(x=f_iw / f_iw, color="k", linestyle="--") + + # print("omegas = ", omegas) + # print("kx_decimate = ", self.sim.oper.kx[::self.spatial_decimate]) + # print("kz_decimate = ", self.sim.oper.ky[::self.spatial_decimate]) + + # print("kx_decimate.shape = ", self.sim.oper.kx[::self.spatial_decimate].shape) + # print("kz_decimate.shape = ", self.sim.oper.ky[::self.spatial_decimate].shape) + + # sin_arr = np.empty( + # shape=(self.sim.oper.kx[::self.spatial_decimate].shape[0], + # self.sim.oper.ky[::self.spatial_decimate].shape[0])) + # for i_row, value in enumerate(self.sim.oper.kx[::self.spatial_decimate]): + # sin_arr[i_row, :] = value / np.sqrt(value**2 +self.sim.oper.ky[::self.spatial_decimate]**2) + + # sin_arr = np.transpose(sin_arr) + # unique = np.unique(sin_arr) + + # # Create 2D array shape omega and sinus theta + # k_sin_arr = np.empty(shape=(len(omegas), unique.shape[0] - 1)) + # print("k_sin_arr shape", k_sin_arr.shape) + + # # Loop in unique values of sinus theta + # for idx_unique, value in enumerate(unique[:-1]): + # indices = np.argwhere(sin_arr==value) + # print("indices = ", indices) + # # same_sin = np.empty(shape=(len(omegas), len(indices))) + # same_sin = np.empty(shape=(len(omegas), 2)) + + # for i_column, idx in enumerate(indices[0:2]): + # same_sin[:, i_column] = temp_spectrum[0, :, idx[0], idx[1]] + + # k_sin_arr[:, idx_unique] = np.mean(same_sin, axis=1) + + # print("unique = ", unique) + # print("unique_shape = ", unique.shape) + # print("k_sin_arr = ", k_sin_arr) + # print("k_sin_arr_shape = ", k_sin_arr.shape) + + # # Plot + # fig3, ax3 = plt.subplots() + # # ax3.set_yscale("log") + # ax3.set_xlabel(r"sin $\theta$") + # ax3.set_ylabel("$\omega$") + # ax3.set_title(r"F(sin $\theta$, $\omega$)") + # SINUS, OMEGA = np.meshgrid(unique[:-1], omegas) + # print("OMEGA", OMEGA) + # print("SINUS", SINUS) + # ax3.pcolormesh(SINUS, OMEGA, k_sin_arr, + # vmin=np.min(k_sin_arr), vmax=np.max(k_sin_arr)/1e16, + # cmap="hsv") + + # ax3.plot([0,0.2], [0, - 0.2 * self.sim.params.N / (2 * np.pi)], + # color="k", linewidth=4) diff --git a/fluidsim/solvers/ns2d/strat/output/spect_energy_budget.py b/fluidsim/solvers/ns2d/strat/output/spect_energy_budget.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9zcGVjdF9lbmVyZ3lfYnVkZ2V0LnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9zcGVjdF9lbmVyZ3lfYnVkZ2V0LnB5 100644 --- a/fluidsim/solvers/ns2d/strat/output/spect_energy_budget.py +++ b/fluidsim/solvers/ns2d/strat/output/spect_energy_budget.py @@ -73,7 +73,7 @@ # Energy budget terms. Nonlinear transfer terms, exchange kinetic and # potential energy B, dissipation terms. transferZ_fft = ( - np.real(rot_fft.conj() * Frot_fft + rot_fft * Frot_fft.conj()) / 2. + np.real(rot_fft.conj() * Frot_fft + rot_fft * Frot_fft.conj()) / 2.0 ) transferEKu_fft = np.real(ux_fft.conj() * Fx_fft) transferEKv_fft = np.real(uy_fft.conj() * Fy_fft) @@ -97,7 +97,7 @@ + uy_fft.conj() * uy_fft + uy_fft * uy_fft.conj() ) - / 2. + / 2.0 ) if self.params.N == 0: dissEA_fft = np.zeros_like(dissEK_fft) @@ -113,7 +113,7 @@ + uy_fft.conj() * Fy_fft + uy_fft * Fy_fft.conj() ) - / 2. + / 2.0 ) # Transfer spectrum 1D Kinetic energy, potential energy and exchange @@ -200,7 +200,7 @@ self.axe_a.plot(khE + khE[1], PiE, "k") self.axe_b.plot(khE + khE[1], PiZ, "g") - def plot(self, tmin=0, tmax=1000, delta_t=2): + def plot(self, tmin=0, tmax=None, delta_t=2): """Plot the energy budget.""" # Load data from file @@ -220,7 +220,10 @@ dset_dissEK_ky = f["dissEK_ky"].value dset_dissEA_ky = f["dissEA_ky"].value + if tmax is None: + tmax = np.max(times) + # Average from tmin and tmax for plot delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) @@ -223,8 +226,8 @@ # Average from tmin and tmax for plot delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -321,5 +324,19 @@ ax2.plot(kyE[1:], DissEK_ky + DissEA_ky, label=r"$D$") ax2.axhline(y=0, color="k", linestyle="--") + # Plot forcing wave-number k_f + nkmax = self.sim.params.forcing.nkmax_forcing + nkmin = self.sim.params.forcing.nkmin_forcing + k_f = ((nkmax + nkmin) / 2) * self.sim.oper.deltak + try: + angle = self.sim.forcing.forcing_maker.angle + except AttributeError: + pass + else: + k_fx = np.sin(angle) * k_f + k_fy = np.cos(angle) * k_f + ax1.axvline(x=k_fx, color="k", linestyle=":", label="$k_{f,x}$") + ax2.axvline(x=k_fy, color="k", linestyle=":", label="$k_{f,z}$") + ax1.legend() ax2.legend() diff --git a/fluidsim/solvers/ns2d/strat/output/spectra.py b/fluidsim/solvers/ns2d/strat/output/spectra.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9zcGVjdHJhLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC9zcGVjdHJhLnB5 100644 --- a/fluidsim/solvers/ns2d/strat/output/spectra.py +++ b/fluidsim/solvers/ns2d/strat/output/spectra.py @@ -80,7 +80,7 @@ spectrum2D_EA = dict_spectra2D["spectrum2D_EA"] spectrum2D = spectrum2D_EK + spectrum2D_EA khE = self.oper.khE - coef_norm = khE ** (3.) + coef_norm = khE ** (3.0) self.axe.loglog(khE, spectrum2D * coef_norm, "k") lin_inf, lin_sup = self.axe.get_ylim() if lin_inf < 10e-6: @@ -95,5 +95,5 @@ def plot1d( self, tmin=0, - tmax=1000, + tmax=None, delta_t=2, @@ -99,6 +99,6 @@ delta_t=2, - coef_compensate_kx=5. / 3, - coef_compensate_kz=3., + coef_compensate_kx=5.0 / 3, + coef_compensate_kz=3.0, ): """Plot spectra one-dimensional.""" @@ -112,6 +112,9 @@ kx = dset_kxE.value ky = dset_kyE.value + if tmax is None: + tmax = np.max(times) + # Open data set 1D spectra dset_spectrum1Dkx_EA = h5file["spectrum1Dkx_EA"] dset_spectrum1Dky_EA = h5file["spectrum1Dky_EA"] @@ -272,7 +275,7 @@ # Compute average from tmin and tmax for plot delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save diff --git a/fluidsim/solvers/ns2d/strat/output/test/test_spectra.py b/fluidsim/solvers/ns2d/strat/output/test/test_spectra.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC90ZXN0L3Rlc3Rfc3BlY3RyYS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC90ZXN0L3Rlc3Rfc3BlY3RyYS5weQ== 100644 --- a/fluidsim/solvers/ns2d/strat/output/test/test_spectra.py +++ b/fluidsim/solvers/ns2d/strat/output/test/test_spectra.py @@ -21,7 +21,7 @@ b_fft = state_spect.get_var("b_fft") ux_fft, uy_fft = oper.vecfft_from_rotfft(rot_fft) - energyK_fft = (1. / 2) * ( + energyK_fft = (1.0 / 2) * ( np.abs(ux_fft.conj() * ux_fft) + np.abs(uy_fft.conj() * uy_fft) ) spectrum1DEK_kx, spectrum1DEK_ky = oper.spectra1D_from_fft(energyK_fft) @@ -30,7 +30,7 @@ self.assertAlmostEqual(spectrum1DEK_ky.sum() * oper.deltaky, energyK) try: - energyA_fft = (1. / 2) * ( + energyA_fft = (1.0 / 2) * ( (np.abs(b_fft.conj() * b_fft) / sim.params.N ** 2) ) except ZeroDivisionError: diff --git a/fluidsim/solvers/ns2d/strat/output/test/test_spectra_multidim.py b/fluidsim/solvers/ns2d/strat/output/test/test_spectra_multidim.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC90ZXN0L3Rlc3Rfc3BlY3RyYV9tdWx0aWRpbS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L291dHB1dC90ZXN0L3Rlc3Rfc3BlY3RyYV9tdWx0aWRpbS5weQ== 100644 --- a/fluidsim/solvers/ns2d/strat/output/test/test_spectra_multidim.py +++ b/fluidsim/solvers/ns2d/strat/output/test/test_spectra_multidim.py @@ -21,7 +21,7 @@ rot_fft = state_spect.get_var("rot_fft") ux_fft, uy_fft = oper.vecfft_from_rotfft(rot_fft) b_fft = state_spect.get_var("b_fft") - energyK_fft = (1. / 2) * ( + energyK_fft = (1.0 / 2) * ( np.abs(ux_fft.conj() * ux_fft) + np.abs(uy_fft.conj() * uy_fft) ) @@ -32,7 +32,7 @@ # Check potential energy EA try: - energyA_fft = (1. / 2) * ( + energyA_fft = (1.0 / 2) * ( (np.abs(b_fft.conj() * b_fft) / sim.params.N ** 2) ) except ZeroDivisionError: @@ -65,7 +65,7 @@ rot_fft = state_spect.get_var("rot_fft") ux_fft, uy_fft = oper.vecfft_from_rotfft(rot_fft) b_fft = state_spect.get_var("b_fft") - energyK_fft = (1. / 2) * ( + energyK_fft = (1.0 / 2) * ( np.abs(ux_fft.conj() * ux_fft) + np.abs(uy_fft.conj() * uy_fft) ) @@ -92,7 +92,7 @@ # Check potential energy EA try: - energyA_fft = (1. / 2) * ( + energyA_fft = (1.0 / 2) * ( (np.abs(b_fft.conj() * b_fft) / sim.params.N ** 2) ) except ZeroDivisionError: diff --git a/fluidsim/solvers/ns2d/strat/solver.py b/fluidsim/solvers/ns2d/strat/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/ns2d/strat/solver.py +++ b/fluidsim/solvers/ns2d/strat/solver.py @@ -59,7 +59,7 @@ """This static method is used to complete the *params* container. """ SimulNS2D._complete_params_with_default(params) - attribs = {"N": 1., "NO_SHEAR_MODES": False} + attribs = {"N": 1.0, "NO_SHEAR_MODES": False} params._set_attribs(attribs) def tendencies_nonlin(self, state_spect=None, old=None): @@ -180,8 +180,8 @@ params = self.params # Compute time derivative kinetic energy - division = 1. / oper.K2_not0 + division = 1.0 / oper.K2_not0 if oper.rank == 0: division[0, 0] = 0 pt_energyK_fft = 0.5 * division * np.real(rot_fft.conj() * f_rot_fft) @@ -184,7 +184,7 @@ if oper.rank == 0: division[0, 0] = 0 pt_energyK_fft = 0.5 * division * np.real(rot_fft.conj() * f_rot_fft) - pt_energyK_fft[np.isinf(pt_energyK_fft)] = 0. + pt_energyK_fft[np.isinf(pt_energyK_fft)] = 0.0 # Compute time derivative potential energy @@ -189,6 +189,6 @@ # Compute time derivative potential energy - pt_energyA_fft = (1. / (2 * params.N ** 2)) * np.real( + pt_energyA_fft = (1.0 / (2 * params.N ** 2)) * np.real( b_fft.conj() * f_b_fft ) @@ -240,5 +240,5 @@ delta_x = Lx / nx - params.nu_2 = 1. * 10e-6 + params.nu_2 = 1.0 * 10e-6 # params.nu_8 = 2.*10e-1*params.forcing.forcing_rate**(1./3)*delta_x**8 @@ -244,6 +244,6 @@ # params.nu_8 = 2.*10e-1*params.forcing.forcing_rate**(1./3)*delta_x**8 - params.N = 1. # Brunt Vaisala frequency + params.N = 1.0 # Brunt Vaisala frequency params.time_stepping.USE_CFL = True params.time_stepping.USE_T_END = True # params.time_stepping.deltat0 = 0.1 # Period of time of the simulation @@ -246,8 +246,8 @@ params.time_stepping.USE_CFL = True params.time_stepping.USE_T_END = True # params.time_stepping.deltat0 = 0.1 # Period of time of the simulation - params.time_stepping.t_end = 5. + params.time_stepping.t_end = 5.0 # params.time_stepping.it_end = 50 params.init_fields.type = "noise" @@ -267,6 +267,6 @@ params.output.periods_print.print_stdout = 0.01 - params.output.periods_save.phys_fields = 2. + params.output.periods_save.phys_fields = 2.0 params.output.periods_save.spectra = 0.5 params.output.periods_save.spatial_means = 0.05 @@ -271,5 +271,5 @@ params.output.periods_save.spectra = 0.5 params.output.periods_save.spatial_means = 0.05 - params.output.periods_save.spect_energy_budg = 1. - params.output.periods_save.increments = 1. + params.output.periods_save.spect_energy_budg = 1.0 + params.output.periods_save.increments = 1.0 @@ -275,5 +275,5 @@ - params.output.periods_plot.phys_fields = 5. + params.output.periods_plot.phys_fields = 5.0 params.output.ONLINE_PLOT_OK = True diff --git a/fluidsim/solvers/ns2d/strat/state.py b/fluidsim/solvers/ns2d/strat/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3N0YXRlLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3N0YXRlLnB5 100644 --- a/fluidsim/solvers/ns2d/strat/state.py +++ b/fluidsim/solvers/ns2d/strat/state.py @@ -64,8 +64,8 @@ rot_fft = self.state_spect.get_var("rot_fft") ux_fft, uy_fft = self.oper.vecfft_from_rotfft(rot_fft) result = ux_fft - # result = self.oper.fft2(self.state_phys.get_var("ux")) + # result = self.oper.fft2(self.state_phys.get_var("ux")) elif key == "uy_fft": rot_fft = self.state_spect.get_var("rot_fft") ux_fft, uy_fft = self.oper.vecfft_from_rotfft(rot_fft) result = uy_fft @@ -68,8 +68,8 @@ elif key == "uy_fft": rot_fft = self.state_spect.get_var("rot_fft") ux_fft, uy_fft = self.oper.vecfft_from_rotfft(rot_fft) result = uy_fft - # result = self.oper.fft2(self.state_phys.get_var("uy")) + # result = self.oper.fft2(self.state_phys.get_var("uy")) elif key == "div_fft": ux_fft = self.compute("ux_fft") uy_fft = self.compute("uy_fft") @@ -101,7 +101,7 @@ # print("1j * omega_k * b_fft", 1j * omega_k * b_fft) # print("(N ** 2) * uy_fft", (N ** 2) * uy_fft) result = (N ** 2) * uy_fft - 1j * omega_k * b_fft - # result = np.zeros(self.oper.shapeK, dtype="complex") + # result = np.zeros(self.oper.shapeK, dtype="complex") elif key == "ap": ap_fft = self.compute("ap_fft") result = self.oper.ifft(ap_fft) @@ -118,7 +118,7 @@ if mpi.rank == 0: print(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result @@ -182,7 +182,7 @@ ap_fft = np.zeros(self.oper.shapeK, dtype="complex") # Compute rot_fft and b_fft from ap_fft - uy_fft = (1. / (2 * self.params.N ** 2)) * (ap_fft + am_fft) + uy_fft = (1.0 / (2 * self.params.N ** 2)) * (ap_fft + am_fft) cond = self.oper.KX != 0 division = np.zeros_like(self.oper.KY) division[cond] = self.oper.KY[cond] / self.oper.KX[cond] @@ -192,7 +192,7 @@ omega_k = self.params.N * self.oper.KX / self.oper.K_not0 b_fft = np.zeros(self.oper.shapeK, dtype="complex") - b_fft[cond] = (1. / (2j * omega_k[cond])) * (ap_fft[cond] - am_fft[cond]) + b_fft[cond] = (1.0 / (2j * omega_k[cond])) * (ap_fft[cond] - am_fft[cond]) return rot_fft, b_fft def _compute_state_from_apfft(self, ap_fft): @@ -203,7 +203,7 @@ am_fft = np.zeros(self.oper.shapeK, dtype="complex") # Compute rot_fft and b_fft from ap_fft - uy_fft = (1. / (2 * self.params.N ** 2)) * (ap_fft + am_fft) + uy_fft = (1.0 / (2 * self.params.N ** 2)) * (ap_fft + am_fft) cond = self.oper.KX != 0 division = np.zeros_like(self.oper.KY) division[cond] = self.oper.KY[cond] / self.oper.KX[cond] @@ -213,9 +213,9 @@ omega_k = self.params.N * self.oper.KX / self.oper.K_not0 b_fft = np.zeros(self.oper.shapeK, dtype="complex") - b_fft[cond] = (1. / (2j * omega_k[cond])) * (ap_fft[cond] - am_fft[cond]) + b_fft[cond] = (1.0 / (2j * omega_k[cond])) * (ap_fft[cond] - am_fft[cond]) return rot_fft, b_fft def init_from_rotfft(self, rot_fft): """Initialize the state from the variable `rot_fft`.""" @@ -217,9 +217,9 @@ return rot_fft, b_fft def init_from_rotfft(self, rot_fft): """Initialize the state from the variable `rot_fft`.""" - b_fft = self.oper.create_arrayK(value=0.) + b_fft = self.oper.create_arrayK(value=0.0) self.init_from_rotbfft(rot_fft, b_fft) def init_statespect_from(self, **kwargs): diff --git a/fluidsim/solvers/ns2d/strat/test_solver.py b/fluidsim/solvers/ns2d/strat/test_solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3Rlc3Rfc29sdmVyLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3Rlc3Rfc29sdmVyLnB5 100644 --- a/fluidsim/solvers/ns2d/strat/test_solver.py +++ b/fluidsim/solvers/ns2d/strat/test_solver.py @@ -35,7 +35,7 @@ nh = 32 params.oper.nx = nh params.oper.ny = nh - Lh = 6. + Lh = 6.0 params.oper.Lx = Lh params.oper.Ly = Lh @@ -39,8 +39,8 @@ params.oper.Lx = Lh params.oper.Ly = Lh - params.oper.coef_dealiasing = 2. / 3 - params.nu_8 = 2. + params.oper.coef_dealiasing = 2.0 / 3 + params.nu_8 = 2.0 params.time_stepping.t_end = 0.5 @@ -71,7 +71,7 @@ nh = 48 params.oper.nx = 2 * nh params.oper.ny = nh - lh = 6. + lh = 6.0 params.oper.Lx = lh params.oper.Ly = lh @@ -75,8 +75,8 @@ params.oper.Lx = lh params.oper.Ly = lh - params.oper.coef_dealiasing = 2. / 3 - params.nu_8 = 2. + params.oper.coef_dealiasing = 2.0 / 3 + params.nu_8 = 2.0 params.time_stepping.t_end = 0.5 diff --git a/fluidsim/solvers/ns2d/strat/time_stepping.py b/fluidsim/solvers/ns2d/strat/time_stepping.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3RpbWVfc3RlcHBpbmcucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3RpbWVfc3RlcHBpbmcucHk= 100644 --- a/fluidsim/solvers/ns2d/strat/time_stepping.py +++ b/fluidsim/solvers/ns2d/strat/time_stepping.py @@ -25,6 +25,15 @@ """ + @classmethod + def _complete_params_with_default(cls, params): + super(TimeSteppingPseudoSpectralStrat, cls)._complete_params_with_default( + params + ) + + # Add parameter coefficient CFL GROUP VELOCITY + params.time_stepping._set_attrib("cfl_coef_group", None) + def _init_compute_time_step(self): """ Initialization compute time step solver ns2d.strat. @@ -33,7 +42,16 @@ # Coefficients dt self.coef_deltat_dispersion_relation = 1.0 - self.coef_group = 1.0 + + try: + self.coef_group = self.params.time_stepping.cfl_coef_group + except AttributeError: + print("self.params.time_stepping.cfl_coef_group not in params") + self.coef_group = 1.0 + + if not self.coef_group: + self.coef_group = 1.0 + self.coef_phase = 1.0 has_vars = self.sim.state.has_vars @@ -51,7 +69,7 @@ self.dispersion_relation = self.sim.compute_dispersion_relation() except AttributeError: print("compute_dispersion_relation is not" "not implemented.") - self.deltat_dispersion_relation = 1. + self.deltat_dispersion_relation = 1.0 else: freq_disp_relation = self.dispersion_relation.max() @@ -62,7 +80,7 @@ self.deltat_dispersion_relation = ( self.coef_deltat_dispersion_relation - * (2. * pi / freq_disp_relation) + * (2.0 * pi / freq_disp_relation) ) # Try to compute deltat_group_vel @@ -72,8 +90,8 @@ ) except AttributeError as e: print("_compute_time_increment_group_and_phase is not implemented", e) - self.deltat_group_vel = 1. - self.deltat_phase_vel = 1. + self.deltat_group_vel = 1.0 + self.deltat_phase_vel = 1.0 else: if mpi.nb_proc > 1: @@ -90,7 +108,7 @@ """ Compute time increment of the forcing. """ - return 1. / (self.sim.params.forcing.forcing_rate ** (1. / 3)) + return 1.0 / (self.sim.params.forcing.forcing_rate ** (1.0 / 3)) def _compute_time_increment_group_and_phase(self): r""" @@ -141,13 +159,26 @@ else: deltat_CFL = self.deltat_max - maybe_new_dt = min( - deltat_CFL, - self.deltat_dispersion_relation, - self.deltat_group_vel, - self.deltat_phase_vel, - self.deltat_max, - ) + # maybe_new_dt = min( + # deltat_CFL, + # self.deltat_dispersion_relation, + # self.deltat_group_vel, + # self.deltat_phase_vel, + # self.deltat_max, + # ) + + # Removed phase velocity (considered not relevant) + if not self.coef_group: + maybe_new_dt = min( + deltat_CFL, self.deltat_dispersion_relation, self.deltat_max + ) + else: + maybe_new_dt = min( + deltat_CFL, + self.deltat_dispersion_relation, + self.deltat_group_vel, + self.deltat_max, + ) if self.params.forcing.enable: maybe_new_dt = min(maybe_new_dt, self.deltat_f) diff --git a/fluidsim/solvers/ns2d/strat/util_pythran.py b/fluidsim/solvers/ns2d/strat/util_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3V0aWxfcHl0aHJhbi5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3N0cmF0L3V0aWxfcHl0aHJhbi5weQ== 100644 --- a/fluidsim/solvers/ns2d/strat/util_pythran.py +++ b/fluidsim/solvers/ns2d/strat/util_pythran.py @@ -1,5 +1,3 @@ - - # pythran export tendencies_nonlin_ns2dstrat( # float64[][], float64[][], float64[][], float64[][], # float64[][], float64[][], float) diff --git a/fluidsim/solvers/ns2d/test/test_solver.py b/fluidsim/solvers/ns2d/test/test_solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3Rlc3QvdGVzdF9zb2x2ZXIucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3Rlc3QvdGVzdF9zb2x2ZXIucHk= 100644 --- a/fluidsim/solvers/ns2d/test/test_solver.py +++ b/fluidsim/solvers/ns2d/test/test_solver.py @@ -31,7 +31,7 @@ nh = 32 params.oper.nx = nh params.oper.ny = nh - Lh = 6. + Lh = 6.0 params.oper.Lx = Lh params.oper.Ly = Lh @@ -35,8 +35,8 @@ params.oper.Lx = Lh params.oper.Ly = Lh - params.oper.coef_dealiasing = 2. / 3 - params.nu_8 = 2. + params.oper.coef_dealiasing = 2.0 / 3 + params.nu_8 = 2.0 params.time_stepping.t_end = 0.5 @@ -68,7 +68,7 @@ nh = 16 params.oper.nx = 2 * nh params.oper.ny = nh - Lh = 6. + Lh = 6.0 params.oper.Lx = Lh params.oper.Ly = Lh @@ -72,8 +72,8 @@ params.oper.Lx = Lh params.oper.Ly = Lh - params.oper.coef_dealiasing = 2. / 3 - params.nu_8 = 2. + params.oper.coef_dealiasing = 2.0 / 3 + params.nu_8 = 2.0 params.time_stepping.t_end = 0.5 diff --git a/fluidsim/solvers/ns2d/util_pythran.py b/fluidsim/solvers/ns2d/util_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczJkL3V0aWxfcHl0aHJhbi5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczJkL3V0aWxfcHl0aHJhbi5weQ== 100644 --- a/fluidsim/solvers/ns2d/util_pythran.py +++ b/fluidsim/solvers/ns2d/util_pythran.py @@ -1,5 +1,3 @@ - - # pythran export compute_Frot( # float64[][], float64[][], float64[][], float64[][], float) diff --git a/fluidsim/solvers/ns3d/bouss/solver.py b/fluidsim/solvers/ns3d/bouss/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL2JvdXNzL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL2JvdXNzL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/ns3d/bouss/solver.py +++ b/fluidsim/solvers/ns3d/bouss/solver.py @@ -210,7 +210,7 @@ params.nu_8 = 2e-6 params.time_stepping.USE_T_END = True - params.time_stepping.t_end = 10. + params.time_stepping.t_end = 10.0 params.init_fields.type = "in_script" @@ -221,7 +221,7 @@ params.output.periods_print.print_stdout = 0.00000000001 - params.output.periods_save.phys_fields = 1. + params.output.periods_save.phys_fields = 1.0 # params.output.periods_save.spectra = 0.5 # params.output.periods_save.spatial_means = 0.05 # params.output.periods_save.spect_energy_budg = 0.5 @@ -246,7 +246,7 @@ X, Y, Z = sim.oper.get_XYZ_loc() - x0 = y0 = z0 = L / 2. + x0 = y0 = z0 = L / 2.0 R2 = (X - x0) ** 2 + (Y - y0) ** 2 + (Z - z0) ** 2 r0 = 0.5 b = -np.exp(-R2 / r0 ** 2) diff --git a/fluidsim/solvers/ns3d/init_fields.py b/fluidsim/solvers/ns3d/init_fields.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL2luaXRfZmllbGRzLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL2luaXRfZmllbGRzLnB5 100644 --- a/fluidsim/solvers/ns3d/init_fields.py +++ b/fluidsim/solvers/ns3d/init_fields.py @@ -46,10 +46,10 @@ def vorticity_1dipole2d(self): oper = self.sim.oper - xs = oper.Lx / 2. - ys = oper.Ly / 2. + xs = oper.Lx / 2.0 + ys = oper.Ly / 2.0 theta = np.pi / 2.3 b = 2.5 omega = np.zeros(oper.oper2d.shapeX_loc) def wz_2LO(XX, YY, b): @@ -51,10 +51,10 @@ theta = np.pi / 2.3 b = 2.5 omega = np.zeros(oper.oper2d.shapeX_loc) def wz_2LO(XX, YY, b): - return 2 * np.exp(-(XX ** 2 + (YY - (b / 2.)) ** 2)) - 2 * np.exp( - -(XX ** 2 + (YY + (b / 2.)) ** 2) + return 2 * np.exp(-(XX ** 2 + (YY - (b / 2.0)) ** 2)) - 2 * np.exp( + -(XX ** 2 + (YY + (b / 2.0)) ** 2) ) XX = oper.oper2d.XX @@ -83,7 +83,7 @@ super(InitFieldsNoise, cls)._complete_params_with_default(params) params.init_fields._set_child( - cls.tag, attribs={"velo_max": 1., "length": None} + cls.tag, attribs={"velo_max": 1.0, "length": None} ) params.init_fields.noise._set_doc( """ @@ -106,6 +106,6 @@ lambda0 = params.init_fields.noise.length if lambda0 is None: - lambda0 = min(oper.Lx, oper.Ly, oper.Lz) / 4. + lambda0 = min(oper.Lx, oper.Ly, oper.Lz) / 4.0 def H_smooth(x, delta): @@ -110,5 +110,5 @@ def H_smooth(x, delta): - return (1. + np.tanh(2 * np.pi * x / delta)) / 2. + return (1.0 + np.tanh(2 * np.pi * x / delta)) / 2.0 k0 = 2 * np.pi / lambda0 @@ -113,6 +113,6 @@ k0 = 2 * np.pi / lambda0 - delta_k0 = 1. * k0 + delta_k0 = 1.0 * k0 K = np.sqrt(oper.K2) velo_max = params.init_fields.noise.velo_max @@ -122,7 +122,7 @@ field = np.random.random(oper.shapeX_loc) field_fft = oper.fft(field) if mpi.rank == 0: - field_fft[0, 0, 0] = 0. + field_fft[0, 0, 0] = 0.0 field_fft *= H_smooth(k0 - K, delta_k0) oper.ifft_as_arg(field_fft, field) @@ -143,6 +143,6 @@ lambda0 = params.init_fields.noise.length if lambda0 is None: - lambda0 = oper.Lx / 4. + lambda0 = oper.Lx / 4.0 def H_smooth(x, delta): @@ -147,6 +147,6 @@ def H_smooth(x, delta): - return (1. + np.tanh(2 * np.pi * x / delta)) / 2. + return (1.0 + np.tanh(2 * np.pi * x / delta)) / 2.0 # to compute always the same field... (for 1 resolution...) np.random.seed(42 + mpi.rank) @@ -158,9 +158,9 @@ vv_fft.append(oper.fft(vi)) if mpi.rank == 0: - vv_fft[ii][0, 0, 0] = 0. + vv_fft[ii][0, 0, 0] = 0.0 oper.project_perpk3d(*vv_fft) oper.dealiasing(*vv_fft) k0 = 2 * np.pi / lambda0 @@ -162,9 +162,9 @@ oper.project_perpk3d(*vv_fft) oper.dealiasing(*vv_fft) k0 = 2 * np.pi / lambda0 - delta_k0 = 1. * k0 + delta_k0 = 1.0 * k0 K = np.sqrt(oper.K2) diff --git a/fluidsim/solvers/ns3d/output/print_stdout.py b/fluidsim/solvers/ns3d/output/print_stdout.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL291dHB1dC9wcmludF9zdGRvdXQucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL291dHB1dC9wcmludF9zdGRvdXQucHk= 100644 --- a/fluidsim/solvers/ns3d/output/print_stdout.py +++ b/fluidsim/solvers/ns3d/output/print_stdout.py @@ -1,4 +1,3 @@ - from __future__ import print_function, division from builtins import range diff --git a/fluidsim/solvers/ns3d/output/spectra.py b/fluidsim/solvers/ns3d/output/spectra.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL291dHB1dC9zcGVjdHJhLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL291dHB1dC9zcGVjdHJhLnB5 100644 --- a/fluidsim/solvers/ns3d/output/spectra.py +++ b/fluidsim/solvers/ns3d/output/spectra.py @@ -125,7 +125,7 @@ if delta_t is not None: for it in range(imin_plot, imax_plot + 1, delta_i_plot): spectrum = dset_spectra_E[it] - spectrum[spectrum < 10e-16] = 0. + spectrum[spectrum < 10e-16] = 0.0 ax.plot(ks, spectrum * coef_norm) spectra = dset_spectra_E[imin_plot : imax_plot + 1] @@ -137,7 +137,7 @@ ax.plot(ks[1:], to_plot[1:], "k--") if coef_plot_k53 is not None: - to_plot = coef_plot_k53 * ks_no0 ** (-5. / 3) * coef_norm + to_plot = coef_plot_k53 * ks_no0 ** (-5.0 / 3) * coef_norm ax.plot(ks[1:], to_plot[1:], "k-.") if xlim is not None: @@ -167,7 +167,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -210,6 +210,6 @@ coef_norm = ks_no0 ** coef_compensate - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum[it] @@ -214,6 +214,6 @@ for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum[it] - EK[EK < 10e-16] = 0. + EK[EK < 10e-16] = 0.0 ax1.plot(ks, EK * coef_norm, "k", linewidth=1) EK = dset_spectrum[imin_plot : imax_plot + 1].mean(0) @@ -217,10 +217,10 @@ ax1.plot(ks, EK * coef_norm, "k", linewidth=1) EK = dset_spectrum[imin_plot : imax_plot + 1].mean(0) - EK[EK < 10e-16] = 0. + EK[EK < 10e-16] = 0.0 ax1.plot(ks, EK * coef_norm, "k", linewidth=2) if coef_plot_k3 is not None: ax1.plot(ks, coef_plot_k3 * ks_no0 ** (-3) * coef_norm, "k--") if coef_plot_k53 is not None: @@ -221,7 +221,7 @@ ax1.plot(ks, EK * coef_norm, "k", linewidth=2) if coef_plot_k3 is not None: ax1.plot(ks, coef_plot_k3 * ks_no0 ** (-3) * coef_norm, "k--") if coef_plot_k53 is not None: - ax1.plot(ks, coef_plot_k53 * ks_no0 ** (-5. / 3) * coef_norm, "k-.") + ax1.plot(ks, coef_plot_k53 * ks_no0 ** (-5.0 / 3) * coef_norm, "k-.") diff --git a/fluidsim/solvers/ns3d/solver.py b/fluidsim/solvers/ns3d/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/ns3d/solver.py +++ b/fluidsim/solvers/ns3d/solver.py @@ -225,6 +225,6 @@ delta_x = params.oper.Lx / params.oper.nx # params.nu_8 = 2.*10e-1*params.forcing.forcing_rate**(1./3)*delta_x**8 - params.nu_8 = 2. * 10e-1 * delta_x ** 8 + params.nu_8 = 2.0 * 10e-1 * delta_x ** 8 params.time_stepping.USE_T_END = True @@ -229,6 +229,6 @@ params.time_stepping.USE_T_END = True - params.time_stepping.t_end = 6. + params.time_stepping.t_end = 6.0 # params.time_stepping.it_end = 2 params.init_fields.type = "noise" @@ -232,8 +232,8 @@ # params.time_stepping.it_end = 2 params.init_fields.type = "noise" - params.init_fields.noise.velo_max = 1. - params.init_fields.noise.length = 1. + params.init_fields.noise.velo_max = 1.0 + params.init_fields.noise.length = 1.0 params.forcing.enable = False # params.forcing.type = 'random' @@ -242,7 +242,7 @@ params.output.periods_print.print_stdout = 0.00000000001 - params.output.periods_save.phys_fields = 1. + params.output.periods_save.phys_fields = 1.0 # params.output.periods_save.spectra = 0.5 # params.output.periods_save.spatial_means = 0.05 # params.output.periods_save.spect_energy_budg = 0.5 diff --git a/fluidsim/solvers/ns3d/state.py b/fluidsim/solvers/ns3d/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0YXRlLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0YXRlLnB5 100644 --- a/fluidsim/solvers/ns3d/state.py +++ b/fluidsim/solvers/ns3d/state.py @@ -64,7 +64,7 @@ else: mpi.printby0(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result diff --git a/fluidsim/solvers/ns3d/strat/output/__init__.py b/fluidsim/solvers/ns3d/strat/output/__init__.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0cmF0L291dHB1dC9fX2luaXRfXy5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0cmF0L291dHB1dC9fX2luaXRfXy5weQ== 100644 --- a/fluidsim/solvers/ns3d/strat/output/__init__.py +++ b/fluidsim/solvers/ns3d/strat/output/__init__.py @@ -1,4 +1,3 @@ - import numpy as np from ...output import Output as OutputNS3D diff --git a/fluidsim/solvers/ns3d/strat/output/spatial_means.py b/fluidsim/solvers/ns3d/strat/output/spatial_means.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0cmF0L291dHB1dC9zcGF0aWFsX21lYW5zLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0cmF0L291dHB1dC9zcGF0aWFsX21lYW5zLnB5 100644 --- a/fluidsim/solvers/ns3d/strat/output/spatial_means.py +++ b/fluidsim/solvers/ns3d/strat/output/spatial_means.py @@ -23,7 +23,7 @@ """Spatial means output.""" def __init__(self, output): - self.one_over_N2 = 1. / output.sim.params.N ** 2 + self.one_over_N2 = 1.0 / output.sim.params.N ** 2 super(SpatialMeansNS3DStrat, self).__init__(output) def _save_one_time(self): diff --git a/fluidsim/solvers/ns3d/strat/output/spectra.py b/fluidsim/solvers/ns3d/strat/output/spectra.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0cmF0L291dHB1dC9zcGVjdHJhLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0cmF0L291dHB1dC9zcGVjdHJhLnB5 100644 --- a/fluidsim/solvers/ns3d/strat/output/spectra.py +++ b/fluidsim/solvers/ns3d/strat/output/spectra.py @@ -1,4 +1,3 @@ - import numpy as np from fluidsim.solvers.ns3d.output.spectra import SpectraNS3D diff --git a/fluidsim/solvers/ns3d/strat/solver.py b/fluidsim/solvers/ns3d/strat/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0cmF0L3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL3N0cmF0L3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/ns3d/strat/solver.py +++ b/fluidsim/solvers/ns3d/strat/solver.py @@ -102,7 +102,7 @@ """This static method is used to complete the *params* container. """ SimulNS3D._complete_params_with_default(params) - attribs = {"N": 1., "NO_SHEAR_MODES": False} + attribs = {"N": 1.0, "NO_SHEAR_MODES": False} params._set_attribs(attribs) def tendencies_nonlin(self, state_spect=None, old=None): @@ -211,6 +211,6 @@ delta_x = params.oper.Lx / params.oper.nx # params.nu_8 = 2.*10e-1*params.forcing.forcing_rate**(1./3)*delta_x**8 - params.nu_8 = 2. * 10e-1 * delta_x ** 8 + params.nu_8 = 2.0 * 10e-1 * delta_x ** 8 params.time_stepping.USE_T_END = True @@ -215,6 +215,6 @@ params.time_stepping.USE_T_END = True - params.time_stepping.t_end = 6. + params.time_stepping.t_end = 6.0 params.time_stepping.it_end = 2 params.init_fields.type = "noise" @@ -218,8 +218,8 @@ params.time_stepping.it_end = 2 params.init_fields.type = "noise" - params.init_fields.noise.velo_max = 1. - params.init_fields.noise.length = 1. + params.init_fields.noise.velo_max = 1.0 + params.init_fields.noise.length = 1.0 # params.forcing.enable = False # params.forcing.type = 'random' @@ -228,7 +228,7 @@ params.output.periods_print.print_stdout = 0.00000000001 - params.output.periods_save.phys_fields = 1. + params.output.periods_save.phys_fields = 1.0 # params.output.periods_save.spectra = 0.5 # params.output.periods_save.spatial_means = 0.05 # params.output.periods_save.spect_energy_budg = 0.5 diff --git a/fluidsim/solvers/ns3d/time_stepping.py b/fluidsim/solvers/ns3d/time_stepping.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL3RpbWVfc3RlcHBpbmcucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL3RpbWVfc3RlcHBpbmcucHk= 100644 --- a/fluidsim/solvers/ns3d/time_stepping.py +++ b/fluidsim/solvers/ns3d/time_stepping.py @@ -1,4 +1,3 @@ - import numpy as np from fluidsim.base.time_stepping.pseudo_spect_cy import TimeSteppingPseudoSpectral diff --git a/fluidsim/solvers/ns3d/try_load.py b/fluidsim/solvers/ns3d/try_load.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL3RyeV9sb2FkLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL3RyeV9sb2FkLnB5 100644 --- a/fluidsim/solvers/ns3d/try_load.py +++ b/fluidsim/solvers/ns3d/try_load.py @@ -22,6 +22,6 @@ delta_x = old_div(params.oper.Lx, params.oper.nx) # params.nu_8 = 2.*10e-1*params.forcing.forcing_rate**(1./3)*delta_x**8 -params.nu_8 = 2. * 10e-1 * delta_x ** 8 +params.nu_8 = 2.0 * 10e-1 * delta_x ** 8 params.time_stepping.USE_T_END = True @@ -26,6 +26,6 @@ params.time_stepping.USE_T_END = True -params.time_stepping.t_end = 7. +params.time_stepping.t_end = 7.0 params.time_stepping.it_end = 2 # params.init_fields.type = 'dipole' @@ -40,7 +40,7 @@ params.output.periods_print.print_stdout = 0.00000000001 -params.output.periods_save.phys_fields = 1. +params.output.periods_save.phys_fields = 1.0 # params.output.periods_save.spectra = 0.5 # params.output.periods_save.spatial_means = 0.05 # params.output.periods_save.spect_energy_budg = 0.5 diff --git a/fluidsim/solvers/ns3d/try_save.py b/fluidsim/solvers/ns3d/try_save.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9uczNkL3RyeV9zYXZlLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9uczNkL3RyeV9zYXZlLnB5 100644 --- a/fluidsim/solvers/ns3d/try_save.py +++ b/fluidsim/solvers/ns3d/try_save.py @@ -23,6 +23,6 @@ delta_x = old_div(params.oper.Lx, params.oper.nx) # params.nu_8 = 2.*10e-1*params.forcing.forcing_rate**(1./3)*delta_x**8 -params.nu_8 = 2. * 10e-1 * delta_x ** 8 +params.nu_8 = 2.0 * 10e-1 * delta_x ** 8 params.time_stepping.USE_T_END = True @@ -27,6 +27,6 @@ params.time_stepping.USE_T_END = True -params.time_stepping.t_end = 5. +params.time_stepping.t_end = 5.0 params.time_stepping.it_end = 2 params.init_fields.type = "dipole" @@ -41,7 +41,7 @@ params.output.periods_print.print_stdout = 0.00000000001 -params.output.periods_save.phys_fields = 1. +params.output.periods_save.phys_fields = 1.0 # params.output.periods_save.spectra = 0.5 # params.output.periods_save.spatial_means = 0.05 # params.output.periods_save.spect_energy_budg = 0.5 diff --git a/fluidsim/solvers/plate2d/diag/solver.py b/fluidsim/solvers/plate2d/diag/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL2RpYWcvc29sdmVyLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL2RpYWcvc29sdmVyLnB5 100644 --- a/fluidsim/solvers/plate2d/diag/solver.py +++ b/fluidsim/solvers/plate2d/diag/solver.py @@ -126,7 +126,7 @@ """This static method is used to complete the *params* container. """ SimulBasePseudoSpectral._complete_params_with_default(params) - attribs = {"beta": 0.} + attribs = {"beta": 0.0} params._set_attribs(attribs) def tendencies_nonlin(self, state_spect=None, old=None): @@ -269,7 +269,7 @@ params.oper.Lx = Lh params.oper.Ly = Lh # params.oper.type_fft = 'FFTWPY' - params.oper.coef_dealiasing = old_div(2., 3) + params.oper.coef_dealiasing = old_div(2.0, 3) delta_x = old_div(params.oper.Lx, params.oper.nx) params.nu_8 = ( @@ -273,5 +273,5 @@ delta_x = old_div(params.oper.Lx, params.oper.nx) params.nu_8 = ( - 2. + 2.0 * 10e-4 @@ -277,5 +277,5 @@ * 10e-4 - * params.forcing.forcing_rate ** (old_div(1., 3)) + * params.forcing.forcing_rate ** (old_div(1.0, 3)) * delta_x ** 8 ) @@ -295,7 +295,7 @@ # '2pix2pi_256x256_2015-03-04_22-36-37/state_phys_t=000.100.hd5') params.forcing.enable = True - params.forcing.forcing_rate = 100. + params.forcing.forcing_rate = 100.0 # params.forcing.nkmax_forcing = 5 # params.forcing.nkmin_forcing = 4 diff --git a/fluidsim/solvers/plate2d/dimensional.py b/fluidsim/solvers/plate2d/dimensional.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL2RpbWVuc2lvbmFsLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL2RpbWVuc2lvbmFsLnB5 100644 --- a/fluidsim/solvers/plate2d/dimensional.py +++ b/fluidsim/solvers/plate2d/dimensional.py @@ -46,7 +46,7 @@ """ - def __init__(self, C, h, L=1., sigma=0.): + def __init__(self, C, h, L=1.0, sigma=0.0): self.C = C self.h = h self.L = L diff --git a/fluidsim/solvers/plate2d/init_fields.py b/fluidsim/solvers/plate2d/init_fields.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL2luaXRfZmllbGRzLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL2luaXRfZmllbGRzLnB5 100644 --- a/fluidsim/solvers/plate2d/init_fields.py +++ b/fluidsim/solvers/plate2d/init_fields.py @@ -19,7 +19,7 @@ def _complete_params_with_default(cls, params): super(cls, cls)._complete_params_with_default(params) params.init_fields._set_child( - cls.tag, attribs={"velo_max": 1., "length": 0} + cls.tag, attribs={"velo_max": 1.0, "length": 0} ) def __call__(self): @@ -32,6 +32,6 @@ lambda0 = params.init_fields.noise.length if lambda0 == 0: - lambda0 = oper.Lx / 4. + lambda0 = oper.Lx / 4.0 def H_smooth(x, delta): @@ -36,6 +36,6 @@ def H_smooth(x, delta): - return (1. + np.tanh(2 * np.pi * x / delta)) / 2. + return (1.0 + np.tanh(2 * np.pi * x / delta)) / 2.0 # to compute always the same field... (for 1 resolution...) np.random.seed(42) # this does not work for MPI... @@ -54,9 +54,9 @@ ) if mpi.rank == 0: - w_fft[0, 0] = 0. - z_fft[0, 0] = 0. + w_fft[0, 0] = 0.0 + z_fft[0, 0] = 0.0 oper.dealiasing(w_fft, z_fft) k0 = 2 * np.pi / lambda0 @@ -59,8 +59,8 @@ oper.dealiasing(w_fft, z_fft) k0 = 2 * np.pi / lambda0 - delta_k0 = 1. * k0 + delta_k0 = 1.0 * k0 w_fft = w_fft * H_smooth(k0 - oper.K, delta_k0) z_fft = z_fft * H_smooth(k0 - oper.K, delta_k0) @@ -93,8 +93,8 @@ w_fft = np.zeros(oper.shapeK_loc, dtype=np.complex128) z_fft = np.zeros(oper.shapeK_loc, dtype=np.complex128) - w_fft[20, 25] = 1. - z_fft[20, 25] = 1. + w_fft[20, 25] = 1.0 + z_fft[20, 25] = 1.0 w = oper.ifft2(w_fft) z = oper.ifft2(z_fft) diff --git a/fluidsim/solvers/plate2d/output/correlations_freq.py b/fluidsim/solvers/plate2d/output/correlations_freq.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC9jb3JyZWxhdGlvbnNfZnJlcS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC9jb3JyZWxhdGlvbnNfZnJlcS5weQ== 100644 --- a/fluidsim/solvers/plate2d/output/correlations_freq.py +++ b/fluidsim/solvers/plate2d/output/correlations_freq.py @@ -211,6 +211,6 @@ ) if mpi.rank == 0: - self.corr4 = (1. / (self.nb_means_times + 1)) * ( + self.corr4 = (1.0 / (self.nb_means_times + 1)) * ( self.nb_means_times * self.corr4 + new_corr4 ) @@ -215,6 +215,6 @@ self.nb_means_times * self.corr4 + new_corr4 ) - self.corr2 = (1. / (self.nb_means_times + 1)) * ( + self.corr2 = (1.0 / (self.nb_means_times + 1)) * ( self.nb_means_times * self.corr2 + new_corr2 ) self.nb_means_times += 1 diff --git a/fluidsim/solvers/plate2d/output/spatial_means.py b/fluidsim/solvers/plate2d/output/spatial_means.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC9zcGF0aWFsX21lYW5zLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC9zcGF0aWFsX21lYW5zLnB5 100644 --- a/fluidsim/solvers/plate2d/output/spatial_means.py +++ b/fluidsim/solvers/plate2d/output/spatial_means.py @@ -93,7 +93,7 @@ # assert that z in not forced Fz_fft = forcing_fft.get_var("z_fft") assert np.allclose( - abs(Fz_fft).max(), 0. + abs(Fz_fft).max(), 0.0 ), "abs(Fz_fft).max(): {}".format(abs(Fz_fft).max()) P1_fft = np.real(w_fft.conj() * Fw_fft) diff --git a/fluidsim/solvers/plate2d/output/spectra.py b/fluidsim/solvers/plate2d/output/spectra.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC9zcGVjdHJhLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC9zcGVjdHJhLnB5 100644 --- a/fluidsim/solvers/plate2d/output/spectra.py +++ b/fluidsim/solvers/plate2d/output/spectra.py @@ -62,7 +62,7 @@ spectrum2D_EE = dict_spectra2D["spectrum2D_EE"] spectrum2D_Etot = spectrum2D_EK + spectrum2D_EL + spectrum2D_EE khE = self.oper.khE - coef_norm = khE ** (3.) + coef_norm = khE ** (3.0) self.axe.loglog(khE, spectrum2D_Etot * coef_norm, "k", linewidth=2) self.axe.loglog(khE, spectrum2D_EK * coef_norm, "r--") self.axe.loglog(khE, spectrum2D_EL * coef_norm, "b--") @@ -142,6 +142,6 @@ ax1.set_yscale("log") coef_norm = kh ** (coef_compensate) - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum1Dkx_EK[it] + dset_spectrum1Dky_EK[it] @@ -146,6 +146,6 @@ for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum1Dkx_EK[it] + dset_spectrum1Dky_EK[it] - EK[EK < 10e-16] = 0. + EK[EK < 10e-16] = 0.0 ax1.plot(kh, EK * coef_norm, "r", linewidth=1) EK = ( @@ -178,7 +178,7 @@ else: delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(old_div(delta_t, delta_t_save))) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -224,6 +224,6 @@ coef_norm = kh ** coef_compensate - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum_EK[it] @@ -228,4 +228,4 @@ for it in range(imin_plot, imax_plot + 1, delta_i_plot): EK = dset_spectrum_EK[it] - EK[EK < 10e-16] = 0. + EK[EK < 10e-16] = 0.0 EL = dset_spectrum_EL[it] @@ -231,3 +231,3 @@ EL = dset_spectrum_EL[it] - EL[EL < 10e-16] = 0. + EL[EL < 10e-16] = 0.0 EE = dset_spectrum_EE[it] @@ -233,5 +233,5 @@ EE = dset_spectrum_EE[it] - EE[EE < 10e-16] = 0. + EE[EE < 10e-16] = 0.0 Etot = EK + EL + EE # print(Etot) @@ -242,5 +242,5 @@ ax1.plot(kh, EE * coef_norm, "y--", linewidth=1) EK = dset_spectrum_EK[imin_plot : imax_plot + 1].mean(0) - EK[EK < 10e-16] = 0. + EK[EK < 10e-16] = 0.0 EL = dset_spectrum_EL[imin_plot : imax_plot + 1].mean(0) @@ -246,3 +246,3 @@ EL = dset_spectrum_EL[imin_plot : imax_plot + 1].mean(0) - EL[EK < 10e-16] = 0. + EL[EK < 10e-16] = 0.0 EE = dset_spectrum_EE[imin_plot : imax_plot + 1].mean(0) @@ -248,5 +248,5 @@ EE = dset_spectrum_EE[imin_plot : imax_plot + 1].mean(0) - EE[EK < 10e-16] = 0. + EE[EK < 10e-16] = 0.0 ax1.plot(kh, EK * coef_norm, "r-", linewidth=2) ax1.plot(kh, EL * coef_norm, "b-", linewidth=2) @@ -254,5 +254,5 @@ ax1.plot(kh, kh ** (-3) * coef_norm, "k:", linewidth=1) ax1.plot( - kh, 0.01 * kh ** (old_div(-5., 3)) * coef_norm, "k-.", linewidth=1 + kh, 0.01 * kh ** (old_div(-5.0, 3)) * coef_norm, "k-.", linewidth=1 ) diff --git a/fluidsim/solvers/plate2d/output/util_pythran.py b/fluidsim/solvers/plate2d/output/util_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC91dGlsX3B5dGhyYW4ucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL291dHB1dC91dGlsX3B5dGhyYW4ucHk= 100644 --- a/fluidsim/solvers/plate2d/output/util_pythran.py +++ b/fluidsim/solvers/plate2d/output/util_pythran.py @@ -1,4 +1,3 @@ - import numpy as np diff --git a/fluidsim/solvers/plate2d/solver.py b/fluidsim/solvers/plate2d/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/plate2d/solver.py +++ b/fluidsim/solvers/plate2d/solver.py @@ -164,7 +164,7 @@ def _complete_params_with_default(params): """Complete the `params` container (static method).""" SimulBasePseudoSpectral._complete_params_with_default(params) - attribs = {"beta": 0.} + attribs = {"beta": 0.0} params._set_attribs(attribs) def tendencies_nonlin(self, state_spect=None, old=None): @@ -298,8 +298,8 @@ params.short_name_type_run = "test" nh = 32 - Lh = 1. + Lh = 1.0 params.oper.nx = nh params.oper.ny = nh params.oper.Lx = Lh params.oper.Ly = Lh @@ -302,7 +302,7 @@ params.oper.nx = nh params.oper.ny = nh params.oper.Lx = Lh params.oper.Ly = Lh - params.oper.coef_dealiasing = 2. / 3 + params.oper.coef_dealiasing = 2.0 / 3 delta_x = Lh / nh @@ -307,6 +307,6 @@ delta_x = Lh / nh - params.nu_8 = 2e1 * params.forcing.forcing_rate ** (1. / 3) * delta_x ** 8 + params.nu_8 = 2e1 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x ** 8 kmax = np.sqrt(2) * np.pi / delta_x deltat = 2 * np.pi / kmax ** 2 / 2 @@ -314,7 +314,7 @@ params.time_stepping.USE_CFL = False params.time_stepping.deltat0 = deltat params.time_stepping.USE_T_END = False - params.time_stepping.t_end = 1. + params.time_stepping.t_end = 1.0 params.time_stepping.it_end = 10 params.init_fields.type = "noise" @@ -330,7 +330,7 @@ params.output.periods_print.print_stdout = 0.05 - params.output.periods_save.phys_fields = 5. + params.output.periods_save.phys_fields = 5.0 params.output.periods_save.spectra = 0.05 params.output.periods_save.spatial_means = 10 * deltat params.output.periods_save.correl_freq = 1 diff --git a/fluidsim/solvers/plate2d/state.py b/fluidsim/solvers/plate2d/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL3N0YXRlLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL3N0YXRlLnB5 100644 --- a/fluidsim/solvers/plate2d/state.py +++ b/fluidsim/solvers/plate2d/state.py @@ -68,7 +68,7 @@ if mpi.rank == 0: print(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result diff --git a/fluidsim/solvers/plate2d/test/test_solver.py b/fluidsim/solvers/plate2d/test/test_solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL3Rlc3QvdGVzdF9zb2x2ZXIucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL3Rlc3QvdGVzdF9zb2x2ZXIucHk= 100644 --- a/fluidsim/solvers/plate2d/test/test_solver.py +++ b/fluidsim/solvers/plate2d/test/test_solver.py @@ -25,7 +25,7 @@ nh = 32 params.oper.nx = nh params.oper.ny = nh - Lh = 6. + Lh = 6.0 params.oper.Lx = Lh params.oper.Ly = Lh @@ -29,8 +29,8 @@ params.oper.Lx = Lh params.oper.Ly = Lh - params.oper.coef_dealiasing = 2. / 3 - params.nu_8 = 2. + params.oper.coef_dealiasing = 2.0 / 3 + params.nu_8 = 2.0 params.time_stepping.USE_CFL = False params.time_stepping.deltat0 = 0.005 @@ -56,8 +56,8 @@ params.short_name_type_run = "test" nh = 24 - Lh = 1. + Lh = 1.0 params.oper.nx = nh params.oper.ny = nh params.oper.Lx = Lh params.oper.Ly = Lh @@ -60,8 +60,8 @@ params.oper.nx = nh params.oper.ny = nh params.oper.Lx = Lh params.oper.Ly = Lh - params.oper.coef_dealiasing = 2. / 3 + params.oper.coef_dealiasing = 2.0 / 3 delta_x = Lh / nh @@ -83,7 +83,9 @@ params.forcing.nkmin_forcing = 2 params.forcing.tcrandom.time_correlation = 100 * deltat - params.nu_8 = 2e1 * params.forcing.forcing_rate ** (1. / 3) * delta_x ** 8 + params.nu_8 = ( + 2e1 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x ** 8 + ) params.output.periods_print.print_stdout = 0.05 @@ -87,7 +89,7 @@ params.output.periods_print.print_stdout = 0.05 - params.output.periods_save.phys_fields = 5. + params.output.periods_save.phys_fields = 5.0 params.output.periods_save.spectra = 0.05 params.output.periods_save.spatial_means = 10 * deltat params.output.periods_save.correl_freq = 1 diff --git a/fluidsim/solvers/plate2d/util_oper_pythran.py b/fluidsim/solvers/plate2d/util_oper_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL3V0aWxfb3Blcl9weXRocmFuLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9wbGF0ZTJkL3V0aWxfb3Blcl9weXRocmFuLnB5 100644 --- a/fluidsim/solvers/plate2d/util_oper_pythran.py +++ b/fluidsim/solvers/plate2d/util_oper_pythran.py @@ -1,5 +1,3 @@ - - # pythran export monge_ampere_step0( # complex128[][], complex128[][], # float64[][], float64[][], float64[][]) diff --git a/fluidsim/solvers/sphere/ns2d/solver.py b/fluidsim/solvers/sphere/ns2d/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zcGhlcmUvbnMyZC9zb2x2ZXIucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zcGhlcmUvbnMyZC9zb2x2ZXIucHk= 100644 --- a/fluidsim/solvers/sphere/ns2d/solver.py +++ b/fluidsim/solvers/sphere/ns2d/solver.py @@ -119,7 +119,7 @@ import numpy as np - T_rot = np.real(Frot_sh.conj() * rot_sh + Frot_sh * rot_sh.conj()) / 2. + T_rot = np.real(Frot_sh.conj() * rot_sh + Frot_sh * rot_sh.conj()) / 2.0 print( ("sum(T_rot) = {0:9.4e} ; sum(abs(T_rot)) = {1:9.4e}").format( self.oper.sum_wavenumbers(T_rot), @@ -144,7 +144,7 @@ params.init_fields.type = "noise" params.time_stepping.USE_CFL = True - params.time_stepping.t_end = 10. + params.time_stepping.t_end = 10.0 # params.time_stepping.deltat0 = 0.1 params.output.periods_save.phys_fields = 0.25 diff --git a/fluidsim/solvers/sw1l/exactlin/modified/output.py b/fluidsim/solvers/sw1l/exactlin/modified/output.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL2V4YWN0bGluL21vZGlmaWVkL291dHB1dC5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL2V4YWN0bGluL21vZGlmaWVkL291dHB1dC5weQ== 100644 --- a/fluidsim/solvers/sw1l/exactlin/modified/output.py +++ b/fluidsim/solvers/sw1l/exactlin/modified/output.py @@ -46,7 +46,7 @@ # compute Ertel and Charney (QG) potential vorticity rot = self.sim.state.get_var("rot") eta = self.sim.state.state_phys.get_var("eta") - ErtelPV_fft = self.oper.fft2((self.sim.params.f + rot) / (1. + eta)) + ErtelPV_fft = self.oper.fft2((self.sim.params.f + rot) / (1.0 + eta)) ux_fft = self.sim.state.get_var("ux_fft") uy_fft = self.sim.state.get_var("uy_fft") rot_fft = self.oper.rotfft_from_vecfft(ux_fft, uy_fft) diff --git a/fluidsim/solvers/sw1l/exactlin/modified/solver.py b/fluidsim/solvers/sw1l/exactlin/modified/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL2V4YWN0bGluL21vZGlmaWVkL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL2V4YWN0bGluL21vZGlmaWVkL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/sw1l/exactlin/modified/solver.py +++ b/fluidsim/solvers/sw1l/exactlin/modified/solver.py @@ -139,6 +139,6 @@ delta_x = params.oper.Lx / params.oper.nx params.nu_8 = ( - 2. * 10e-1 * params.forcing.forcing_rate ** (1. / 3) * delta_x ** 8 + 2.0 * 10e-1 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x ** 8 ) @@ -143,6 +143,6 @@ ) - params.time_stepping.t_end = 2. + params.time_stepping.t_end = 2.0 params.init_fields.type = "vortex_grid" @@ -151,10 +151,10 @@ params.output.periods_print.print_stdout = 0.25 - params.output.periods_save.phys_fields = 1. + params.output.periods_save.phys_fields = 1.0 params.output.periods_save.spectra = 0.5 params.output.periods_save.spect_energy_budg = 0.5 params.output.periods_save.increments = 0.5 params.output.periods_save.pdf = 0.5 params.output.periods_save.time_signals_fft = False @@ -155,10 +155,10 @@ params.output.periods_save.spectra = 0.5 params.output.periods_save.spect_energy_budg = 0.5 params.output.periods_save.increments = 0.5 params.output.periods_save.pdf = 0.5 params.output.periods_save.time_signals_fft = False - params.output.periods_plot.phys_fields = 0. + params.output.periods_plot.phys_fields = 0.0 params.output.phys_fields.field_to_plot = "div" diff --git a/fluidsim/solvers/sw1l/exactlin/solver.py b/fluidsim/solvers/sw1l/exactlin/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL2V4YWN0bGluL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL2V4YWN0bGluL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/sw1l/exactlin/solver.py +++ b/fluidsim/solvers/sw1l/exactlin/solver.py @@ -114,5 +114,5 @@ if key == "q_fft": omega = self.oper.create_arrayK(value=0) elif key == "ap_fft": - omega = 1.j * np.sqrt(self.params.f ** 2 + self.params.c2 * K2) + omega = 1.0j * np.sqrt(self.params.f ** 2 + self.params.c2 * K2) elif key == "am_fft": @@ -118,5 +118,5 @@ elif key == "am_fft": - omega = -1.j * np.sqrt(self.params.f ** 2 + self.params.c2 * K2) + omega = -1.0j * np.sqrt(self.params.f ** 2 + self.params.c2 * K2) return omega def verify_tendencies( @@ -204,6 +204,6 @@ delta_x = params.oper.Lx / params.oper.nx params.nu_8 = ( - 2. * 10e-1 * params.forcing.forcing_rate ** (1. / 3) * delta_x ** 8 + 2.0 * 10e-1 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x ** 8 ) @@ -208,6 +208,6 @@ ) - params.time_stepping.t_end = 2. + params.time_stepping.t_end = 2.0 params.init_fields.type = "noise" @@ -216,10 +216,10 @@ params.output.periods_print.print_stdout = 0.25 - params.output.periods_save.phys_fields = 1. + params.output.periods_save.phys_fields = 1.0 params.output.periods_save.spectra = 0.5 params.output.periods_save.spect_energy_budg = 0.5 params.output.periods_save.increments = 0.5 params.output.periods_save.pdf = 0.5 params.output.periods_save.time_signals_fft = False @@ -220,10 +220,10 @@ params.output.periods_save.spectra = 0.5 params.output.periods_save.spect_energy_budg = 0.5 params.output.periods_save.increments = 0.5 params.output.periods_save.pdf = 0.5 params.output.periods_save.time_signals_fft = False - params.output.periods_plot.phys_fields = 0. + params.output.periods_plot.phys_fields = 0.0 params.output.phys_fields.field_to_plot = "div" diff --git a/fluidsim/solvers/sw1l/init_fields.py b/fluidsim/solvers/sw1l/init_fields.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL2luaXRfZmllbGRzLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL2luaXRfZmllbGRzLnB5 100644 --- a/fluidsim/solvers/sw1l/init_fields.py +++ b/fluidsim/solvers/sw1l/init_fields.py @@ -33,7 +33,7 @@ from fluidsim.base.init_fields import InitFieldsBase, SpecificInitFields from fluidsim.solvers.ns2d.init_fields import ( - InitFieldsNoise as InitFieldsNoiseNS2D + InitFieldsNoise as InitFieldsNoiseNS2D, ) from fluidsim.solvers.ns2d.init_fields import InitFieldsJet, InitFieldsDipole @@ -51,7 +51,7 @@ @classmethod def _complete_params_with_default(cls, params): super(InitFieldsWave, cls)._complete_params_with_default(params) - params.init_fields._set_child(cls.tag, attribs={"eta_max": 1., "ikx": 2}) + params.init_fields._set_child(cls.tag, attribs={"eta_max": 1.0, "ikx": 2}) def __call__(self): oper = self.sim.oper @@ -61,7 +61,7 @@ kx = oper.deltakx * ikx eta_fft = np.zeros_like(self.sim.state.get_var("eta_fft")) - cond = np.logical_and(oper.KX == kx, oper.KY == 0.) + cond = np.logical_and(oper.KX == kx, oper.KY == 0.0) eta_fft[cond] = eta_max oper.project_fft_on_realX(eta_fft) @@ -94,7 +94,7 @@ def _complete_params_with_default(cls, params): super(InitFieldsVortexGrid, cls)._complete_params_with_default(params) params.init_fields._set_child( - cls.tag, attribs={"omega_max": 1., "n_vort": 8, "sd": None} + cls.tag, attribs={"omega_max": 1.0, "n_vort": 8, "sd": None} ) def __call__(self): @@ -121,8 +121,8 @@ dx_vort = Lx / N_vort dy_vort = Ly / N_vort - x_vort = np.linspace(0, Lx, N_vort + 1) + dx_vort / 2. - y_vort = np.linspace(0, Ly, N_vort + 1) + dy_vort / 2. + x_vort = np.linspace(0, Lx, N_vort + 1) + dx_vort / 2.0 + y_vort = np.linspace(0, Ly, N_vort + 1) + dy_vort / 2.0 sign_list = self._random_plus_minus_list() if SD is None: @@ -126,7 +126,7 @@ sign_list = self._random_plus_minus_list() if SD is None: - SD = min(dx_vort, dy_vort) / 12. + SD = min(dx_vort, dy_vort) / 12.0 params.sd = SD amp = params.omega_max diff --git a/fluidsim/solvers/sw1l/modified/output.py b/fluidsim/solvers/sw1l/modified/output.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL21vZGlmaWVkL291dHB1dC5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL21vZGlmaWVkL291dHB1dC5weQ== 100644 --- a/fluidsim/solvers/sw1l/modified/output.py +++ b/fluidsim/solvers/sw1l/modified/output.py @@ -27,6 +27,6 @@ uy_fft = self.sim.state.state_spect.get_var("uy_fft") eta_fft = self.sim.state.state_spect.get_var("eta_fft") energyA_fft = self.sim.params.c2 * np.abs(eta_fft) ** 2 / 2 - energyK_fft = np.abs(ux_fft) ** 2 / 2. + np.abs(uy_fft) ** 2 / 2. + energyK_fft = np.abs(ux_fft) ** 2 / 2.0 + np.abs(uy_fft) ** 2 / 2.0 rot_fft = self.oper.rotfft_from_vecfft(ux_fft, uy_fft) uxr_fft, uyr_fft = self.oper.vecfft_from_rotfft(rot_fft) @@ -31,6 +31,6 @@ rot_fft = self.oper.rotfft_from_vecfft(ux_fft, uy_fft) uxr_fft, uyr_fft = self.oper.vecfft_from_rotfft(rot_fft) - energyKr_fft = np.abs(uxr_fft) ** 2 / 2. + np.abs(uyr_fft) ** 2 / 2. + energyKr_fft = np.abs(uxr_fft) ** 2 / 2.0 + np.abs(uyr_fft) ** 2 / 2.0 return energyK_fft, energyA_fft, energyKr_fft def compute_energiesKA_fft(self): @@ -38,10 +38,10 @@ uy_fft = self.sim.state.state_spect.get_var("uy_fft") eta_fft = self.sim.state.state_spect.get_var("eta_fft") energyA_fft = self.sim.params.c2 * np.abs(eta_fft) ** 2 / 2 - energyK_fft = np.abs(ux_fft) ** 2 / 2. + np.abs(uy_fft) ** 2 / 2. + energyK_fft = np.abs(ux_fft) ** 2 / 2.0 + np.abs(uy_fft) ** 2 / 2.0 return energyK_fft, energyA_fft def compute_PV_fft(self): # compute Ertel and Charney (QG) potential vorticity rot = self.sim.state.get_var("rot") eta = self.sim.state.state_phys.get_var("eta") @@ -42,10 +42,10 @@ return energyK_fft, energyA_fft def compute_PV_fft(self): # compute Ertel and Charney (QG) potential vorticity rot = self.sim.state.get_var("rot") eta = self.sim.state.state_phys.get_var("eta") - ErtelPV_fft = self.oper.fft2((self.sim.params.f + rot) / (1. + eta)) + ErtelPV_fft = self.oper.fft2((self.sim.params.f + rot) / (1.0 + eta)) ux_fft = self.sim.state.state_spect.get_var("ux_fft") uy_fft = self.sim.state.state_spect.get_var("uy_fft") rot_fft = self.oper.rotfft_from_vecfft(ux_fft, uy_fft) diff --git a/fluidsim/solvers/sw1l/modified/solver.py b/fluidsim/solvers/sw1l/modified/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL21vZGlmaWVkL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL21vZGlmaWVkL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/sw1l/modified/solver.py +++ b/fluidsim/solvers/sw1l/modified/solver.py @@ -136,6 +136,6 @@ delta_x = params.oper.Lx / params.oper.nx params.nu_8 = ( - 2. * 10e-1 * params.forcing.forcing_rate ** (1. / 3) * delta_x ** 8 + 2.0 * 10e-1 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x ** 8 ) @@ -140,6 +140,6 @@ ) - params.time_stepping.t_end = 2. + params.time_stepping.t_end = 2.0 params.init_fields.type = "noise" @@ -148,10 +148,10 @@ params.output.periods_print.print_stdout = 0.25 - params.output.periods_save.phys_fields = 1. + params.output.periods_save.phys_fields = 1.0 params.output.periods_save.spectra = 0.5 params.output.periods_save.spect_energy_budg = 0.5 params.output.periods_save.increments = 0.5 params.output.periods_save.pdf = 0.5 params.output.periods_save.time_signals_fft = False @@ -152,10 +152,10 @@ params.output.periods_save.spectra = 0.5 params.output.periods_save.spect_energy_budg = 0.5 params.output.periods_save.increments = 0.5 params.output.periods_save.pdf = 0.5 params.output.periods_save.time_signals_fft = False - params.output.periods_plot.phys_fields = 0. + params.output.periods_plot.phys_fields = 0.0 params.output.phys_fields.field_to_plot = "div" diff --git a/fluidsim/solvers/sw1l/modified/state.py b/fluidsim/solvers/sw1l/modified/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL21vZGlmaWVkL3N0YXRlLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL21vZGlmaWVkL3N0YXRlLnB5 100644 --- a/fluidsim/solvers/sw1l/modified/state.py +++ b/fluidsim/solvers/sw1l/modified/state.py @@ -89,7 +89,7 @@ if mpi.rank == 0: print(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result diff --git a/fluidsim/solvers/sw1l/onlywaves/solver.py b/fluidsim/solvers/sw1l/onlywaves/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL29ubHl3YXZlcy9zb2x2ZXIucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL29ubHl3YXZlcy9zb2x2ZXIucHk= 100644 --- a/fluidsim/solvers/sw1l/onlywaves/solver.py +++ b/fluidsim/solvers/sw1l/onlywaves/solver.py @@ -111,5 +111,5 @@ K2 = self.oper.K2 # return self.oper.create_arrayK(value=0) if key == "ap_fft": - omega = 1.j * np.sqrt(self.params.f ** 2 + self.params.c2 * K2) + omega = 1.0j * np.sqrt(self.params.f ** 2 + self.params.c2 * K2) elif key == "am_fft": @@ -115,5 +115,5 @@ elif key == "am_fft": - omega = -1.j * np.sqrt(self.params.f ** 2 + self.params.c2 * K2) + omega = -1.0j * np.sqrt(self.params.f ** 2 + self.params.c2 * K2) return omega def verify_tendencies( @@ -201,6 +201,6 @@ delta_x = params.oper.Lx / params.oper.nx params.nu_8 = ( - 2. * 10e-1 * params.forcing.forcing_rate ** (1. / 3) * delta_x ** 8 + 2.0 * 10e-1 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x ** 8 ) @@ -205,6 +205,6 @@ ) - params.time_stepping.t_end = 2. + params.time_stepping.t_end = 2.0 params.init_fields.type = "noise" @@ -213,10 +213,10 @@ params.output.periods_print.print_stdout = 0.25 - params.output.periods_save.phys_fields = 1. + params.output.periods_save.phys_fields = 1.0 params.output.periods_save.spectra = 0.5 params.output.periods_save.spect_energy_budg = 0.5 params.output.periods_save.increments = 0.5 params.output.periods_save.pdf = 0.5 params.output.periods_save.time_signals_fft = False @@ -217,10 +217,10 @@ params.output.periods_save.spectra = 0.5 params.output.periods_save.spect_energy_budg = 0.5 params.output.periods_save.increments = 0.5 params.output.periods_save.pdf = 0.5 params.output.periods_save.time_signals_fft = False - params.output.periods_plot.phys_fields = 0. + params.output.periods_plot.phys_fields = 0.0 params.output.phys_fields.field_to_plot = "div" diff --git a/fluidsim/solvers/sw1l/output/__init__.py b/fluidsim/solvers/sw1l/output/__init__.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9fX2luaXRfXy5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9fX2luaXRfXy5weQ== 100644 --- a/fluidsim/solvers/sw1l/output/__init__.py +++ b/fluidsim/solvers/sw1l/output/__init__.py @@ -119,7 +119,7 @@ def compute_enstrophy_fft(self): r"""Calculate enstrophy from vorticity in the spectral space.""" rot_fft = self.sim.state.get_var("rot_fft") - return np.abs(rot_fft) ** 2 / 2. + return np.abs(rot_fft) ** 2 / 2.0 def compute_PV_fft(self): r"""Compute Ertel and Charney (QG) potential vorticity. @@ -131,7 +131,7 @@ get_var = self.sim.state.get_var rot = get_var("rot") eta = self.sim.state.state_phys.get_var("eta") - ErtelPV_fft = self.oper.fft2((self.sim.params.f + rot) / (1. + eta)) + ErtelPV_fft = self.oper.fft2((self.sim.params.f + rot) / (1.0 + eta)) rot_fft = get_var("rot_fft") eta_fft = get_var("eta_fft") CharneyPV_fft = rot_fft - self.sim.params.f * eta_fft @@ -140,10 +140,10 @@ def compute_PE_fft(self): """Compute Ertel and Charney (QG) potential enstrophy.""" ErtelPV_fft, CharneyPV_fft = self.compute_PV_fft() - return (abs(ErtelPV_fft) ** 2 / 2., abs(CharneyPV_fft) ** 2 / 2.) + return (abs(ErtelPV_fft) ** 2 / 2.0, abs(CharneyPV_fft) ** 2 / 2.0) def compute_CharneyPE_fft(self): """Compute Charney (QG) potential enstrophy.""" rot_fft = self.sim.state.get_var("rot_fft") eta_fft = self.sim.state.get_var("eta_fft") CharneyPV_fft = rot_fft - self.sim.params.f * eta_fft @@ -144,10 +144,10 @@ def compute_CharneyPE_fft(self): """Compute Charney (QG) potential enstrophy.""" rot_fft = self.sim.state.get_var("rot_fft") eta_fft = self.sim.state.get_var("eta_fft") CharneyPV_fft = rot_fft - self.sim.params.f * eta_fft - return abs(CharneyPV_fft) ** 2 / 2. + return abs(CharneyPV_fft) ** 2 / 2.0 def compute_energies(self): """Compute kinetic, available potential and rotational kinetic energies.""" @@ -231,7 +231,7 @@ ux_fft = get_var("ux_fft") uy_fft = get_var("uy_fft") energyK_fft = ( - np.real(Jx_fft.conj() * ux_fft + Jy_fft.conj() * uy_fft) / 2. + np.real(Jx_fft.conj() * ux_fft + Jy_fft.conj() * uy_fft) / 2.0 ) rot_fft = get_var("rot_fft") @@ -239,7 +239,7 @@ rotJ_fft = self.oper.rotfft_from_vecfft(Jx_fft, Jy_fft) Jxr_fft, Jyr_fft = self.oper.vecfft_from_rotfft(rotJ_fft) energyKr_fft = ( - np.real(Jxr_fft.conj() * uxr_fft + Jyr_fft.conj() * uyr_fft) / 2. + np.real(Jxr_fft.conj() * uxr_fft + Jyr_fft.conj() * uyr_fft) / 2.0 ) return energyK_fft, energyA_fft, energyKr_fft @@ -253,7 +253,7 @@ ux_fft = get_var("ux_fft") uy_fft = get_var("uy_fft") energyK_fft = ( - np.real(Jx_fft.conj() * ux_fft + Jy_fft.conj() * uy_fft) / 2. + np.real(Jx_fft.conj() * ux_fft + Jy_fft.conj() * uy_fft) / 2.0 ) return energyK_fft, energyA_fft diff --git a/fluidsim/solvers/sw1l/output/normal_mode.py b/fluidsim/solvers/sw1l/output/normal_mode.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9ub3JtYWxfbW9kZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9ub3JtYWxfbW9kZS5weQ== 100644 --- a/fluidsim/solvers/sw1l/output/normal_mode.py +++ b/fluidsim/solvers/sw1l/output/normal_mode.py @@ -74,7 +74,7 @@ am_fft = am_fft * 2 ** 0.5 * c2 / (sigma * K) bvec_fft = np.array([q_fft, ap_fft, am_fft]) if mpi.rank == 0 or self.oper.is_sequential: - bvec_fft[:, 0, 0] = 0. + bvec_fft[:, 0, 0] = 0.0 return bvec_fft @@ -128,7 +128,7 @@ # np.testing.assert_allclose(qmat_py, self.qmat, rtol=1e-14) if mpi.rank == 0 or oper.is_sequential: - self.qmat[:, :, 0, 0] = 0. + self.qmat[:, :, 0, 0] = 0.0 def normalmodefft_from_keyfft(self, key): """Returns the normal mode decomposition for the state_spect key specified.""" @@ -187,7 +187,7 @@ return key_modes, normal_mode_vec_phys def _group_matrix_using_dict(self, key_matrix, value_matrix, grouping): - value_dict = dict.fromkeys(grouping, 0.) + value_dict = dict.fromkeys(grouping, 0.0) n1, n2 = key_matrix.shape for i in range(n1): for j in range(n2): diff --git a/fluidsim/solvers/sw1l/output/print_stdout.py b/fluidsim/solvers/sw1l/output/print_stdout.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9wcmludF9zdGRvdXQucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9wcmludF9zdGRvdXQucHk= 100644 --- a/fluidsim/solvers/sw1l/output/print_stdout.py +++ b/fluidsim/solvers/sw1l/output/print_stdout.py @@ -1,4 +1,3 @@ - from __future__ import print_function, division from builtins import range diff --git a/fluidsim/solvers/sw1l/output/spatial_means.py b/fluidsim/solvers/sw1l/output/spatial_means.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9zcGF0aWFsX21lYW5zLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9zcGF0aWFsX21lYW5zLnB5 100644 --- a/fluidsim/solvers/sw1l/output/spatial_means.py +++ b/fluidsim/solvers/sw1l/output/spatial_means.py @@ -61,5 +61,5 @@ # Compute and save skewness and kurtosis. eta = self.sim.state.state_phys.get_var("eta") - meaneta2 = 2. / self.c2 * energyA + meaneta2 = 2.0 / self.c2 * energyA if meaneta2 == 0: @@ -65,4 +65,4 @@ if meaneta2 == 0: - skew_eta = 0. - kurt_eta = 0. + skew_eta = 0.0 + kurt_eta = 0.0 else: @@ -68,5 +68,5 @@ else: - skew_eta = np.mean(eta ** 3) / meaneta2 ** (3. / 2) + skew_eta = np.mean(eta ** 3) / meaneta2 ** (3.0 / 2) kurt_eta = np.mean(eta ** 4) / meaneta2 ** (2) ux = self.sim.state.state_phys.get_var("ux") @@ -77,6 +77,6 @@ rot = self.sim.oper.ifft2(rot_fft) meanrot2 = self.sum_wavenumbers(abs(rot_fft) ** 2) if meanrot2 == 0: - skew_rot = 0. - kurt_rot = 0. + skew_rot = 0.0 + kurt_rot = 0.0 else: @@ -82,5 +82,5 @@ else: - skew_rot = np.mean(rot ** 3) / meanrot2 ** (3. / 2) + skew_rot = np.mean(rot ** 3) / meanrot2 ** (3.0 / 2) kurt_rot = np.mean(rot ** 4) / meanrot2 ** (2) if mpi.rank == 0: @@ -599,9 +599,9 @@ dict_results = self.load() t = dict_results["t"] - dt = np.gradient(t, 1.) + dt = np.gradient(t, 1.0) fig, axarr = plt.subplots(len(keys), sharex=True) i = 0 for k in keys: E = dict_results[k] @@ -603,9 +603,9 @@ fig, axarr = plt.subplots(len(keys), sharex=True) i = 0 for k in keys: E = dict_results[k] - dE_dt = abs(np.gradient(E, 1.) / dt) + dE_dt = abs(np.gradient(E, 1.0) / dt) dE_dt_avg = "{0:11.6e}".format(dE_dt.mean()) try: axarr[i].semilogy(t, dE_dt, label=dE_dt_avg) @@ -729,7 +729,7 @@ Feta = self.sim.oper.ifft2(Feta_fft) eta = self.sim.state.state_phys.get_var("eta") - h = eta + 1. + h = eta + 1.0 ux = self.sim.state.state_phys.get_var("ux") uy = self.sim.state.state_phys.get_var("uy") diff --git a/fluidsim/solvers/sw1l/output/spect_energy_budget.py b/fluidsim/solvers/sw1l/output/spect_energy_budget.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9zcGVjdF9lbmVyZ3lfYnVkZ2V0LnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9zcGVjdF9lbmVyZ3lfYnVkZ2V0LnB5 100644 --- a/fluidsim/solvers/sw1l/output/spect_energy_budget.py +++ b/fluidsim/solvers/sw1l/output/spect_energy_budget.py @@ -36,7 +36,7 @@ ux = self.sim.state.state_phys.get_var("ux") uy = self.sim.state.state_phys.get_var("uy") eta = self.sim.state.state_phys.get_var("eta") - h = 1. + eta + h = 1.0 + eta Jx = h * ux Jy = h * uy @@ -50,7 +50,7 @@ eta_fft = get_var("eta_fft") h_fft = eta_fft.copy() if mpi.rank == 0: - h_fft[0, 0] = 1. + h_fft[0, 0] = 1.0 rot_fft = oper.rotfft_from_vecfft(ux_fft, uy_fft) urx_fft, ury_fft = oper.vecfft_from_rotfft(rot_fft) @@ -138,7 +138,7 @@ # ) hdiv_fft = oper.fft2(h * div) - convP_fft = self.c2 / 2. * inner_prod(h_fft, hdiv_fft) + convP_fft = self.c2 / 2.0 * inner_prod(h_fft, hdiv_fft) convP2D = self.spectrum2D_from_fft(convP_fft) del (convP_fft, h_fft, hdiv_fft) @@ -149,7 +149,7 @@ del (EP_fft) convK_fft = ( - 1. + 1.0 / 2 * ( -inner_prod(ux_fft, px_EP_fft) @@ -444,7 +444,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -487,7 +487,7 @@ khE = khE + 1 - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot, delta_i_plot): transferEKr = dset_transfer2D_EKr[it] transferEAr = dset_transfer2D_EAr[it] @@ -605,7 +605,7 @@ ax2.set_xscale("log") ax2.set_yscale("linear") - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot + 1, delta_i_plot): transferCPE = dset_transfer2D_CPE[it] PiCPE = cumsum_inv(transferCPE) * self.oper.deltak @@ -665,9 +665,9 @@ if self.params.f != 0: ugx_fft, ugy_fft, etag_fft = self.oper.uxuyetafft_from_qfft(q_fft) uax_fft, uay_fft, etaa_fft = self.oper.uxuyetafft_from_afft(a_fft) - # velocity influenced by linear terms - # u_infl_lin_x = udx_fft + uax_fft - # u_infl_lin_y = udy_fft + uay_fft + # velocity influenced by linear terms + # u_infl_lin_x = udx_fft + uax_fft + # u_infl_lin_y = udy_fft + uay_fft # compute flux of Charney PE Fq_fft = self.fnonlinfft_from_uxuy_funcfft(urx, ury, q_fft) @@ -808,7 +808,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -849,7 +849,7 @@ ax1.set_xscale("log") ax1.set_yscale("linear") - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot, delta_i_plot): transferEK = dset_transfer2D_EK[it] transferEA = dset_transfer2D_EA[it] @@ -899,7 +899,7 @@ ax2.set_xscale("log") ax2.set_yscale("linear") - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot + 1, delta_i_plot): transferCPE = dset_transfer2D_CPE[it] PiCPE = cumsum_inv(transferCPE) * self.oper.deltak @@ -940,10 +940,10 @@ } # NonQuad. K.E. - Quad A.P.E. transfer terms coeff = { - "uuu": -1., - "uvu": -1., - "vuv": -1., - "vvv": -1., + "uuu": -1.0, + "uvu": -1.0, + "vuv": -1.0, + "vvv": -1.0, "eeu": 0.5 * c2, "eev": 0.5 * c2, "uud": -0.5, @@ -984,7 +984,7 @@ *Tq_keys[key] ) - Tq_fft = dict.fromkeys(triad_key_modes[0], 0.) + Tq_fft = dict.fromkeys(triad_key_modes[0], 0.0) n_modes = triad_key_modes[0].shape[0] for i in range(n_modes): # GGG, GGA etc. k = triad_key_modes[0][i] @@ -1004,7 +1004,7 @@ ) Cq_coeff = {"ue": -c2, "ve": -c2} - Cq_fft = dict.fromkeys(dyad_key_modes[0], 0.) + Cq_fft = dict.fromkeys(dyad_key_modes[0], 0.0) n_modes = dyad_key_modes[0].shape[0] for i in range(n_modes): # GG, AG, aG, AA k = dyad_key_modes[0][i] @@ -1167,7 +1167,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -1227,5 +1227,5 @@ P = self.sim.params.forcing.forcing_rate norm = 1 if P == 0 else P - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot, delta_i_plot): @@ -1231,5 +1231,5 @@ for it in range(imin_plot, imax_plot, delta_i_plot): - transferEtot = 0. + transferEtot = 0.0 for key in ["GGG", "AGG", "GAAs", "GAAd", "AAA"]: transferEtot += h5file["Tq_" + key][it] PiEtot = cumsum_inv(transferEtot) * self.oper.deltak / norm @@ -1294,5 +1294,5 @@ Cflux_AA = cumsum_inv(exchange_AA) * self.oper.deltak Cflux_mean = cumsum_inv(exchange_mean) * self.oper.deltak - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot, delta_i_plot): @@ -1298,5 +1298,5 @@ for it in range(imin_plot, imax_plot, delta_i_plot): - exchangetot = 0. + exchangetot = 0.0 for key in ["GG", "AG", "aG", "AA"]: exchangetot += h5file["Cq_" + key][it] Cfluxtot = cumsum_inv(exchangetot) * self.oper.deltak @@ -1338,10 +1338,10 @@ } coeff = { - "uuu": -1., - "uvu": -1., - "vuv": -1., - "vvv": -1., + "uuu": -1.0, + "uvu": -1.0, + "vuv": -1.0, + "vvv": -1.0, "eeu": -c2, "eev": -c2, } diff --git a/fluidsim/solvers/sw1l/output/spectra.py b/fluidsim/solvers/sw1l/output/spectra.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9zcGVjdHJhLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC9zcGVjdHJhLnB5 100644 --- a/fluidsim/solvers/sw1l/output/spectra.py +++ b/fluidsim/solvers/sw1l/output/spectra.py @@ -129,7 +129,7 @@ spectrum2D_E = spectrum2D_EK + spectrum2D_EA spectrum2D_EKd = spectrum2D_EK - spectrum2D_EKr khE = self.oper.khE - coef_norm = khE ** (3.) + coef_norm = khE ** (3.0) self.axe.loglog(khE, spectrum2D_E * coef_norm, "k") self.axe.loglog(khE, spectrum2D_EK * coef_norm, "r") self.axe.loglog(khE, spectrum2D_EA * coef_norm, "b") @@ -169,7 +169,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -208,7 +208,7 @@ # min_to_plot = 1e-16 - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot + 1, delta_i_plot): E_K = dset_spectrum1Dkx_EK[it] + dset_spectrum1Dky_EK[it] # E_K[E_K<min_to_plot] = 0. @@ -242,7 +242,7 @@ kh_pos = kh[kh > 0] coef_norm = coef_norm[kh > 0] ax1.plot(kh_pos, kh_pos ** (-3) * coef_norm, "k--", linewidth=1) - ax1.plot(kh_pos, kh_pos ** (-5. / 3) * coef_norm, "k-.", linewidth=1) + ax1.plot(kh_pos, kh_pos ** (-5.0 / 3) * coef_norm, "k-.", linewidth=1) def plot2d( self, @@ -266,7 +266,7 @@ delta_t_save = np.mean(times[1:] - times[0:-1]) delta_i_plot = int(np.round(delta_t / delta_t_save)) - if delta_i_plot == 0 and delta_t != 0.: + if delta_i_plot == 0 and delta_t != 0.0: delta_i_plot = 1 delta_t = delta_i_plot * delta_t_save @@ -304,7 +304,7 @@ coef_norm = kh ** coef_compensate machine_zero = 1e-15 - if delta_t != 0.: + if delta_t != 0.0: for it in range(imin_plot, imax_plot + 1, delta_i_plot): for k, c in zip(keys, colors): dset = self._get_field_to_plot(it, k, h5file) @@ -351,7 +351,7 @@ coef_norm = coef_norm[kh > 0] ax1.plot(kh_pos, kh_pos ** (-2) * coef_norm, "k-", linewidth=1) ax1.plot(kh_pos, kh_pos ** (-3) * coef_norm, "k--", linewidth=1) - ax1.plot(kh_pos, kh_pos ** (-5. / 3) * coef_norm, "k-.", linewidth=1) + ax1.plot(kh_pos, kh_pos ** (-5.0 / 3) * coef_norm, "k-.", linewidth=1) font = {"family": "serif", "weight": "normal", "size": 16} postxt = kh.max() @@ -363,7 +363,7 @@ ) ax1.text( postxt, - postxt ** (-5. / 3 + coef_compensate), + postxt ** (-5.0 / 3 + coef_compensate), r"$k^{-5/3}$", fontdict=font, ) diff --git a/fluidsim/solvers/sw1l/output/test/test_print_stdout.py b/fluidsim/solvers/sw1l/output/test/test_print_stdout.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC90ZXN0L3Rlc3RfcHJpbnRfc3Rkb3V0LnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC90ZXN0L3Rlc3RfcHJpbnRfc3Rkb3V0LnB5 100644 --- a/fluidsim/solvers/sw1l/output/test/test_print_stdout.py +++ b/fluidsim/solvers/sw1l/output/test/test_print_stdout.py @@ -20,7 +20,7 @@ try: self.assertTrue( np.allclose( - self.dict_results["E"], dict_spatial_means["E"], atol=1.e-4 + self.dict_results["E"], dict_spatial_means["E"], atol=1.0e-4 ) ) except AssertionError: diff --git a/fluidsim/solvers/sw1l/output/test/test_spect_energy_budg.py b/fluidsim/solvers/sw1l/output/test/test_spect_energy_budg.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC90ZXN0L3Rlc3Rfc3BlY3RfZW5lcmd5X2J1ZGcucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC90ZXN0L3Rlc3Rfc3BlY3RfZW5lcmd5X2J1ZGcucHk= 100644 --- a/fluidsim/solvers/sw1l/output/test/test_spect_energy_budg.py +++ b/fluidsim/solvers/sw1l/output/test/test_spect_energy_budg.py @@ -79,7 +79,7 @@ b0_fft = module.norm_mode.bvec_fft[0] bp_fft = module.norm_mode.bvec_fft[1] bm_fft = module.norm_mode.bvec_fft[2] - ux_fft[0, 0] = uy_fft[0, 0] = eta_fft[0, 0] = 0. + ux_fft[0, 0] = uy_fft[0, 0] = eta_fft[0, 0] = 0.0 energy_UU = ( inner_prod(ux_fft, ux_fft) + inner_prod(uy_fft, uy_fft) @@ -122,9 +122,9 @@ key_modes, py_ux_fft_modes = module.norm_mode.normalmodefft_from_keyfft( "py_ux_fft" ) - ux_fft2 = uy_fft2 = eta_fft2 = py_ux_fft2 = 0. + ux_fft2 = uy_fft2 = eta_fft2 = py_ux_fft2 = 0.0 for mode in range(3): ux_fft2 += ux_fft_modes[mode] uy_fft2 += uy_fft_modes[mode] eta_fft2 += eta_fft_modes[mode] py_ux_fft2 += py_ux_fft_modes[mode] @@ -126,9 +126,9 @@ for mode in range(3): ux_fft2 += ux_fft_modes[mode] uy_fft2 += uy_fft_modes[mode] eta_fft2 += eta_fft_modes[mode] py_ux_fft2 += py_ux_fft_modes[mode] - ux_fft[0, 0] = uy_fft[0, 0] = eta_fft[0, 0] = py_ux_fft[0, 0] = 0. + ux_fft[0, 0] = uy_fft[0, 0] = eta_fft[0, 0] = py_ux_fft[0, 0] = 0.0 atol = 1e-15 rtol = 1e-14 np.testing.assert_allclose(ux_fft2, ux_fft, rtol, atol) @@ -145,7 +145,7 @@ self.solver + " does not use normal mode spect_energy_budg", ) - Cq_tot_modes = 0. + Cq_tot_modes = 0.0 for k in self.exchange_keys: Cq_tot_modes += self.dict_results[k] @@ -172,7 +172,7 @@ self.solver + "does not use normal mode spect_energy_budg", ) - Tq_tot_modes = 0. + Tq_tot_modes = 0.0 for k in self.transfer_keys: Tq_tot_modes += self.dict_results[k] @@ -204,8 +204,8 @@ TPdiv_exact = 0.25 * sim.params.c2 * inner_prod(div_fft, etaeta_fft) TPq_exact_coef = -0.5 * sim.params.c2 else: - TKdiv_exact = 0. - TPdiv_exact = 0. + TKdiv_exact = 0.0 + TPdiv_exact = 0.0 TPq_exact_coef = -sim.params.c2 etaux_fft = sim.oper.fft2(eta * ux) @@ -315,7 +315,7 @@ self.solver + "does not use normal mode spect_energy_budg", ) - Tq_tot_modes = 0. + Tq_tot_modes = 0.0 for k in self.transfer_keys: Tq_tot_modes += self.dict_results[k] diff --git a/fluidsim/solvers/sw1l/output/util_pythran.py b/fluidsim/solvers/sw1l/output/util_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC91dGlsX3B5dGhyYW4ucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL291dHB1dC91dGlsX3B5dGhyYW4ucHk= 100644 --- a/fluidsim/solvers/sw1l/output/util_pythran.py +++ b/fluidsim/solvers/sw1l/output/util_pythran.py @@ -15,8 +15,8 @@ qmat = np.array( [ [ - -1j * 2. ** 0.5 * ck * KY, + -1j * 2.0 ** 0.5 * ck * KY, +1j * f * KY + KX * sigma, +1j * f * KY - KX * sigma, ], [ @@ -19,8 +19,8 @@ +1j * f * KY + KX * sigma, +1j * f * KY - KX * sigma, ], [ - +1j * 2. ** 0.5 * ck * KX, + +1j * 2.0 ** 0.5 * ck * KX, -1j * f * KX + KY * sigma, -1j * f * KX - KY * sigma, ], @@ -24,5 +24,5 @@ -1j * f * KX + KY * sigma, -1j * f * KX - KY * sigma, ], - [2. ** 0.5 * f * K, c * K2, c * K2], + [2.0 ** 0.5 * f * K, c * K2, c * K2], ] @@ -28,5 +28,5 @@ ] - ) / (2. ** 0.5 * sigma * K_not0) + ) / (2.0 ** 0.5 * sigma * K_not0) return qmat diff --git a/fluidsim/solvers/sw1l/solver.py b/fluidsim/solvers/sw1l/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/sw1l/solver.py +++ b/fluidsim/solvers/sw1l/solver.py @@ -258,7 +258,7 @@ """Compute nonlinear tendencies for the sw1l model""" F1x, F1y = compute_Frot(rot, ux, uy, f) gradx_fft, grady_fft = gradfft_from_fft( - fft2(c2 * eta + (ux ** 2 + uy ** 2) / 2.) + fft2(c2 * eta + (ux ** 2 + uy ** 2) / 2.0) ) dealiasing(gradx_fft, grady_fft) Fx_fft[:] = fft2(F1x) - gradx_fft @@ -286,6 +286,6 @@ delta_x = params.oper.Lx / params.oper.nx params.nu_8 = ( - 2. * 10e-1 * params.forcing.forcing_rate ** (1. / 3) * delta_x ** 8 + 2.0 * 10e-1 * params.forcing.forcing_rate ** (1.0 / 3) * delta_x ** 8 ) @@ -290,6 +290,6 @@ ) - params.time_stepping.t_end = 1. + params.time_stepping.t_end = 1.0 # params.time_stepping.USE_CFL = False # params.time_stepping.deltat0 = 0.01 @@ -307,7 +307,7 @@ params.output.periods_save.pdf = 0.5 params.output.periods_save.time_signals_fft = True - params.output.periods_plot.phys_fields = 0. + params.output.periods_plot.phys_fields = 0.0 params.output.phys_fields.field_to_plot = "eta" diff --git a/fluidsim/solvers/sw1l/state.py b/fluidsim/solvers/sw1l/state.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3N0YXRlLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3N0YXRlLnB5 100644 --- a/fluidsim/solvers/sw1l/state.py +++ b/fluidsim/solvers/sw1l/state.py @@ -115,7 +115,7 @@ if mpi.rank == 0: print(to_print + "\nreturn an array of zeros.") - result = self.oper.create_arrayX(value=0.) + result = self.oper.create_arrayX(value=0.0) if SAVE_IN_DICT: self.vars_computed[key] = result @@ -293,10 +293,10 @@ eta_fft = old_div( ( - 1.j * self.oper.KX * tempx_fft / K2_not0 - + 1.j * self.oper.KY * tempy_fft / K2_not0 + 1.0j * self.oper.KX * tempx_fft / K2_not0 + + 1.0j * self.oper.KY * tempy_fft / K2_not0 - old_div(uu2_fft, 2) ), self.params.c2, ) if mpi.rank == 0: @@ -298,9 +298,9 @@ - old_div(uu2_fft, 2) ), self.params.c2, ) if mpi.rank == 0: - eta_fft[0, 0] = 0. + eta_fft[0, 0] = 0.0 self.oper.dealiasing(eta_fft) return eta_fft diff --git a/fluidsim/solvers/sw1l/test_operators.py b/fluidsim/solvers/sw1l/test_operators.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3Rlc3Rfb3BlcmF0b3JzLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3Rlc3Rfb3BlcmF0b3JzLnB5 100644 --- a/fluidsim/solvers/sw1l/test_operators.py +++ b/fluidsim/solvers/sw1l/test_operators.py @@ -11,7 +11,7 @@ from .operators import OperatorsPseudoSpectralSW1L -def create_oper(type_fft=None, coef_dealiasing=2. / 3): +def create_oper(type_fft=None, coef_dealiasing=2.0 / 3): params = ParamContainer(tag="params") @@ -29,7 +29,7 @@ params.oper.nx = nh params.oper.ny = nh - Lh = 6. + Lh = 6.0 params.oper.Lx = Lh params.oper.Ly = Lh @@ -59,7 +59,7 @@ ap_fft = oper.create_arrayK_random() am_fft = oper.create_arrayK_random() if mpi.rank == 0: - q_fft[0, 0] = ap_fft[0, 0] = am_fft[0, 0] = 0. + q_fft[0, 0] = ap_fft[0, 0] = am_fft[0, 0] = 0.0 ux_fft, uy_fft, eta_fft = oper.uxuyetafft_from_qapamfft( q_fft, ap_fft, am_fft diff --git a/fluidsim/solvers/sw1l/util_oper_pythran.py b/fluidsim/solvers/sw1l/util_oper_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3V0aWxfb3Blcl9weXRocmFuLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3V0aWxfb3Blcl9weXRocmFuLnB5 100644 --- a/fluidsim/solvers/sw1l/util_oper_pythran.py +++ b/fluidsim/solvers/sw1l/util_oper_pythran.py @@ -23,8 +23,8 @@ for i1 in range(n1): if i0 == 0 and i1 == 0 and rank == 0: q_fft[i0, i1] = 0 - ap_fft[i0, i1] = ux_fft[0, 0] + 1.j * uy_fft[0, 0] - am_fft[i0, i1] = ux_fft[0, 0] - 1.j * uy_fft[0, 0] + ap_fft[i0, i1] = ux_fft[0, 0] + 1.0j * uy_fft[0, 0] + am_fft[i0, i1] = ux_fft[0, 0] - 1.0j * uy_fft[0, 0] else: rot_fft = 1j * ( @@ -54,8 +54,8 @@ for i1 in range(n1): if i0 == 0 and i1 == 0 and rank == 0: q_fft[i0, i1] = 0 - ap_fft[i0, i1] = ux_fft[0, 0] + 1.j * uy_fft[0, 0] - am_fft[i0, i1] = ux_fft[0, 0] - 1.j * uy_fft[0, 0] + ap_fft[i0, i1] = ux_fft[0, 0] + 1.0j * uy_fft[0, 0] + am_fft[i0, i1] = ux_fft[0, 0] - 1.0j * uy_fft[0, 0] else: q_fft[i0, i1] = 1j * ( KX[i0, i1] * uy_fft[i0, i1] - KY[i0, i1] * ux_fft[i0, i1] diff --git a/fluidsim/solvers/sw1l/util_pythran.py b/fluidsim/solvers/sw1l/util_pythran.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3V0aWxfcHl0aHJhbi5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy9zdzFsL3V0aWxfcHl0aHJhbi5weQ== 100644 --- a/fluidsim/solvers/sw1l/util_pythran.py +++ b/fluidsim/solvers/sw1l/util_pythran.py @@ -1,4 +1,3 @@ - # pythran export compute_Frot( # float64[][], float64[][], float64[][], # float or int) diff --git a/fluidsim/solvers/test/test_ns.py b/fluidsim/solvers/test/test_ns.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy90ZXN0L3Rlc3RfbnMucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy90ZXN0L3Rlc3RfbnMucHk= 100644 --- a/fluidsim/solvers/test/test_ns.py +++ b/fluidsim/solvers/test/test_ns.py @@ -30,7 +30,7 @@ params.oper.nx = nh params.oper.ny = nh - Lh = 6. + Lh = 6.0 params.oper.Lx = Lh params.oper.Ly = Lh @@ -34,6 +34,6 @@ params.oper.Lx = Lh params.oper.Ly = Lh - params.oper.coef_dealiasing = 2. / 3 + params.oper.coef_dealiasing = 2.0 / 3 if dissipation_enable: @@ -38,5 +38,5 @@ if dissipation_enable: - params.nu_8 = 2. + params.nu_8 = 2.0 try: @@ -41,7 +41,7 @@ try: - params.f = 1. - params.c2 = 200. + params.f = 1.0 + params.c2 = 200.0 except AttributeError: pass @@ -118,7 +118,7 @@ Frot_fft = tendencies_fft.get_var("rot_fft") rot_fft = state_spect.get_var("rot_fft") - T_rot = (Frot_fft.conj() * rot_fft + Frot_fft * rot_fft.conj()).real / 2. + T_rot = (Frot_fft.conj() * rot_fft + Frot_fft * rot_fft.conj()).real / 2.0 sum_T = oper.sum_wavenumbers(T_rot) self.assertZero(sum_T, zero_places) @@ -149,7 +149,7 @@ b_fft = state_spect.get_var("b_fft") transferEK = np.real(ux_fft.conj() * Fx_fft + uy_fft.conj() * Fy_fft) - transferEA = (1. / self.sim.params.N ** 2) * np.real( + transferEA = (1.0 / self.sim.params.N ** 2) * np.real( b_fft.conj() * Fb_fft ) diff --git a/fluidsim/solvers/test/test_sw1l.py b/fluidsim/solvers/test/test_sw1l.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy90ZXN0L3Rlc3Rfc3cxbC5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy90ZXN0L3Rlc3Rfc3cxbC5weQ== 100644 --- a/fluidsim/solvers/test/test_sw1l.py +++ b/fluidsim/solvers/test/test_sw1l.py @@ -41,7 +41,7 @@ ) q_fft = self.sim.state.get_var("q_fft") - T_q = (Fq_fft.conj() * q_fft + Fq_fft * q_fft.conj()).real / 2. + T_q = (Fq_fft.conj() * q_fft + Fq_fft * q_fft.conj()).real / 2.0 sum_T = oper.sum_wavenumbers(T_q) self.assertZero(sum_T, 5, warn=False) @@ -84,7 +84,7 @@ try: Fq_fft = tendencies_fft.get_var("q_fft") except ValueError: - Fq_fft = self.sim.oper.create_arrayK(value=0.j) + Fq_fft = self.sim.oper.create_arrayK(value=0.0j) return self.sim.oper.uxuyetafft_from_qapamfft(Fq_fft, Fap_fft, Fam_fft) diff --git a/fluidsim/solvers/waves2d/solver.py b/fluidsim/solvers/waves2d/solver.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vc29sdmVycy93YXZlczJkL3NvbHZlci5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vc29sdmVycy93YXZlczJkL3NvbHZlci5weQ== 100644 --- a/fluidsim/solvers/waves2d/solver.py +++ b/fluidsim/solvers/waves2d/solver.py @@ -109,7 +109,7 @@ """This static method is used to complete the *params* container. """ SimulBasePseudoSpectral._complete_params_with_default(params) - attribs = {"c2": 1., "f": 0} + attribs = {"c2": 1.0, "f": 0} params._set_attribs(attribs) @classmethod @@ -129,7 +129,7 @@ else: tendencies_fft = old - tendencies_fft[:] = 0. + tendencies_fft[:] = 0.0 return tendencies_fft @@ -138,7 +138,7 @@ if key == "f_fft": omega = self.oper.create_arrayK(value=0) elif key == "g_fft": - omega = 1.j * np.sqrt( + omega = 1.0j * np.sqrt( self.params.f ** 2 + self.params.c2 * self.oper.K2 ) return omega @@ -166,5 +166,5 @@ delta_x = old_div(params.oper.Lx, params.oper.nx) params.nu_8 = ( - 2. + 2.0 * 10e-1 @@ -170,5 +170,5 @@ * 10e-1 - * params.forcing.forcing_rate ** (old_div(1., 3)) + * params.forcing.forcing_rate ** (old_div(1.0, 3)) * delta_x ** 8 ) @@ -172,7 +172,7 @@ * delta_x ** 8 ) - params.time_stepping.t_end = 1. + params.time_stepping.t_end = 1.0 params.time_stepping.USE_CFL = False params.init_fields.type = "noise" diff --git a/fluidsim/util/console/bench_analysis.py b/fluidsim/util/console/bench_analysis.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vdXRpbC9jb25zb2xlL2JlbmNoX2FuYWx5c2lzLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vdXRpbC9jb25zb2xlL2JlbmNoX2FuYWx5c2lzLnB5 100644 --- a/fluidsim/util/console/bench_analysis.py +++ b/fluidsim/util/console/bench_analysis.py @@ -20,6 +20,9 @@ def load_bench(path_dir, solver, hostname="any"): """Load benchmarks results saved as JSON files.""" + if solver.startswith("fluidsim"): + solver = solver.split(".", 1)[1] + dicts = [] for path in glob(path_dir + "/result_bench_{}*.json".format(solver)): with open(path) as f: diff --git a/fluidsim/util/console/profile.py b/fluidsim/util/console/profile.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vdXRpbC9jb25zb2xlL3Byb2ZpbGUucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vdXRpbC9jb25zb2xlL3Byb2ZpbGUucHk= 100644 --- a/fluidsim/util/console/profile.py +++ b/fluidsim/util/console/profile.py @@ -38,7 +38,7 @@ description = "Profile time-elapsed in various function calls" -def run_profile(sim, nb_dim=2, path_results=".", plot=False): +def run_profile(sim, nb_dim=2, path_results=".", plot=False, verbose=True): """Profile a simulation run and save the results in `profile.pstats` Parameters @@ -53,8 +53,9 @@ """ path, t_as_str = get_path_file(sim, path_results, "profile", ".pstats") t0 = time() - cProfile.runctx("sim.time_stepping.start()", globals(), locals(), path) + with stdout_redirected(not verbose): + cProfile.runctx("sim.time_stepping.start()", globals(), locals(), path) t_end = time() if sim.oper.rank == 0: times = analyze_stats(path, nb_dim, plot) @@ -57,9 +58,11 @@ t_end = time() if sim.oper.rank == 0: times = analyze_stats(path, nb_dim, plot) - - print("\nelapsed time = {:.3f} s".format(t_end - t0)) - + print(f"\nelapsed time = {t_end - t0:.3f} s") + name_solver = sim.__module__.rsplit(".", maxsplit=1)[0] + print( + f"To display the results:\nfluidsim-profile -p -sf {path} -s {name_solver}" + ) print( "\nwith gprof2dot and graphviz (command dot):\n" @@ -64,4 +67,4 @@ print( "\nwith gprof2dot and graphviz (command dot):\n" - "gprof2dot -f pstats {} | dot -Tpng -o profile.png".format(path) + f"gprof2dot -f pstats {path} | dot -Tpng -o profile.png" ) @@ -67,4 +70,5 @@ ) + else: # Retain only rank 0 profiles os.remove(path) @@ -120,7 +124,7 @@ nb_dim = int(dim[0]) - with stdout_redirected(): + with stdout_redirected(not verbose): sim = Simul(params) try: @@ -124,16 +128,7 @@ sim = Simul(params) try: - if verbose: - run_profile(sim, nb_dim, path_dir) - else: - with stdout_redirected(): - path = run_profile(sim, nb_dim, path_dir) - - print( - "To display the results:\n" "fluidsim-profile -p -sf " + path - ) - + run_profile(sim, nb_dim, path_dir, verbose=verbose) except Exception as e: if raise_error: raise @@ -185,7 +180,7 @@ def run(args): """Run `fluidsim profile` command.""" - if args.stats_file is not None: + if args.stats_file is not None and args.solver is None: # get solver from name... Not clean at all... tmp = os.path.split(args.stats_file)[-1] args.solver = tmp.split("result_profile_")[-1].split("_")[0] @@ -245,7 +240,7 @@ ax=None, times_descending=False, for_latex=False, - **kwargs + **kwargs, ): """Plot a pie chart """ percentages = [] @@ -323,7 +318,7 @@ if nb_dim not in (2, 3): raise NotImplementedError - total_time = 0. + total_time = 0.0 for key, value in stats.stats.items(): time = value[2] total_time += time @@ -332,7 +327,7 @@ key_fft = "fft{}d".format(nb_dim) kinds = _kinds + (key_fft,) - times = {k: 0. for k in kinds} + times = {k: 0.0 for k in kinds} for key, value in stats.stats.items(): name = key[2] diff --git a/fluidsim/util/console/test_profile.py b/fluidsim/util/console/test_profile.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vdXRpbC9jb25zb2xlL3Rlc3RfcHJvZmlsZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vdXRpbC9jb25zb2xlL3Rlc3RfcHJvZmlsZS5weQ== 100644 --- a/fluidsim/util/console/test_profile.py +++ b/fluidsim/util/console/test_profile.py @@ -1,4 +1,3 @@ - import unittest import sys from glob import glob diff --git a/fluidsim/util/console/util.py b/fluidsim/util/console/util.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vdXRpbC9jb25zb2xlL3V0aWwucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vdXRpbC9jb25zb2xlL3V0aWwucHk= 100644 --- a/fluidsim/util/console/util.py +++ b/fluidsim/util/console/util.py @@ -125,5 +125,5 @@ # params.forcing.nkmin_forcing = 3 # params.forcing.forcing_rate = 1. - params.nu_8 = 1. + params.nu_8 = 1.0 try: @@ -129,7 +129,7 @@ try: - params.f = 1. - params.c2 = 200. + params.f = 1.0 + params.c2 = 200.0 except AttributeError: pass try: @@ -132,8 +132,8 @@ except AttributeError: pass try: - params.N = 1. + params.N = 1.0 except AttributeError: pass @@ -137,7 +137,7 @@ except AttributeError: pass - params.time_stepping.deltat0 = 1.e-6 + params.time_stepping.deltat0 = 1.0e-6 params.time_stepping.USE_CFL = False params.time_stepping.it_end = it_end params.time_stepping.USE_T_END = False @@ -193,5 +193,5 @@ # params.forcing.nkmin_forcing = 4 # params.forcing.forcing_rate = 1. - params.nu_8 = 1. + params.nu_8 = 1.0 try: @@ -197,7 +197,7 @@ try: - params.f = 1. - params.c2 = 200. + params.f = 1.0 + params.c2 = 200.0 except AttributeError: pass try: @@ -200,11 +200,11 @@ except AttributeError: pass try: - params.N = 1. + params.N = 1.0 except AttributeError: pass if "noise" in params.init_fields.available_types: params.init_fields.type = "noise" @@ -205,10 +205,10 @@ except AttributeError: pass if "noise" in params.init_fields.available_types: params.init_fields.type = "noise" - params.time_stepping.deltat0 = 1.e-4 + params.time_stepping.deltat0 = 1.0e-4 params.time_stepping.USE_CFL = False params.time_stepping.it_end = it_end params.time_stepping.USE_T_END = False @@ -309,7 +309,7 @@ pid = str(os.getpid()) nb_proc = "np={}".format(mpi.nb_proc) type_fft = sim.params.oper.type_fft.split(".")[-1].replace("_", "-") - nfile = ( + name_file = ( "_".join( [ "result", @@ -324,7 +324,7 @@ + ext ) - path = os.path.join(path_results, nfile) + path = os.path.join(path_results, name_file) return path, t_as_str diff --git a/fluidsim/util/testing.py b/fluidsim/util/testing.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vdXRpbC90ZXN0aW5nLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vdXRpbC90ZXN0aW5nLnB5 100644 --- a/fluidsim/util/testing.py +++ b/fluidsim/util/testing.py @@ -151,6 +151,7 @@ """ suite = unittest.TestSuite() for module in modules: + module = module.replace(os.path.sep, ".") module = import_module(module) tests = unittest.defaultTestLoader.loadTestsFromModule(module) suite.addTests(tests) diff --git a/fluidsim/util/util.py b/fluidsim/util/util.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_Zmx1aWRzaW0vdXRpbC91dGlsLnB5..d518cba80100a7dda4c0ac799c06b46c6fee5871_Zmx1aWRzaW0vdXRpbC91dGlsLnB5 100644 --- a/fluidsim/util/util.py +++ b/fluidsim/util/util.py @@ -64,6 +64,16 @@ return sorted(keys) -def module_solver_from_key(key=None, package="fluidsim.solvers"): +def _get_key_package(key, package): + """Compute (key, package) from (key, package) with default value""" + if package is None: + if key.startswith("fluidsim"): + package, key = key.split(".", 1) + else: + package = "fluidsim.solvers" + return key, package + + +def module_solver_from_key(key=None, package=None): """Return the string corresponding to a module solver.""" key = key.lower() @@ -68,5 +78,7 @@ """Return the string corresponding to a module solver.""" key = key.lower() + key, package = _get_key_package(key, package) + keys = available_solver_keys(package) if key in keys: @@ -83,7 +95,7 @@ return module_solver -def import_module_solver_from_key(key=None, package="fluidsim.solvers"): +def import_module_solver_from_key(key=None, package=None): """Import and reload the solver. Parameters @@ -93,6 +105,8 @@ The short name of a solver. """ + key, package = _get_key_package(key, package) + return import_module(module_solver_from_key(key, package)) @@ -96,9 +110,9 @@ return import_module(module_solver_from_key(key, package)) -def get_dim_from_solver_key(key, package="fluidsim.solvers"): +def get_dim_from_solver_key(key, package=None): """Try to guess the dimension from the solver key (via the operator name). """ cls = import_simul_class_from_key(key, package) info = cls.InfoSolver() @@ -100,6 +114,12 @@ """Try to guess the dimension from the solver key (via the operator name). """ cls = import_simul_class_from_key(key, package) info = cls.InfoSolver() + class_name = info.classes.Operators.class_name + + # special cases: + if class_name == "OperatorsPseudoSpectralSW1L": + return "2" + for dim in range(4): @@ -105,5 +125,5 @@ for dim in range(4): - if str(dim) in info.classes.Operators.class_name: + if str(dim) in class_name: return str(dim) raise NotImplementedError( @@ -107,8 +127,7 @@ return str(dim) raise NotImplementedError( - "Cannot deduce dimension of the solver from the name " - + info.classes.Operators.class_name + "Cannot deduce dimension of the solver from the name " + class_name ) @@ -112,7 +131,7 @@ ) -def import_simul_class_from_key(key, package="fluidsim.solvers"): +def import_simul_class_from_key(key, package=None): """Import and reload a simul class. Parameters @@ -139,7 +158,7 @@ class ModulesSolvers(dict): """Dictionary to gather imported solvers.""" - def __init__(self, names_solvers, package="fluidsim.solvers"): + def __init__(self, names_solvers, package=None): for key in names_solvers: self[key] = import_module_solver_from_key(key, package) @@ -204,12 +223,9 @@ params.output.HAS_TO_SAVE = False params.output.ONLINE_PLOT_OK = False - if params.forcing.type.startswith("in_script"): - params.forcing.enable = False - try: params.preprocess.enable = False except AttributeError: pass fix_old_params(params) @@ -210,9 +226,10 @@ try: params.preprocess.enable = False except AttributeError: pass fix_old_params(params) + params.forcing.enable = False sim = solver.Simul(params) return sim @@ -361,7 +378,7 @@ words = line.split() t_s = float(words[6]) - # in order to get the informations at the end of the file, + # in order to get the information at the end of the file, # we do not want to read the full file... file_stdout.seek(0, 2) # go to the end nb_caract = file_stdout.tell() @@ -524,7 +541,7 @@ if len(self.paths) == 1: path = self.paths[0] else: - t_s = -1. + t_s = -1.0 for path_temp in self.paths: t_s_temp, t_e = times_start_end_from_path(path_temp) if t_s_temp > t_s: diff --git a/pylintrc b/pylintrc index 9bccb25fe016aed4b58d7978626bbeb12912e6db_cHlsaW50cmM=..d518cba80100a7dda4c0ac799c06b46c6fee5871_cHlsaW50cmM= 100644 --- a/pylintrc +++ b/pylintrc @@ -48,7 +48,7 @@ # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=C0103 +disable=C0103,W0621,W0212,C0330,W1202,W1203 [REPORTS] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_cHlwcm9qZWN0LnRvbWw= --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[build-system] +requires = ["setuptools", "wheel", "numpy", "fluidpythran>=0.0.4"] \ No newline at end of file diff --git a/scripts/ns2d.strat/coeff_diss.py b/scripts/ns2d.strat/coeff_diss.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_c2NyaXB0cy9uczJkLnN0cmF0L2NvZWZmX2Rpc3MucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L2NvZWZmX2Rpc3MucHk= 100644 --- a/scripts/ns2d.strat/coeff_diss.py +++ b/scripts/ns2d.strat/coeff_diss.py @@ -1,3 +1,4 @@ + """ coeff_diss.py ============= @@ -13,10 +14,8 @@ 4. Change path in `coeff_diss.py` """ -from __future__ import print_function - import os import h5py import shutil import numpy as np import matplotlib.pyplot as plt @@ -18,8 +17,10 @@ import os import h5py import shutil import numpy as np import matplotlib.pyplot as plt +import argparse + from math import pi from glob import glob @@ -31,8 +32,30 @@ from ns2dstrat_lmode import make_parameters_simulation, modify_parameters +### PARAMETERS ### +parser = argparse.ArgumentParser() +parser.add_argument("gamma", type=float) +args = parser.parse_args() + + +# CONDITIONS +nb_wavenumbers_y = 16 +threshold_ratio = 1e1 +min_factor = 0.7 + +# SIMULATION +gamma = args.gamma +F = np.sin(pi / 4) # F = omega_l / N +sigma = 1 # sigma = omega_l / (pi * f_cf); f_cf freq time correlation forcing in s-1 +nu_8 = 1e-16 +NO_SHEAR_MODES = False +t_end = 8. + +PLOT_FIGURES = False +################### + def load_mean_spect_energy_budg(sim, tmin=0, tmax=1000): """ Loads data spect_energy_budget. It computes the mean between tmin and tmax. """ @@ -34,9 +57,9 @@ def load_mean_spect_energy_budg(sim, tmin=0, tmax=1000): """ Loads data spect_energy_budget. It computes the mean between tmin and tmax. """ - print("path_file", sim.output.spect_energy_budg.path_file) + with h5py.File(sim.output.spect_energy_budg.path_file, "r") as f: times = f["times"].value kxE = f["kxE"].value @@ -133,23 +156,7 @@ pass return sim - - -################################################# -### Parameters script ### -# Parameters simulations -gamma = 1. -F = np.sin(pi / 4) # F = omega_l / N -sigma = 1 # sigma = omega_l / (pi * f_cf); f_cf freq time correlation forcing in s-1 -nu_8 = 1e-16 - -coef_modif_resol = 3 / 2 - -NO_SHEAR_MODES = False -min_factor = 0.7 - -# Notation for gamma -gamma_not = str(gamma) -if "." in gamma_not: - gamma_not = gamma_not.split(".")[0] + "_" + gamma_not.split(".")[1] +def _compute_ikdiss(dissE_kx, dissE_ky): + idx_diss_max = np.argmax(abs(dissE_kx)) + idy_diss_max = np.argmax(abs(dissE_ky)) @@ -155,25 +162,3 @@ -# Create directory in DataSim -path_root_dir = "/fsnet/project/meige/2015/15DELDUCA/DataSim" -path_dir = os.path.join(path_root_dir, "Coef_Diss_gamma{}".format(gamma_not)) -if mpi.rank == 0 and not os.path.exists(path_dir): - os.mkdir(path_dir) - -# Check list simulations in directory -paths_sim = sorted(glob(os.path.join(path_dir, "NS*"))) - -# Write in .txt file -path_file = os.path.join(path_dir, "results.txt") - -# import sys -# sys.exit() - -# paths_sim = [] -# resolutions = [] -# dissipations = [] - -PLOT_FIGURES = True -PLOT_FIGURES = PLOT_FIGURES and mpi.rank == 0 - -if len(paths_sim) == 0: + return idx_diss_max, idy_diss_max @@ -179,20 +164,5 @@ - params = make_parameters_simulation(gamma, F, sigma, nu_8, t_end=8., NO_SHEAR_MODES=NO_SHEAR_MODES) - sim = Simul(params) - - # Normalization of the field and start - sim = normalization_initialized_field(sim) - - sim.time_stepping.start() - - # Parameters condition - nb_wavenumbers_y = 8 - nb_wavenumbers_x = nb_wavenumbers_y * (sim.params.oper.nx // sim.params.oper.ny) - - # Creation time and energy array - time_total = 0 - energies = [] - viscosities = [] - - time_total += sim.time_stepping.t +def _compute_ikmax(kxE, kyE): + idx_dealiasing = np.argmin(abs(kxE - sim.oper.kxmax_dealiasing)) + idy_dealiasing = np.argmin(abs(kyE - sim.oper.kymax_dealiasing)) @@ -198,15 +168,3 @@ - dict_spatial = sim.output.spatial_means.load() - energy = dict_spatial["E"] - energy = np.mean(energy[len(energy) // 2:]) - energies.append(energy) - viscosities.append(sim.params.nu_8) - - # Compute injection of energy begin simulation - pe_k = dict_spatial["PK_tot"] - pe_a = dict_spatial["PA_tot"] - pe_tot = pe_k + pe_a - print("pe_tot", pe_tot[2]) - - injection_energy_0 = pe_tot[2] + return idx_dealiasing, idy_dealiasing @@ -212,8 +170,5 @@ - # Compute the data spectra energy budget - kxE, kyE, dissE_kx, dissE_ky = load_mean_spect_energy_budg(sim, tmin=2., tmax=1000) - - # Loads the spectral energy budget - kxmax_dealiasing = sim.oper.kxmax_dealiasing - kymax_dealiasing = sim.oper.kymax_dealiasing +def compute_delta_ik(kxE, kyE, dissE_kx, dissE_ky): + idx_diss_max, idy_diss_max = _compute_ikdiss(dissE_kx, dissE_ky) + idx_dealiasing, idy_dealiasing = _compute_ikmax(kxE, kyE) @@ -219,12 +174,4 @@ - # Computes index kmax_dealiasing & kmax_dissipation - idx_dealiasing = np.argmin(abs(kxE - kxmax_dealiasing)) - idy_dealiasing = np.argmin(abs(kyE - kymax_dealiasing)) - - # Compute difference - diff, idx_diss_max, idy_diss_max = compute_diff(idx_dealiasing, idy_dealiasing, dissE_kx, dissE_ky) - - # idx_target = idx_dealiasing - (nb_wavenumbers_x - 1) idy_target = idy_dealiasing - (nb_wavenumbers_y - 1) @@ -228,4 +175,6 @@ idx_target = idx_dealiasing - (nb_wavenumbers_x - 1) idy_target = idy_dealiasing - (nb_wavenumbers_y - 1) + delta_ikx = idx_target - idx_diss_max + delta_iky = idy_target - idy_diss_max @@ -231,13 +180,3 @@ - # Plot dissipation - if PLOT_FIGURES: - plt.ion() - fig, ax = plt.subplots() - ax.set_title("$D(k_y)$") - ax.set_xlabel("$k_y$") - ax.set_ylabel("$D(k_y)$") - ax.plot(kyE, dissE_ky, label="nu8 = {:.2e}, diff = {}".format( - sim.params.nu_8, abs(idy_diss_max - idy_dealiasing))) - ax.plot(kymax_dealiasing, 0, 'xr') - ax.axvline(x=sim.oper.deltaky * idy_target, color="k") + return idx_target, idy_target, delta_ikx, delta_iky @@ -243,10 +182,7 @@ - fig2, ax2 = plt.subplots() - ax2.set_title("$D(k_x)$") - ax2.set_xlabel("$k_x$") - ax2.set_ylabel("$D(k_x)$") - ax2.plot(kxE, dissE_kx, label="nu8 = {:.2e}, diff = {}".format( - sim.params.nu_8, abs(idx_diss_max - idx_dealiasing))) - ax2.plot(kxmax_dealiasing, 0, 'xr') - ax2.axvline(x=sim.oper.deltakx * idx_target, color="k") +def compute_energy_spatial(sim): + """ Compute energy without energy in shear modes """ + dict_spatial = sim.output.spatial_means.load() + E = dict_spatial["E"] - dict_spatial["E_shear"] + t = dict_spatial["t"] @@ -252,7 +188,6 @@ - ax.legend() - ax2.legend() - - fig.canvas.draw() - fig2.canvas.draw() + PK_tot = dict_spatial["PK_tot"] + PA_tot = dict_spatial["PA_tot"] + P_tot = PK_tot + PA_tot + return E, t, P_tot @@ -258,8 +193,4 @@ - plt.pause(1e-3) - - # Dissipation vs time - fig3, ax3 = plt.subplots() - ax3.set_xlabel("times") - ax3.set_ylabel(r"$\nu_8$") +def modify_factor(sim): + params = _deepcopy(sim.params) @@ -265,3 +196,5 @@ - ax3.plot(time_total, viscosities[-1], '.') + nu_8_old = params.nu_8 + params_old = sim.params + sim_old = sim @@ -267,7 +200,5 @@ - # Energy Vs time - fig4, ax4 = plt.subplots() - ax4.plot(time_total, energy, '.') - ax4.set_xlabel("times") - ax4.set_ylabel("Energy") + params.nu_8 = params.nu_8 * factor + params.init_fields.type = 'in_script' + params.time_stepping.t_end = t_end @@ -273,8 +204,4 @@ - # Factor Vs time - fig5, ax5 = plt.subplots() - ax5.plot(time_total, 1, '.') - ax5.set_xlabel("times") - ax5.set_ylabel("Factor") + return params, nu_8_old @@ -279,17 +206,6 @@ - it = 0 - p = 1 - # Check ... - while True: - - if mpi.rank == 0: - # Define conditions - diff_x = abs(idx_dealiasing - idx_diss_max) - diff_y = abs(idy_dealiasing - idy_diss_max) - print("diff_x", diff_x) - print("diff_y", diff_y) - - ratio_x = dissE_kx[idx_diss_max] / dissE_kx[idx_dealiasing - 1] - ratio_y = dissE_ky[idy_diss_max] / dissE_ky[idy_dealiasing - 1] +def write_to_file(path, to_print, mode="a"): + with open(path, mode) as f: + f.write(to_print) @@ -295,10 +211,8 @@ - cond_ratio_x = ratio_x > 1e1 - cond_ratio_y = ratio_y > 1e1 - print("cond_ratio_x", ratio_x) - print("cond_ratio_y", ratio_y) - - diff_x_target = abs(idx_target - idx_diss_max) - diff_y_target = abs(idy_target - idy_diss_max) - diff_target = max(diff_x_target, diff_y_target) +def make_float_value_for_path(value): + value_not = str(value) + if "." in value_not: + return value_not.split(".")[0] + "_" + value_not.split(".")[1] + else: + return value_not @@ -304,9 +218,5 @@ - if time_total > 1000: - print( - "The stationarity has not " + \ - "reached after {} simulations.".format(it_)) - break - # Check ratio D(k_peak) / D(k_max - 1) - if cond_ratio_x and cond_ratio_y: +def check_dissipation(): + ratio_x = dissE_kx[idx_diss_max] / dissE_kx[idx_dealiasing - 1] + ratio_y = dissE_ky[idy_diss_max] / dissE_ky[idy_dealiasing - 1] @@ -312,8 +222,3 @@ - # Check differences - if diff_x > nb_wavenumbers_x and diff_y > nb_wavenumbers_y: - print("diff_target = ", diff_target) - print("p", p) - factor = max(((nb_wavenumbers_y / 2) / diff_target) ** (0.2), min_factor) - print("factor = ", factor) + idx_target, idy_target, delta_ikx, delta_iky = compute_delta_ik(kxE, kyE, dissE_kx, dissE_ky) @@ -319,12 +224,7 @@ - p += 1 - should_I_stop = False - else: - print("Checking stationarity... with nu8 = {}".format(params_old.nu_8)) - dict_spatial = sim.output.spatial_means.load() - E = dict_spatial["E"] - t = dict_spatial["t"] - ratio = np.mean(np.diff(E[2:]) / np.diff(t[2:])) - print("ratio_energy = ", ratio) - print("injection_energy_0 = ", injection_energy_0) + if time_total > 1000: + print( + "The stationarity has not " + \ + "reached after {} simulations.".format(it)) + should_I_stop = "non_stationarity" @@ -330,8 +230,5 @@ - print("nu_8_old", nu_8_old) - print("nu_8", params.nu_8) - print("abs(nu_8_old - nu_8) = ", abs(nu_8_old - params.nu_8)) - print("abs(nu_8_old - nu_8) / nu_8 = ", abs(nu_8_old - params.nu_8) / params.nu_8) - if (ratio / injection_energy_0) < 0.5 and \ - abs(nu_8_old - params.nu_8) / params.nu_8 < 0.05: + if ratio_x > threshold_ratio and ratio_y > threshold_ratio: + + if delta_ikx > 0 and delta_iky > 0: @@ -337,11 +234,6 @@ - print(f"Stationarity is reached.\n nu_8 = {params.nu_8}") - # sim.output.phys_fields.plot() - should_I_stop = True - # break - else: - should_I_stop = False - - factor = 1. - + if delta_ikx > delta_iky: + print("limited by y") + norm = idy_dealiasing + delta_ikmin = delta_iky + nb_wavenumbers_y // 4 else: @@ -347,2 +239,5 @@ else: + print("limited by x") + norm = idx_dealiasing + delta_ikmin = delta_ikx + nb_wavenumbers_x // 4 @@ -348,6 +243,4 @@ - factor = 1 + (1 / min(ratio_x, ratio_y)) - print("factor = ", factor) - p += 1 - should_I_stop = False + factor = max((1 - (delta_ikmin / norm)) ** 1.5, 0.5) + should_I_stop = False @@ -353,8 +246,2 @@ - # Print values... - print("params.nu_8", sim.params.nu_8) - print("abs(idx_dealiasing - idx_diss_max)", diff_x) - print("abs(idy_dealiasing - idy_diss_max)", diff_y) - print("cond_ratio_x", dissE_kx[idx_diss_max] / dissE_kx[idx_dealiasing - 1]) - print("cond_ratio_y", dissE_ky[idy_diss_max] / dissE_ky[idy_dealiasing - 1]) else: @@ -360,17 +247,14 @@ else: - factor = None - should_I_stop = None - - if mpi.nb_proc > 1: - # send factor and should_I_stop - factor = mpi.comm.bcast(factor, root=0) - should_I_stop = mpi.comm.bcast(should_I_stop, root=0) - print("rank {} ; factor {}".format(mpi.comm.Get_rank(), factor)) - - if should_I_stop: - break - - it += 1 - # Modification parameters - params = _deepcopy(sim.params) + print("Checking stationarity... with nu8 = {}".format(nu_8_old)) + E, t, P_tot = compute_energy_spatial(sim) + ratio = np.mean(np.diff(E[2:]) / np.diff(t[2:])) + if (ratio / injection_energy_0) < 0.5 and \ + abs(nu_8_old - params.nu_8) / params.nu_8 < 0.05: + print("Stationarity is reached.\n nu_8 = {}".format(params.nu_8)) + factor = 1. + should_I_stop = True + else: + should_I_stop = False + factor = 1. + else: @@ -376,5 +260,4 @@ - nu_8_old = params.nu_8 - params_old = sim.params - sim_old = sim + factor = 1 + (1 / min(ratio_x, ratio_y)) + should_I_stop = False @@ -380,5 +263,5 @@ - params.nu_8 = params.nu_8 * factor - params.init_fields.type = 'in_script' - params.time_stepping.t_end = 8. + return factor, should_I_stop + +################################################# @@ -384,8 +267,3 @@ - # Create new object simulation - rot_fft, b_fft = get_state_from_sim(sim) - sim = Simul(params) - sim.state.init_statespect_from(rot_fft=rot_fft, b_fft=b_fft) - sim.state.statephys_from_statespect() - sim.time_stepping.start() +gamma_not = make_float_value_for_path(gamma) @@ -391,9 +269,6 @@ - # Add values to time array and energy array - time_total += sim.time_stepping.t - dict_spatial = sim.output.spatial_means.load() - energy = dict_spatial["E"] - energy = np.mean(energy[len(energy) // 2:]) - energies.append(energy) - viscosities.append(sim.params.nu_8) +# Create directory in path +path_root = "/fsnet/project/meige/2015/15DELDUCA/DataSim/Coef_Diss" +name_directory = "Coef_Diss_gamma{}".format(gamma_not) +path = os.path.join(path_root, name_directory) @@ -399,7 +274,4 @@ - # Computes new index k_max_dissipation - kxE, kyE, dissE_kx, dissE_ky = load_mean_spect_energy_budg( - sim, tmin=2, tmax=1000) - - diff, idx_diss_max, idy_diss_max = compute_diff(idx_dealiasing, idy_dealiasing, dissE_kx, dissE_ky) +if mpi.rank == 0 and not os.path.exists(path): + os.mkdir(path) @@ -405,7 +277,4 @@ - if PLOT_FIGURES: - ax.plot(kyE, dissE_ky, label="nu8 = {:.2e}, diff = {}".format( - params.nu_8, abs(idy_diss_max - idy_dealiasing))) - ax2.plot(kxE, dissE_kx, label="nu8 = {:.2e}, diff = {}".format( - params.nu_8, abs(idx_diss_max - idx_dealiasing))) +# Check list simulations in directory +paths_sim = sorted(glob(os.path.join(path, "NS*"))) @@ -411,4 +280,4 @@ - fig.canvas.draw() - fig2.canvas.draw() +# Write in .txt file +path_file_write = os.path.join(path, "results.txt") @@ -414,7 +283,3 @@ - plt.pause(1e-4) - - ax3.plot(time_total, viscosities[-1], "x") - ax3.autoscale() - fig3.canvas.draw() +PLOT_FIGURES = PLOT_FIGURES and mpi.rank == 0 @@ -420,9 +285,7 @@ - ax4.plot(time_total, energy, "x") - ax4.autoscale() - fig4.canvas.draw() - - ax5.plot(time_total, factor, 'x') - ax5.autoscale() - fig5.canvas.draw() +# Write temporal results in .txt file +path_file_write2 = os.path.join(path, "results_check_nu8.txt") +if mpi.rank == 0: + if os.path.exists(path_file_write2): + os.remove(path_file_write2) @@ -428,9 +291,12 @@ - plt.pause(1e-4) - if mpi.rank == 0: - with open(path_file, "w") as f: - to_print = ("resolution = {} \n" - "nu8 = {} \n".format( - sim.params.oper.nx, - params.nu_8)) +if len(paths_sim) == 0: + # Make FIRST SIMULATION + params = make_parameters_simulation(gamma, F, sigma, nu_8, t_end=t_end, NO_SHEAR_MODES=NO_SHEAR_MODES) + sim = Simul(params) + sim = normalization_initialized_field(sim) + sim.time_stepping.start() +else: + # Look for path largest resolution + new_file = glob(paths_sim[-1] + "/State_phys*")[-1] + path_file = glob(new_file + "/state_phys*")[0] @@ -436,14 +302,8 @@ - f.write(to_print) - - shutil.move(sim.params.path_run, path_dir) - - - -else: - plt.close("all") + # Compute resolution from path + res_str = os.path.basename(new_file).split("_")[-1] sim = load_sim_for_plot(paths_sim[-1]) params = _deepcopy(sim.params) @@ -445,9 +305,9 @@ sim = load_sim_for_plot(paths_sim[-1]) params = _deepcopy(sim.params) - params.oper.nx = int(params.oper.nx * coef_modif_resol) - params.oper.ny = int(params.oper.ny * coef_modif_resol) + params.oper.nx = int(res_str.split("x")[0]) + params.oper.ny = int(res_str.split("x")[1]) params.init_fields.type = "from_file" @@ -452,4 +312,4 @@ params.init_fields.type = "from_file" - params.init_fields.from_file.path = paths_sim[-1] + "/State_phys_360x90/state_phys_t008.002_it=0.nc" + params.init_fields.from_file.path = path_file @@ -455,5 +315,5 @@ - params.time_stepping.t_end += 8. + params.time_stepping.t_end += t_end params.NEW_DIR_RESULTS = True @@ -462,7 +322,20 @@ sim = Simul(params) sim.time_stepping.start() - # Parameters condition - nb_wavenumbers_y = 8 - nb_wavenumbers_x = nb_wavenumbers_y * (sim.params.oper.nx // sim.params.oper.ny) + +# Parameters condition +nb_wavenumbers_x = nb_wavenumbers_y * (sim.params.oper.nx // sim.params.oper.ny) + +# Creation time and energy array +time_total = 0 +time_total += sim.time_stepping.t + +energy, t, P_tot = compute_energy_spatial(sim) +energy = np.mean(energy[len(energy) // 2:]) +injection_energy_0 = P_tot[2] + +energies = [] +viscosities = [] +energies.append(energy) +viscosities.append(sim.params.nu_8) @@ -468,5 +341,10 @@ - # Creation time and energy array - time_total = 0 - time_total += sim.time_stepping.t +# Write results into temporal file +if mpi.rank == 0: + to_print = ("####\n" + "t = {:.4e} \n" + "E = {:.4e} \n" + "nu8 = {:.4e} \n" + "factor = {:.4e} \n").format( + time_total, energy, sim.params.nu_8, 1) @@ -472,4 +350,9 @@ - energies = [] - viscosities = [] + write_to_file(path_file_write2, to_print, mode="w") + +# Compute the data spectra energy budget +kxE, kyE, dissE_kx, dissE_ky = load_mean_spect_energy_budg(sim, tmin=2., tmax=1000) +idx_diss_max, idy_diss_max = _compute_ikdiss(dissE_kx, dissE_ky) +idx_dealiasing, idy_dealiasing = _compute_ikmax(kxE, kyE) +idx_target, idy_target, delta_ikx, delta_iky = compute_delta_ik(kxE, kyE, dissE_kx, dissE_ky) @@ -475,7 +358,13 @@ - dict_spatial = sim.output.spatial_means.load() - energy = dict_spatial["E"] - energy = np.mean(energy[len(energy) // 2:]) - energies.append(energy) - viscosities.append(sim.params.nu_8) +# Plot dissipation +if PLOT_FIGURES: + plt.ion() + fig, ax = plt.subplots() + ax.set_title("$D(k_y)$") + ax.set_xlabel("$k_y$") + ax.set_ylabel("$D(k_y)$") + ax.plot(kyE, dissE_ky, label="nu8 = {:.2e}, diff = {}".format( + sim.params.nu_8, abs(idy_diss_max - idy_dealiasing))) + ax.plot(sim.oper.kymax_dealiasing, 0, 'xr') + ax.axvline(x=sim.oper.deltaky * idy_target, color="k") @@ -481,7 +370,25 @@ - # Compute injection of energy begin simulation - pe_k = dict_spatial["PK_tot"] - pe_a = dict_spatial["PA_tot"] - pe_tot = pe_k + pe_a - print("pe_tot", pe_tot[2]) + fig2, ax2 = plt.subplots() + ax2.set_title("$D(k_x)$") + ax2.set_xlabel("$k_x$") + ax2.set_ylabel("$D(k_x)$") + ax2.plot(kxE, dissE_kx, label="nu8 = {:.2e}, diff = {}".format( + sim.params.nu_8, abs(idx_diss_max - idx_dealiasing))) + ax2.plot(sim.oper.kxmax_dealiasing, 0, 'xr') + ax2.axvline(x=sim.oper.deltakx * idx_target, color="k") + + ax.legend() + ax2.legend() + + fig.canvas.draw() + fig2.canvas.draw() + + plt.pause(1e-3) + + # Dissipation vs time + fig3, ax3 = plt.subplots() + ax3.set_xlabel("times") + ax3.set_ylabel(r"$\nu_8$") + + ax3.plot(time_total, viscosities[-1], '.') @@ -487,3 +394,14 @@ - injection_energy_0 = pe_tot[2] + # Energy Vs time + fig4, ax4 = plt.subplots() + ax4.plot(time_total, energy, '.') + ax4.set_xlabel("times") + ax4.set_ylabel("Energy") + + # Factor Vs time + fig5, ax5 = plt.subplots() + ax5.plot(time_total, 1, '.') + ax5.set_xlabel("times") + ax5.set_ylabel("Factor") + @@ -489,7 +407,20 @@ - # Compute the data spectra energy budget - kxE, kyE, dissE_kx, dissE_ky = load_mean_spect_energy_budg(sim, tmin=2., tmax=1000) - print("kxE", kxE) - # Save nu_8 sim0 : - nu8_old = sim.params.nu_8 +it = 0 +p = 1 +# Check ... +while True: + + if mpi.rank == 0: + factor, should_I_stop = check_dissipation() + else: + factor = None + should_I_stop = None + + if mpi.nb_proc > 1: + # send factor and should_I_stop + factor = mpi.comm.bcast(factor, root=0) + should_I_stop = mpi.comm.bcast(should_I_stop, root=0) + + if should_I_stop: + break @@ -495,9 +426,17 @@ - # Loads the spectral energy budget - kxmax_dealiasing = sim.oper.kxmax_dealiasing - kymax_dealiasing = sim.oper.kymax_dealiasing - print("kxmax_dealiasing", kxmax_dealiasing) - # Computes index kmax_dealiasing & kmax_dissipation - idx_dealiasing = np.argmin(abs(kxE - kxmax_dealiasing)) - idy_dealiasing = np.argmin(abs(kyE - kymax_dealiasing)) + if mpi.rank == 0: + print("factor = ", factor) + print("nu_8 OLD = ", sim.params.nu_8) + print("nu_8 NEW = ", sim.params.nu_8 * factor) + + it += 1 + # Modification parameters + params, nu_8_old = modify_factor(sim) + + # Create new object simulation + rot_fft, b_fft = get_state_from_sim(sim) + sim = Simul(params) + sim.state.init_statespect_from(rot_fft=rot_fft, b_fft=b_fft) + sim.state.statephys_from_statespect() + sim.time_stepping.start() @@ -503,4 +442,9 @@ - # Compute difference - diff, idx_diss_max, idy_diss_max = compute_diff(idx_dealiasing, idy_dealiasing, dissE_kx, dissE_ky) + if mpi.rank == 0: + # Add values to time array and energy array + time_total += sim.time_stepping.t + energy, t, P_tot = compute_energy_spatial(sim) + energy = np.mean(energy[len(energy) // 2:]) + energies.append(energy) + viscosities.append(sim.params.nu_8) @@ -506,6 +450,18 @@ - # - idx_target = idx_dealiasing - (nb_wavenumbers_x - 1) - idy_target = idy_dealiasing - (nb_wavenumbers_y - 1) + # Computes new index k_max_dissipation + kxE, kyE, dissE_kx, dissE_ky = load_mean_spect_energy_budg( + sim, tmin=2., tmax=1000) + idx_diss_max, idy_diss_max = _compute_ikdiss(dissE_kx, dissE_ky) + idx_dealiasing, idy_dealiasing = _compute_ikmax(kxE, kyE) + + # Write results into temporal file + to_print = ("####\n" + "t = {:.4e} \n" + "E = {:.4e} \n" + "nu8 = {:.4e} \n" + "factor = {:.4e} \n").format( + time_total, energy, sim.params.nu_8, factor) + + write_to_file(path_file_write2, to_print, mode="a") if PLOT_FIGURES: @@ -510,9 +466,3 @@ if PLOT_FIGURES: - # Plot dissipation - plt.ion() - fig, ax = plt.subplots() - ax.set_title("$D(k_y)$") - ax.set_xlabel("$k_y$") - ax.set_ylabel("$D(k_y)$") ax.plot(kyE, dissE_ky, label="nu8 = {:.2e}, diff = {}".format( @@ -518,10 +468,3 @@ ax.plot(kyE, dissE_ky, label="nu8 = {:.2e}, diff = {}".format( - sim.params.nu_8, abs(idy_diss_max - idy_dealiasing))) - ax.plot(kymax_dealiasing, 0, 'xr') - ax.axvline(x=sim.oper.deltaky * idy_target, color="k") - - fig2, ax2 = plt.subplots() - ax2.set_title("$D(k_x)$") - ax2.set_xlabel("$k_x$") - ax2.set_ylabel("$D(k_x)$") + params.nu_8, abs(idy_diss_max - idy_dealiasing))) ax2.plot(kxE, dissE_kx, label="nu8 = {:.2e}, diff = {}".format( @@ -527,11 +470,6 @@ ax2.plot(kxE, dissE_kx, label="nu8 = {:.2e}, diff = {}".format( - sim.params.nu_8, abs(idx_diss_max - idx_dealiasing))) - ax2.plot(kxmax_dealiasing, 0, 'xr') - ax2.axvline(x=sim.oper.deltakx * idx_target, color="k") - - ax.legend() - ax2.legend() + params.nu_8, abs(idx_diss_max - idx_dealiasing))) fig.canvas.draw() fig2.canvas.draw() @@ -534,51 +472,6 @@ fig.canvas.draw() fig2.canvas.draw() - plt.pause(1e-3) - - # Dissipation vs time - fig3, ax3 = plt.subplots() - ax3.set_xlabel("times") - ax3.set_ylabel(r"$\nu_8$") - - ax3.plot(time_total, viscosities[-1], '.') - - # Energy Vs time - fig4, ax4 = plt.subplots() - ax4.plot(time_total, energy, '.') - ax4.set_xlabel("times") - ax4.set_ylabel("Energy") - - # Factor Vs time - fig5, ax5 = plt.subplots() - ax5.plot(time_total, 1, '.') - ax5.set_xlabel("times") - ax5.set_ylabel("Factor") - - - it = 0 - p = 1 - # Check ... - while True: - - if mpi.rank == 0: - - # Define conditions - diff_x = abs(idx_dealiasing - idx_diss_max) - diff_y = abs(idy_dealiasing - idy_diss_max) - print("diff_x", diff_x) - print("diff_y", diff_y) - - ratio_x = dissE_kx[idx_diss_max] / dissE_kx[idx_dealiasing - 1] - ratio_y = dissE_ky[idy_diss_max] / dissE_ky[idy_dealiasing - 1] - - cond_ratio_x = ratio_x > 1e1 - cond_ratio_y = ratio_y > 1e1 - print("cond_ratio_x", ratio_x) - print("cond_ratio_y", ratio_y) - - diff_x_target = abs(idx_target - idx_diss_max) - diff_y_target = abs(idy_target - idy_diss_max) - diff_target = max(diff_x_target, diff_y_target) + plt.pause(1e-4) @@ -584,59 +477,5 @@ - if time_total > 1000: - print( - "The stationarity has not " + \ - "reached after {} simulations.".format(it)) - break - # Check ratio D(k_peak) / D(k_max - 1) - if cond_ratio_x and cond_ratio_y: - - # Check differences - if diff_x > nb_wavenumbers_x and diff_y > nb_wavenumbers_y: - print("diff_target = ", diff_target) - print("p", p) - # factor = max(((nb_wavenumbers_y / 2) / diff_target) ** (0.2), min_factor) - factor = ((nb_wavenumbers_y / 2) / diff_target) ** (1. / p) - print("factor = ", factor) - - p += 1 - should_I_stop = False - else: - print("Checking stationarity... with nu8 = {}".format(params_old.nu_8)) - dict_spatial = sim.output.spatial_means.load() - E = dict_spatial["E"] - t = dict_spatial["t"] - ratio = np.mean(np.diff(E[2:]) / np.diff(t[2:])) - print("ratio_energy = ", ratio) - print("injection_energy_0 = ", injection_energy_0) - - print("nu_8_old", nu_8_old) - print("nu_8", params.nu_8) - print("abs(nu_8_old - nu_8) = ", abs(nu_8_old - params.nu_8)) - print("abs(nu_8_old - nu_8) / nu_8 = ", abs(nu_8_old - params.nu_8) / params.nu_8) - if (ratio / injection_energy_0) < 0.5 and \ - abs(nu_8_old - params.nu_8) / params.nu_8 < 0.05: - - print(f"Stationarity is reached.\n nu_8 = {params.nu_8}") - should_I_stop = True - # sim.output.phys_fields.plot() - # break - else: - should_I_stop = False - - factor = 1. - - - else: - - factor = 1 + (1 / min(ratio_x, ratio_y)) - print("factor = ", factor) - p += 1 - should_I_stop = False - - # Print values... - print("params.nu_8", sim.params.nu_8) - print("abs(idx_dealiasing - idx_diss_max)", diff_x) - print("abs(idy_dealiasing - idy_diss_max)", diff_y) - print("cond_ratio_x", dissE_kx[idx_diss_max] / dissE_kx[idx_dealiasing - 1]) - print("cond_ratio_y", dissE_ky[idy_diss_max] / dissE_ky[idy_dealiasing - 1]) + ax3.plot(time_total, viscosities[-1], "x") + ax3.autoscale() + fig3.canvas.draw() @@ -642,55 +481,5 @@ - else: - factor = None - should_I_stop = None - - if mpi.nb_proc > 1: - # send factor and should_I_stop - factor = mpi.comm.bcast(factor, root=0) - should_I_stop = mpi.comm.bcast(should_I_stop, root=0) - - if should_I_stop: - break - - it += 1 - # Modification parameters - params = _deepcopy(sim.params) - - nu_8_old = params.nu_8 - params_old = sim.params - sim_old = sim - - params.nu_8 = params.nu_8 * factor - params.init_fields.type = 'in_script' - params.time_stepping.t_end = 8. - - # Create new object simulation - rot_fft, b_fft = get_state_from_sim(sim) - sim = Simul(params) - sim.state.init_statespect_from(rot_fft=rot_fft, b_fft=b_fft) - sim.state.statephys_from_statespect() - sim.time_stepping.start() - - if mpi.rank == 0: - - # Add values to time array and energy array - time_total += sim.time_stepping.t - dict_spatial = sim.output.spatial_means.load() - energy = dict_spatial["E"] - energy = np.mean(energy[len(energy) // 2:]) - energies.append(energy) - viscosities.append(sim.params.nu_8) - - # Computes new index k_max_dissipation - kxE, kyE, dissE_kx, dissE_ky = load_mean_spect_energy_budg( - sim, tmin=2, tmax=1000) - - diff, idx_diss_max, idy_diss_max = compute_diff(idx_dealiasing, idy_dealiasing, dissE_kx, dissE_ky) - - if PLOT_FIGURES: - - ax.plot(kyE, dissE_ky, label="nu8 = {:.2e}, diff = {}".format( - params.nu_8, abs(idy_diss_max - idy_dealiasing))) - ax2.plot(kxE, dissE_kx, label="nu8 = {:.2e}, diff = {}".format( - params.nu_8, abs(idx_diss_max - idx_dealiasing))) + ax4.plot(time_total, energy, "x") + ax4.autoscale() + fig4.canvas.draw() @@ -696,28 +485,5 @@ - fig.canvas.draw() - fig2.canvas.draw() - - plt.pause(1e-4) - - ax3.plot(time_total, viscosities[-1], "x") - ax3.autoscale() - fig3.canvas.draw() - - ax4.plot(time_total, energy, "x") - ax4.autoscale() - fig4.canvas.draw() - - ax5.plot(time_total, factor, 'x') - ax5.autoscale() - fig5.canvas.draw() - - plt.pause(1e-4) - if mpi.rank == 0: - with open(path_file, "r+") as f: - to_print = ("resolution = {} \n" - "nu8 = {} \n".format( - sim.params.oper.nx, - params.nu_8)) - - f.write(to_print) + ax5.plot(time_total, factor, 'x') + ax5.autoscale() + fig5.canvas.draw() @@ -723,28 +489,3 @@ - shutil.move(sim.params.path_run, path_dir) - - # modif_resolution (in util) - # pass - - - - -##### SAVE ##### -# nb_wavenumbers_y = 8 -# nb_wavenumbers_x = nb_wavenumbers_y * (params.oper.nx // params.oper.ny) - -# # Creation time and energy array -# time_total = 0 -# energies = [] -# viscosities = [] - -# sim.time_stepping.start() - -# time_total += sim.time_stepping.t - -# dict_spatial = sim.output.spatial_means.load() -# energy = dict_spatial["E"] -# energy = np.mean(energy[len(energy) // 2:]) -# energies.append(energy) -# viscosities.append(sim.params.nu_8) + plt.pause(1e-4) @@ -750,110 +491,8 @@ -# # Compute injection of energy begin simulation -# pe_k = dict_spatial["PK_tot"] -# pe_a = dict_spatial["PA_tot"] -# pe_tot = pe_k + pe_a -# print("pe_tot", pe_tot[2]) - -# injection_energy_0 = pe_tot[2] - -# # Compute the data spectra energy budget -# kxE, kyE, dissE_kx, dissE_ky = load_mean_spect_energy_budg(sim, tmin=2., tmax=1000) - -# # Save nu_8 sim0 : -# nu8_old = sim.params.nu_8 - -# # Loads the spectral energy budget -# kxmax_dealiasing = sim.oper.kxmax_dealiasing -# kymax_dealiasing = sim.oper.kymax_dealiasing - -# # Computes index kmax_dealiasing & kmax_dissipation -# idx_dealiasing = np.argmin(abs(kxE - kxmax_dealiasing)) -# idy_dealiasing = np.argmin(abs(kyE - kymax_dealiasing)) - -# # Compute difference -# diff, idx_diss_max, idy_diss_max = compute_diff(idx_dealiasing, idy_dealiasing, dissE_kx, dissE_ky) - -# # -# idx_target = idx_dealiasing - (nb_wavenumbers_x - 1) -# idy_target = idy_dealiasing - (nb_wavenumbers_y - 1) - - -# # Plot dissipation -# plt.ion() -# fig, ax = plt.subplots() -# ax.set_title("$D(k_y)$") -# ax.set_xlabel("$k_y$") -# ax.set_ylabel("$D(k_y)$") -# ax.plot(kyE, dissE_ky, label="nu8 = {:.2e}, diff = {}".format( -# sim.params.nu_8, abs(idy_diss_max - idy_dealiasing))) -# ax.plot(kymax_dealiasing, 0, 'xr') -# ax.axvline(x=sim.oper.ky[idy_target], color="k") - -# fig2, ax2 = plt.subplots() -# ax2.set_title("$D(k_x)$") -# ax2.set_xlabel("$k_x$") -# ax2.set_ylabel("$D(k_x)$") -# ax2.plot(kxE, dissE_kx, label="nu8 = {:.2e}, diff = {}".format( -# sim.params.nu_8, abs(idx_diss_max - idx_dealiasing))) -# ax2.plot(kxmax_dealiasing, 0, 'xr') -# ax2.axvline(x=sim.oper.kx[idx_target], color="k") - - -# ax.legend() -# ax2.legend() - -# fig.canvas.draw() -# fig2.canvas.draw() - -# plt.pause(1e-3) - - -# # Dissipation vs time -# fig3, ax3 = plt.subplots() -# ax3.set_xlabel("times") -# ax3.set_ylabel(r"$\nu_8$") - -# ax3.plot(time_total, viscosities[-1], '.') - -# # Energy Vs time -# fig4, ax4 = plt.subplots() -# ax4.plot(time_total, energy, '.') -# ax4.set_xlabel("times") -# ax4.set_ylabel("Energy") - -# # Factor Vs time -# fig5, ax5 = plt.subplots() -# ax5.plot(time_total, 1, '.') -# ax5.set_xlabel("times") -# ax5.set_ylabel("Factor") - - -# it = 0 -# p = 1 -# # Check ... -# while True: - -# # Define conditions -# diff_x = abs(idx_dealiasing - idx_diss_max) -# diff_y = abs(idy_dealiasing - idy_diss_max) -# print("diff_x", diff_x) -# print("diff_y", diff_y) - -# ratio_x = dissE_kx[idx_diss_max] / dissE_kx[idx_dealiasing - 1] -# ratio_y = dissE_ky[idy_diss_max] / dissE_ky[idy_dealiasing - 1] - -# cond_ratio_x = ratio_x > 1e1 -# cond_ratio_y = ratio_y > 1e1 -# print("cond_ratio_x", ratio_x) -# print("cond_ratio_y", ratio_y) - -# diff_x_target = abs(idx_target - idx_diss_max) -# diff_y_target = abs(idy_target - idy_diss_max) -# diff_target = max(diff_x_target, diff_y_target) - -# if time_total > 1000: -# print( -# "The stationarity has not " + \ -# "reached after {} simulations.".format(it_)) -# break +if mpi.rank == 0: + if len(paths_sim) == 0: + to_print = ("gamma,nx,nu8 \n") + to_print += ("{},{},{} \n".format( + gamma, sim.params.oper.nx, params.nu_8)) + mode_write = "w" @@ -859,55 +498,6 @@ -# # Check ratio D(k_peak) / D(k_max - 1) -# if cond_ratio_x and cond_ratio_y: - -# # Check differences -# if diff_x > nb_wavenumbers_x and diff_y > nb_wavenumbers_y: -# print("diff_target = ", diff_target) -# print("p", p) -# factor = ((nb_wavenumbers_y / 2) / diff_target) ** (0.1 / p) -# print("factor = ", factor) - -# p += 1 -# else: -# print("Checking stationarity... with nu8 = {}".format(params_old.nu_8)) -# dict_spatial = sim.output.spatial_means.load() -# E = dict_spatial["E"] -# t = dict_spatial["t"] -# ratio = np.mean(np.diff(E[2:]) / np.diff(t[2:])) -# print("ratio_energy = ", ratio) -# print("injection_energy_0 = ", injection_energy_0) - -# print("nu_8_old", nu_8_old) -# print("nu_8", params.nu_8) -# print("abs(nu_8_old - nu_8) = ", abs(nu_8_old - params.nu_8)) -# print("abs(nu_8_old - nu_8) / nu_8 = ", abs(nu_8_old - params.nu_8) / params.nu_8) -# if (ratio / injection_energy_0) < 0.5 and \ -# abs(nu_8_old - params.nu_8) / params.nu_8 < 0.05: - -# print(f"Stationarity is reached.\n nu_8 = {params.nu_8}") -# sim.output.phys_fields.plot() -# break - -# factor = 1. - -# else: - -# factor = 1 + (1 / min(ratio_x, ratio_y)) -# print("factor = ", factor) -# p += 1 - -# # Print values... -# print("params.nu_8", sim.params.nu_8) -# print("abs(idx_dealiasing - idx_diss_max)", diff_x) -# print("abs(idy_dealiasing - idy_diss_max)", diff_y) -# print("cond_ratio_x", dissE_kx[idx_diss_max] / dissE_kx[idx_dealiasing - 1]) -# print("cond_ratio_y", dissE_ky[idy_diss_max] / dissE_ky[idy_dealiasing - 1]) - -# it += 1 -# # Modification parameters -# params = _deepcopy(sim.params) - -# nu_8_old = params.nu_8 -# params_old = sim.params -# sim_old = sim + else: + to_print = ("{},{},{} \n".format( + gamma, sim.params.oper.nx, params.nu_8)) + mode_write = "a" @@ -913,27 +503,3 @@ -# params.nu_8 = params.nu_8 * factor -# params.init_fields.type = 'in_script' -# params.time_stepping.t_end = 8. - -# # Create new object simulation -# rot_fft, b_fft = get_state_from_sim(sim) -# sim = Simul(params) -# sim.state.init_statespect_from(rot_fft=rot_fft, b_fft=b_fft) -# sim.state.statephys_from_statespect() -# sim.time_stepping.start() - -# # Add values to time array and energy array -# time_total += sim.time_stepping.t -# dict_spatial = sim.output.spatial_means.load() -# energy = dict_spatial["E"] -# energy = np.mean(energy[len(energy) // 2:]) -# energies.append(energy) -# viscosities.append(sim.params.nu_8) - - -# # Computes new index k_max_dissipation -# kxE, kyE, dissE_kx, dissE_ky = load_mean_spect_energy_budg( -# sim, tmin=2, tmax=1000) - -# diff, idx_diss_max, idy_diss_max = compute_diff(idx_dealiasing, idy_dealiasing, dissE_kx, dissE_ky) + write_to_file(path_file_write, to_print, mode=mode_write) @@ -939,31 +505,2 @@ -# ax.plot(kyE, dissE_ky, label="nu8 = {:.2e}, diff = {}".format( -# params.nu_8, abs(idy_diss_max - idy_dealiasing))) -# ax2.plot(kxE, dissE_kx, label="nu8 = {:.2e}, diff = {}".format( -# params.nu_8, abs(idx_diss_max - idx_dealiasing))) - -# # ax.legend() -# # ax2.legend() - -# fig.canvas.draw() -# fig2.canvas.draw() - -# plt.pause(1e-4) - -# # its.append(it) -# # viscosities.append(params.nu_8) -# # line.set_data(its, viscosities) - -# ax3.plot(time_total, viscosities[-1], "x") -# ax3.autoscale() -# fig3.canvas.draw() - -# ax4.plot(time_total, energy, "x") -# ax4.autoscale() -# fig4.canvas.draw() - -# ax5.plot(time_total, factor, 'x') -# ax5.autoscale() -# fig5.canvas.draw() - -# plt.pause(1e-4) + shutil.move(sim.params.path_run, path) diff --git a/scripts/ns2d.strat/compute_anisotropy.py b/scripts/ns2d.strat/compute_anisotropy.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L2NvbXB1dGVfYW5pc290cm9weS5weQ== --- /dev/null +++ b/scripts/ns2d.strat/compute_anisotropy.py @@ -0,0 +1,91 @@ +""" +compute_anisotropy.py +===================== +1/10/2018 + +Function to compute the anisotropy of a simulation. + +""" +from glob import glob + +import h5py +import numpy as np + +from fluidsim import load_params_simul + +def _compute_array_times_from_path(path_simulation): + """ + Compute array with times from path simulation. + + Parameters + ---------- + path_simulation : str + Path of the simulation. + """ + times_phys_files = [] + + paths_phys_files = glob(path_simulation + "/state_phys_t*") + for path in paths_phys_files: + if not "=" in path.split("state_phys_t")[1].split(".nc")[0]: + times_phys_files.append( + float(path.split("state_phys_t")[1].split(".nc")[0])) + else: + continue + return np.asarray(times_phys_files) + +def compute_anisotropy(path_simulation, tmin=None): + """ + It computes the anisotropy of a simulation. + + Parameters + ---------- + path_simulation : str + Path of the simulation. + + tmin : float + Lower limit to compute the time average. + By default it takes the last 10 files. + """ + + # Print out + res_out = float(path_simulation.split("NS2D.strat_")[1].split("x")[0]) + gamma_str = path_simulation.split("_gamma")[1].split("_")[0] + if gamma_str.startswith("0"): + gamma_out = float(gamma_str[0] + "." + gamma_str[1]) + else: + gamma_out = float(gamma_str) + + print("Compute anisotropy nx = {} and gamma {}..".format(res_out, gamma_out)) + + # Load data energy spectra file. + with h5py.File(path_simulation + "/spectra1D.h5", "r") as f: + kx = f["kxE"].value + times = f["times"].value + spectrumkx_EK_ux = f["spectrum1Dkx_EK_ux"].value + spectrumkx_EK = f["spectrum1Dkx_EK"].value + spectrumkx_EK_uy = f["spectrum1Dkx_EK_uy"].value + dt_state_phys = np.median(np.diff(times)) + + # Compute start time average itmin + dt = np.median(np.diff(times)) + if not tmin: + nb_files = 10 + tmin = np.max(times) - (nb_files * dt) + itmin = np.argmin(abs(times - tmin)) + + # Compute delta_kx + params = load_params_simul(path_simulation) + delta_kx = 2 * np.pi / params.oper.Lx + + # Compute spatial averaged energy from spectra + EK_ux = np.sum(np.mean(spectrumkx_EK_ux[itmin:,:], axis=0) * delta_kx) + EK = np.sum(np.mean(spectrumkx_EK[itmin:,:], axis=0) * delta_kx) + + return EK_ux / EK + +if __name__ == "__main__": + path_simulation = ("/fsnet/project/meige/2015/15DELDUCA/DataSim/" + + "sim1920_no_shear_modes/NS2D.strat_1920x480_S2pix1.571_F07_gamma05_2018-08-14_10-01-22") + + anisotropy = compute_anisotropy(path_simulation) + print("anisotropy = {}".format(anisotropy)) diff --git a/scripts/ns2d.strat/compute_flow_features.py b/scripts/ns2d.strat/compute_flow_features.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L2NvbXB1dGVfZmxvd19mZWF0dXJlcy5weQ== --- /dev/null +++ b/scripts/ns2d.strat/compute_flow_features.py @@ -0,0 +1,92 @@ +""" +compute_flow_features.py +======================== +28/09/2018 + +""" +import os +import numpy as np +import h5py + +from glob import glob +import matplotlib.pyplot as plt + +from fluidsim import load_params_simul + +# Argparse arguments +nx = 3840 +n_files_average = 50 # Number of files to perform the time average + +# Create paths +path_root = "/fsnet/project/meige/2015/15DELDUCA/DataSim" + +if nx == 1920: + directory = "sim{}_no_shear_modes".format(nx) +elif nx == 3840 or nx == 7680: + directory = "sim{}_modif_res_no_shear_modes".format(nx) +else: + raise ValueError(".") + +path_simulations = sorted(glob(os.path.join(path_root, directory, "NS2D*"))) + +gammas = [] +anisotropies_gammas = [] +ratio_dissipations = [] +for ipath, path in enumerate(path_simulations): + params = params = load_params_simul(path) + + # Add gamma to list gammas + gamma_str = path.split("_gamma")[1].split("_")[0] + if gamma_str.startswith("0"): + gammas.append(float(gamma_str[0] + "." + gamma_str[1])) + else: + gammas.append(float(gamma_str)) + + # Compute time average ratio ux**2 / uy**2 (anisotropy) + print("Computing anisotropy for gamma {}...".format(gammas[ipath])) + path_phys_files = glob(path + "/state_phys_t*") + anisotropies = [] + for path_file in path_phys_files[-n_files_average:]: + with h5py.File(path_file, "r") as f: + ux = f["state_phys"]["ux"].value + uz = f["state_phys"]["uy"].value + anisotropies.append(np.mean(ux**2) / np.mean(uz**2)) + anisotropies_gammas.append(np.mean(anisotropies)) + + # Compute ratio D(k_x)/epsilon + print("Computing ratio dissipation for gamma {}...".format(gammas[ipath])) + with h5py.File(path + "/spect_energy_budg.h5", "r") as f: + kx = f['kxE'].value + kz = f['kyE'].value + dset_dissEKu_kx = f['dissEKu_kx'] + dset_dissEKv_kx = f['dissEKv_kx'] + dset_dissEA_kx = f['dissEA_kx'] + + delta_kx = kx[1] - kx[0] + delta_kz = kz[1] - kz[0] + + dissEK_kx = (dset_dissEKu_kx[-n_files_average:] + \ + dset_dissEKv_kx[-n_files_average:]) + dissEA_kx = dset_dissEA_kx[-n_files_average:] + dissE_kx = (dissEK_kx + dissEA_kx).mean(0) + D_kx = dissE_kx.cumsum() * delta_kx + + # Compute k_fx + k_fx = (np.sin(params.forcing.tcrandom_anisotropic.angle) * + params.forcing.nkmax_forcing * max(delta_kx, delta_kz)) + ik_fx = np.argmin(abs(kx - k_fx )) + + # Compute ratio + ratio_dissipations.append(D_kx[ik_fx] / D_kx[-1]) + +fig1, ax1 = plt.subplots() +ax1.set_xlabel(r"$\gamma$") +ax1.set_ylabel(r"$U_x^2/U_z^2$") +ax1.plot(gammas, anisotropies_gammas, 'ro') + +fig2, ax2 = plt.subplots() +ax2.set_xlabel(r"$\gamma$") +ax2.set_ylabel(r"$D(k_{fx})/D(k_{x, max})$") +ax2.plot(gammas, ratio_dissipations, 'bo') + +plt.show() diff --git a/scripts/ns2d.strat/compute_ratio_dissipation.py b/scripts/ns2d.strat/compute_ratio_dissipation.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L2NvbXB1dGVfcmF0aW9fZGlzc2lwYXRpb24ucHk= --- /dev/null +++ b/scripts/ns2d.strat/compute_ratio_dissipation.py @@ -0,0 +1,57 @@ +""" +compute_ratio_dissipation.py +============================ +02/10/2018 +""" + +import h5py +import numpy as np + +from fluidsim import load_params_simul + +def compute_ratio_dissipation(path_simulation, tmin=None): + """ + Compute ratio dissipation from path simulation. + """ + # Print out + res_out = float(path_simulation.split("NS2D.strat_")[1].split("x")[0]) + gamma_str = path_simulation.split("_gamma")[1].split("_")[0] + if gamma_str.startswith("0"): + gamma_out = float(gamma_str[0] + "." + gamma_str[1]) + else: + gamma_out = float(gamma_str) + + print("Compute dissipation nx = {} and gamma {}..".format(res_out, gamma_out)) + + # Load object parameters + params = load_params_simul(path_simulation) + + with h5py.File(path_simulation + "/spect_energy_budg.h5", "r") as f: + times = f["times"].value + kx = f["kxE"].value + kz = f['kyE'].value + dset_dissEKu_kx = f['dissEKu_kx'] + dset_dissEKv_kx = f['dissEKv_kx'] + dset_dissEA_kx = f["dissEA_kx"] + + # Compute itmin time average + if not tmin: + nb_files = 10 + dt = np.median(np.diff(times)) + tmin = np.max(times) - (nb_files * dt) + itmin = np.argmin(abs(times - tmin)) + + # Compute dissipation curve + delta_kx = np.median(np.diff(kx)) + delta_kz = np.median(np.diff(abs(kz))) + dissEK_kx = dset_dissEKu_kx[-itmin:] + dset_dissEKv_kx[-itmin:] + dissEA_kx = dset_dissEA_kx[-itmin:] + dissE_kx = (dissEK_kx + dissEA_kx).mean(0) + D_kx = dissE_kx.cumsum() * delta_kx + + # Compute k_fx + k_fx = (np.sin(params.forcing.tcrandom_anisotropic.angle) * + params.forcing.nkmax_forcing * max(delta_kx, delta_kz)) + ik_fx = np.argmin(abs(kx - k_fx )) + + return D_kx[ik_fx] / D_kx[-1] diff --git a/scripts/ns2d.strat/compute_reynolds_froude.py b/scripts/ns2d.strat/compute_reynolds_froude.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L2NvbXB1dGVfcmV5bm9sZHNfZnJvdWRlLnB5 --- /dev/null +++ b/scripts/ns2d.strat/compute_reynolds_froude.py @@ -0,0 +1,107 @@ +""" +compute_reynolds_froude.py +========================== +1/10/2018 + +""" + +import h5py +import numpy as np + +from fluidsim import load_params_simul + +def _compute_epsilon_from_path(path_simulation, tmin=None): + """ + Computes the mean dissipation from tmin + """ + # Load data dissipation + with open(path_simulation + "/spatial_means.txt", "r") as f: + lines = f.readlines() + + lines_t = [] + lines_epsK = [] + + for il, line in enumerate(lines): + if line.startswith("time ="): + lines_t.append(line) + if line.startswith("epsK ="): + lines_epsK.append(line) + + nt = len(lines_t) + t = np.empty(nt) + epsK = np.empty(nt) + + for il in range(nt): + line = lines_t[il] + words = line.split() + t[il] = float(words[2]) + + line = lines_epsK[il] + words = line.split() + epsK[il] = float(words[2]) + + # Compute start time average itmin + dt_spatial = np.median(np.diff(t)) + + if not tmin: + nb_files = 100 + tmin = np.max(t) - (dt_spatial * nb_files) + + itmin = np.argmin((abs(t - tmin))) + + return np.mean(epsK[itmin:], axis=0) + +def _compute_lx_from_path(path_simulation, tmin=None): + """ + Compute horizontal length from path using appendix B. Brethouwer 2007 + """ + + # Load parameters from simulation + params = load_params_simul(path_simulation) + + with h5py.File(path_simulation + "/spectra1D.h5", "r") as f: + times_spectra = f["times"].value + kx = f["kyE"].value + spectrum1Dkx_EK_ux = f["spectrum1Dkx_EK_ux"].value + + # Compute time average spectra + dt = np.median(np.diff(times_spectra)) + + if not tmin: + nb_files = 100 + tmin = np.max(times_spectra) - (dt * nb_files) + itmin = np.argmin(abs(times_spectra - tmin)) + + spectrum1Dkx_EK_ux = np.mean(spectrum1Dkx_EK_ux[-itmin:, :], axis=0) + + # Remove modes dealiased + ikxmax = np.argmin(abs(kx - (np.max(kx) * params.oper.coef_dealiasing))) + kx = kx[:ikxmax] + spectrum1Dkx_EK_ux = spectrum1Dkx_EK_ux[:ikxmax] + delta_kx = np.median(np.diff(kx)) + + # Compute horizontal length scale Brethouwer 2007 + return (np.sum(spectrum1Dkx_EK_ux * delta_kx) / + np.sum(kx * spectrum1Dkx_EK_ux * delta_kx)) + +def compute_buoyancy_reynolds(path_simulation, tmin=None): + """ + Compute the buoyancy Reynolds number. + """ + params = load_params_simul(path_simulation) + epsK = _compute_epsilon_from_path(path_simulation, tmin=tmin) + lx = _compute_lx_from_path(path_simulation, tmin=tmin) + + F_h = ((epsK / lx**2)**(1/3)) * (1 / params.N) + + eta_8 = (params.nu_8 ** 3 / epsK)**(1/22) + Re_8 = (lx/eta_8)**(22/3) + + R_b = Re_8 * F_h**8 + return F_h, Re_8, R_b + +# path_simulation = "/fsnet/project/meige/2015/15DELDUCA/DataSim/sim1920_no_shear_modes/NS2D.strat_1920x480_S2pix1.571_F07_gamma02_2018-08-14_09-59-55" +# F_h, Re_8, R_b = compute_buoyancy_reynolds(path_simulation) +# print("F_h", F_h) +# print("Re_8", Re_8) +# print("R_b", R_b) diff --git a/scripts/ns2d.strat/make_table_parameters.py b/scripts/ns2d.strat/make_table_parameters.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L21ha2VfdGFibGVfcGFyYW1ldGVycy5weQ== --- /dev/null +++ b/scripts/ns2d.strat/make_table_parameters.py @@ -0,0 +1,101 @@ +""" +make_table_parameters.py +========================= +28/09/2018 + +""" +import os +import h5py +import numpy as np + +from glob import glob + +from fluidsim import load_sim_for_plot + +# Argparse arguments +nx = 1920 +MAKE_TABLE = False + +# Parameters script +n_files_tmean = 100 + +# Create path +path_root = "/fsnet/project/meige/2015/15DELDUCA/DataSim" + +if nx == 1920: + directory = "sim1920_no_shear_modes" + +path_simulations = sorted(glob(os.path.join(path_root, directory, "NS2D*"))) + +if MAKE_TABLE: + path_table = ("/home/users/calpelin7m/" + + "Phd/docs/Manuscript/buoyancy_reynolds_table_n{}.tex".format(nx)) + + to_print = ("\\begin{table}[h]\n" + "\\centering \n" + "\\begin{tabular}{cccc} \n" + "\\toprule[1.5pt] \n" + \ + "\\bm{$\gamma$} & \\bm{$F_h$} & \\bm{$Re_8$} & \\bm{$\mathcal{R}$} \\\\ \n" + "\\midrule\ \n") + +for path in path_simulations: + + # Load object simulations + sim = load_sim_for_plot(path) + + # Compute gamma from path + gamma_str = path.split("_gamma")[1].split("_")[0] + if gamma_str.startswith("0"): + gamma_table = float(gamma_str[0] + "." + gamma_str[1]) + else: + gamma_table = float(gamma_str) + + # Compute mean kinetic dissipation + dict_spatial = sim.output.spatial_means.load() + + times = dict_spatial["t"] + epsK_tot = dict_spatial["epsK_tot"] + epsK_tmean = np.mean(epsK_tot[-n_files_tmean:], axis=0) + print("epsilon", epsK_tmean) + # Compute horizontal scale as Appendix B. Brethouwer (2007) + path_spectra = path + "/spectra1D.h5" + + with h5py.File(path_spectra, "r") as f: + times_spectra = f["times"].value + kx = f["kyE"].value + spectrum1Dkx_EK_ux = f["spectrum1Dkx_EK_ux"].value + + spectrum1Dkx_EK_ux = np.mean(spectrum1Dkx_EK_ux[-100:, :], axis=0) + ## Remove modes with dealiasing + ikxmax = np.argmin(abs(kx - sim.oper.kxmax_dealiasing)) + kx = kx[:ikxmax] + spectrum1Dkx_EK_ux = spectrum1Dkx_EK_ux[:ikxmax] + delta_kx = sim.oper.deltakx + lx = (np.sum(spectrum1Dkx_EK_ux * delta_kx) / + np.sum(kx * spectrum1Dkx_EK_ux * delta_kx)) + print("lx", lx) + # Compute eta_8 + eta_8 = (sim.params.nu_8 ** 3 / epsK_tmean)**(1/22) + print("eta_8", eta_8) + + # Compute Re_8 + Re_8 = (lx/eta_8)**(22/3) + print("Re_8", Re_8) + + # Compute horizontal Froude + F_h = ((epsK_tmean / lx**2)**(1/3)) * (1/sim.params.N) + print("F_h", F_h) + + # Reynolds buoyancy 8 + Rb8 = Re_8 * F_h**8 + print("Rb8", Rb8) + + if MAKE_TABLE: + to_print += ("{} & {:.4f} & {:.4e} & {:.4e} \\\\ \n".format( + gamma_table, F_h, Re_8, Rb8)) + +if MAKE_TABLE: + with open(path_table, "w") as f: + to_print += ("\\end{tabular} \n" + "\\end{table}") + f.write(to_print) diff --git a/scripts/ns2d.strat/ns2dstrat_lmode.py b/scripts/ns2d.strat/ns2dstrat_lmode.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_c2NyaXB0cy9uczJkLnN0cmF0L25zMmRzdHJhdF9sbW9kZS5weQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L25zMmRzdHJhdF9sbW9kZS5weQ== 100644 --- a/scripts/ns2d.strat/ns2dstrat_lmode.py +++ b/scripts/ns2d.strat/ns2dstrat_lmode.py @@ -60,7 +60,6 @@ k_f = ((nkmax_forcing + nkmin_forcing) / 2) * max(2 * pi / Lx, 2 * pi / Lz) forcing_rate = (1 / tau_af**7) * ((2 * pi) / k_f)**2 omega_af = 2 * pi / tau_af - params.N = (gamma / F) * omega_af params.nu_8 = nu_8 @@ -93,7 +92,7 @@ ##### PARAMETERS ##### ###################### - gamma = 0 # gamma = omega_l / omega_af + gamma = 0.2 # gamma = omega_l / omega_af F = np.sin(pi / 4) # F = omega_l / N sigma = 1 # sigma = omega_l / (pi * f_cf); f_cf freq time correlation forcing in s-1 nu_8 = 1e-15 @@ -103,14 +102,6 @@ # Start simulation sim = Simul(params) - # Date 13/07/2018 - # gammas = [0.2, 0] - # for gamma in gammas: - # params = make_parameters_simulation(gamma, F, sigma, nu_8, t_end=100.) - # sim = Simul(params) - # print("sim.params.N", sim.params.N) - - ##################################### # START NORMALIZATION INITIALIZATION (if nx != nz) # Normalize initialization @@ -155,5 +146,4 @@ # END NORMALIZATION INITIALIZATION ################################### - sim.time_stepping.start() diff --git a/scripts/ns2d.strat/plot_reynolds_froude.py b/scripts/ns2d.strat/plot_reynolds_froude.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L3Bsb3RfcmV5bm9sZHNfZnJvdWRlLnB5 --- /dev/null +++ b/scripts/ns2d.strat/plot_reynolds_froude.py @@ -0,0 +1,105 @@ +""" +plot_reynolds_froude.py +======================== +1/10/2018 + +Makes plot buoyancy reynolds Vs Froude. +""" + +import os +import numpy as np +import matplotlib.pyplot as plt + +from glob import glob + +from compute_anisotropy import compute_anisotropy +from compute_ratio_dissipation import compute_ratio_dissipation +from compute_reynolds_froude import compute_buoyancy_reynolds +from fluiddyn.output.rcparams import set_rcparams + +def _get_resolution_from_dir(path_simulation): + return path_simulation.split("NS2D.strat_")[1].split("x")[0] + +# Create path simulations +path_root = "/fsnet/project/meige/2015/15DELDUCA/DataSim" +directories = ["sim960_no_shear_modes", + "sim1920_no_shear_modes", + "sim1920_modif_res_no_shear_modes", + "sim3840_modif_res_no_shear_modes"] + +# directories = ["sim960_no_shear_modes", +# "sim1920_no_shear_modes"] + +paths_simulations = [] +for directory in directories: + paths_simulations += sorted(glob(os.path.join(path_root, directory, "NS2D*"))) + +froudes = [] +reynoldsb = [] +anisotropies = [] +dissipations = [] +markers = [] + +set_rcparams(fontsize=14, for_article=True) + +fig, ax = plt.subplots() +ax.set_xlabel(r"$F_h$") +ax.set_ylabel(r"$\mathcal{R}$") +ax.set_xscale("log") +ax.set_yscale("log") +fig.text(0.8, 4e-7, r"$\frac{D(k_{fx})}{D(k_x)}$", fontsize=16) + + +for path in paths_simulations: + F_h, Re_8, R_b = compute_buoyancy_reynolds(path) + anisotropy = compute_anisotropy(path) + dissipation = compute_ratio_dissipation(path) + res = _get_resolution_from_dir(path) + + froudes.append(F_h) + reynoldsb.append(R_b) + anisotropies.append(anisotropy) + dissipations.append(dissipation) + + if res == "960": + markers.append("o") + elif res == "1920": + markers.append("s") + elif res == "3840": + markers.append("^") + + print("F_h", F_h) + print("Re_8", Re_8) + print("R_b", R_b) + +for _f, _r, _a, _d, _m in zip(froudes, reynoldsb, anisotropies, dissipations, markers): + scatter = ax.scatter(_f, _r, s=250 * (_a**2), c=_d, vmin=0, vmax=0.3, marker=_m) +# plt.show() + +# areas = 250 * np.asarray(anisotropies)**2 +# scatter = ax.scatter(froudes, reynoldsb, s=areas, c=dissipations, alpha=0.7, vmin=0, vmax=0.3) +ax.scatter(max(froudes), 1e2 * min(reynoldsb), s=250 * np.asarray(0.5)**2, c="red") +ax.scatter(max(froudes), min(reynoldsb), s=250 * np.asarray(1.0)**2, c="red") +ax.text(0.12, 90 * min(reynoldsb), "anisotropy=0", fontsize=12, color="r") +ax.text(0.12, min(reynoldsb), "anisotropy=1", fontsize=12, color="r") +fig.colorbar(scatter) + +# Legend +import matplotlib.lines as mlines +import matplotlib.pyplot as plt + +blue_star = mlines.Line2D([], [], color='red', marker='o', linestyle='None', + markersize=8, label=r'$n_x = 960$') +red_square = mlines.Line2D([], [], color='red', marker='s', linestyle='None', + markersize=8, label=r'$n_x = 1920$') +purple_triangle = mlines.Line2D([], [], color='red', marker='^', linestyle='None', + markersize=8, label=r'$n_x = 3840$') + +ax.legend(handles=[blue_star, red_square, purple_triangle], + loc="upper center", + bbox_to_anchor=(0.5,1.1), + borderaxespad=0., + ncol=len(markers), + handletextpad=0.1, + fontsize=12) +plt.show() diff --git a/scripts/ns2d.strat/simul_from_state.py b/scripts/ns2d.strat/simul_from_state.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L3NpbXVsX2Zyb21fc3RhdGUucHk= --- /dev/null +++ b/scripts/ns2d.strat/simul_from_state.py @@ -0,0 +1,67 @@ +""" +simul_from_state.py +=================== +""" + + +import os +from glob import glob +import argparse +from copy import deepcopy as _deepcopy +from fluidsim import load_sim_for_plot +from fluidsim.solvers.ns2d.strat.solver import Simul + +parser = argparse.ArgumentParser() +parser.add_argument("gamma", type=float) +parser.add_argument("NO_SHEAR_MODES", type=int) +args = parser.parse_args() + +path_root = "/fsnet/project/meige/2015/15DELDUCA/DataSim/Coef_Diss" +paths_gamma = glob(os.path.join(path_root, "Coef_Diss_gamma*")) + +if args.gamma == 0.2: + index = 0 +elif args.gamma == 0.5: + index = 1 +elif args.gamma == 1.0: + index = 2 + +paths_sim = sorted(glob(paths_gamma[index] + "/NS2D.strat*")) +path_file = glob(paths_sim[-1] + "/state_phys*")[-1] + + +sim = load_sim_for_plot(paths_sim[-1]) + +params = _deepcopy(sim.params) + +params.oper.NO_SHEAR_MODES = bool(args.NO_SHEAR_MODES) + +params.init_fields.type = "from_file" +params.init_fields.from_file.path = path_file + +params.time_stepping.USE_CFL = False +params.time_stepping.t_end += 500 +params.time_stepping.deltat0 = sim.time_stepping.deltat * 0.5 + +params.NEW_DIR_RESULTS = True + +params.oper.type_fft = "fft2d.mpi_with_fftw1d" + +params.output.HAS_TO_SAVE = True + +params.output.sub_directory = "sim480" +if args.NO_SHEAR_MODES: + params.output.sub_directory += "_no_shear_modes" + +params.output.periods_save.phys_fields = 2e-1 +params.output.periods_save.spatial_means = 0.5 +params.output.periods_save.spectra = 0.5 +params.output.periods_save.spect_energy_budg = 0.5 +params.output.periods_save.spatio_temporal_spectra = 1. + +params.output.spatio_temporal_spectra.size_max_file = 100 +params.output.spatio_temporal_spectra.spatial_decimate = 4 + + +sim = Simul(params) +sim.time_stepping.start() diff --git a/scripts/ns2d.strat/submit_legi.py b/scripts/ns2d.strat/submit_legi.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L3N1Ym1pdF9sZWdpLnB5 --- /dev/null +++ b/scripts/ns2d.strat/submit_legi.py @@ -0,0 +1,29 @@ +import argparse +from fluiddyn.clusters.legi import Calcul + +# To launch script (for gamma = 0.2): +# python submit_legi.py 0.2 + +parser = argparse.ArgumentParser() +parser.add_argument("gamma", type=float) +args = parser.parse_args() + +cluster = Calcul() +cluster.commands_setting_env.append( + 'export FLUIDSIM_PATH="/fsnet/project/meige/2015/15DELDUCA/DataSim"') + +name_run_root = "find_coeff_nu8_gamma={}".format(args.gamma) + +walltime = '24:00:00' +nb_proc = 8 + +command_to_submit = "python coeff_diss.py {}".format(args.gamma) + +cluster.submit_command( + command_to_submit, + name_run=name_run_root, + nb_cores_per_node=nb_proc, + walltime=walltime, + nb_mpi_processes=nb_proc, + omp_num_threads=1, + idempotent=True, delay_signal_walltime=300, ask=False) diff --git a/scripts/ns2d.strat/submit_simul_from_state.py b/scripts/ns2d.strat/submit_simul_from_state.py new file mode 100644 index 0000000000000000000000000000000000000000..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2NyaXB0cy9uczJkLnN0cmF0L3N1Ym1pdF9zaW11bF9mcm9tX3N0YXRlLnB5 --- /dev/null +++ b/scripts/ns2d.strat/submit_simul_from_state.py @@ -0,0 +1,34 @@ +""" +submit_simul_from_state.py +========================== +""" +import argparse +from fluiddyn.clusters.legi import Calcul + +parser = argparse.ArgumentParser() +parser.add_argument("gamma", type=float) +parser.add_argument("NO_SHEAR_MODES", type=int) +args = parser.parse_args() + +cluster = Calcul() +cluster.commands_setting_env.append( + 'export FLUIDSIM_PATH="/fsnet/project/meige/2015/15DELDUCA/DataSim"') + +name_run_root = "sim480_gamma={}_NO_SHEAR_MODES={}".format( + args.gamma, bool(args.NO_SHEAR_MODES)) + +walltime = '24:00:00' +# nb_proc = cluster.nb_cores_per_node +nb_proc = 8 + +command_to_submit = "python simul_from_state.py {} {}".format( + args.gamma, args.NO_SHEAR_MODES) + +cluster.submit_command( + command_to_submit, + name_run=name_run_root, + nb_cores_per_node=nb_proc, + walltime=walltime, + nb_mpi_processes=nb_proc, + omp_num_threads=1, + idempotent=True, delay_signal_walltime=300, ask=False) diff --git a/setup.cfg b/setup.cfg index 9bccb25fe016aed4b58d7978626bbeb12912e6db_c2V0dXAuY2Zn..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2V0dXAuY2Zn 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [flake8] -ignore = E225,E226,E303,E201,E202, W503 +ignore = E501,E225,E226,E303,E201,E202,E203,W503 [coverage:run] source = ./fluidsim @@ -19,3 +19,7 @@ [coverage:xml] output = .coverage/coverage.xml +[options] +setup_requires = + fluidpythran + numpy diff --git a/setup.py b/setup.py index 9bccb25fe016aed4b58d7978626bbeb12912e6db_c2V0dXAucHk=..d518cba80100a7dda4c0ac799c06b46c6fee5871_c2V0dXAucHk= 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,2 @@ - -from __future__ import print_function - import os import sys @@ -4,5 +1,7 @@ import os import sys +from pathlib import Path + from time import time from runpy import run_path from datetime import datetime @@ -14,4 +13,5 @@ from Cython.Distutils.extension import Extension from Cython.Distutils import build_ext from Cython.Compiler import Options as CythonOptions + has_cython = True @@ -17,5 +17,5 @@ has_cython = True - ext_source = 'pyx' + ext_source = "pyx" except ImportError: from setuptools import Extension from distutils.command.build_ext import build_ext @@ -19,4 +19,5 @@ except ImportError: from setuptools import Extension from distutils.command.build_ext import build_ext + has_cython = False @@ -22,5 +23,5 @@ has_cython = False - ext_source = 'c' + ext_source = "c" try: from pythran.dist import PythranExtension @@ -24,7 +25,8 @@ try: from pythran.dist import PythranExtension + use_pythran = True except ImportError: use_pythran = False @@ -27,6 +29,7 @@ use_pythran = True except ImportError: use_pythran = False + import numpy as np @@ -31,7 +34,8 @@ import numpy as np -from config import ( - MPI4PY, FFTW3, monkeypatch_parallel_build, get_config, logger) +f"In >=2018, you should use a Python supporting f-strings!" + +from config import MPI4PY, FFTW3, monkeypatch_parallel_build, get_config, logger if use_pythran: try: @@ -39,8 +43,9 @@ class fluidsim_build_ext(build_ext, PythranBuildExt): pass + except ImportError: fluidsim_build_ext = build_ext else: fluidsim_build_ext = build_ext @@ -42,10 +47,16 @@ except ImportError: fluidsim_build_ext = build_ext else: fluidsim_build_ext = build_ext +here = Path(__file__).parent.absolute() + +from fluidpythran.files_maker import make_pythran_files + +paths = ["fluidsim/base/time_stepping/pseudo_spect.py"] +make_pythran_files([here / path for path in paths]) time_start = time() config = get_config() # handle environ (variables) in config @@ -47,10 +58,10 @@ time_start = time() config = get_config() # handle environ (variables) in config -if 'environ' in config: - os.environ.update(config['environ']) +if "environ" in config: + os.environ.update(config["environ"]) monkeypatch_parallel_build() @@ -54,11 +65,9 @@ monkeypatch_parallel_build() -logger.info('Running fluidsim setup.py on platform ' + sys.platform) - -here = os.path.abspath(os.path.dirname(__file__)) +logger.info("Running fluidsim setup.py on platform " + sys.platform) if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[0:2] < (3, 2): raise RuntimeError("Python version 2.7 or >= 3.2 required.") # Get the long description from the relevant file @@ -60,8 +69,8 @@ if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[0:2] < (3, 2): raise RuntimeError("Python version 2.7 or >= 3.2 required.") # Get the long description from the relevant file -with open(os.path.join(here, 'README.rst')) as f: +with open(os.path.join(here, "README.rst")) as f: long_description = f.read() lines = long_description.splitlines(True) @@ -66,5 +75,5 @@ long_description = f.read() lines = long_description.splitlines(True) -long_description = ''.join(lines[14:]) +long_description = "".join(lines[14:]) # Get the version from the relevant file @@ -69,9 +78,9 @@ # Get the version from the relevant file -d = run_path('fluidsim/_version.py') -__version__ = d['__version__'] -__about__ = d['__about__'] +d = run_path("fluidsim/_version.py") +__version__ = d["__version__"] +__about__ = d["__about__"] print(__about__) # Get the development status from the version string @@ -74,9 +83,9 @@ print(__about__) # Get the development status from the version string -if 'a' in __version__: - devstatus = 'Development Status :: 3 - Alpha' -elif 'b' in __version__: - devstatus = 'Development Status :: 4 - Beta' +if "a" in __version__: + devstatus = "Development Status :: 3 - Alpha" +elif "b" in __version__: + devstatus = "Development Status :: 4 - Beta" else: @@ -82,5 +91,5 @@ else: - devstatus = 'Development Status :: 5 - Production/Stable' + devstatus = "Development Status :: 5 - Production/Stable" ext_modules = [] @@ -84,6 +93,6 @@ ext_modules = [] -logger.info('Importing mpi4py: {}'.format(MPI4PY)) +logger.info("Importing mpi4py: {}".format(MPI4PY)) define_macros = [] @@ -88,4 +97,4 @@ define_macros = [] -if has_cython and os.getenv('TOXENV') is not None: +if has_cython and os.getenv("TOXENV") is not None: cython_defaults = CythonOptions.get_directive_defaults() @@ -91,4 +100,4 @@ cython_defaults = CythonOptions.get_directive_defaults() - cython_defaults['linetrace'] = True - define_macros.append(('CYTHON_TRACE_NOGIL', '1')) + cython_defaults["linetrace"] = True + define_macros.append(("CYTHON_TRACE_NOGIL", "1")) @@ -94,3 +103,3 @@ -path_sources = 'fluidsim/base/time_stepping' +path_sources = "fluidsim/base/time_stepping" ext_cyfunc = Extension( @@ -96,7 +105,5 @@ ext_cyfunc = Extension( - 'fluidsim.base.time_stepping.pseudo_spect_cy', - include_dirs=[ - path_sources, - np.get_include()], - libraries=['m'], + "fluidsim.base.time_stepping.pseudo_spect_cy", + include_dirs=[path_sources, np.get_include()], + libraries=["m"], library_dirs=[], @@ -102,6 +109,7 @@ library_dirs=[], - sources=[path_sources + '/pseudo_spect_cy.' + ext_source], - define_macros=define_macros) + sources=[path_sources + "/pseudo_spect_cy." + ext_source], + define_macros=define_macros, +) ext_modules.append(ext_cyfunc) @@ -105,6 +113,8 @@ ext_modules.append(ext_cyfunc) -logger.info('The following extensions could be built if necessary:\n' + - ''.join([ext.name + '\n' for ext in ext_modules])) +logger.info( + "The following extensions could be built if necessary:\n" + + "".join([ext.name + "\n" for ext in ext_modules]) +) @@ -110,6 +120,10 @@ - -install_requires = ['fluiddyn >= 0.2.3', 'future >= 0.16', - 'h5py', 'h5netcdf'] +install_requires = [ + "fluiddyn >= 0.2.3", + "future >= 0.16", + "h5py", + "h5netcdf", + "fluidpythran >= 0.0.3", +] if FFTW3: @@ -114,6 +128,6 @@ if FFTW3: - install_requires += ['pyfftw >= 0.10.4', 'fluidfft >= 0.2.4'] + install_requires.extend(["pyfftw >= 0.10.4", "fluidfft >= 0.2.6"]) def modification_date(filename): @@ -123,6 +137,6 @@ def make_pythran_extensions(modules): exclude_pythran = tuple( - key for key, value in config['exclude_pythran'].items() - if value) + key for key, value in config["exclude_pythran"].items() if value + ) if len(exclude_pythran) > 0: @@ -128,6 +142,9 @@ if len(exclude_pythran) > 0: - logger.info('Pythran files in the packages ' + str(exclude_pythran) + - ' will not be built.') - develop = sys.argv[-1] == 'develop' + logger.info( + "Pythran files in the packages " + + str(exclude_pythran) + + " will not be built." + ) + develop = sys.argv[-1] == "develop" extensions = [] for mod in modules: @@ -132,5 +149,5 @@ extensions = [] for mod in modules: - package = mod.rsplit('.', 1)[0] + package = mod.rsplit(".", 1)[0] if any(package == excluded for excluded in exclude_pythran): continue @@ -135,5 +152,5 @@ if any(package == excluded for excluded in exclude_pythran): continue - base_file = mod.replace('.', os.path.sep) - py_file = base_file + '.py' + base_file = mod.replace(".", os.path.sep) + py_file = base_file + ".py" # warning: does not work on Windows @@ -139,3 +156,3 @@ # warning: does not work on Windows - suffix = get_config_var('EXT_SUFFIX') or '.so' + suffix = get_config_var("EXT_SUFFIX") or ".so" bin_file = base_file + suffix @@ -141,8 +158,5 @@ bin_file = base_file + suffix - logger.info('make_pythran_extension: {} -> {} '.format( - py_file, os.path.basename(bin_file))) - if not develop or not os.path.exists(bin_file) or \ - modification_date(bin_file) < modification_date(py_file): - pext = PythranExtension( - mod, [py_file], extra_compile_args=['-O3'] + logger.info( + "make_pythran_extension: {} -> {} ".format( + py_file, os.path.basename(bin_file) ) @@ -148,3 +162,10 @@ ) + ) + if ( + not develop + or not os.path.exists(bin_file) + or modification_date(bin_file) < modification_date(py_file) + ): + pext = PythranExtension(mod, [py_file], extra_compile_args=["-O3"]) pext.include_dirs.append(np.get_include()) # bug pythran extension... @@ -149,8 +170,9 @@ pext.include_dirs.append(np.get_include()) # bug pythran extension... - compile_arch = os.getenv('CARCH', 'native') - pext.extra_compile_args.extend(['-O3', - '-march={}'.format(compile_arch)]) + compile_arch = os.getenv("CARCH", "native") + pext.extra_compile_args.extend( + ["-O3", "-march={}".format(compile_arch), "-DUSE_XSIMD"] + ) # pext.extra_link_args.extend(['-fopenmp']) extensions.append(pext) return extensions @@ -158,5 +180,6 @@ if use_pythran: ext_names = [] - for root, dirs, files in os.walk('fluidsim'): + for root, dirs, files in os.walk("fluidsim"): + path_dir = Path(root) for name in files: @@ -162,3 +185,7 @@ for name in files: - if name.endswith('_pythran.py'): + if ( + name.endswith("_pythran.py") + or path_dir.name == "_pythran" + and name.endswith(".py") + ): path = os.path.join(root, name) @@ -164,7 +191,6 @@ path = os.path.join(root, name) - ext_names.append( - path.replace(os.path.sep, '.').split('.py')[0]) + ext_names.append(path.replace(os.path.sep, ".").split(".py")[0]) ext_modules += make_pythran_extensions(ext_names) console_scripts = [ @@ -167,8 +193,9 @@ ext_modules += make_pythran_extensions(ext_names) console_scripts = [ - 'fluidsim = fluidsim.util.console.__main__:run', - 'fluidsim-test = fluidsim.util.testing:run', - 'fluidsim-create-xml-description = fluidsim.base.output:run'] + "fluidsim = fluidsim.util.console.__main__:run", + "fluidsim-test = fluidsim.util.testing:run", + "fluidsim-create-xml-description = fluidsim.base.output:run", +] @@ -174,3 +201,3 @@ -for command in ['profile', 'bench', 'bench-analysis']: +for command in ["profile", "bench", "bench-analysis"]: console_scripts.append( @@ -176,5 +203,8 @@ console_scripts.append( - 'fluidsim-' + command + - ' = fluidsim.util.console.__main__:run_' + command.replace('-', '_')) + "fluidsim-" + + command + + " = fluidsim.util.console.__main__:run_" + + command.replace("-", "_") + ) @@ -179,45 +209,43 @@ -setup(name='fluidsim', - version=__version__, - description=('Framework for studying fluid dynamics with simulations.'), - long_description=long_description, - keywords='Fluid dynamics, research', - author='Pierre Augier', - author_email='pierre.augier@legi.cnrs.fr', - url='https://bitbucket.org/fluiddyn/fluidsim', - license='CeCILL', - classifiers=[ - # How mature is this project? Common values are - # 3 - Alpha - # 4 - Beta - # 5 - Production/Stable - devstatus, - 'Intended Audience :: Science/Research', - 'Intended Audience :: Education', - 'Topic :: Scientific/Engineering', - 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)', - # actually CeCILL License (GPL compatible license for French laws) - # - # Specify the Python versions you support here. In particular, - # ensure that you indicate whether you support Python 2, - # Python 3 or both. - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Cython', - 'Programming Language :: C', - ], - python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*', - packages=find_packages(exclude=['doc', 'examples']), - install_requires=install_requires, - extras_require=dict( - doc=['Sphinx>=1.1', 'numpydoc'], - parallel=['mpi4py']), - cmdclass={"build_ext": fluidsim_build_ext}, - ext_modules=ext_modules, - entry_points={'console_scripts': console_scripts}) +setup( + name="fluidsim", + version=__version__, + description=("Framework for studying fluid dynamics with simulations."), + long_description=long_description, + keywords="Fluid dynamics, research", + author="Pierre Augier", + author_email="pierre.augier@legi.cnrs.fr", + url="https://bitbucket.org/fluiddyn/fluidsim", + license="CeCILL", + classifiers=[ + # How mature is this project? Common values are + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + devstatus, + "Intended Audience :: Science/Research", + "Intended Audience :: Education", + "Topic :: Scientific/Engineering", + "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", + # actually CeCILL License (GPL compatible license for French laws) + # + # Specify the Python versions you support here. In particular, + # ensure that you indicate whether you support Python 2, + # Python 3 or both. + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Cython", + "Programming Language :: C", + ], + python_requires=">=3.6", + packages=find_packages(exclude=["doc", "examples"]), + install_requires=install_requires, + extras_require=dict(doc=["Sphinx>=1.1", "numpydoc"], parallel=["mpi4py"]), + cmdclass={"build_ext": fluidsim_build_ext}, + ext_modules=ext_modules, + entry_points={"console_scripts": console_scripts}, +) @@ -223,2 +251,2 @@ -logger.info('Setup completed in {:.3f} seconds.'.format(time() - time_start)) +logger.info("Setup completed in {:.3f} seconds.".format(time() - time_start)) diff --git a/tox.ini b/tox.ini index 9bccb25fe016aed4b58d7978626bbeb12912e6db_dG94LmluaQ==..d518cba80100a7dda4c0ac799c06b46c6fee5871_dG94LmluaQ== 100644 --- a/tox.ini +++ b/tox.ini @@ -10,8 +10,8 @@ # this directory. [tox] envlist = - py{27,35,36} - py{27,36}-pythran + py{36} + py{36}-pythran lint codecov @@ -20,4 +20,5 @@ whitelist_externals = make usedevelop = True deps = + pip==18.0 coverage @@ -23,4 +24,5 @@ coverage + fluidpythran mako numpy matplotlib @@ -46,6 +48,7 @@ passenv = CODECOV_TOKEN sitepackages = True deps = + pip==18.0 codecov cython whitelist_externals = make @@ -58,6 +61,7 @@ [testenv:codecov-travis] passenv = CI TRAVIS TRAVIS_* deps = + pip==18.0 codecov cython usedevelop = False @@ -68,6 +72,7 @@ [testenv:lint] deps = + pip==18.0 pylint whitelist_externals = make usedevelop = False