OGS
checkMesh.cpp
Go to the documentation of this file.
1
10#include <tclap/CmdLine.h>
11
12#ifdef USE_PETSC
13#include <mpi.h>
14#endif
15
16#include <spdlog/fmt/bundled/ranges.h>
17
18#include <array>
19#include <string>
20
21#include "BaseLib/FileTools.h"
22#include "BaseLib/MemWatch.h"
23#include "BaseLib/RunTime.h"
24#include "BaseLib/StringTools.h"
25#include "GeoLib/AABB.h"
26#include "InfoLib/GitInfo.h"
29#include "MeshLib/Mesh.h"
30#include "MeshLib/Node.h"
33
34int main(int argc, char* argv[])
35{
36 TCLAP::CmdLine cmd(
37 "Checks mesh properties.\n\n"
38 "OpenGeoSys-6 software, version " +
40 ".\n"
41 "Copyright (c) 2012-2024, OpenGeoSys Community "
42 "(http://www.opengeosys.org)",
44 TCLAP::UnlabeledValueArg<std::string> mesh_arg(
45 "mesh-file", "input mesh file", true, "", "string");
46 cmd.add(mesh_arg);
47 TCLAP::SwitchArg valid_arg("v", "validation", "validate the mesh");
48 cmd.add(valid_arg);
49 TCLAP::SwitchArg print_properties_arg(
50 "p", "print_properties", "print properties stored in the mesh");
51 cmd.add(print_properties_arg);
52
53 cmd.parse(argc, argv);
54
55#ifdef USE_PETSC
56 MPI_Init(&argc, &argv);
57#endif
58
59 // read the mesh file
60 BaseLib::MemWatch mem_watch;
61 const unsigned long mem_without_mesh(mem_watch.getVirtMemUsage());
62 BaseLib::RunTime run_time;
63 run_time.start();
64 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(
65 mesh_arg.getValue(), true /* compute_element_neighbors */));
66 if (!mesh)
67 {
68#ifdef USE_PETSC
69 MPI_Finalize();
70#endif
71 return EXIT_FAILURE;
72 }
73
74 const unsigned long mem_with_mesh(mem_watch.getVirtMemUsage());
75 if (mem_with_mesh > 0)
76 {
77 INFO("Memory size: {} MiB",
78 (mem_with_mesh - mem_without_mesh) / (1024 * 1024));
79 (void)mem_with_mesh;
80 }
81 INFO("Time for reading: {:g} s", run_time.elapsed());
82
83 // Geometric information
84 const GeoLib::AABB aabb(
86 INFO("Axis aligned bounding box: {}", aabb);
87
88 auto const [min, max] = minMaxEdgeLength(mesh->getElements());
89 INFO("Min/max edge lengths: [{:g}, {:g}]", min, max);
90
91 // Element information
92
94
95 if (print_properties_arg.isSet())
96 {
98 INFO("MaterialID-list: [{}]",
100 ", "));
101 }
102
103 if (valid_arg.isSet())
104 {
105 // MeshValidation outputs error messages
106 // Remark: MeshValidation can modify the original mesh
108 }
109#ifdef USE_PETSC
110 MPI_Finalize();
111#endif
112 return EXIT_SUCCESS;
113}
Definition of the AABB class.
Definition of the Element class.
Filename manipulation routines.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of the MemWatch class.
Definition of the MeshInformation class.
Definition of the MeshValidation class.
Definition of the Mesh class.
Definition of the Node class.
Definition of the RunTime class.
Definition of string helper functions.
int main(int argc, char *argv[])
Definition checkMesh.cpp:34
unsigned long getVirtMemUsage()
Definition MemWatch.cpp:59
Count the running time.
Definition RunTime.h:29
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:42
void start()
Start the timer.
Definition RunTime.h:32
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
static GeoLib::AABB getBoundingBox(const MeshLib::Mesh &mesh)
Returns the bounding box of the mesh.
static void writeMeshValidationResults(MeshLib::Mesh &mesh)
static std::vector< int > getMaterialIDs(const MeshLib::Mesh &mesh)
writes out a list of all material IDs that occur in the mesh.
static void writeAllNumbersOfElementTypes(const MeshLib::Mesh &mesh)
writes all numbers of element types
static void writePropertyVectorInformation(const MeshLib::Mesh &mesh)
writes out property vector information
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
Definition of readMeshFromFile function.