|
svMultiPhysics
|
A mesh stored in one of the VTK XML file formats. More...
#include <VtkData.h>
Public Member Functions | |
| VtkData ()=default | |
| Default constructor. | |
| virtual | ~VtkData ()=default |
| Virtual destructor. | |
| virtual void | read_file (const std::string &file_name) |
| Read the mesh data from a VTK file. | |
| virtual void | create_grid ()=0 |
| Create an empty grid. | |
| virtual void | write () const =0 |
| Write the mesh data to a VTK file. | |
| Array< int > | get_connectivity () const |
| Get the connectivity of the mesh elements. | |
| Array< double > | get_points () const |
| Get the points of the mesh. | |
| int | num_elems () const |
| Get the number of elements in the mesh. | |
| int | elem_type () const |
| Get the element type. | |
| int | num_points_per_elem () const |
| Get the number of points per element. | |
| int | num_points () const |
| Get the number of points in the mesh. | |
| void | set_element_data (const std::string &data_name, const Array< double > &data) |
| Set a double-valued element data array. | |
| void | set_element_data (const std::string &data_name, const Array< int > &data) |
| Set an int-valued element data array. | |
| void | set_element_data (const std::string &data_name, const Vector< int > &data) |
| Set an int-valued element data vector. | |
| void | set_point_data (const std::string &data_name, const Array< double > &data) |
| Set a double-valued point data array. | |
| void | set_point_data (const std::string &data_name, const Array< int > &data) |
| Set an int-valued point data array. | |
| void | set_point_data (const std::string &data_name, const Vector< int > &data) |
| Set an int-valued point data array. | |
| void | set_points (const Array< double > &points) |
| Set the point coordinates of the mesh. | |
| void | set_connectivity (const int nsd, const Array< int > &conn) |
| Set the mesh connectivity to define the elements. | |
| void | set_time_value (const double time) |
| Store a time value as field data. | |
| bool | has_cell_data (const std::string &data_name) const |
| Check if a given cell data array exists. | |
| bool | has_point_data (const std::string &data_name) const |
| Check if a given point data array exists. | |
| void | copy_points (Array< double > &points) const |
| Copy the mesh points to an Array. | |
| void | copy_point_data (const std::string &data_name, Array< double > &mesh_data) const |
| Copy an array of point data from the mesh into the given Array. | |
| void | copy_point_data (const std::string &data_name, Vector< double > &mesh_data) const |
| Copy an array of point data from the mesh into the given Vector. | |
| void | copy_point_data (const std::string &data_name, Vector< int > &mesh_data) const |
| Copy an array of int-valued point data from the mesh into the given Vector. | |
| void | copy_cell_data (const std::string &data_name, Array< double > &mesh_data) const |
| Copy an array of cell data from the mesh into the given Array. | |
| void | copy_cell_data (const std::string &data_name, Vector< double > &mesh_data) const |
| Copy an array of cell data from the mesh into the given Vector. | |
| void | copy_cell_data (const std::string &data_name, Vector< int > &mesh_data) const |
| Copy an array of int-valued cell data from the mesh into the given Vector. | |
| Array< double > | get_point_data (const std::string &data_name) const |
| Get an array of point data from the mesh. | |
| std::vector< std::string > | get_point_data_names () const |
| Get a list of point data names. | |
| std::pair< int, int > | get_cell_data_dimensions (const std::string &data_name) const |
| Get the dimensions of a cell data array. | |
Static Public Member Functions | |
| static VtkData * | create_reader (const std::string &file_name) |
| Create an object to read a mesh from a VTK file. | |
| static VtkData * | create_writer (const std::string &file_name) |
| Create an object to write a mesh to a VTK file. | |
Protected Member Functions | |
| virtual void | read_file_internal (const std::string &file_name)=0 |
| Read the mesh data from a file. | |
| virtual int | cell_type (int nsd, int np_elem) const =0 |
| Get the VTK cell type for a given number of spatial dimensions and number of points per element. | |
| virtual void | insert_cell (int vtk_cell_type, vtkSmartPointer< vtkIdList > elem_nodes)=0 |
| Insert a new cell into the VTK data object. | |
Protected Attributes | |
| vtkSmartPointer< vtkPointSet > | vtk_data |
| std::string | file_name_ |
| Filename that the mesh is read from, or written to. | |
| int | elem_type_ = -1 |
| Type of elements in the mesh. | |
| int | num_elems_ = 0 |
| Number of elements. | |
| int | num_points_per_elem_ = 0 |
| Number of points per element. | |
| int | num_points_ = 0 |
| Number of points. | |
A mesh stored in one of the VTK XML file formats.
The mesh is held as a vtkPointSet, and consists of the point coordinates, the element connectivity, and any number of named data arrays associated with the points, with the elements, or with the mesh as a whole (field data). The class provides the operations needed to read those from a file, to build them up before writing a file, and to copy them to and from the Array and Vector types used by the solver.
The file format determines how the mesh is represented, which is what the derived classes provide: VtkVtpData holds a surface mesh as a vtkPolyData, VtkVtuData a volume mesh as a vtkUnstructuredGrid. Use create_reader() and create_writer() to obtain an object of the type matching a given file name.
|
default |
Default constructor.
|
virtualdefault |
Virtual destructor.
|
protectedpure virtual |
Get the VTK cell type for a given number of spatial dimensions and number of points per element.
Derived classes must override this to implement the appropriate mapping from the number of spatial dimensions and number of points per element to the VTK cell type.
| svmp::FE::InvalidArgumentException | if there is no cell type that the file format can hold for the given element |
Implemented in VtkVtpData, and VtkVtuData.
| void VtkData::copy_cell_data | ( | const std::string & | data_name, |
| Array< double > & | mesh_data | ||
| ) | const |
Copy an array of cell data from the mesh into the given Array.
| [in] | data_name | The name of the cell data array to copy. |
| [out] | mesh_data | The array to copy the cell data into. It must be of size (num_components, num_cells). |
| svmp::FE::InvalidArgumentException | if the mesh has no double-valued cell data array with the given name, or if its values do not fit in mesh_data |
| void VtkData::copy_cell_data | ( | const std::string & | data_name, |
| Vector< double > & | mesh_data | ||
| ) | const |
Copy an array of cell data from the mesh into the given Vector.
| [in] | data_name | The name of the cell data array to copy. |
| [out] | mesh_data | The vector to copy the cell data into. It must be of size (num_points). |
| svmp::FE::InvalidArgumentException | if the mesh has no double-valued cell data array with the given name, or if its values do not fit in mesh_data |
| void VtkData::copy_cell_data | ( | const std::string & | data_name, |
| Vector< int > & | mesh_data | ||
| ) | const |
Copy an array of int-valued cell data from the mesh into the given Vector.
| [in] | data_name | The name of the cell data array to copy. |
| [out] | mesh_data | The vector to copy the cell data into. It must be of size (num_points). |
| svmp::FE::InvalidArgumentException | if the mesh has no int-valued cell data array with the given name, or if its values do not fit in mesh_data |
| void VtkData::copy_point_data | ( | const std::string & | data_name, |
| Array< double > & | mesh_data | ||
| ) | const |
Copy an array of point data from the mesh into the given Array.
| [in] | data_name | The name of the point data array to copy. |
| [out] | mesh_data | The array to copy the point data into. It must be of size (num_components, num_points). |
| svmp::FE::InvalidArgumentException | if the mesh has no double-valued point data array with the given name, or if its values do not fit in mesh_data |
| void VtkData::copy_point_data | ( | const std::string & | data_name, |
| Vector< double > & | mesh_data | ||
| ) | const |
Copy an array of point data from the mesh into the given Vector.
| [in] | data_name | The name of the point data array to copy. |
| [out] | mesh_data | The vector to copy the point data into. It must be of size (num_points). |
| svmp::FE::InvalidArgumentException | if the mesh has no double-valued point data array with the given name, or if its values do not fit in mesh_data |
| void VtkData::copy_point_data | ( | const std::string & | data_name, |
| Vector< int > & | mesh_data | ||
| ) | const |
Copy an array of int-valued point data from the mesh into the given Vector.
| [in] | data_name | The name of the point data array to copy. |
| [out] | mesh_data | The vector to copy the point data into. It must be of size (num_points). |
| svmp::FE::InvalidArgumentException | if the mesh has no int-valued point data array with the given name, or if its values do not fit in mesh_data |
| void VtkData::copy_points | ( | Array< double > & | points | ) | const |
Copy the mesh points to an Array.
| [out] | points | The array to copy the mesh points into. It must be of size (3, num_points). |
| svmp::FE::InvalidArgumentException | if the points do not fit in the array |
|
pure virtual |
Create an empty grid.
Derived classes need to override this function by implementing the appropriate logic to create an empty grid. This will include initializing the correct vtkPointSet object.
Implemented in VtkVtpData, and VtkVtuData.
|
static |
Create an object to read a mesh from a VTK file.
The concrete type is selected from the file extension, and the mesh is read as part of the construction. The file extension must be 'vtp' or 'vtu'.
| [in] | file_name | The name of the VTK file to read. |
| svmp::FE::InvalidArgumentException | if the file extension is not 'vtp' or 'vtu' |
|
static |
Create an object to write a mesh to a VTK file.
The concrete type is selected from the file extension, and the object is created holding an empty mesh. The file extension must be 'vtp' or 'vtu'. The file itself is written by write(), once the mesh has been defined.
| [in] | file_name | The name of the VTK file to write. |
| svmp::FE::InvalidArgumentException | if the file extension is not 'vtp' or 'vtu' |
| int VtkData::elem_type | ( | ) | const |
Get the element type.
| std::pair< int, int > VtkData::get_cell_data_dimensions | ( | const std::string & | data_name | ) | const |
Get the dimensions of a cell data array.
| [in] | data_name | The name of the cell data array to get the dimensions of. |
| Array< int > VtkData::get_connectivity | ( | ) | const |
Get the connectivity of the mesh elements.
| Array< double > VtkData::get_point_data | ( | const std::string & | data_name | ) | const |
Get an array of point data from the mesh.
| svmp::FE::InvalidArgumentException | if the mesh has no double-valued point data array with the given name |
| std::vector< std::string > VtkData::get_point_data_names | ( | ) | const |
Get a list of point data names.
| Array< double > VtkData::get_points | ( | ) | const |
Get the points of the mesh.
| bool VtkData::has_cell_data | ( | const std::string & | data_name | ) | const |
Check if a given cell data array exists.
| bool VtkData::has_point_data | ( | const std::string & | data_name | ) | const |
Check if a given point data array exists.
|
protectedpure virtual |
Insert a new cell into the VTK data object.
Derived classes must override this to implement the appropriate insertion call.
| [in] | vtk_cell_type | The VTK cell type of the element. |
| [in] | elem_nodes | The list of point IDs that define the element. |
Implemented in VtkVtpData, and VtkVtuData.
| int VtkData::num_elems | ( | ) | const |
Get the number of elements in the mesh.
| int VtkData::num_points | ( | ) | const |
Get the number of points in the mesh.
| int VtkData::num_points_per_elem | ( | ) | const |
Get the number of points per element.
|
virtual |
Read the mesh data from a VTK file.
| svmp::FileFormatException | if the file cannot be read, or if it contains no points or no elements |
|
protectedpure virtual |
Read the mesh data from a file.
Derived classes need to override this function by implementing the appropriate reading logic. This will include selecting the correct VTK reader, and initializing vtk_data.
Implemented in VtkVtpData, and VtkVtuData.
| void VtkData::set_connectivity | ( | const int | nsd, |
| const Array< int > & | conn | ||
| ) |
Set the mesh connectivity to define the elements.
The elements are appended to those already defined, so a mesh made of several parts is built up by calling this once per part.
| [in] | nsd | The number of spatial dimensions, which together with the number of points per element determines the element type. |
| [in] | conn | The connectivity, of size (num_points_per_elem, num_elems). Each column holds the point indices of one element. |
| svmp::FE::InvalidArgumentException | if a point index does not refer to one of the points of the mesh |
| void VtkData::set_element_data | ( | const std::string & | data_name, |
| const Array< double > & | data | ||
| ) |
Set a double-valued element data array.
| [in] | data_name | The name of the data array to set. |
| [in] | data | The data array to set, holding one value per element. |
| svmp::FE::InvalidArgumentException | if the number of values differs from the number of elements of the mesh |
| void VtkData::set_element_data | ( | const std::string & | data_name, |
| const Array< int > & | data | ||
| ) |
Set an int-valued element data array.
| [in] | data_name | The name of the data array to set. |
| [in] | data | The data array to set, holding one value per element. |
| svmp::FE::InvalidArgumentException | if the number of values differs from the number of elements of the mesh |
| void VtkData::set_element_data | ( | const std::string & | data_name, |
| const Vector< int > & | data | ||
| ) |
Set an int-valued element data vector.
| [in] | data_name | The name of the data array to set. |
| [in] | data | The data vector to set, holding one value per element. |
| svmp::FE::InvalidArgumentException | if the number of values differs from the number of elements of the mesh |
| void VtkData::set_point_data | ( | const std::string & | data_name, |
| const Array< double > & | data | ||
| ) |
Set a double-valued point data array.
| [in] | data_name | The name of the data array to set. |
| [in] | data | The data array to set, holding one value per point. |
| svmp::FE::InvalidArgumentException | if the number of values differs from the number of points of the mesh |
| void VtkData::set_point_data | ( | const std::string & | data_name, |
| const Array< int > & | data | ||
| ) |
Set an int-valued point data array.
| [in] | data_name | The name of the data array to set. |
| [in] | data | The data array to set, holding one value per point. |
| svmp::FE::InvalidArgumentException | if the number of values differs from the number of points of the mesh |
| void VtkData::set_point_data | ( | const std::string & | data_name, |
| const Vector< int > & | data | ||
| ) |
Set an int-valued point data array.
| [in] | data_name | The name of the data array to set. |
| [in] | data | The data array to set, holding one value per point. |
| svmp::FE::InvalidArgumentException | if the number of values differs from the number of points of the mesh |
| void VtkData::set_points | ( | const Array< double > & | points | ) |
Set the point coordinates of the mesh.
| [in] | points | The coordinates, of size (3, num_points). |
| svmp::FE::InvalidArgumentException | if there are no points or fewer than three coordinates are given for each point |
| void VtkData::set_time_value | ( | const double | time | ) |
Store a time value as field data.
The value is written as a single-tuple Float64 field data array named 'TimeValue'. VTK XML readers such as ParaView turn this array into the pipeline time of the data object.
| [in] | time | The time value to associate with the data. |
|
pure virtual |
Write the mesh data to a VTK file.
| svmp::CoreException | if the file cannot be written |
Implemented in VtkVtpData, and VtkVtuData.
|
protected |
Type of elements in the mesh.
|
protected |
Filename that the mesh is read from, or written to.
|
protected |
Number of elements.
|
protected |
Number of points.
|
protected |
Number of points per element.
|
protected |
Pointer to the underlying VTK data object. The concrete type will be either vtkPolyData, for VTP files, or vtkUnstructuredGrid, for VTU files.