mpi4py_fft.utilities package¶
Submodules¶
mpi4py_fft.utilities.generate_xdmf module¶
-
mpi4py_fft.utilities.generate_xdmf.
generate_xdmf
(h5filename, periodic=True, order='paraview')[source]¶ Generate XDMF-files
Parameters: - h5filename (str) – Name of hdf5-file that we want to decorate with xdmf
- periodic (bool or dim-sequence of bools, optional) – If true along axis i, assume data is periodic. Only affects the calculation of the domain size and only if the domain is given as 2-tuple of origin+dx.
- order (str) –
paraview
orvisit
For some reason Paraview and Visit requires the mesh stored in opposite order in the XDMF-file for 2D slices. Make choice of order here.
mpi4py_fft.utilities.h5py_file module¶
-
class
mpi4py_fft.utilities.h5py_file.
HDF5File
(h5name, T, domain=None, mode='a', **kw)[source]¶ Bases:
mpi4py_fft.utilities.file_base.FileBase
Class for reading/writing data to HDF5 format
Parameters: h5name (str) – Name of hdf5 file to be created.
T (PFFT) – Instance of a
PFFT
class. Must be the same as the space used for storing withHDF5Writer.write
.domain (Sequence, optional) –
The spatial domain. Sequence of either
- 2-tuples, where each 2-tuple contains the (origin, length) of each dimension, e.g., (0, 2*pi).
- Arrays of coordinates, e.g., np.linspace(0, 2*pi, N). One array per dimension.
mode (str, optional) –
r
,w
ora
for read, write or append. Default isa
.
-
read
(u, name, **kw)[source]¶ Read into array
u
Parameters: - u (array) – The array to read into.
- name (str) – Name of array to be read.
- forward_output (bool, optional) – Whether the array to be read is the output of a forward transform or not. Default is False.
- step (int, optional) – Index of field to be read. Default is 0.
-
write
(step, fields, **kw)[source]¶ Write snapshot
step
offields
to HDF5 fileParameters: - step (int) – Index of snapshot.
- fields (dict) – The fields to be dumped to file. (key, value) pairs are group name and either arrays or 2-tuples, respectively. The arrays are complete arrays to be stored, whereas 2-tuples are arrays with associated global slices.
- forward_output (bool, optional) – Whether fields to be stored are shaped as the output of a forward transform or not. Default is False.
Example
>>> from mpi4py import MPI >>> from mpi4py_fft import PFFT, HDF5File, newDistArray >>> comm = MPI.COMM_WORLD >>> T = PFFT(comm, (15, 16, 17)) >>> u = newDistArray(T, forward_output=False, val=1) >>> v = newDistArray(T, forward_output=False, val=2) >>> f = HDF5File('h5filename.h5', T) >>> f.write(0, {'u': [u, (u, [slice(None), 4, slice(None)])], ... 'v': [v, (v, [slice(None), 5, 5])]}) >>> f.write(1, {'u': [u, (u, [slice(None), 4, slice(None)])], ... 'v': [v, (v, [slice(None), 5, 5])]})
This stores data within two main groups
u
andv
. The HDF5 file will in the end contain groups:/u/3D/{0, 1} /u/2D/slice_4_slice/{0, 1} /v/3D/{0, 1} /v/1D/slice_5_5/{0, 1}
Note
The list of slices used in storing only parts of the arrays are views of the global arrays.
mpi4py_fft.utilities.nc_file module¶
-
class
mpi4py_fft.utilities.nc_file.
NCFile
(ncname, T, domain=None, clobber=True, mode='r', **kw)[source]¶ Bases:
mpi4py_fft.utilities.file_base.FileBase
Class for writing data to NetCDF4 format
Parameters: ncname (str) – Name of netcdf file to be created
T (PFFT) – Instance of a
PFFT
class. Must be the same as the space used for storing withNCWriter.write
domain (Sequence) –
The spatial domain. Sequence of either
- 2-tuples, where each 2-tuple contains the (origin, length) of each dimension, e.g., (0, 2*pi).
- Arrays of coordinates, e.g., np.linspace(0, 2*pi, N). One array per dimension.
clobber (bool, optional)
mode (str) –
r
orw
for read or write. Default is ‘r’.
Note
Each class instance creates one unique NetCDF4-file, with one step-counter. It is possible to store multiple fields in each file, but all snapshots of the fields must be taken at the same time. If you want one field stored every 10th timestep and another every 20th timestep, then use two different class instances and as such two NetCDF4-files.
-
read
(u, name, **kw)[source]¶ Read into array
u
Parameters: - u (array) – The array to read into.
- name (str) – Name of array to be read.
- step (int, optional) – Index of field to be read. Default is 0.
-
write
(step, fields, **kw)[source]¶ Write snapshot step of
fields
to NetCDF4 fileParameters: - step (int) – Index of snapshot
- fields (dict) – The fields to be dumped to file. (key, value) pairs are group name and either arrays or 2-tuples, respectively. The arrays are complete arrays to be stored, whereas 2-tuples are arrays with associated global slices.
mpi4py_fft.utilities.file_base module¶
-
class
mpi4py_fft.utilities.file_base.
FileBase
(T, domain=None, **kw)[source]¶ Bases:
object
Base class for reading/writing structured arrays
Parameters: T (PFFT) – Instance of a
PFFT
class.domain (sequence, optional) –
The spatial domain. Sequence of either
- 2-tuples, where each 2-tuple contains the (origin, length) of each dimension, e.g., (0, 2*pi).
- Arrays of coordinates, e.g., np.linspace(0, 2*pi, N). One array per dimension.
-
read
(u, name, **kw)[source]¶ Read into array
u
Parameters: - u (array) – The array to read into.
- name (str) – Name of array to be read.
-
write
(step, fields, **kw)[source]¶ Write snapshot
step
offields
to fileParameters: - step (int) – Index of snapshot.
- fields (dict) – The fields to be dumped to file. (key, value) pairs are group name and either arrays or 2-tuples, respectively. The arrays are complete arrays to be stored, whereas 2-tuples are arrays with associated global slices.