OGS
readMeshFromFile.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "readMeshFromFile.h"
5
6#ifdef USE_PETSC
7#include <petsc.h>
8#endif
9
10#include <boost/algorithm/string/erase.hpp>
11
12#include "BaseLib/FileTools.h"
13#include "BaseLib/Logging.h"
14#include "BaseLib/MPI.h"
15#include "BaseLib/StringTools.h"
18#include "MeshLib/Mesh.h"
19
20#ifdef USE_PETSC
23#endif
24
25namespace
26{
27MeshLib::Mesh* readMeshFromFileSerial(const std::string& file_name,
28 bool const compute_element_neighbors)
29{
30 if (BaseLib::hasFileExtension(".msh", file_name))
31 {
33 return meshIO.loadMeshFromFile(file_name);
34 }
35
36 if (BaseLib::hasFileExtension(".vtu", file_name))
37 {
39 file_name, compute_element_neighbors);
40 }
41
42 if (BaseLib::hasFileExtension(".vtk", file_name))
43 {
45 file_name, compute_element_neighbors);
46 }
47
48 ERR("readMeshFromFile(): Unknown mesh file format in file {:s}.",
49 file_name);
50 return nullptr;
51}
52} // namespace
53
54namespace MeshLib
55{
56namespace IO
57{
58MeshLib::Mesh* readMeshFromFile(const std::string& file_name,
59 bool const compute_element_neighbors)
60{
61#ifdef USE_PETSC
63 if (mpi.size > 1)
64 {
66 const std::string file_name_base =
68 return read_pmesh.read(file_name_base);
69 }
70 if (mpi.size == 1)
71 {
72 std::unique_ptr<Mesh> mesh{
73 readMeshFromFileSerial(file_name, compute_element_neighbors)};
74
75 if (!mesh)
76 {
77 return nullptr;
78 }
79
80 return new MeshLib::NodePartitionedMesh(*mesh);
81 }
82 return nullptr;
83#endif
84 return readMeshFromFileSerial(file_name, compute_element_neighbors);
85}
86
87} // end namespace IO
88} // end namespace MeshLib
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Interface for handling mesh files from OGS-5 and below. (*.msh files)
Definition MeshIO.h:26
MeshLib::Mesh * loadMeshFromFile(const std::string &file_name)
Read mesh from file.
Definition MeshIO.cpp:267
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)
MPI_Comm communicator
Definition MPI.h:58