OGS
scaleProperty.cpp File Reference
#include <tclap/CmdLine.h>
#include <algorithm>
#include <cmath>
#include <memory>
#include <numeric>
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
Include dependency graph for scaleProperty.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 23 of file scaleProperty.cpp.

24 {
25  TCLAP::CmdLine cmd(
26  "Scales a property of a mesh.\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> out_mesh_arg(
35  "o",
36  "out-mesh",
37  "the mesh is stored to a file of this name",
38  true,
39  "",
40  "filename for mesh output");
41  cmd.add(out_mesh_arg);
42 
43  TCLAP::ValueArg<std::string> property_arg(
44  "p",
45  "property-name",
46  "the name of the property the values are stored for",
47  true,
48  "",
49  "property name as string");
50  cmd.add(property_arg);
51 
52  TCLAP::ValueArg<std::string> mesh_arg(
53  "m", "mesh", "the mesh is read from this file", true, "", "file name");
54  cmd.add(mesh_arg);
55 
56  std::vector<std::string> allowed_units{"mm/a", "mm/month", "m/s"};
57  TCLAP::ValuesConstraint<std::string> allowed_units_constraints{
58  allowed_units};
59  TCLAP::ValueArg<std::string> unit_arg("u",
60  "input-unit",
61  "input unit of the data",
62  true,
63  "m/s",
64  &allowed_units_constraints);
65  cmd.add(unit_arg);
66 
67  cmd.parse(argc, argv);
68 
69  std::unique_ptr<MeshLib::Mesh> mesh(
70  MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
71 
72  double scale(1.0);
73  if (unit_arg.getValue() == "m/s")
74  {
75  scale = 1.0;
76  }
77  else if (unit_arg.getValue() == "mm/a")
78  {
79  scale = 1e-3 / (365.25 * 86400);
80  }
81  else if (unit_arg.getValue() == "mm/month")
82  {
83  scale = 1e-3 * (12.0 / (365.25 * 86400));
84  }
85 
86  MeshLib::scaleMeshPropertyVector(*mesh, property_arg.getValue(), scale);
87 
88  MeshLib::IO::writeMeshToFile(*mesh, out_mesh_arg.getValue());
89 
90  return EXIT_SUCCESS;
91 }
GITINFOLIB_EXPORT const std::string ogs_version
void scale(PETScVector &x, double const a)
Definition: LinAlg.cpp:44
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)
void scaleMeshPropertyVector(MeshLib::Mesh &mesh, std::string const &property_name, double factor)
Definition: Mesh.cpp:244

References GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), MathLib::LinAlg::scale(), MeshLib::scaleMeshPropertyVector(), and MeshLib::IO::writeMeshToFile().