svMultiPhysics
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
VtkData Class Referenceabstract

A mesh stored in one of the VTK XML file formats. More...

#include <VtkData.h>

Inheritance diagram for VtkData:
[legend]

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ VtkData()

VtkData::VtkData ( )
default

Default constructor.

◆ ~VtkData()

virtual VtkData::~VtkData ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ cell_type()

virtual int VtkData::cell_type ( int  nsd,
int  np_elem 
) const
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.

Exceptions
svmp::FE::InvalidArgumentExceptionif there is no cell type that the file format can hold for the given element

Implemented in VtkVtpData, and VtkVtuData.

◆ copy_cell_data() [1/3]

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.

Parameters
[in]data_nameThe name of the cell data array to copy.
[out]mesh_dataThe array to copy the cell data into. It must be of size (num_components, num_cells).
Exceptions
svmp::FE::InvalidArgumentExceptionif the mesh has no double-valued cell data array with the given name, or if its values do not fit in mesh_data

◆ copy_cell_data() [2/3]

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.

Parameters
[in]data_nameThe name of the cell data array to copy.
[out]mesh_dataThe vector to copy the cell data into. It must be of size (num_points).
Exceptions
svmp::FE::InvalidArgumentExceptionif the mesh has no double-valued cell data array with the given name, or if its values do not fit in mesh_data

◆ copy_cell_data() [3/3]

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.

Parameters
[in]data_nameThe name of the cell data array to copy.
[out]mesh_dataThe vector to copy the cell data into. It must be of size (num_points).
Exceptions
svmp::FE::InvalidArgumentExceptionif the mesh has no int-valued cell data array with the given name, or if its values do not fit in mesh_data

◆ copy_point_data() [1/3]

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.

Parameters
[in]data_nameThe name of the point data array to copy.
[out]mesh_dataThe array to copy the point data into. It must be of size (num_components, num_points).
Exceptions
svmp::FE::InvalidArgumentExceptionif the mesh has no double-valued point data array with the given name, or if its values do not fit in mesh_data

◆ copy_point_data() [2/3]

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.

Parameters
[in]data_nameThe name of the point data array to copy.
[out]mesh_dataThe vector to copy the point data into. It must be of size (num_points).
Exceptions
svmp::FE::InvalidArgumentExceptionif the mesh has no double-valued point data array with the given name, or if its values do not fit in mesh_data

◆ copy_point_data() [3/3]

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.

Parameters
[in]data_nameThe name of the point data array to copy.
[out]mesh_dataThe vector to copy the point data into. It must be of size (num_points).
Exceptions
svmp::FE::InvalidArgumentExceptionif the mesh has no int-valued point data array with the given name, or if its values do not fit in mesh_data

◆ copy_points()

void VtkData::copy_points ( Array< double > &  points) const

Copy the mesh points to an Array.

Parameters
[out]pointsThe array to copy the mesh points into. It must be of size (3, num_points).
Exceptions
svmp::FE::InvalidArgumentExceptionif the points do not fit in the array

◆ create_grid()

virtual void VtkData::create_grid ( )
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.

◆ create_reader()

VtkData * VtkData::create_reader ( const std::string &  file_name)
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'.

Parameters
[in]file_nameThe name of the VTK file to read.
Returns
A pointer to a newly allocated object holding the mesh read from the file. The caller owns the object and must delete it.
Exceptions
svmp::FE::InvalidArgumentExceptionif the file extension is not 'vtp' or 'vtu'

◆ create_writer()

VtkData * VtkData::create_writer ( const std::string &  file_name)
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.

Parameters
[in]file_nameThe name of the VTK file to write.
Returns
A pointer to a newly allocated object holding an empty mesh. The caller owns the object and must delete it.
Exceptions
svmp::FE::InvalidArgumentExceptionif the file extension is not 'vtp' or 'vtu'

◆ elem_type()

int VtkData::elem_type ( ) const

Get the element type.

◆ get_cell_data_dimensions()

std::pair< int, int > VtkData::get_cell_data_dimensions ( const std::string &  data_name) const

Get the dimensions of a cell data array.

Parameters
[in]data_nameThe name of the cell data array to get the dimensions of.
Returns
A pair of integers representing the number of components and the number of tuples in the array.

◆ get_connectivity()

Array< int > VtkData::get_connectivity ( ) const

Get the connectivity of the mesh elements.

Returns
An array of size (num_points_per_elem, num_elems) containing the connectivity of the mesh elements. Each column corresponds to an element, and each row corresponds to a point index in that element.

◆ get_point_data()

Array< double > VtkData::get_point_data ( const std::string &  data_name) const

Get an array of point data from the mesh.

Exceptions
svmp::FE::InvalidArgumentExceptionif the mesh has no double-valued point data array with the given name
Todo:
[michelebucelli] This should fall back onto copy_point_data.

◆ get_point_data_names()

std::vector< std::string > VtkData::get_point_data_names ( ) const

Get a list of point data names.

Returns
A vector of strings containing the names of the point data arrays.

◆ get_points()

Array< double > VtkData::get_points ( ) const

Get the points of the mesh.

Returns
An array of size (3, num_points) containing the coordinates of the mesh points. Each column corresponds to a point, and each row corresponds to a coordinate (x, y, z).

◆ has_cell_data()

bool VtkData::has_cell_data ( const std::string &  data_name) const

Check if a given cell data array exists.

◆ has_point_data()

bool VtkData::has_point_data ( const std::string &  data_name) const

Check if a given point data array exists.

◆ insert_cell()

virtual void VtkData::insert_cell ( int  vtk_cell_type,
vtkSmartPointer< vtkIdList >  elem_nodes 
)
protectedpure virtual

Insert a new cell into the VTK data object.

Derived classes must override this to implement the appropriate insertion call.

Parameters
[in]vtk_cell_typeThe VTK cell type of the element.
[in]elem_nodesThe list of point IDs that define the element.

Implemented in VtkVtpData, and VtkVtuData.

◆ num_elems()

int VtkData::num_elems ( ) const

Get the number of elements in the mesh.

◆ num_points()

int VtkData::num_points ( ) const

Get the number of points in the mesh.

◆ num_points_per_elem()

int VtkData::num_points_per_elem ( ) const

Get the number of points per element.

◆ read_file()

void VtkData::read_file ( const std::string &  file_name)
virtual

Read the mesh data from a VTK file.

Exceptions
svmp::FileFormatExceptionif the file cannot be read, or if it contains no points or no elements

◆ read_file_internal()

virtual void VtkData::read_file_internal ( const std::string &  file_name)
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.

◆ set_connectivity()

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.

Parameters
[in]nsdThe number of spatial dimensions, which together with the number of points per element determines the element type.
[in]connThe connectivity, of size (num_points_per_elem, num_elems). Each column holds the point indices of one element.
Exceptions
svmp::FE::InvalidArgumentExceptionif a point index does not refer to one of the points of the mesh

◆ set_element_data() [1/3]

void VtkData::set_element_data ( const std::string &  data_name,
const Array< double > &  data 
)

Set a double-valued element data array.

Parameters
[in]data_nameThe name of the data array to set.
[in]dataThe data array to set, holding one value per element.
Exceptions
svmp::FE::InvalidArgumentExceptionif the number of values differs from the number of elements of the mesh

◆ set_element_data() [2/3]

void VtkData::set_element_data ( const std::string &  data_name,
const Array< int > &  data 
)

Set an int-valued element data array.

Parameters
[in]data_nameThe name of the data array to set.
[in]dataThe data array to set, holding one value per element.
Exceptions
svmp::FE::InvalidArgumentExceptionif the number of values differs from the number of elements of the mesh

◆ set_element_data() [3/3]

void VtkData::set_element_data ( const std::string &  data_name,
const Vector< int > &  data 
)

Set an int-valued element data vector.

Parameters
[in]data_nameThe name of the data array to set.
[in]dataThe data vector to set, holding one value per element.
Exceptions
svmp::FE::InvalidArgumentExceptionif the number of values differs from the number of elements of the mesh

◆ set_point_data() [1/3]

void VtkData::set_point_data ( const std::string &  data_name,
const Array< double > &  data 
)

Set a double-valued point data array.

Parameters
[in]data_nameThe name of the data array to set.
[in]dataThe data array to set, holding one value per point.
Exceptions
svmp::FE::InvalidArgumentExceptionif the number of values differs from the number of points of the mesh

◆ set_point_data() [2/3]

void VtkData::set_point_data ( const std::string &  data_name,
const Array< int > &  data 
)

Set an int-valued point data array.

Parameters
[in]data_nameThe name of the data array to set.
[in]dataThe data array to set, holding one value per point.
Exceptions
svmp::FE::InvalidArgumentExceptionif the number of values differs from the number of points of the mesh

◆ set_point_data() [3/3]

void VtkData::set_point_data ( const std::string &  data_name,
const Vector< int > &  data 
)

Set an int-valued point data array.

Parameters
[in]data_nameThe name of the data array to set.
[in]dataThe data array to set, holding one value per point.
Exceptions
svmp::FE::InvalidArgumentExceptionif the number of values differs from the number of points of the mesh

◆ set_points()

void VtkData::set_points ( const Array< double > &  points)

Set the point coordinates of the mesh.

Parameters
[in]pointsThe coordinates, of size (3, num_points).
Exceptions
svmp::FE::InvalidArgumentExceptionif there are no points or fewer than three coordinates are given for each point

◆ set_time_value()

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.

Parameters
[in]timeThe time value to associate with the data.

◆ write()

virtual void VtkData::write ( ) const
pure virtual

Write the mesh data to a VTK file.

Exceptions
svmp::CoreExceptionif the file cannot be written

Implemented in VtkVtpData, and VtkVtuData.

Member Data Documentation

◆ elem_type_

int VtkData::elem_type_ = -1
protected

Type of elements in the mesh.

◆ file_name_

std::string VtkData::file_name_
protected

Filename that the mesh is read from, or written to.

◆ num_elems_

int VtkData::num_elems_ = 0
protected

Number of elements.

◆ num_points_

int VtkData::num_points_ = 0
protected

Number of points.

◆ num_points_per_elem_

int VtkData::num_points_per_elem_ = 0
protected

Number of points per element.

◆ vtk_data

vtkSmartPointer<vtkPointSet> VtkData::vtk_data
protected

Pointer to the underlying VTK data object. The concrete type will be either vtkPolyData, for VTP files, or vtkUnstructuredGrid, for VTU files.


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