OGS
checkMesh.cpp File Reference
#include <spdlog/fmt/ranges.h>
#include <tclap/CmdLine.h>
#include <array>
#include <string>
#include "BaseLib/FileTools.h"
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/MemWatch.h"
#include "BaseLib/RunTime.h"
#include "BaseLib/StringTools.h"
#include "BaseLib/TCLAPArguments.h"
#include "GeoLib/AABB.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
#include "MeshToolsLib/MeshInformation.h"
#include "MeshToolsLib/MeshQuality/MeshValidation.h"
Include dependency graph for checkMesh.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 26 of file checkMesh.cpp.

27{
28 TCLAP::CmdLine cmd(
29 "Checks mesh properties.\n\n"
30 "OpenGeoSys-6 software, version " +
32 ".\n"
33 "Copyright (c) 2012-2026, OpenGeoSys Community "
34 "(http://www.opengeosys.org)",
36 TCLAP::UnlabeledValueArg<std::string> mesh_arg(
37 "mesh-file", "Input (.vtu | .msh). Mesh file", true, "", "INPUT_FILE");
38 cmd.add(mesh_arg);
39 TCLAP::SwitchArg valid_arg("v", "validation", "validate the mesh");
40 cmd.add(valid_arg);
41 TCLAP::SwitchArg print_properties_arg(
42 "p", "print_properties", "print properties stored in the mesh");
43 cmd.add(print_properties_arg);
44 auto log_level_arg = BaseLib::makeLogLevelArg();
45 cmd.add(log_level_arg);
46
47 cmd.parse(argc, argv);
48
49 BaseLib::MPI::Setup mpi_setup(argc, argv);
50 BaseLib::initOGSLogger(log_level_arg.getValue());
51
52 // read the mesh file
53 BaseLib::MemWatch mem_watch;
54 const unsigned long mem_without_mesh(mem_watch.getVirtMemUsage());
55 BaseLib::RunTime run_time;
56 run_time.start();
57 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(
58 mesh_arg.getValue(), true /* compute_element_neighbors */));
59 if (!mesh)
60 {
61 return EXIT_FAILURE;
62 }
63
64 const unsigned long mem_with_mesh(mem_watch.getVirtMemUsage());
65 if (mem_with_mesh > 0)
66 {
67 INFO("Memory size: {} MiB",
68 (mem_with_mesh - mem_without_mesh) / (1024 * 1024));
69 (void)mem_with_mesh;
70 }
71 INFO("Time for reading: {:g} s", run_time.elapsed());
72
73 // Geometric information
74 const GeoLib::AABB aabb(
76 INFO("Axis aligned bounding box: {}", aabb);
77
78 auto const [min, max] = minMaxEdgeLength(mesh->getElements());
79 INFO("Min/max edge lengths: [{:g}, {:g}]", min, max);
80
81 // Element information
82
84
85 if (print_properties_arg.isSet())
86 {
88 INFO("MaterialID-list: [{}]",
90 ", "));
91 }
92
93 if (valid_arg.isSet())
94 {
95 // MeshValidation outputs error messages
96 // Remark: MeshValidation can modify the original mesh
98 }
99 return EXIT_SUCCESS;
100}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
unsigned long getVirtMemUsage()
Definition MemWatch.cpp:48
Count the running time.
Definition RunTime.h:18
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:31
void start()
Start the timer.
Definition RunTime.h:21
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:45
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
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:56
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
std::pair< double, double > minMaxEdgeLength(std::vector< Element * > const &elements)
Returns the minimum and maximum edge length for given elements.
Definition Mesh.cpp:179

References BaseLib::RunTime::elapsed(), MeshToolsLib::MeshInformation::getBoundingBox(), MeshToolsLib::MeshInformation::getMaterialIDs(), BaseLib::MemWatch::getVirtMemUsage(), INFO(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), BaseLib::RunTime::start(), MeshToolsLib::MeshInformation::writeAllNumbersOfElementTypes(), MeshToolsLib::MeshInformation::writeMeshValidationResults(), and MeshToolsLib::MeshInformation::writePropertyVectorInformation().