OGS
AddElementQuality.cpp
Go to the documentation of this file.
1
10#include <tclap/CmdLine.h>
11
12#include <array>
13#include <string>
14
15#include "BaseLib/MPI.h"
16#include "BaseLib/RunTime.h"
17#include "InfoLib/GitInfo.h"
20#include "MeshLib/Mesh.h"
21#include "MeshLib/MeshEnums.h"
24
25int main(int argc, char* argv[])
26{
27 TCLAP::CmdLine cmd(
28 "Add element quality as a mesh property.\n\n"
29 "OpenGeoSys-6 software, version " +
31 ".\n"
32 "Copyright (c) 2012-2024, OpenGeoSys Community "
33 "(http://www.opengeosys.org)",
35
36 TCLAP::ValueArg<std::string> mesh_out_arg(
37 "o", "output_mesh_file", "output mesh file", true, "", "string");
38 cmd.add(mesh_out_arg);
39 std::vector<std::string> allowed_element_criterions{
40 "ElementSize", "EdgeRatio", "EquiAngleSkew", "RadiusEdgeRatio",
41 "SizeDifference"};
42 TCLAP::ValuesConstraint<std::string> element_criterions{
43 allowed_element_criterions};
44 TCLAP::ValueArg<std::string> criterion_arg{
45 "c", "quality_criterion", "quality criterion", true,
46 "", &element_criterions};
47 cmd.add(criterion_arg);
48 TCLAP::ValueArg<std::string> mesh_in_arg(
49 "i", "input_mesh_file", "input mesh file", true, "", "string");
50 cmd.add(mesh_in_arg);
51 cmd.parse(argc, argv);
52
53 BaseLib::MPI::Setup mpi_setup(argc, argv);
54
55 // read the mesh file
56 BaseLib::RunTime run_time;
57 run_time.start();
58 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(
59 mesh_in_arg.getValue(), true /* compute_element_neighbors */));
60 if (!mesh)
61 {
62 return EXIT_FAILURE;
63 }
64 INFO("Time for reading: {:g} s", run_time.elapsed());
65
66 // Geometric information
67 MeshLib::MeshQualityType const type =
68 MeshLib::String2MeshQualityType(criterion_arg.getValue());
69 MeshToolsLib::ElementQualityInterface element_quality(*mesh, type);
70 auto const element_quality_vector = element_quality.getQualityVector();
71 MeshLib::addPropertyToMesh(*mesh, criterion_arg.getValue(),
73 element_quality_vector);
74 INFO("Writing mesh '{:s}' ... ", mesh_out_arg.getValue());
75 MeshLib::IO::writeMeshToFile(*mesh, mesh_out_arg.getValue());
76 INFO("done.");
77 return EXIT_SUCCESS;
78}
int main(int argc, char *argv[])
Definition of the ElementQualityInterface class.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of mesh-related Enumerations.
Definition of the Mesh class.
Definition of the RunTime class.
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
std::vector< double > const getQualityVector() const
Returns the vector containing a quality measure for each element.
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)
Definition of readMeshFromFile function.