OGS
scaleProperty.cpp File Reference
#include <tclap/CmdLine.h>
#include <algorithm>
#include <cmath>
#include <memory>
#include <numeric>
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/TCLAPArguments.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Utils/scaleMeshPropertyVector.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 20 of file scaleProperty.cpp.

21{
22 TCLAP::CmdLine cmd(
23 "Scales a property of a mesh.\n\n"
24 "OpenGeoSys-6 software, version " +
26 ".\n"
27 "Copyright (c) 2012-2026, OpenGeoSys Community "
28 "(http://www.opengeosys.org)",
30
31 TCLAP::ValueArg<std::string> out_mesh_arg(
32 "o",
33 "out-mesh",
34 "Output (.vtu). The output mesh is stored to a file of this name",
35 true,
36 "",
37 "OUTPUT_FILE");
38 cmd.add(out_mesh_arg);
39
40 TCLAP::ValueArg<std::string> property_arg(
41 "p",
42 "property-name",
43 "the name of the property the values are stored for",
44 true,
45 "",
46 "PROP_NAME");
47 cmd.add(property_arg);
48
49 TCLAP::ValueArg<std::string> mesh_arg(
50 "m", "mesh", "Input (.vtu). The input mesh is read from this file",
51 true, "", "INPUT_FILE");
52 cmd.add(mesh_arg);
53
54 std::vector<std::string> allowed_units{"mm/a", "mm/month", "m/s"};
55 TCLAP::ValuesConstraint<std::string> allowed_units_constraints{
56 allowed_units};
57 TCLAP::ValueArg<std::string> unit_arg("u",
58 "input-unit",
59 "input unit of the data",
60 true,
61 "m/s",
62 &allowed_units_constraints);
63 cmd.add(unit_arg);
64
65 auto log_level_arg = BaseLib::makeLogLevelArg();
66 cmd.add(log_level_arg);
67 cmd.parse(argc, argv);
68
69 BaseLib::MPI::Setup mpi_setup(argc, argv);
70 BaseLib::initOGSLogger(log_level_arg.getValue());
71
72 std::unique_ptr<MeshLib::Mesh> mesh(
73 MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
74
75 double scale(1.0);
76 if (unit_arg.getValue() == "m/s")
77 {
78 scale = 1.0;
79 }
80 else if (unit_arg.getValue() == "mm/a")
81 {
82 scale = 1e-3 / (365.25 * 86400);
83 }
84 else if (unit_arg.getValue() == "mm/month")
85 {
86 scale = 1e-3 * (12.0 / (365.25 * 86400));
87 }
88
89 MeshLib::scaleMeshPropertyVector(*mesh, property_arg.getValue(), scale);
90
91 MeshLib::IO::writeMeshToFile(*mesh, out_mesh_arg.getValue());
92
93 return EXIT_SUCCESS;
94}
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:56
GITINFOLIB_EXPORT const std::string ogs_version
void scale(PETScVector &x, PetscScalar const a)
Definition LinAlg.cpp:37
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)

References BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), MeshLib::scaleMeshPropertyVector(), and MeshLib::IO::writeMeshToFile().