OGS
checkMesh.cpp
Go to the documentation of this file.
1
10#include <spdlog/fmt/bundled/ranges.h>
11#include <tclap/CmdLine.h>
12
13#include <array>
14#include <string>
15
16#include "BaseLib/FileTools.h"
17#include "BaseLib/MPI.h"
18#include "BaseLib/MemWatch.h"
19#include "BaseLib/RunTime.h"
20#include "BaseLib/StringTools.h"
21#include "GeoLib/AABB.h"
22#include "InfoLib/GitInfo.h"
25#include "MeshLib/Mesh.h"
26#include "MeshLib/Node.h"
29
30int main(int argc, char* argv[])
31{
32 TCLAP::CmdLine cmd(
33 "Checks mesh properties.\n\n"
34 "OpenGeoSys-6 software, version " +
36 ".\n"
37 "Copyright (c) 2012-2024, OpenGeoSys Community "
38 "(http://www.opengeosys.org)",
40 TCLAP::UnlabeledValueArg<std::string> mesh_arg(
41 "mesh-file", "input mesh file", true, "", "string");
42 cmd.add(mesh_arg);
43 TCLAP::SwitchArg valid_arg("v", "validation", "validate the mesh");
44 cmd.add(valid_arg);
45 TCLAP::SwitchArg print_properties_arg(
46 "p", "print_properties", "print properties stored in the mesh");
47 cmd.add(print_properties_arg);
48
49 cmd.parse(argc, argv);
50
51 BaseLib::MPI::Setup mpi_setup(argc, argv);
52
53 // read the mesh file
54 BaseLib::MemWatch mem_watch;
55 const unsigned long mem_without_mesh(mem_watch.getVirtMemUsage());
56 BaseLib::RunTime run_time;
57 run_time.start();
58 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(
59 mesh_arg.getValue(), true /* compute_element_neighbors */));
60 if (!mesh)
61 {
62 return EXIT_FAILURE;
63 }
64
65 const unsigned long mem_with_mesh(mem_watch.getVirtMemUsage());
66 if (mem_with_mesh > 0)
67 {
68 INFO("Memory size: {} MiB",
69 (mem_with_mesh - mem_without_mesh) / (1024 * 1024));
70 (void)mem_with_mesh;
71 }
72 INFO("Time for reading: {:g} s", run_time.elapsed());
73
74 // Geometric information
75 const GeoLib::AABB aabb(
77 INFO("Axis aligned bounding box: {}", aabb);
78
79 auto const [min, max] = minMaxEdgeLength(mesh->getElements());
80 INFO("Min/max edge lengths: [{:g}, {:g}]", min, max);
81
82 // Element information
83
85
86 if (print_properties_arg.isSet())
87 {
89 INFO("MaterialID-list: [{}]",
91 ", "));
92 }
93
94 if (valid_arg.isSet())
95 {
96 // MeshValidation outputs error messages
97 // Remark: MeshValidation can modify the original mesh
99 }
100 return EXIT_SUCCESS;
101}
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:30
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.