VTK  9.3.0
VTXHelper.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
4 /*
5  * VTXHelper.h : collection of helper function needed by VTK::IOADIOS2 module
6  *
7  * Created on: May 3, 2019
8  * Author: William F Godoy godoywf@ornl.gov
9  */
10 
11 #ifndef VTK_IO_ADIOS2_VTX_COMMON_VTXHelper_h
12 #define VTK_IO_ADIOS2_VTX_COMMON_VTXHelper_h
13 
14 #include "VTXTypes.h"
15 
16 #include <cstddef> //std::size_t
17 #include <set>
18 #include <string>
19 #include <utility> // std::pair
20 #include <vector>
21 
22 #include <vtk_mpi.h>
23 
24 #include "vtkDataArray.h"
25 #include "vtkIdTypeArray.h"
26 #include "vtkSmartPointer.h"
27 
28 #include <vtk_pugixml.h>
29 
30 #include <adios2.h>
31 
32 namespace vtx
33 {
34 namespace helper
35 {
36 VTK_ABI_NAMESPACE_BEGIN
37 
39 MPI_Comm MPIGetComm();
40 
42 int MPIGetRank();
43 
45 int MPIGetSize();
46 
56 pugi::xml_document XMLDocument(const std::string& input, bool debugMode, const std::string& hint);
57 
69 pugi::xml_node XMLNode(std::string nodeName, const pugi::xml_document& xmlDocument, bool debugMode,
70  const std::string& hint, bool isMandatory = true, bool isUnique = false);
71 
84 pugi::xml_node XMLNode(std::string nodeName, const pugi::xml_node& upperNode, bool debugMode,
85  const std::string& hint, bool isMandatory = true, bool isUnique = false);
86 
93 
104 pugi::xml_attribute XMLAttribute(std::string attributeName, const pugi::xml_node& node,
105  bool debugMode, const std::string& hint, bool isMandatory = true);
106 
112 std::string SetToCSV(const std::set<std::string>& input) noexcept;
113 
120 template <class T>
121 std::vector<T> StringToVector(const std::string& input) noexcept;
122 
128 std::size_t TotalElements(const std::vector<std::size_t>& dimensions) noexcept;
129 
139 types::DataSet XMLInitDataSet(const pugi::xml_node& dataSetNode,
140  const std::set<std::string>& specialNames, bool persist = false);
141 
146 template <class T>
148 
154 
160 adios2::Box<adios2::Dims> PartitionCart1D(const adios2::Dims& shape);
161 
167 template <class T, class U>
168 std::vector<T> MapKeysToVector(const std::map<T, U>& input) noexcept;
169 
175 template <class T>
176 void Print(const std::vector<T>& input, const std::string& name);
177 
184 size_t LinearizePoint(const adios2::Dims& shape, const adios2::Dims& point) noexcept;
185 
191 std::string GetFileName(const std::string& fileName) noexcept;
192 
198 std::string GetEngineType(const std::string& fileName) noexcept;
199 
206 bool EndsWith(const std::string& input, const std::string& ends) noexcept;
207 
208 VTK_ABI_NAMESPACE_END
209 } // end namespace helper
210 } // end namespace vtx
211 
212 #include "VTXHelper.inl"
213 
214 #endif /* VTK_IO_ADIOS2_VTX_COMMON_VTXHelper_h */
@ point
Definition: vtkX3D.h:236
@ name
Definition: vtkX3D.h:219
@ string
Definition: vtkX3D.h:490
types::DataSet XMLInitDataSet(const pugi::xml_node &dataSetNode, const std::set< std::string > &specialNames, bool persist=false)
Initialize DataSet structure from parsing a pugi::xml_node, loops through DataArray nodes.
vtkSmartPointer< vtkDataArray > NewDataArray()
Return a derived class of vtkDataArray specialized for supported types.
bool EndsWith(const std::string &input, const std::string &ends) noexcept
Check if input ends with a certain (ends) string.
std::string GetEngineType(const std::string &fileName) noexcept
Set the appropriate engine type based on recognized user input.
std::string FileToString(const std::string &fileName)
Translate file contents to string.
pugi::xml_attribute XMLAttribute(std::string attributeName, const pugi::xml_node &node, bool debugMode, const std::string &hint, bool isMandatory=true)
Get a node attribute identified by its key.
vtkSmartPointer< vtkIdTypeArray > NewDataArrayIdType()
Special type for vtkIdTypeArray.
std::size_t TotalElements(const std::vector< std::size_t > &dimensions) noexcept
Return product of all dimensions components to get the total number of elements.
adios2::Box< adios2::Dims > PartitionCart1D(const adios2::Dims &shape)
Simple partition to load balance shape across viz processes.
std::vector< T > MapKeysToVector(const std::map< T, U > &input) noexcept
Map's keys to a vector.
size_t LinearizePoint(const adios2::Dims &shape, const adios2::Dims &point) noexcept
Linear index for a point within a box with shape dimensions from zero origin.
std::vector< T > StringToVector(const std::string &input) noexcept
Converts a single string "s1 s2 s3" list to a vector vector ={ "s1", "s2", "s3" };.
int MPIGetSize()
Get current MPI size from MPIGetComm.
pugi::xml_document XMLDocument(const std::string &input, bool debugMode, const std::string &hint)
Get safely a pugi::xml_document from XML as a string.
MPI_Comm MPIGetComm()
Get current MPI global communicator from VTK.
std::string GetFileName(const std::string &fileName) noexcept
Set the appropriate file name based on recognized user input.
void Print(const std::vector< T > &input, const std::string &name)
Print a vector with an associated name.
pugi::xml_node XMLNode(std::string nodeName, const pugi::xml_document &xmlDocument, bool debugMode, const std::string &hint, bool isMandatory=true, bool isUnique=false)
Get safely a pugi::xml_document from a pugmi::xml_document.
std::string SetToCSV(const std::set< std::string > &input) noexcept
Convert a set of strings into a csv "string1,string2,string3" string.
int MPIGetRank()
Get current MPI rank from MPIGetComm.
std::map< std::string, DataArray > DataSet
key: variable name, value: DataArray
Definition: VTXTypes.h:28