adios2
Descriptions of the contents of the adios2 module.
- class pysemtools.io.adios2.stream.DataStreamer(comm, from_nek=True)
Class used to communicate data between codes using adios2.
Use this to send and recieve data.
The data is always transported as a 1d array, so it is necessary to reshape.
- Parameters:
- commComm
MPI communicator.
- from_nekbool
Define if the data that is being stream comes from a nek-like code. (Default value = True).
- Attributes:
- glb_nelvint
Total number of elements in the global domain.
- lxyzint
Number of points per element.
- gdimint
Problem dimension.
- nelvint
Number of elements that this rank has.
Methods
finalize
()Finalize the execution of the module.
recieve
([fld, variable])Recieve data from another code using adios2.
stream
(fld)Send data to another code using adios2.
Examples
This type must be paired with another streaming in the other executable/code. The codes will not start if the streams are not paired.
A full of example of recieving data is shown below. It is possible to pair with other classes to, for example, write data to disk.
>>> ds = data_streamer_c(comm) >>> x = get_fld_from_ndarray(ds.recieve(), ds.lx, ds.ly, ds.lz, ds.nelv) # Recieve and reshape x >>> y = get_fld_from_ndarray(ds.recieve(), ds.lx, ds.ly, ds.lz, ds.nelv) # Recieve and reshape y >>> z = get_fld_from_ndarray(ds.recieve(), ds.lx, ds.ly, ds.lz, ds.nelv) # Recieve and reshape z >>> ds.finalize() >>> msh = msh_c(comm, x = x, y = y, z = z) >>> write_fld_file_from_list("field0.f00001", comm, msh, [x, y, z])
To send data to the other code, use the stream method.
>>> ds.stream(x.reshape(x.size))
- finalize()
Finalize the execution of the module.
Used to close reader and writer. The stream will end and the code will not be coupled.
- recieve(fld=None, variable='f2py_field')
Recieve data from another code using adios2.
The data is always transported as a 1d array, so it is necessary to reshape to deinred shape.
- Parameters:
- fldndarray
Buffer to contain the data. If None, it will be created. (Default value = None).
- variablestr
Name of the adios2 variable to be read. Neko used default name. Change as needed. This name can remain the same during the execution even if different quantities are being transported. (Default value = “f2py_field”).
- Returns:
- ndarray
Returns the field that was recieved.
- stream(fld)
Send data to another code using adios2.
Couple 2 code or executables.
- Parameters:
- fldndarray
Field to be sent. Must be a 1d array.
- class pysemtools.io.adios2.compress.DataCompressor(comm, mesh_info=None, wrd_size=4)
Class used to write compressed data to disk.
This Assumes that the input data has a msh object available.
- Parameters:
- commComm
MPI communicator.
- mesh_infodict
Dictionary with mesh information.
- wrd_sizeint
Word size to write data. (Default value = 4). Single precsiion is 4, double is 8.
Methods
read
(comm[, fname, variable_names])Read data from disk using adios2.
write
(comm[, fname, variable_names, data])Write data to disk using adios2.
- Returns:
Examples
This class is used to write data to disk. The data is compressed using bzip2.
>>> mesh_info = {"glb_nelv": msh.glb_nelv, "lxyz": msh.lxyz, "gdim": msh.gdim} >>> dc = DataCompressor(comm, mesh_info = mesh_info, wrd_size = 4)
- read(comm, fname='compress.bp', variable_names=None)
Read data from disk using adios2.
Read compressed data and internally decompress it.
- Parameters:
- commComm
MPI communicator.
- fnamestr
File name to read. (Default value = “compress.bp”).
- variable_nameslist
List of string with the names of the variables to read. These names NEED to match the names adios2 used to write the data.
- Returns:
- list
List of numpy arrays with the data read. the ndarrays in the list are 1d.
Examples
This function is used to read data from disk. The data is compressed using bzip2.
>>> variable_names = ["x", "y", "z"] >>> data = dc.read(comm, fname = "compress.bp", variable_names = variable_names)
- write(comm, fname='compress.bp', variable_names=None, data=None)
Write data to disk using adios2.
Lossless compression with bzip2.
- Parameters:
- commComm
MPI communicator.
- fnamestr
File name to write. (Default value = “compress.bp”).
- variable_nameslist
List of string with the names of the variables to write. This is very important, as adios2 will use these names to process the data.
- datalist
List of numpy arrays with the data to write. Corresponding in index to variable_names. The arrays must be 1d.
Examples
This function is used to write data to disk. The data is compressed using bzip2.
>>> variable_names = ["x", "y", "z"] >>> data = [msh.x, msh.y, msh.z] >>> dc.write(comm, fname = "compress.bp", variable_names = variable_names, data = data)
- pysemtools.io.adios2.compress.write_field(comm, msh=None, fld=None, fname='compressed_field0.f00001', wrd_size=4, write_mesh=True)
Wrapper to data compressor writer.
Writes nek like data compressed.
- Parameters:
- commComm
MPI communicator.
- mshMesh
Mesh object to write. (Default value = None).
- fldField
Field object to write. (Default value = None).
- fnamestr
File name to write. (Default value = “compressed_field0.f00001”).
- wrd_sizeint
Word size to write data. (Default value = 4). Single precsiion is 4, double is 8.
- write_meshbool
Flag to write the mesh. (Default value = True).
Examples
This function is used to write data to disk. The data is compressed using bzip2.
>>> write_field(comm, msh = msh, fld = fld, fname = "compressed_field0.f00001", wrd_size = 4, write_mesh = True)
- pysemtools.io.adios2.compress.read_field(comm, fname='compressed_field0.f00001')
Wrapper to data compressor reader.
Reads nek like data compressed.
- Parameters:
- commComm
MPI communicator.
- fnamestr
File name to read. (Default value = “compressed_field0.f00001”).
- Returns:
- msh: Mesh
Mesh object read.
- fldField
Field object read.
Examples
This function is used to read data from disk. The data is compressed using bzip2.
>>> msh, fld = read_field(comm, fname = "compressed_field0.f00001")