Skip to content

Commit a081670

Browse files
committed
Merge branch 'topic/default/type_fft' into 'branch/default'
FLUIDSIM_TYPE_FFT Closes #164 See merge request fluiddyn/fluidsim!415
2 parents 9747cd6 + 4227788 commit a081670

File tree

11 files changed

+398
-363
lines changed

11 files changed

+398
-363
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pytest_cov_html_full:
103103

104104
define _pytest_mpi_operators3d
105105
$(call _init_coverage)
106-
FLUIDSIM_TYPE_FFT=$(1) TRANSONIC_NO_REPLACE=1 mpirun -np $(MPI_NUM_PROCS) coverage run -p -m pytest -v --exitfirst fluidsim/operators/test/test_operators3d.py -p no:warnings
106+
FLUIDSIM_TYPE_FFT3D=$(1) TRANSONIC_NO_REPLACE=1 mpirun -np $(MPI_NUM_PROCS) coverage run -p -m pytest -v --exitfirst fluidsim/operators/test/test_operators3d.py -p no:warnings
107107
$(call _end_coverage_combine)
108108
endef
109109

@@ -118,8 +118,8 @@ pytest_mpi_with_pfft:
118118

119119
pytest_mpi_with_p3dfft:
120120
$(call _init_coverage)
121-
FLUIDSIM_TYPE_FFT=fft3d.mpi_with_p3dfft TRANSONIC_NO_REPLACE=1 mpirun -np $(MPI_NUM_PROCS) \
121+
FLUIDSIM_TYPE_FFT3D=fft3d.mpi_with_p3dfft TRANSONIC_NO_REPLACE=1 mpirun -np $(MPI_NUM_PROCS) \
122122
coverage run -p -m pytest -v --exitfirst fluidsim/operators/test/test_operators3d.py::TestCoarse
123-
FLUIDSIM_TYPE_FFT=fft3d.mpi_with_p3dfft TRANSONIC_NO_REPLACE=1 mpirun -np $(MPI_NUM_PROCS) \
123+
FLUIDSIM_TYPE_FFT3D=fft3d.mpi_with_p3dfft TRANSONIC_NO_REPLACE=1 mpirun -np $(MPI_NUM_PROCS) \
124124
coverage run -p -m pytest -v --exitfirst fluidsim/operators/test/test_operators3d.py -k "not TestCoarse"
125125
$(call _end_coverage_combine)

doc/install.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ Fluidsim is sensitive to environment variables:
142142

143143
- `FLUIDDYN_PATH_SCRATCH`: working directory (can be useful on some clusters).
144144

145+
- `FLUIDSIM_TYPE_FFT2D` and `FLUIDSIM_TYPE_FFT3D`: set the Fluidfft method
146+
(see <https://fluidfft.readthedocs.io/en/latest/plugins.html>).
147+
145148
## Dependencies with different flavours
146149

147150
## Fluidfft

fluidsim/operators/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.. autosummary::
77
:toctree:
88
9+
base
910
operators0d
1011
operators2d
1112
operators3d

fluidsim/operators/base.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,39 @@
55
66
Provides:
77
8-
.. autoclass:: OperatorBase1D
8+
.. autoclass:: OperatorBase
9+
:members:
10+
:private-members:
11+
12+
.. autoclass:: OperatorsBase1D
913
:members:
1014
:private-members:
1115
1216
"""
1317

18+
import os
19+
20+
from warnings import warn
21+
1422
import numpy as np
1523

1624
from fluiddyn.util import mpi
1725

1826

27+
def _get_type_fft_from_params_and_env(params, dim: str):
28+
var_name = "FLUIDSIM_TYPE_FFT" + dim
29+
if var_name in os.environ:
30+
if params.oper.type_fft == "default":
31+
type_fft = os.environ[var_name]
32+
print(f"Using {var_name}={type_fft}")
33+
return type_fft
34+
elif params.oper.type_fft != "sequential":
35+
warn(f"not using {var_name} since params.oper.type_fft != 'default'")
36+
return params.oper.type_fft
37+
else:
38+
return params.oper.type_fft
39+
40+
1941
class OperatorBase:
2042
def _modify_sim_repr_maker(self, sim_repr_maker):
2143
if not hasattr(self, "produce_str_describing_oper"):

fluidsim/operators/operators2d.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
1010
"""
1111

12+
import sys
13+
1214
from warnings import warn
1315
from random import uniform
14-
import sys
1516

1617
import numpy as np
1718

@@ -22,7 +23,7 @@
2223
from fluidsim.base.params import Parameters
2324
from ..base.setofvariables import SetOfVariables
2425
from .. import _is_testing
25-
from .base import OperatorBase
26+
from .base import OperatorBase, _get_type_fft_from_params_and_env
2627

2728
ts = Transonic()
2829

@@ -139,7 +140,7 @@ def __init__(self, params):
139140
ny,
140141
params.oper.Lx,
141142
params.oper.Ly,
142-
fft=params.oper.type_fft,
143+
fft=_get_type_fft_from_params_and_env(params, "2D"),
143144
coef_dealiasing=params.oper.coef_dealiasing,
144145
)
145146

fluidsim/operators/operators3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from .operators2d import OperatorsPseudoSpectral2D as OpPseudoSpectral2D
2727
from .. import _is_testing
28-
from .base import OperatorBase
28+
from .base import OperatorBase, _get_type_fft_from_params_and_env
2929

3030
ts = Transonic()
3131

@@ -226,7 +226,7 @@ def __init__(self, params=None):
226226
params.oper.Lx,
227227
params.oper.Ly,
228228
params.oper.Lz,
229-
fft=params.oper.type_fft,
229+
fft=_get_type_fft_from_params_and_env(params, "3D"),
230230
coef_dealiasing=params.oper.coef_dealiasing,
231231
)
232232

fluidsim/operators/test/test_operators2d.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ def create_oper(type_fft=None, coef_dealiasing=2.0 / 3, **kwargs):
3232
params.oper.Lx = Lh
3333
params.oper.Ly = Lh
3434

35-
if "FLUIDSIM_TYPE_FFT" in os.environ:
36-
type_fft = os.environ["FLUIDSIM_TYPE_FFT"]
37-
print(f"{type_fft = }")
38-
39-
if type_fft is not None:
40-
params.oper.type_fft = type_fft
41-
4235
params.oper.coef_dealiasing = coef_dealiasing
4336

4437
oper = OperatorsPseudoSpectral2D(params=params)
@@ -173,10 +166,6 @@ def test_coarse(self, allclose):
173166

174167
params.oper.truncation_shape = "spherical"
175168

176-
if "FLUIDSIM_TYPE_FFT" in os.environ:
177-
params.oper.type_fft = os.environ["FLUIDSIM_TYPE_FFT"]
178-
print(f"{params.oper.type_fft = }")
179-
180169
oper = self.Oper(params)
181170

182171
params_coarse = deepcopy(params)

fluidsim/operators/test/test_operators3d.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515

1616
def xfail_if_fluidfft_class_not_importable(func):
17-
if not FLUIDFFT_INSTALLED or "FLUIDSIM_TYPE_FFT" not in os.environ:
17+
if not FLUIDFFT_INSTALLED or "FLUIDSIM_TYPE_FFT3D" not in os.environ:
1818
return func
1919

2020
from fluidfft import import_fft_class
2121

2222
try:
23-
import_fft_class(os.environ["FLUIDSIM_TYPE_FFT"])
23+
import_fft_class(os.environ["FLUIDSIM_TYPE_FFT3D"])
2424
except ImportError:
2525
ImportError_fft_class = True
2626
else:
@@ -41,10 +41,6 @@ def oper():
4141
p.oper.nz = 4
4242
p.oper.Lx = p.oper.Ly = p.oper.Lz = 2 * np.pi
4343

44-
if "FLUIDSIM_TYPE_FFT" in os.environ:
45-
p.oper.type_fft = os.environ["FLUIDSIM_TYPE_FFT"]
46-
print(f"{p.oper.type_fft = }")
47-
4844
return OperatorsPseudoSpectral3D(params=p)
4945

5046

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_mpi_fft_lib(session, method_fft, nprocs=2, _k_expr=None, env=None):
3030
env = {}
3131
else:
3232
env = env.copy()
33-
env.update({"TRANSONIC_NO_REPLACE": "1", "FLUIDSIM_TYPE_FFT": method_fft})
33+
env.update({"TRANSONIC_NO_REPLACE": "1", "FLUIDSIM_TYPE_FFT3D": method_fft})
3434

3535
print(f"test for method {method_fft}")
3636
session.run(*cmd, external=True, env=env)

0 commit comments

Comments
 (0)