Writer¶
Proxy Class to write files.
Parameters¶
- base:
Base
Base to dump in a file.
- base:
- filename: str
The name of the output file. Two tags may be used to tell Antares which part of the filename will be variable, the
<zone>
tag and the<instant>
tag.For example, if one has a base made of two zones (e.g. rotor and stator) and two instants per rows (e.g. t00 and t01), if the filename is set as
<zone>_instant_<instant>.dat
, then the written files will be:rotor_instant_t00.dat rotor_instant_t01.dat stator_instant_t00.dat stator_instant_t01.dat
- zone_format: str, default= ‘%s’
To interpret the zone name defined by the tag
<zone>
of filename, Antares uses string formatting. Only two regular expressions are available by now,%s
and%0[0-9]*d
.
- instant_format: str, default= ‘%s’
To interpret the instant name defined by the tag
<instant>
of filename, Antares uses string formatting. Only two regular expressions are available by now,%s
and%0[0-9]*d
.
- topology_format: str
The format of the topology file. If not given, the topology file will not be written.
- scripts_format: str
The format of the cfd scripts. If not given, the cfd scripts will not be written.
- bnd_dir: str, default= ‘./’
Location of the boundary data directory. Useful when topology_format is given.
- scripts_dir: str, default= ‘./’
Location of the cfd scripts directory. Useful when scripts_format is given.
- coordinates: list(str)
The mesh coordinates (used for some format like vtk).
- dtype: str, default= ‘float64’
The data type used to dump data.
- memory_mode: bool, default= False
If memory mode is True, the base is deleted on the fly to limit memory usage.
Main functions¶
- class antares.io.Writer.Writer(file_format=None, **kwargs)¶
Proxy class for file writers.
- __init__(file_format=None, **kwargs)¶
Initialize the Writer instance.
- Parameters:
file_format (str) – the format of the file(s).
- dump()¶
Dump all Zones and all Instants of a Base to files.
For each format below, the associated keys supplement the above shared settable keys.
HDF5 CGNS¶
Description¶
Write files with the CGNS format.
This writer ‘hdf_cgns’ supports MPI parallelism.
The root node of the hierarchical HDF5 data structure may contain groups, and groups may contain datasets.
Parameters¶
see Common Parameters from Writer Proxy.
- link: str, default= ‘single’
Can take the value:
‘zone’: 1 file per zone + 1 master file
‘proc’: 1 file per processor + 1 master file
‘single’: 1 file, different possible strategies
‘merged’: write 1 temporary file per processor then merge them into a single file
- strategy: str, default= ‘one_pass’
Only for link = ‘single’. Can take the value:
‘one_pass’: the file is collectively created and filled in one pass (encouraged in sequential)
‘two_passes’: the file structure is created during a first pass by one processor and it is filled individually in parallel (encouraged in parallel)
‘update_copy’: the file is copied by one processor and its solution is updates individually in parallel (encouraged for a base having a large number of zones but a few data)
- source_filename: str, default= None
Name of the CGNS file to copy and update solution. It must have strictly the same structure (zones and shape of zones) as the base. Only for link = ‘single’ and strategy = ‘update_copy’.
- append: bool, default= False
If True, append the base in the existing CGNS file.
- base_name: str, default= BASE_NAME
Name of the CGNSBase_t node.
- rename_vars: bool, default= True
Rename Antares variables with CGNS names.
- mixed_conn: bool, default= False
Write all elements in a single CGNS node as mixed elements.
Preconditions¶
The input base could contain structured and unstructured zones.
Postconditions¶
The output only contain one time solution.
Example¶
The following example shows how to write a file ‘case.cgns’.
import antares
writer = Writer('hdf_cgns')
writer['filename'] = 'case.cgns'
writer['base'] = base
writer.dump()
Tecplot (binary)¶
Description¶
Write files with tecplot binary format (v75, v112).
https://cerfacs.fr/antares/doc/_downloads/bin_tp_V112_data_format.dat
Preconditions¶
The Tecplot title of the header section is searched in Base.attrs
with the key TecplotHeaderTitle.
The Tecplot parameter FileType is searched in Base.attrs
with the
key TecplotFileType.
The attrs Time is searched in Instant.attrs
. If the values of
Instant.attrs['Time']
are the same for some Instant
, then
the corresponding instants will be considered identical, and only one of them
will be considered in the output file. Therefore, the output file will not
contain all the Instant
of the base.
Postconditions¶
An instant may contain (‘rho’, ‘cell’) and (‘rho’, ‘node’) for example, then the tecplot variable names would be ‘rho_cell’ and ‘rho’.
Variables and connectivities that are shared are not written as such in the tecplot file. So if you read the written file back in Antares, it will take more memory.
If there are only variables located at cell in the base, data are written as node values.
Example¶
The following example shows how to write one file.
import antares
myw = antares.Writer('bin_tp')
myw['filename'] = 'file.plt'
myw['base'] = base
myw.dump()
The following example shows how to write one file per zone with the tag ‘<zone>’.
import antares
myw = antares.Writer('bin_tp')
myw['filename'] = 'file_<zone>.plt'
myw['base'] = base
myw.dump()
The following example shows how to write one file per zone per instant with the tags ‘<zone>’ and ‘<instant>’.
import antares
myw = antares.Writer('bin_tp')
myw['filename'] = 'file_<zone>_<instant>.plt'
myw['base'] = base
myw.dump()
- class antares.io.writer.WriterTecplotBinary.WriterTecplotBinary¶
CSV¶
Comma-separated values CSV format.
Parameters¶
- separator: str, default= ;
Separator character between numbers.
- with_col_num: bool, default= True
Add column number to variable names if enabled: ‘a’ -> ‘a(0)’.
- class antares.io.writer.WriterCSV.WriterCSV¶
Writer for CSV (Comma-separated values) format.
The first line contain the name of variables separated by the separator string. Columns may have different sizes. Rows are composed of numbers separated by the separator string.
This is an Instant writer. So, if many zones are in a base, then it will write many files if the tag ‘<zone>’ is in the ‘filename’.
This is an Instant writer (It only writes an Instant in a file). So, if many zones are in a base, then it will write many files if the tag ‘<zone>’ is in the ‘filename’. Otherwise, the zone name is appended at the end of the ‘filename’.
Binary VTK¶
VTK format.
Parameters¶
- append: bool, default= False
If True, append the base in the existing ‘_xmlbase.pvd’ file. This allows the user to write zones and instants on-the-fly.
- class antares.io.writer.WriterVtk.WriterVtk¶
HDF5 Jaguar Restart¶
Writer HDF JAGUAR RESTART
Parameters¶
- strategy: str, default= ‘h5py_ll’
Can be one of:
‘monoproc’: the file is created by one proc. This must be used for initial solution creation only.
‘h5py_hl’: Parallel write with h5py high level API. Simple but slow because writes multiple times to reorder cells.
‘h5py_ll’: Parallel write with h5py low level API. Use hyperslabs to perform reordering with only one write.
‘fortran’: Parallel write with fortran HDF5 write. Most efficient way to write but need compilation.
- class antares.io.writer.WriterHdfJaguarRestart.WriterHdfJaguarRestart¶
Writer to write bases for high order JAGUAR solver.
Write only one time solution.
Seq: Write only initial solution. Parallel: Reorder and write high order solution from Jaguar coprocessing.
Several parallel write modes have been tested:
h5py_sorted_highAPI: ‘h5py_hl’
h5py_sorted_lowAPI: ‘h5py_ll’
fortran_sorted_opt2: ‘fortran’
In sorted results, the efficiency is from best to worst: fortran > h5py_ll > h5py hl
Here, only h5py low level API (restart_mode=h5py_ll) is used because it has an efficiency near of the pure fortran, but it is much easier to modify and debug. For final best performance, a pure fortran code can be derived quite easily based of existing one from the python h5py_ll code.
HDF5 AVBP¶
Description¶
Write files for the AVBP code
More information on the format can be found here.
The root node of the hierarchical HDF5 data structure may contain groups, and groups may contain datasets.
Parameters¶
see Common Parameters from Writer Proxy.
- filename: str
Tags
<zone>
and<instant>
are not used.
- groups_vars: list or tuple
Give the location of solution variables in AVBP groups for the solution file.
example to write ‘rhou’ and ‘rhov’ in group1 and ‘pressure’ in group2:
groups_vars = (('group1', ['rhou', 'rhov']), ('group2', ['pressure']))
example to write all variables in group1:
groups_vars = 'group1'
Warning
you may end up with a file that does not respect the AVBP format.
Preconditions¶
The input base must have a single zone and a single instant (or a shared instant).
The instant may contain the group names as keys in its Instant.attrs
.
The values are lists of avbp variable names.
e.g.:
instant.attrs[‘GaseousPhase’] = [‘rhou’, ‘rho’]
instant.attrs[‘Additionals’] = [‘tau_turb_x’, ‘tau_turb_y’, ‘tau_turb_z’]
This information is used to write variables in the right groups.
Postconditions¶
The outputs are the mesh file named filename.mesh.h5 and the solution file named filename.sol.h5. The file named filename.asciiBound.key is output if the zone has boundary conditions.
Mesh File:¶
If some instant variables are in
antares.core.Constants.KNOWN_COORDINATES
, then the mesh file is created.
If the zone contains boundary conditions in Zone.boundaries
, then the
file asciiBound.key is created.
If the coordinates of the base are not [‘x’, ‘y’, ‘z’], then they are renamed in-place.
The group ‘Parameters’ is created. All entries of Zone.attrs
are
written to datasets in this group.
The group ‘Coordinates’ and its datasets [‘x’, ‘y’, ‘z’] are created.
The group ‘Connectivity’ and its datasets ‘<elt_type>->node’ are created.
If the zone contains boundary conditions in Zone.boundaries
, then the
group ‘Boundary’ is created. All entries in Boundary.container
compatible with the AVBP format will be considered, the groups
[‘Periodicity’, ‘Patch’] and the datasets
[‘PatchGeoType’, ‘Patch->area’, ‘bnode->normal’, ‘bnd_<elt_type>->face’,
‘bnd_<elt_type>->elem’].
All variables from the entry ‘VertexData’ of Instant.attrs
and the
variable ‘volume’ will be created as datasets in the group ‘VertexData’. If no
such variables are in the instant, then the group is not created.
Solution File:¶
If some variables are different from [‘x’, ‘y’, ‘z’] and the variables contained
in the entry ‘VertexData’ of Instant.attrs
, then the solution file is
created.
The group ‘Parameters’ is created. All entries of Zone.attrs
in
[‘dtsum’, ‘nit_av’, ‘niter’, ‘nnode’, ‘t_av’, ‘versionstring’, ‘gitid’]
are written to datasets in this group. By default,
[‘dtsum’, ‘niter’, ‘nnode’, ‘versionstring’] are set to
[0, 0, <instant.shape>, ‘AVBP Version V7.X’].
All variables are written in the following groups [‘GaseousPhase’, ‘Reactions’, ‘RhoSpecies’, ‘LiquidPhase’, ‘FictiveSpecies’, ‘Additionals’, ‘Sparkignition’, ‘RealGas’, ‘Average’] or new user-defined groups following the option groups_vars or the AVBP file format.
Example¶
The following example shows how to write a mesh file ‘case.mesh.h5’, and a solution file ‘case.sol.h5’, and a file ‘case.asciiBound.key’.
import antares
writer = Writer('hdf_avbp')
writer['filename'] = 'case'
writer['base'] = base
writer.dump()
The following example shows the same thing, but with some user modification for the placement of some variables in groups.
import antares
writer = Writer('hdf_avbp')
writer['filename'] = 'case'
writer['base'] = base
writer['groups_vars'] = (('Additionals', ['rho', 'rhou']),
('Reactions', ['pressure']))
writer.dump()
HDF5 antares¶
Description¶
Write files with antares HDF5 format.
Parameters¶
see Common Parameters from Writer Proxy.
- format:
str
in [‘2015’, ‘2022’], default= ‘2015’ The file format version.
format 2015: The zone/instant/variable ‘list_keys’ are stored in h5 attrs.
format 2022: The zone/instant/variable ‘list_keys’ are stored in h5 datasets. This format can handle very long lists of strings.
- format:
- xmf:
bool
, default= True Write the associated .xmf file.
- xmf:
Preconditions¶
Postconditions¶
The name of the filename is suffixed with ‘.h5’. The name of the filename is suffixed with ‘.xmf’ if xmf is True.
The .xmf file is not created for 1D data.
A base level attribute ‘Antares version’ is automatically added to the base. This attribute contains the version Antares used to write the files.
The base, zone and instant level attributes are written in the following groups:
“Parameters” under the root group for base level attributes.
“Zone parameters” under the zone group for zone level attributes.
“Instant parameters” under the instant group for instant level attributes.
Example¶
The following example shows how to write one file.
import antares
myw = antares.Writer('hdf_antares')
myw['filename'] = 'file'
myw['base'] = base
myw.dump()