OGS
NodePartitionedMeshReader.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <mpi.h>
17
18#include <iosfwd>
19#include <string>
20#include <vector>
21
22#include "BaseLib/MPI.h"
24#include "MeshLib/IO/NodeData.h"
26#include "MeshLib/Properties.h"
27
28namespace MeshLib
29{
30class Node;
31class Element;
32class Properties;
33
34namespace IO
35{
39{
40public:
42 explicit NodePartitionedMeshReader(MPI_Comm comm);
43
45
54 MeshLib::NodePartitionedMesh* read(const std::string& file_name_base);
55
56private:
59
61 MPI_Datatype _mpi_node_type;
62
65
68 {
69 unsigned long
71 unsigned long number_of_base_nodes;
73 unsigned long
76 unsigned long
79 unsigned long
83 unsigned long
86 unsigned long
90 unsigned long
92 unsigned long offset[5];
94 unsigned long extra_flag;
95
96 std::size_t size() const { return 14; }
97 unsigned long* data() { return &number_of_nodes; }
99
111 std::string const& mesh_name,
112 std::vector<MeshLib::Node*> const& mesh_nodes,
113 std::vector<unsigned long> const& glb_node_ids,
114 std::vector<MeshLib::Element*> const& mesh_elems,
115 MeshLib::Properties const& properties) const;
116
138 template <typename DATA>
139 bool readDataFromFile(std::string const& filename, MPI_Offset offset,
140 MPI_Datatype type, DATA& data) const;
141
166 MeshLib::NodePartitionedMesh* readMesh(const std::string& file_name_base);
167
168 MeshLib::Properties readProperties(const std::string& file_name_base) const;
169
170 void readProperties(const std::string& file_name_base,
172 MeshLib::Properties& p) const;
173
175 std::vector<std::optional<MeshLib::IO::PropertyVectorMetaData>> const&
176 vec_pvmd,
179 std::istream& is,
180 MeshLib::Properties& p) const;
181
182 template <typename T>
184 std::istream& is, MeshLib::IO::PropertyVectorMetaData const& pvmd,
186 MeshLib::MeshItemType t, unsigned long global_offset,
187 MeshLib::Properties& p) const
188 {
189 MeshLib::PropertyVector<T>* pv = p.createNewPropertyVector<T>(
190 pvmd.property_name, t, pvmd.number_of_components);
191 pv->resize(pvpmd.number_of_tuples * pvmd.number_of_components);
192
193 // Locate the start position of the data in the file for the current
194 // rank.
195 is.seekg(global_offset +
196 pvpmd.offset * pvmd.number_of_components * sizeof(T));
197 // read the values
198 if (!is.read(reinterpret_cast<char*>(pv->data()),
199 pv->size() * sizeof(T)))
200 OGS_FATAL(
201 "Error in NodePartitionedMeshReader::readProperties: "
202 "Could not read part {:d} of the PropertyVector.",
203 mpi_.rank);
204 }
205
208 template <typename T>
210 std::istream& is, MeshLib::IO::PropertyVectorMetaData const& pvmd,
211 MeshLib::MeshItemType t, unsigned long global_offset,
212 MeshLib::Properties& p) const
213 {
214 MeshLib::PropertyVector<T>* pv = p.createNewPropertyVector<T>(
215 pvmd.property_name, t, pvmd.number_of_components);
216
217 std::size_t const property_vector_size =
219 pv->resize(property_vector_size);
220
221 // Locate the start position of the data in the file for the current
222 // rank.
223 is.seekg(global_offset + property_vector_size * sizeof(T) * mpi_.rank);
224
225 // read the values
226 if (!is.read(reinterpret_cast<char*>(pv->data()),
227 pv->size() * sizeof(T)))
228 {
229 OGS_FATAL(
230 "Error in NodePartitionedMeshReader::readProperties: "
231 "Could not read part {:d} of the PropertyVector.",
232 mpi_.rank);
233 }
234 }
235
243 void setNodes(const std::vector<NodeData>& node_data,
244 std::vector<MeshLib::Node*>& mesh_node,
245 std::vector<unsigned long>& glb_node_ids) const;
246
255 void setElements(const std::vector<MeshLib::Node*>& mesh_nodes,
256 const std::vector<unsigned long>& elem_data,
257 std::vector<MeshLib::Element*>& mesh_elems,
258 const bool ghost = false) const;
259};
260} // end namespace IO
261} // end namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:26
Definition of the class Properties that implements a container of properties.
Definition of mesh class for partitioned mesh (by node) for parallel computing within the framework o...
void createPropertyVectorPart(std::istream &is, MeshLib::IO::PropertyVectorMetaData const &pvmd, MeshLib::IO::PropertyVectorPartitionMetaData const &pvpmd, MeshLib::MeshItemType t, unsigned long global_offset, MeshLib::Properties &p) const
void setElements(const std::vector< MeshLib::Node * > &mesh_nodes, const std::vector< unsigned long > &elem_data, std::vector< MeshLib::Element * > &mesh_elems, const bool ghost=false) const
Set mesh elements from a temporary array containing node data read from file.
bool readDataFromFile(std::string const &filename, MPI_Offset offset, MPI_Datatype type, DATA &data) const
MeshLib::NodePartitionedMesh * readMesh(const std::string &file_name_base)
Create a NodePartitionedMesh object, read binary mesh data in the manner of parallel,...
MeshLib::NodePartitionedMesh * read(const std::string &file_name_base)
Create a NodePartitionedMesh object, read data to it, and return a pointer to it. Data files are in b...
void setNodes(const std::vector< NodeData > &node_data, std::vector< MeshLib::Node * > &mesh_node, std::vector< unsigned long > &glb_node_ids) const
Set mesh nodes from a temporary array containing node data read from file.
void createSpecificPropertyVectorPart(std::istream &is, MeshLib::IO::PropertyVectorMetaData const &pvmd, MeshLib::MeshItemType t, unsigned long global_offset, MeshLib::Properties &p) const
MPI_Datatype _mpi_node_type
MPI data type for struct NodeData.
void registerNodeDataMpiType()
Define MPI data type for NodeData struct.
struct MeshLib::IO::NodePartitionedMeshReader::PartitionedMeshInfo _mesh_info
MeshLib::Properties readProperties(const std::string &file_name_base) const
MeshLib::NodePartitionedMesh * newMesh(std::string const &mesh_name, std::vector< MeshLib::Node * > const &mesh_nodes, std::vector< unsigned long > const &glb_node_ids, std::vector< MeshLib::Element * > const &mesh_elems, MeshLib::Properties const &properties) const
Create a new mesh of NodePartitionedMesh after reading and processing the data.
BaseLib::MPI::Mpi mpi_
Pointer to MPI communicator, the rank and the size.
void readDomainSpecificPartOfPropertyVectors(std::vector< std::optional< MeshLib::IO::PropertyVectorMetaData > > const &vec_pvmd, MeshLib::IO::PropertyVectorPartitionMetaData const &pvpmd, MeshLib::MeshItemType t, std::istream &is, MeshLib::Properties &p) const
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition Properties.h:36
std::size_t size() const
MeshItemType
Definition Location.h:21
A collection of integers that configure the partitioned mesh data.
unsigned long number_of_nodes
0: Number of all nodes of a partition,
unsigned long number_of_global_nodes
7: Number of all nodes of global mesh,