OGS
readMeshFromFile.cpp
Go to the documentation of this file.
1 
18 #include "readMeshFromFile.h"
19 
20 #ifdef USE_PETSC
21 #include <petsc.h>
22 #endif
23 
24 #include <boost/algorithm/string/erase.hpp>
25 
26 #include "BaseLib/FileTools.h"
27 #include "BaseLib/Logging.h"
28 #include "BaseLib/StringTools.h"
31 #include "MeshLib/Mesh.h"
32 
33 #ifdef USE_PETSC
36 #endif
37 
38 namespace
39 {
40 MeshLib::Mesh* readMeshFromFileSerial(const std::string& file_name)
41 {
42  if (BaseLib::hasFileExtension(".msh", file_name))
43  {
45  return meshIO.loadMeshFromFile(file_name);
46  }
47 
48  if (BaseLib::hasFileExtension(".vtu", file_name))
49  {
51  }
52 
53  if (BaseLib::hasFileExtension(".vtk", file_name))
54  {
56  }
57 
58  ERR("readMeshFromFile(): Unknown mesh file format in file {:s}.",
59  file_name);
60  return nullptr;
61 }
62 } // namespace
63 
64 namespace MeshLib
65 {
66 namespace IO
67 {
68 MeshLib::Mesh* readMeshFromFile(const std::string& file_name)
69 {
70 #ifdef USE_PETSC
71  int world_size;
72  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
73  if (world_size > 1)
74  {
75  MeshLib::IO::NodePartitionedMeshReader read_pmesh(MPI_COMM_WORLD);
76  const std::string file_name_base =
77  BaseLib::dropFileExtension(file_name);
78  return read_pmesh.read(file_name_base);
79  }
80  else if (world_size == 1)
81  {
82  MeshLib::Mesh* mesh = readMeshFromFileSerial(file_name);
83  MeshLib::NodePartitionedMesh* part_mesh =
85  delete mesh;
86  return part_mesh;
87  }
88  return nullptr;
89 #else
90  return readMeshFromFileSerial(file_name);
91 #endif
92 }
93 
94 } // end namespace IO
95 } // end namespace MeshLib
Filename manipulation routines.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Definition of the MeshIO class.
Definition of the Mesh class.
Declare a class to read node-wise partitioned mesh with MPI functions.
Definition of mesh class for partitioned mesh (by node) for parallel computing within the framework o...
Definition of string helper functions.
Implementation of the VtuInterface class.
Interface for handling mesh files from OGS-5 and below. (*.msh files)
Definition: MeshIO.h:37
MeshLib::Mesh * loadMeshFromFile(const std::string &file_name)
Read mesh from file.
Definition: MeshIO.cpp:41
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...
static MeshLib::Mesh * readVTKFile(std::string const &file_name)
static MeshLib::Mesh * readVTUFile(std::string const &file_name)
std::string dropFileExtension(std::string const &filename)
Definition: FileTools.cpp:169
bool hasFileExtension(std::string const &extension, std::string const &filename)
Definition: FileTools.cpp:191
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
MeshLib::Mesh * readMeshFromFileSerial(const std::string &file_name)
Definition of readMeshFromFile function.