GridFormat 0.4.0
I/O-Library for grid-like data structures
Loading...
Searching...
No Matches
GridFormat::Writer< G > Class Template Reference

Interface to the writers for all supported file formats. Depending on the chosen format, this exposes the interface of grid file or time series writers. More...

#include <writer.hpp>

Detailed Description

template<Concepts::Grid G>
class GridFormat::Writer< G >

Typically you would construct this class with one of the predefined file format instances. For example, with the .vtu file format:

GridFormat::Writer writer{GridFormat::vtu, grid};
Interface to the writers for all supported file formats. Depending on the chosen format,...
Definition: writer.hpp:90
const Grid & grid() const
Return a reference to the underlying grid.
Definition: writer.hpp:326
Note
The constructor checks that the grid you are passing in is actually an lvalue-reference. If not, compilation will fail. This is because all writers take the grid per reference and their lifetime is bound to the lifetime of the given grid.
Template Parameters
GridThe type of grid which should be written out.

Public Types

using Grid = G
 

Public Member Functions

template<typename FileFormat , WriterDetail::Compatible< Grid > _Grid>
requires (WriterDetail::has_sequential_factory<FileFormat, Grid>)
 Writer (const FileFormat &f, _Grid &&grid)
 Construct a sequential grid file writer.
 
template<typename FileFormat , WriterDetail::Compatible< Grid > _Grid>
requires (WriterDetail::has_sequential_time_series_factory<FileFormat, Grid>)
 Writer (const FileFormat &f, _Grid &&grid, const std::string &base_filename)
 Construct a sequential time series writer.
 
template<typename FileFormat , WriterDetail::Compatible< Grid > _Grid, Concepts::Communicator Comm>
requires (WriterDetail::has_parallel_factory<FileFormat, Grid, Comm>)
 Writer (const FileFormat &f, _Grid &&grid, const Comm &comm)
 Construct a parallel grid file writer.
 
template<typename FileFormat , WriterDetail::Compatible< Grid > _Grid, Concepts::Communicator Comm>
requires (WriterDetail::has_parallel_time_series_factory<FileFormat, Grid, Comm>)
 Writer (const FileFormat &f, _Grid &&grid, const Comm &comm, const std::string &base_filename)
 Construct a parallel time series file writer.
 
template<std::derived_from< GridWriter< Grid > > W>
requires (!std::is_lvalue_reference_v<W>)
 Writer (W &&writer)
 Construct a grid file writer from a writer implementation.
 
template<std::derived_from< TimeSeriesGridWriter< Grid > > W>
requires (!std::is_lvalue_reference_v<W>)
 Writer (W &&writer)
 Construct a time series file writer from a writer implementation.
 
std::string write (const std::string &filename) const
 Write the grid and data to a file.
 
template<Concepts::Scalar T>
std::string write (const T &time_value) const
 Write a time step in a time series.
 
template<typename Field >
void set_meta_data (const std::string &name, Field &&field)
 Set a meta data field to be added to the output.
 
template<typename Field >
void set_point_field (const std::string &name, Field &&field)
 Set a point data field to be added to the output.
 
template<typename Field , typename T >
void set_point_field (const std::string &name, Field &&field, const Precision< T > &prec)
 Overload with custom precision with which to write the field.
 
template<typename Field >
void set_cell_field (const std::string &name, Field &&field)
 Set a cell data field to be added to the output.
 
template<typename Field , typename T >
void set_cell_field (const std::string &name, Field &&field, const Precision< T > &prec)
 Overload with custom precision with which to write the field.
 
FieldPtr remove_meta_data (const std::string &name)
 Remove a meta data field from the output.
 
FieldPtr remove_point_field (const std::string &name)
 Remove a point field from the output.
 
FieldPtr remove_cell_field (const std::string &name)
 Remove a cell field from the output.
 
void clear ()
 Remove all data inserted to the writer.
 
void set_ignore_warnings (bool value)
 Ignore/consider warnings (default: true)
 
template<typename Writer >
void copy_fields (Writer &out) const
 Copy all inserted fields into another writer.
 
const std::optional< WriterOptions > & writer_options () const
 Return the basic options used by this writer.
 
const Grid & grid () const
 Return a reference to the underlying grid.
 

Friends

decltype(auto) point_fields (const Writer &w)
 Return a range over all point fields that were added to the given writer.
 
decltype(auto) cell_fields (const Writer &w)
 Return a range over all cell fields that were added to the given writer.
 
decltype(auto) meta_data_fields (const Writer &w)
 Return a range over all meta data fields that were added to the given writer.
 

Constructor & Destructor Documentation

◆ Writer() [1/4]

template<Concepts::Grid G>
template<typename FileFormat , WriterDetail::Compatible< Grid > _Grid>
requires (WriterDetail::has_sequential_factory<FileFormat, Grid>)
GridFormat::Writer< G >::Writer ( const FileFormat &  f,
_Grid &&  grid 
)
inline
Parameters
fThe file format which should be written.
gridThe grid which should be written out.

◆ Writer() [2/4]

template<Concepts::Grid G>
template<typename FileFormat , WriterDetail::Compatible< Grid > _Grid>
requires (WriterDetail::has_sequential_time_series_factory<FileFormat, Grid>)
GridFormat::Writer< G >::Writer ( const FileFormat &  f,
_Grid &&  grid,
const std::string &  base_filename 
)
inline
Parameters
fThe file format which should be written.
gridThe grid which should be written out.
base_filenameThe name of the file (without extension) into which to write.

◆ Writer() [3/4]

template<Concepts::Grid G>
template<typename FileFormat , WriterDetail::Compatible< Grid > _Grid, Concepts::Communicator Comm>
requires (WriterDetail::has_parallel_factory<FileFormat, Grid, Comm>)
GridFormat::Writer< G >::Writer ( const FileFormat &  f,
_Grid &&  grid,
const Comm &  comm 
)
inline
Parameters
fThe file format which should be written.
gridThe grid which should be written out.
commThe communicator for parallel communication.

◆ Writer() [4/4]

template<Concepts::Grid G>
template<typename FileFormat , WriterDetail::Compatible< Grid > _Grid, Concepts::Communicator Comm>
requires (WriterDetail::has_parallel_time_series_factory<FileFormat, Grid, Comm>)
GridFormat::Writer< G >::Writer ( const FileFormat &  f,
_Grid &&  grid,
const Comm &  comm,
const std::string &  base_filename 
)
inline
Parameters
fThe file format which should be written.
gridThe grid which should be written out.
commThe communicator for parallel communication.
base_filenameThe name of the file (without extension) into which to write.

Member Function Documentation

◆ copy_fields()

template<Concepts::Grid G>
template<typename Writer >
void GridFormat::Writer< G >::copy_fields ( Writer< G > &  out) const
inline
Parameters
outThe writer into which to copy all fields of this writer.

◆ remove_cell_field()

template<Concepts::Grid G>
FieldPtr GridFormat::Writer< G >::remove_cell_field ( const std::string &  name)
inline
Parameters
nameThe name of the cell field.

◆ remove_meta_data()

template<Concepts::Grid G>
FieldPtr GridFormat::Writer< G >::remove_meta_data ( const std::string &  name)
inline
Parameters
nameThe name of the meta data field.

◆ remove_point_field()

template<Concepts::Grid G>
FieldPtr GridFormat::Writer< G >::remove_point_field ( const std::string &  name)
inline
Parameters
nameThe name of the point field.

◆ set_cell_field() [1/2]

template<Concepts::Grid G>
template<typename Field >
void GridFormat::Writer< G >::set_cell_field ( const std::string &  name,
Field &&  field 
)
inline
Parameters
nameThe name of the cell data field.
fieldThe actual cell data.
Note
Cell data is usually given as lambdas that are invocable with cells of the grid. You can also pass in custom fields that inherit from the Field class. This is discouraged, however.

◆ set_cell_field() [2/2]

template<Concepts::Grid G>
template<typename Field , typename T >
void GridFormat::Writer< G >::set_cell_field ( const std::string &  name,
Field &&  field,
const Precision< T > &  prec 
)
inline
Note
Can be used to save space on disk and increase the write speed if you know that your field can be represented sufficiently well by a smaller precision.

◆ set_meta_data()

template<Concepts::Grid G>
template<typename Field >
void GridFormat::Writer< G >::set_meta_data ( const std::string &  name,
Field &&  field 
)
inline
Parameters
nameThe name of the meta data field.
fieldThe actual meta data.
Note
Supported metadata are scalar values, strings, or ranges of scalars.

◆ set_point_field() [1/2]

template<Concepts::Grid G>
template<typename Field >
void GridFormat::Writer< G >::set_point_field ( const std::string &  name,
Field &&  field 
)
inline
Parameters
nameThe name of the point data field.
fieldThe actual point data.
Note
Point data is usually given as lambdas that are invocable with points of the grid. You can also pass in custom fields that inherit from the Field class. This is discouraged, however.

◆ set_point_field() [2/2]

template<Concepts::Grid G>
template<typename Field , typename T >
void GridFormat::Writer< G >::set_point_field ( const std::string &  name,
Field &&  field,
const Precision< T > &  prec 
)
inline
Note
Can be used to save space on disk and increase the write speed if you know that your field can be represented sufficiently well by a smaller precision.

◆ write() [1/2]

template<Concepts::Grid G>
std::string GridFormat::Writer< G >::write ( const std::string &  filename) const
inline
Parameters
filenameThe name of file into which to write (without extension).
Note
Calling this function is only allowed if the writer was created as a grid file writer. If this instance is a time series writer, calling this function will throw an exception.

◆ write() [2/2]

template<Concepts::Grid G>
template<Concepts::Scalar T>
std::string GridFormat::Writer< G >::write ( const T &  time_value) const
inline
Parameters
time_valueThe time corresponding to this time step.
Note
Calling this function is only allowed if the writer was created as a time series file writer. If this instance is a grid file writer, calling this function will throw an exception.

◆ writer_options()

template<Concepts::Grid G>
const std::optional< WriterOptions > & GridFormat::Writer< G >::writer_options ( ) const
inline
Note
This is used internally and not be required by users.

Friends And Related Function Documentation

◆ cell_fields

template<Concepts::Grid G>
decltype(auto) cell_fields ( const Writer< G > &  w)
friend
Parameters
wThe writer whose fields to return
Returns
A range over key-value pairs containing the name and a pointer to actual field.  
Note
You can use range-based for loops with structured bindings, for instance:
for (const auto& [name, field_ptr] : cell_fields(writer)) { ... }
friend decltype(auto) cell_fields(const Writer &w)
Return a range over all cell fields that were added to the given writer.
Definition: writer.hpp:356

◆ meta_data_fields

template<Concepts::Grid G>
decltype(auto) meta_data_fields ( const Writer< G > &  w)
friend
Parameters
wThe writer whose fields to return
Returns
A range over key-value pairs containing the name and a pointer to actual field.  
Note
You can use range-based for loops with structured bindings, for instance:
for (const auto& [name, field_ptr] : meta_data_fields(writer)) { ... }
friend decltype(auto) meta_data_fields(const Writer &w)
Return a range over all meta data fields that were added to the given writer.
Definition: writer.hpp:371

◆ point_fields

template<Concepts::Grid G>
decltype(auto) point_fields ( const Writer< G > &  w)
friend
Parameters
wThe writer whose fields to return
Returns
A range over key-value pairs containing the name and a pointer to actual field.  
Note
You can use range-based for loops with structured bindings, for instance:
for (const auto& [name, field_ptr] : point_fields(writer)) { ... }
friend decltype(auto) point_fields(const Writer &w)
Return a range over all point fields that were added to the given writer.
Definition: writer.hpp:341

The documentation for this class was generated from the following file: