OGS
readMeshFromFile.cpp
Go to the documentation of this file.
1
14#include "readMeshFromFile.h"
15
16#ifdef USE_PETSC
17#include <petsc.h>
18#endif
19
20#include <boost/algorithm/string/erase.hpp>
21
22#include "BaseLib/FileTools.h"
23#include "BaseLib/Logging.h"
24#include "BaseLib/MPI.h"
25#include "BaseLib/StringTools.h"
28#include "MeshLib/Mesh.h"
29
30#ifdef USE_PETSC
33#endif
34
35namespace
36{
37MeshLib::Mesh* readMeshFromFileSerial(const std::string& file_name,
38 bool const compute_element_neighbors)
39{
40 if (BaseLib::hasFileExtension(".msh", file_name))
41 {
43 return meshIO.loadMeshFromFile(file_name);
44 }
45
46 if (BaseLib::hasFileExtension(".vtu", file_name))
47 {
49 file_name, compute_element_neighbors);
50 }
51
52 if (BaseLib::hasFileExtension(".vtk", file_name))
53 {
55 file_name, compute_element_neighbors);
56 }
57
58 ERR("readMeshFromFile(): Unknown mesh file format in file {:s}.",
59 file_name);
60 return nullptr;
61}
62} // namespace
63
64namespace MeshLib
65{
66namespace IO
67{
68MeshLib::Mesh* readMeshFromFile(const std::string& file_name,
69 bool const compute_element_neighbors)
70{
71#ifdef USE_PETSC
73 if (mpi.size > 1)
74 {
76 const std::string file_name_base =
78 return read_pmesh.read(file_name_base);
79 }
80 if (mpi.size == 1)
81 {
82 std::unique_ptr<Mesh> mesh{
83 readMeshFromFileSerial(file_name, compute_element_neighbors)};
84
85 if (!mesh)
86 {
87 return nullptr;
88 }
89
90 return new MeshLib::NodePartitionedMesh(*mesh);
91 }
92 return nullptr;
93#endif
94 return readMeshFromFileSerial(file_name, compute_element_neighbors);
95}
96
97} // end namespace IO
98} // end namespace MeshLib
Filename manipulation routines.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
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:278
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 * readVTUFile(std::string const &file_name, bool const compute_element_neighbors=false)
static MeshLib::Mesh * readVTKFile(std::string const &file_name, bool const compute_element_neighbors=false)
std::string dropFileExtension(std::string const &filename)
bool hasFileExtension(std::string const &extension, std::string const &filename)
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
MeshLib::Mesh * readMeshFromFileSerial(const std::string &file_name, bool const compute_element_neighbors)
Definition of readMeshFromFile function.
MPI_Comm communicator
Definition MPI.h:60