MCPcopy Create free account
hub / github.com/DedalusProject/dedalus / fill_random

Method fill_random

dedalus/core/field.py:898–943  ·  view source on GitHub ↗

Fill field with random data. If a seed is specified, the global data is reproducibly generated for any process mesh. Parameters ---------- layout : Layout object, 'c', or 'g', optional Layout for setting field data. Default: current layout.

(self, layout=None, scales=None, seed=None, chunk_size=2**20, distribution='standard_normal', **kw)

Source from the content-addressed store, hash-verified

896 return data
897
898 def fill_random(self, layout=None, scales=None, seed=None, chunk_size=2**20, distribution='standard_normal', **kw):
899 """
900 Fill field with random data. If a seed is specified, the global data is
901 reproducibly generated for any process mesh.
902
903 Parameters
904 ----------
905 layout : Layout object, 'c', or 'g', optional
906 Layout for setting field data. Default: current layout.
907 scales : number or tuple of numbers, optional
908 Scales for setting field data. Default: current scales.
909 seed : int, optional
910 RNG seed. Default: None.
911 chunk_size : int, optional
912 Chunk size for drawing from distribution. Should be less than locally
913 available memory. Default: 2**20, corresponding to 8 MB of float64.
914 distribution : str, optional
915 Distribution name, corresponding to numpy random Generator method.
916 Default: 'standard_normal'.
917 **kw : dict
918 Other keywords passed to the distribution method.
919 """
920 init_layout = self.layout
921 # Set scales if requested
922 if scales is not None:
923 self.preset_scales(scales)
924 if layout is None:
925 self.preset_layout(init_layout)
926 # Set layout if requested
927 if layout is not None:
928 self.preset_layout(layout)
929 # Build global chunked random array (does not require global-sized memory)
930 shape = tuple(cs.dim for cs in self.tensorsig) + self.global_shape
931 if self.is_complex:
932 shape = shape + (2,)
933 global_data = ChunkedRandomArray(shape, seed, chunk_size, distribution, **kw)
934 # Extract local data
935 component_slices = tuple(slice(None) for cs in self.tensorsig)
936 spatial_slices = self.layout.slices(self.domain, self.scales)
937 local_slices = component_slices + spatial_slices
938 local_data = global_data[local_slices]
939 if self.is_real:
940 self.data[:] = local_data
941 else:
942 self.data.real[:] = local_data[..., 0]
943 self.data.imag[:] = local_data[..., 1]
944
945 def low_pass_filter(self, shape=None, scales=None):
946 """

Callers 15

test_jacobi_convertFunction · 0.95
test_trace_implicitFunction · 0.95
test_radial_multiplyFunction · 0.95
test_radial_dotFunction · 0.95
test_radial_crossFunction · 0.95
test_meridional_multiplyFunction · 0.95
test_meridional_dotFunction · 0.95
test_meridional_crossFunction · 0.95
test_eval_jacobi_nccFunction · 0.95
test_eval_fourier_nccFunction · 0.95

Calls 4

ChunkedRandomArrayClass · 0.85
preset_scalesMethod · 0.80
preset_layoutMethod · 0.80
slicesMethod · 0.80

Tested by 15

test_jacobi_convertFunction · 0.76
test_trace_implicitFunction · 0.76
test_radial_multiplyFunction · 0.76
test_radial_dotFunction · 0.76
test_radial_crossFunction · 0.76
test_meridional_multiplyFunction · 0.76
test_meridional_dotFunction · 0.76
test_meridional_crossFunction · 0.76
test_eval_jacobi_nccFunction · 0.76
test_eval_fourier_nccFunction · 0.76