OGS
scaleProperty.cpp
Go to the documentation of this file.
1
12#include <tclap/CmdLine.h>
13
14#include <algorithm>
15#include <cmath>
16#include <memory>
17#include <numeric>
18
19#include "BaseLib/MPI.h"
20#include "InfoLib/GitInfo.h"
23#include "MeshLib/Mesh.h"
25
26int main(int argc, char* argv[])
27{
28 TCLAP::CmdLine cmd(
29 "Scales a property of a mesh.\n\n"
30 "OpenGeoSys-6 software, version " +
32 ".\n"
33 "Copyright (c) 2012-2024, OpenGeoSys Community "
34 "(http://www.opengeosys.org)",
36
37 TCLAP::ValueArg<std::string> out_mesh_arg(
38 "o",
39 "out-mesh",
40 "the mesh is stored to a file of this name",
41 true,
42 "",
43 "filename for mesh output");
44 cmd.add(out_mesh_arg);
45
46 TCLAP::ValueArg<std::string> property_arg(
47 "p",
48 "property-name",
49 "the name of the property the values are stored for",
50 true,
51 "",
52 "property name as string");
53 cmd.add(property_arg);
54
55 TCLAP::ValueArg<std::string> mesh_arg(
56 "m", "mesh", "the mesh is read from this file", true, "", "file name");
57 cmd.add(mesh_arg);
58
59 std::vector<std::string> allowed_units{"mm/a", "mm/month", "m/s"};
60 TCLAP::ValuesConstraint<std::string> allowed_units_constraints{
61 allowed_units};
62 TCLAP::ValueArg<std::string> unit_arg("u",
63 "input-unit",
64 "input unit of the data",
65 true,
66 "m/s",
67 &allowed_units_constraints);
68 cmd.add(unit_arg);
69
70 cmd.parse(argc, argv);
71
72 BaseLib::MPI::Setup mpi_setup(argc, argv);
73
74 std::unique_ptr<MeshLib::Mesh> mesh(
75 MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
76
77 double scale(1.0);
78 if (unit_arg.getValue() == "m/s")
79 {
80 scale = 1.0;
81 }
82 else if (unit_arg.getValue() == "mm/a")
83 {
84 scale = 1e-3 / (365.25 * 86400);
85 }
86 else if (unit_arg.getValue() == "mm/month")
87 {
88 scale = 1e-3 * (12.0 / (365.25 * 86400));
89 }
90
91 MeshLib::scaleMeshPropertyVector(*mesh, property_arg.getValue(), scale);
92
93 MeshLib::IO::writeMeshToFile(*mesh, out_mesh_arg.getValue());
94
95 return EXIT_SUCCESS;
96}
Git information.
Definition of the Mesh class.
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)
void scaleMeshPropertyVector(MeshLib::Mesh &mesh, std::string const &property_name, double factor)
Definition of readMeshFromFile function.
int main(int argc, char *argv[])