You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: drdmannturb/fluctuation_generation/sampling_methods.py
+37-64
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@
3
3
"""
4
4
5
5
importos
6
-
frommathimport*
7
6
8
7
importnumpyasnp
9
8
importscipy.fftpackasfft
@@ -16,14 +15,16 @@
16
15
17
16
18
17
classSampling_method_base:
19
-
"""Meta class for different sampling methods. Each of these requires a ``RandomField`` object, which is a subclass of :py:class:``GaussianRandomField``."""
18
+
"""Meta class for different sampling methods. Each of these requires a ``RandomField`` object, which is
19
+
a subclass of :py:class:``GaussianRandomField``."""
20
20
21
21
def__init__(self, RandomField):
22
22
"""
23
23
Parameters
24
24
----------
25
25
RandomField : GaussianRandomField
26
-
The random field from which to sample from. This object also determines all of the physical quantities and domain partitioning.
26
+
The random field from which to sample from. This object also determines all of the physical quantities
"""Sampling method specifically in the frequency domain. This metaclass involves a single precomputation of the covariance spectrum of the underlying ``GaussianRandomField``. Refer to specific subclasses for details on what each of these entails, but generally, the approximate square-root of each associated spectral tensor is computed and transformed into the frequency domain.
38
+
"""Sampling method specifically in the frequency domain. This metaclass involves a single precomputation of the
39
+
covariance spectrum of the underlying ``GaussianRandomField``. Refer to specific subclasses for details on what
40
+
each of these entails, but generally, the approximate square-root of each associated spectral tensor is computed
41
+
and transformed into the frequency domain.
38
42
39
43
The norm of the transform is defined as the square-root of the length-scale.
### - Uses the Fastest Fourier Transform in the West
57
-
58
-
59
54
classSampling_FFTW(Sampling_method_freq):
60
-
"""Sampling with FFTW. Two stencils for the forward and inverse FFTs are generated using the following FFTW flags: ``"FFTW_MEASURE", "FFTW_DESTROY_INPUT", "FFTW_UNALIGNED"``.
55
+
"""Sampling with FFTW. Two stencils for the forward and inverse FFTs are generated using the following FFTW flags:
### - Uses the Fastest Fourier Transform in the West
85
+
classSampling_VF_FFTW(Sampling_method_freq):
86
+
"""Random vector fields using
99
87
88
+
FFTW applied to a vector field. This should be used in conjunction with :py:class:`VectorGaussianRandomField`.
89
+
This sampling method is also multi-threaded across 4 threads, or else the maximum allowed by the environment. As in
90
+
:py:class:`Sampling_FFTW`, the following FFTW flags are used: ``"FFTW_MEASURE", "FFTW_DESTROY_INPUT",
91
+
"FFTW_UNALIGNED"``.
100
92
101
-
classSampling_VF_FFTW(Sampling_method_freq):
102
-
"""FFTW applied to a vector field. This should be used in conjunction with :py:class:`VectorGaussianRandomField`. This sampling method is also multi-threaded across 4 threads, or else the maximum allowed by the environment. As in :py:class:`Sampling_FFTW`, the following FFTW flags are used: ``"FFTW_MEASURE", "FFTW_DESTROY_INPUT", "FFTW_UNALIGNED"``."""
93
+
Due to properties of the FFT, only stationary covariances are admissible.
94
+
"""
103
95
104
96
def__init__(self, RandomField):
105
97
super().__init__(RandomField)
106
98
107
99
importpyfftw
108
100
109
-
n_cpu=4
110
-
try:
111
-
n_cpu=int(os.environ["OMP_NUM_THREADS"])
112
-
except:
113
-
pass
101
+
# WARN: User might have OMP_NUM_THREADS set to something invalid here
0 commit comments