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/StringTools.h"
27#include "MeshLib/Mesh.h"
28
29#ifdef USE_PETSC
32#endif
33
34namespace
35{
36MeshLib::Mesh* readMeshFromFileSerial(const std::string& file_name)
37{
38 if (BaseLib::hasFileExtension(".msh", file_name))
39 {
41 return meshIO.loadMeshFromFile(file_name);
42 }
43
44 if (BaseLib::hasFileExtension(".vtu", file_name))
45 {
47 }
48
49 if (BaseLib::hasFileExtension(".vtk", file_name))
50 {
52 }
53
54 ERR("readMeshFromFile(): Unknown mesh file format in file {:s}.",
55 file_name);
56 return nullptr;
57}
58} // namespace
59
60namespace MeshLib
61{
62namespace IO
63{
64MeshLib::Mesh* readMeshFromFile(const std::string& file_name)
65{
66#ifdef USE_PETSC
67 int mpi_init;
68 MPI_Initialized(&mpi_init);
69 if (mpi_init == 1)
70 {
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 =
78 return read_pmesh.read(file_name_base);
79 }
80 if (world_size == 1)
81 {
82 std::unique_ptr<Mesh> mesh{readMeshFromFileSerial(file_name)};
83 return new MeshLib::NodePartitionedMesh(*mesh);
84 }
85 return nullptr;
86 }
87#endif
88 return readMeshFromFileSerial(file_name);
89}
90
91} // end namespace IO
92} // 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:273
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:174
bool hasFileExtension(std::string const &extension, std::string const &filename)
Definition: FileTools.cpp:196
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
MeshLib::Mesh * readMeshFromFileSerial(const std::string &file_name)
Definition of readMeshFromFile function.