OGS
scaleProperty.cpp File Reference

Detailed Description

Definition in file scaleProperty.cpp.

#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 28 of file scaleProperty.cpp.

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