OGS 6.2.0-97-g4a610c866
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 
26 namespace MeshLib
27 {
28 class Node;
29 class Element;
30 class Properties;
31 
32 namespace IO
33 {
37 {
38 public:
40  NodePartitionedMeshReader(MPI_Comm comm);
41 
43 
52  MeshLib::NodePartitionedMesh* read(const std::string &file_name_base);
53 
54 private:
56  MPI_Comm _mpi_comm;
57 
60 
62  int _mpi_rank;
63 
65  MPI_Datatype _mpi_node_type;
66 
68  struct NodeData
69  {
70  std::size_t index;
71  double x;
72  double y;
73  double z;
74  };
75 
78 
81  {
82  unsigned long nodes;
83  unsigned long base_nodes;
84  unsigned long regular_elements;
86  unsigned long
89  unsigned long active_base_nodes;
90  unsigned long
93  unsigned long global_base_nodes;
94  unsigned long global_nodes;
96  unsigned long offset[5];
97  unsigned long extra_flag;
100 
101  std::size_t size() const { return 14; }
102  unsigned long* data() { return &nodes; }
103  } _mesh_info;
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 
139  template <typename DATA>
140  bool readBinaryDataFromFile(std::string const& filename, MPI_Offset offset,
141  MPI_Datatype type, DATA& data) const;
142 
166  MeshLib::NodePartitionedMesh* readBinary(const std::string &file_name_base);
167 
169  const std::string& file_name_base) const;
170 
171  void readPropertiesBinary(const std::string& file_name_base,
173  MeshLib::Properties& p) const;
174 
176  std::vector<boost::optional<MeshLib::IO::PropertyVectorMetaData>> const&
177  vec_pvmd,
180  std::istream& is,
181  MeshLib::Properties& p) const;
182 
183  template <typename T>
185  std::istream& is, MeshLib::IO::PropertyVectorMetaData const& pvmd,
187  MeshLib::MeshItemType t, unsigned long global_offset,
188  MeshLib::Properties& p) const
189  {
191  pvmd.property_name, t, pvmd.number_of_components);
192  pv->resize(pvpmd.number_of_tuples * pvmd.number_of_components);
193  // jump to the place for reading the specific part of the
194  // PropertyVector
195  is.seekg(global_offset + pvpmd.offset * sizeof(T));
196  // read the values
197  unsigned long const number_of_bytes = pvmd.data_type_size_in_bytes *
198  pvpmd.number_of_tuples *
200  if (!is.read(reinterpret_cast<char*>(pv->data()), number_of_bytes))
201  OGS_FATAL(
202  "Error in NodePartitionedMeshReader::readPropertiesBinary: "
203  "Could not read part %d of the PropertyVector.",
204  _mpi_rank);
205  }
206 
220  bool openASCIIFiles(std::string const& file_name_base,
221  std::ifstream& is_cfg, std::ifstream& is_node,
222  std::ifstream& is_elem) const;
223 
232  bool readCastNodesASCII(std::ifstream& is_node, const int part_id,
233  std::vector<MeshLib::Node*> &mesh_nodes,
234  std::vector<unsigned long> &glb_node_ids) const;
235 
247  bool readCastElemsASCII(std::ifstream& is_elem, const int part_id,
248  const std::size_t data_size, const bool process_ghost,
249  const std::vector<MeshLib::Node*> &mesh_nodes,
250  std::vector<MeshLib::Element*> &mesh_elems) const;
251 
271  MeshLib::NodePartitionedMesh* readASCII(const std::string &file_name_base);
272 
283  void readElementASCII(std::ifstream &ins,
284  std::vector<unsigned long>& elem_data,
285  const bool ghost = false) const;
286 
293  void setNodes(const std::vector<NodeData> &node_data,
294  std::vector<MeshLib::Node*> &mesh_node,
295  std::vector<unsigned long> &glb_node_ids) const;
296 
304  void setElements(const std::vector<MeshLib::Node*> &mesh_nodes,
305  const std::vector<unsigned long> &elem_data,
306  std::vector<MeshLib::Element*> &mesh_elems,
307  const bool ghost = false) const;
308 };
309 } // end namespace IO
310 } // end namespace MeshLib
bool readBinaryDataFromFile(std::string const &filename, MPI_Offset offset, MPI_Datatype type, DATA &data) const
Parallel reading of a binary file via MPI_File_read, and it is called by readBinary to read files of ...
Definition of mesh class for partitioned mesh (by node) for parallel computing within the framework o...
unsigned long ghost_elements
3: Number of ghost element of a partition,
void readDomainSpecificPartOfPropertyVectors(std::vector< boost::optional< MeshLib::IO::PropertyVectorMetaData >> const &vec_pvmd, MeshLib::IO::PropertyVectorPartitionMetaData const &pvpmd, MeshLib::MeshItemType t, std::istream &is, MeshLib::Properties &p) const
PropertyVector< T > * createNewPropertyVector(std::string const &name, MeshItemType mesh_item_type, std::size_t n_components=1)
Definition: Properties.h:15
A collection of integers that configure the partitioned mesh data.
MPI_Datatype _mpi_node_type
MPI data type for struct NodeData.
MPI_Comm _mpi_comm
Pointer to MPI communicator.
void readElementASCII(std::ifstream &ins, std::vector< unsigned long > &elem_data, const bool ghost=false) const
Read elements data from ASCII file.
int _mpi_comm_size
Number of processes in the communicator: _mpi_comm.
MeshLib::NodePartitionedMesh * readASCII(const std::string &file_name_base)
Create a NodePartitionedMesh object, read ASCII mesh data, and return a pointer to it...
bool readCastNodesASCII(std::ifstream &is_node, const int part_id, std::vector< MeshLib::Node *> &mesh_nodes, std::vector< unsigned long > &glb_node_ids) const
Read mesh nodes from an ASCII file and cast to the corresponding rank.
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 tempory array containing node data read from file.
bool openASCIIFiles(std::string const &file_name_base, std::ifstream &is_cfg, std::ifstream &is_node, std::ifstream &is_elem) const
Open ASCII files of node partitioned mesh data.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties...
Definition: Properties.h:37
unsigned long nodes
0: Number of all nodes of a partition,
MeshLib::NodePartitionedMesh * readBinary(const std::string &file_name_base)
Create a NodePartitionedMesh object, read binary mesh data in the manner of parallel, and return a pointer to it. Four binary files have to been read in this function named as: file_name_base+_partitioned_msh_cfg[number of partitions].bin file_name_base+_partitioned_msh_nod[number of partitions].bin file_name_base+_partitioned_msh_ele[number of partitions].bin file_name_base+_partitioned_msh_ele_g[number of partitions].bin in which, the first file contains an array of integers for the PartitionMeshInfo for all partitions.
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 tempory array containing node data read from file.
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 eith...
MeshItemType
Definition: Location.h:21
Interface for heuristic search length strategy.
Definition: ProjectData.h:29
MeshLib::Properties readPropertiesBinary(const std::string &file_name_base) const
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 registerNodeDataMpiType()
Define MPI data type for NodeData struct.
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.
Definition of the class Properties that implements a container of properties.
bool readCastElemsASCII(std::ifstream &is_elem, const int part_id, const std::size_t data_size, const bool process_ghost, const std::vector< MeshLib::Node *> &mesh_nodes, std::vector< MeshLib::Element *> &mesh_elems) const
Read mesh elements from an ASCII file and cast to the corresponding rank.
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
struct MeshLib::IO::NodePartitionedMeshReader::PartitionedMeshInfo _mesh_info
unsigned long active_nodes
5: Number of all active nodes a parition,