OGS
AddElementQuality.cpp File Reference

Detailed Description

Definition in file AddElementQuality.cpp.

#include <tclap/CmdLine.h>
#include <mpi.h>
#include <array>
#include <string>
#include "BaseLib/RunTime.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/MeshEnums.h"
#include "MeshLib/Utils/addPropertyToMesh.h"
#include "MeshToolsLib/MeshQuality/ElementQualityInterface.h"
Include dependency graph for AddElementQuality.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 28 of file AddElementQuality.cpp.

29{
30 TCLAP::CmdLine cmd(
31 "Add element quality as a mesh property.\n\n"
32 "OpenGeoSys-6 software, version " +
34 ".\n"
35 "Copyright (c) 2012-2024, OpenGeoSys Community "
36 "(http://www.opengeosys.org)",
38
39 TCLAP::ValueArg<std::string> mesh_out_arg(
40 "o", "output_mesh_file", "output mesh file", true, "", "string");
41 cmd.add(mesh_out_arg);
42 std::vector<std::string> allowed_element_criterions{
43 "ElementSize", "EdgeRatio", "EquiAngleSkew", "RadiusEdgeRatio",
44 "SizeDifference"};
45 TCLAP::ValuesConstraint<std::string> element_criterions{
46 allowed_element_criterions};
47 TCLAP::ValueArg<std::string> criterion_arg{
48 "c", "quality_criterion", "quality criterion", true,
49 "", &element_criterions};
50 cmd.add(criterion_arg);
51 TCLAP::ValueArg<std::string> mesh_in_arg(
52 "i", "input_mesh_file", "input mesh file", true, "", "string");
53 cmd.add(mesh_in_arg);
54 cmd.parse(argc, argv);
55
56#ifdef USE_PETSC
57 MPI_Init(&argc, &argv);
58#endif
59
60 // read the mesh file
61 BaseLib::RunTime run_time;
62 run_time.start();
63 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(
64 mesh_in_arg.getValue(), true /* compute_element_neighbors */));
65 if (!mesh)
66 {
67#ifdef USE_PETSC
68 MPI_Finalize();
69#endif
70 return EXIT_FAILURE;
71 }
72 INFO("Time for reading: {:g} s", run_time.elapsed());
73
74 // Geometric information
75 MeshLib::MeshQualityType const type =
76 MeshLib::String2MeshQualityType(criterion_arg.getValue());
77 MeshToolsLib::ElementQualityInterface element_quality(*mesh, type);
78 auto const element_quality_vector = element_quality.getQualityVector();
79 MeshLib::addPropertyToMesh(*mesh, criterion_arg.getValue(),
81 element_quality_vector);
82 INFO("Writing mesh '{:s}' ... ", mesh_out_arg.getValue());
83 MeshLib::IO::writeMeshToFile(*mesh, mesh_out_arg.getValue());
84 INFO("done.");
85#ifdef USE_PETSC
86 MPI_Finalize();
87#endif
88 return EXIT_SUCCESS;
89}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
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
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)
MeshLib::MeshQualityType String2MeshQualityType(std::string const &s)
MeshQualityType
Describes a mesh quality metric.
Definition MeshEnums.h:70
void addPropertyToMesh(Mesh &mesh, std::string_view name, MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)

References MeshLib::addPropertyToMesh(), MeshLib::Cell, BaseLib::RunTime::elapsed(), MeshToolsLib::ElementQualityInterface::getQualityVector(), INFO(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), BaseLib::RunTime::start(), MeshLib::String2MeshQualityType(), and MeshLib::IO::writeMeshToFile().