Field
Descriptions of the contents of the Field class, which is used to collect data to be post-processed.
- class pysemtools.datatypes.field.Field(comm, data=None)
Class that contains fields.
This is the main class used to contain data that can be used for post processing. The data does not generarly need to be present in this class, as it is typically enough to have the data as ndarrays of shape (nelv, lz, ly, lx) for each field. However this class provides a easy interface to collect data tha is somehow associated.
It also allows to easily write data to disk. As all the data in this class will be stored in the same file.
- Parameters:
- commComm
MPI comminicator object.
- dataHexaData, optional
HexaData object that contains the coordinates of the domain.
- Attributes:
- fieldsdict
Dictionary that contains the fields. The keys are the field names and the values are lists of ndarrays. The keys for these dictionaries are the same as for Hexadata objects, i.e. vel, pres, temp, scal.
- vel_fieldsint
Number of velocity fields.
- pres_fieldsint
Number of pressure fields.
- temp_fieldsint
Number of temperature fields.
- scal_fieldsint
Number of scalar fields.
- tfloat
Time of the data.
Methods
Update number of fields.
clear
- Returns:
Examples
If a hexadata object: data is read from disk, the field object can be created directly from it.
>>> from pysemtools.datatypes.field import Field >>> fld = Mesh(comm, data = data)
If one wishes to use the data in the fields. It is possible to reference it with a ndarray of shape (nelv, lz, ly, lx) as follows:
>>> u = fld.fields["vel"][0] >>> v = fld.fields["vel"][1] >>> w = fld.fields["vel"][2] >>> vel_magnitude = np.sqrt(u**2 + v**2 + w**2)
A field object can be created empty and then fields can be added to it. Useful to write data to disk. if a ndarray u is created with shape (nelv, lz, ly, lx) it can be added to the field object as follows:
>>> from pysemtools.datatypes.field import Field >>> fld = Field(comm) >>> fld.fields["vel"].append(u) >>> fld.update_vars()
This fld object can then be used to write fld files from field u created in the code.
- update_vars()
Update number of fields.
Update the number of fields in the class in the event that it has been modified. This is needed for writing data properly if more arrays are added to the class.
Examples
A field object can be created empty and then fields can be added to it. Useful to write data to disk. if a ndarray u is created with shape (nelv, lz, ly, lx) it can be added to the field object as follows:
>>> from pysemtools.datatypes.field import Field >>> fld = Field(comm) >>> fld.fields["vel"].append(u) >>> fld.update_vars()
This fld object can then be used to write fld files from field u created in the code.
FieldRegistry
Descriptions of the contents of the FieldRegistry class, which extends the Field class and is used to collect data to be post-processed.
- class pysemtools.datatypes.field.FieldRegistry(comm, data=None, bckend='numpy')
Class that contains fields.
This class extends the main field class, as it contains a registry that allows to easily reference the fields.
- Parameters:
- commComm
MPI comminicator object.
- dataHexaData, optional
HexaData object that contains the coordinates of the domain.
Methods
add_field
(comm[, field_name, field, ...])Add fields to the registry.
clear
()Clear the registry and the fields.
rename_registry_key
([old_key, new_key])Rename a key in the registry.
Update the registry with the fields that are present in the fields dictionary.
- add_field(comm, field_name='', field=None, file_type=None, file_name=None, file_key=None, dtype=<class 'numpy.float64'>)
Add fields to the registry. They will be stored in the fields dictionary to easily write them.
- Parameters:
- commComm
MPI comminicator object.
- field_namestr
Name of the field to be added. where the field is added thepends on the name
- fieldndarray
Field to be added to the registry. If this is provided, it is assumed to be a ndarray. It will then be added to the registry.
- file_typestr
Type of the file to be added. If this is provided, it is assumed to be a file. Currently, only “fld” supported.
- file_namestr
File name of the field to be added. If this is provided, it is assumed to be a file. It will then be added to the registry.
- file_keystr
File key. This will be search in the file. For nek file, the key have the following format: “vel_0”, “vel_1”, “pres”, “temp”, “scal_0”, “scal_1”, etc. Only for “vel” we read the 2/3 components at the same time
- dtypenp.dtype
Data type of the field. Default is np.double.
- clear()
Clear the registry and the fields.
- rename_registry_key(old_key='', new_key='')
Rename a key in the registry.
- Parameters:
- old_keystr
Old key to be renamed.
- new_keystr
New key to be used.
Notes
If you update the registry, some keys might be overwritten or multiple keys might reference the same data.
- update_vars()
Update the registry with the fields that are present in the fields dictionary.