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
23#include "MeshLib/IO/NodeData.h"
25#include "MeshLib/Properties.h"
26
27namespace MeshLib
28{
29class Node;
30class Element;
31class Properties;
32
33namespace IO
34{
38{
39public:
41 explicit NodePartitionedMeshReader(MPI_Comm comm);
42
44
53 MeshLib::NodePartitionedMesh* read(const std::string& file_name_base);
54
55private:
57 MPI_Comm _mpi_comm;
58
61
64
66 MPI_Datatype _mpi_node_type;
67
70
73 {
74 unsigned long
76 unsigned long number_of_base_nodes;
78 unsigned long
81 unsigned long
84 unsigned long
88 unsigned long
91 unsigned long
95 unsigned long
97 unsigned long offset[5];
99 unsigned long extra_flag;
100
101 std::size_t size() const { return 14; }
102 unsigned long* data() { return &number_of_nodes; }
104
116 std::string const& mesh_name,
117 std::vector<MeshLib::Node*> const& mesh_nodes,
118 std::vector<unsigned long> const& glb_node_ids,
119 std::vector<MeshLib::Element*> const& mesh_elems,
120 MeshLib::Properties const& properties) const;
121
143 template <typename DATA>
144 bool readDataFromFile(std::string const& filename, MPI_Offset offset,
145 MPI_Datatype type, DATA& data) const;
146
171 MeshLib::NodePartitionedMesh* readMesh(const std::string& file_name_base);
172
173 MeshLib::Properties readProperties(const std::string& file_name_base) const;
174
175 void readProperties(const std::string& file_name_base,
177 MeshLib::Properties& p) const;
178
180 std::vector<std::optional<MeshLib::IO::PropertyVectorMetaData>> const&
181 vec_pvmd,
184 std::istream& is,
185 MeshLib::Properties& p) const;
186
187 template <typename T>
189 std::istream& is, MeshLib::IO::PropertyVectorMetaData const& pvmd,
191 MeshLib::MeshItemType t, unsigned long global_offset,
192 MeshLib::Properties& p) const
193 {
194 MeshLib::PropertyVector<T>* pv = p.createNewPropertyVector<T>(
195 pvmd.property_name, t, pvmd.number_of_components);
196 pv->resize(pvpmd.number_of_tuples * pvmd.number_of_components);
197
198 // Locate the start position of the data in the file for the current
199 // rank.
200 is.seekg(global_offset +
201 pvpmd.offset * pvmd.number_of_components * sizeof(T));
202 // read the values
203 if (!is.read(reinterpret_cast<char*>(pv->data()),
204 pv->size() * sizeof(T)))
205 OGS_FATAL(
206 "Error in NodePartitionedMeshReader::readProperties: "
207 "Could not read part {:d} of the PropertyVector.",
208 _mpi_rank);
209 }
210
213 template <typename T>
215 std::istream& is, MeshLib::IO::PropertyVectorMetaData const& pvmd,
216 MeshLib::MeshItemType t, unsigned long global_offset,
217 MeshLib::Properties& p) const
218 {
219 MeshLib::PropertyVector<T>* pv = p.createNewPropertyVector<T>(
220 pvmd.property_name, t, pvmd.number_of_components);
221
222 std::size_t const property_vector_size =
224 pv->resize(property_vector_size);
225
226 // Locate the start position of the data in the file for the current
227 // rank.
228 is.seekg(global_offset + property_vector_size * sizeof(T) * _mpi_rank);
229
230 // read the values
231 if (!is.read(reinterpret_cast<char*>(pv->data()),
232 pv->size() * sizeof(T)))
233 {
234 OGS_FATAL(
235 "Error in NodePartitionedMeshReader::readProperties: "
236 "Could not read part {:d} of the PropertyVector.",
237 _mpi_rank);
238 }
239 }
240
248 void setNodes(const std::vector<NodeData>& node_data,
249 std::vector<MeshLib::Node*>& mesh_node,
250 std::vector<unsigned long>& glb_node_ids) const;
251
260 void setElements(const std::vector<MeshLib::Node*>& mesh_nodes,
261 const std::vector<unsigned long>& elem_data,
262 std::vector<MeshLib::Element*>& mesh_elems,
263 const bool ghost = false) const;
264};
265} // end namespace IO
266} // 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.
int _mpi_comm_size
Number of processes in the communicator: _mpi_comm.
MPI_Comm _mpi_comm
Pointer to MPI communicator.
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.
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,