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/RunTime.h"
16 #include "InfoLib/GitInfo.h"
19 #include "MeshLib/Mesh.h"
20 #include "MeshLib/MeshEnums.h"
22 
23 int main(int argc, char* argv[])
24 {
25  TCLAP::CmdLine cmd(
26  "Add element quality as a mesh property.\n\n"
27  "OpenGeoSys-6 software, version " +
29  ".\n"
30  "Copyright (c) 2012-2021, OpenGeoSys Community "
31  "(http://www.opengeosys.org)",
33 
34  TCLAP::ValueArg<std::string> mesh_out_arg(
35  "o", "output_mesh_file", "output mesh file", true, "", "string");
36  cmd.add(mesh_out_arg);
37  std::vector<std::string> allowed_element_criterions{
38  "ElementSize", "EdgeRatio", "EquiAngleSkew", "RadiusEdgeRatio",
39  "SizeDifference"};
40  TCLAP::ValuesConstraint<std::string> element_criterions{
41  allowed_element_criterions};
42  TCLAP::ValueArg<std::string> criterion_arg{
43  "c", "quality_criterion", "quality criterion", true,
44  "", &element_criterions};
45  cmd.add(criterion_arg);
46  TCLAP::ValueArg<std::string> mesh_in_arg(
47  "i", "input_mesh_file", "input mesh file", true, "", "string");
48  cmd.add(mesh_in_arg);
49  cmd.parse(argc, argv);
50 
51  // read the mesh file
52  BaseLib::RunTime run_time;
53  run_time.start();
54  std::unique_ptr<MeshLib::Mesh> mesh(
55  MeshLib::IO::readMeshFromFile(mesh_in_arg.getValue()));
56  if (!mesh)
57  {
58  return EXIT_FAILURE;
59  }
60  INFO("Time for reading: {:g} s", run_time.elapsed());
61 
62  // Geometric information
63  MeshLib::MeshQualityType const type =
64  MeshLib::String2MeshQualityType(criterion_arg.getValue());
65  MeshLib::ElementQualityInterface element_quality(*mesh, type);
66  auto const element_quality_vector = element_quality.getQualityVector();
67  MeshLib::addPropertyToMesh(*mesh, criterion_arg.getValue(),
69  element_quality_vector);
70  INFO("Writing mesh '{:s}' ... ", mesh_out_arg.getValue());
71  MeshLib::IO::writeMeshToFile(*mesh, mesh_out_arg.getValue());
72  INFO("done.");
73  return EXIT_SUCCESS;
74 }
int main(int argc, char *argv[])
Definition of the ElementQualityInterface class.
Git information.
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
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)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)
MeshLib::MeshQualityType String2MeshQualityType(std::string const &s)
Definition: MeshEnums.cpp:211
MeshQualityType
Describes a mesh quality metric.
Definition: MeshEnums.h:70
void addPropertyToMesh(Mesh &mesh, std::string const &name, MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)
Definition: Mesh.h:193
Definition of readMeshFromFile function.