OGS
NodePartitionedMeshReader.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <iosfwd>
17#include <string>
18#include <vector>
19
20#include <mpi.h>
21
23#include "MeshLib/Properties.h"
25
26namespace MeshLib
27{
28class Node;
29class Element;
30class Properties;
31
32namespace IO
33{
37{
38public:
40 explicit NodePartitionedMeshReader(MPI_Comm comm);
41
43
51 MeshLib::NodePartitionedMesh* read(const std::string &file_name_base);
52
53private:
55 MPI_Comm _mpi_comm;
56
59
62
64 MPI_Datatype _mpi_node_type;
65
67 struct NodeData
68 {
69 std::size_t index;
70 double x;
71 double y;
72 double z;
73 };
74
77
80 {
81 unsigned long nodes;
82 unsigned long base_nodes;
84 unsigned long regular_elements;
86 unsigned long
88 unsigned long active_base_nodes;
90 unsigned long
92 unsigned long global_base_nodes;
95 unsigned long global_nodes;
96 unsigned long offset[5];
98 unsigned long extra_flag;
99
100 std::size_t size() const { return 14; }
101 unsigned long* data() { return &nodes; }
103
115 std::string const& mesh_name,
116 std::vector<MeshLib::Node*> const& mesh_nodes,
117 std::vector<unsigned long> const& glb_node_ids,
118 std::vector<MeshLib::Element*> const& mesh_elems,
119 MeshLib::Properties const& properties) const;
120
141 template <typename DATA>
142 bool readDataFromFile(std::string const& filename, MPI_Offset offset,
143 MPI_Datatype type, DATA& data) const;
144
168 MeshLib::NodePartitionedMesh* readMesh(const std::string &file_name_base);
169
171 const std::string& file_name_base) const;
172
173 void readProperties(const std::string& file_name_base,
175 MeshLib::Properties& p) const;
176
178 std::vector<std::optional<MeshLib::IO::PropertyVectorMetaData>> const&
179 vec_pvmd,
182 std::istream& is,
183 MeshLib::Properties& p) const;
184
185 template <typename T>
187 std::istream& is, MeshLib::IO::PropertyVectorMetaData const& pvmd,
189 MeshLib::MeshItemType t, unsigned long global_offset,
190 MeshLib::Properties& p) const
191 {
192 MeshLib::PropertyVector<T>* pv = p.createNewPropertyVector<T>(
194 pv->resize(pvpmd.number_of_tuples * pvmd.number_of_components);
195 // jump to the place for reading the specific part of the
196 // PropertyVector
197 is.seekg(global_offset +
198 pvpmd.offset * pvmd.number_of_components * sizeof(T));
199 // read the values
200 unsigned long const number_of_bytes = pvmd.data_type_size_in_bytes *
201 pvpmd.number_of_tuples *
203 if (!is.read(reinterpret_cast<char*>(pv->data()), number_of_bytes))
204 OGS_FATAL(
205 "Error in NodePartitionedMeshReader::readProperties: "
206 "Could not read part {:d} of the PropertyVector.",
207 _mpi_rank);
208 }
209
216 void setNodes(const std::vector<NodeData> &node_data,
217 std::vector<MeshLib::Node*> &mesh_node,
218 std::vector<unsigned long> &glb_node_ids) const;
219
227 void setElements(const std::vector<MeshLib::Node*> &mesh_nodes,
228 const std::vector<unsigned long> &elem_data,
229 std::vector<MeshLib::Element*> &mesh_elems,
230 const bool ghost = false) const;
231};
232} // end namespace IO
233} // 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.
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
static const double t
MeshItemType
Definition: Location.h:21
A collection of integers that configure the partitioned mesh data.
unsigned long active_nodes
5: Number of all active nodes a partition,
unsigned long ghost_elements
3: Number of ghost element of a partition,
unsigned long nodes
0: Number of all nodes of a partition,
unsigned long global_nodes
7: Number of all nodes of global mesh,