OGS
swapNodeCoordinateAxes.cpp File Reference

Detailed Description

Definition in file swapNodeCoordinateAxes.cpp.

#include <tclap/CmdLine.h>
#include <array>
#include <memory>
#include <string>
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
Include dependency graph for swapNodeCoordinateAxes.cpp:

Go to the source code of this file.

Functions

static void swapNodeCoordinateAxes (MeshLib::Mesh const &mesh, std::array< int, 3 > const &new_axes_indices)
 
static bool parseNewOrder (std::string const &str_order, std::array< int, 3 > &new_axes_indices)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 90 of file swapNodeCoordinateAxes.cpp.

91{
92 TCLAP::CmdLine cmd(
93 "Swap node coordinate values.\n\n"
94 "OpenGeoSys-6 software, version " +
96 ".\n"
97 "Copyright (c) 2012-2024, OpenGeoSys Community "
98 "(http://www.opengeosys.org)",
100 TCLAP::ValueArg<std::string> input_arg(
101 "i", "input-mesh-file", "input mesh file", true, "", "string");
102 cmd.add(input_arg);
103 TCLAP::ValueArg<std::string> output_arg(
104 "o", "output-mesh-file", "output mesh file", true, "", "string");
105 cmd.add(output_arg);
106 TCLAP::ValueArg<std::string> new_order_arg(
107 "n", "new-order",
108 "the new order of swapped coordinate values (e.g. 'xzy' for converting "
109 "XYZ values to XZY values)",
110 true, "", "string");
111 cmd.add(new_order_arg);
112 cmd.parse(argc, argv);
113
114 BaseLib::MPI::Setup mpi_setup(argc, argv);
115
116 const std::string str_order = new_order_arg.getValue();
117 std::array<int, 3> new_order = {{}};
118 if (!parseNewOrder(str_order, new_order))
119 {
120 return EXIT_FAILURE;
121 }
122
123 std::unique_ptr<MeshLib::Mesh> mesh(
124 MeshLib::IO::readMeshFromFile(input_arg.getValue()));
125 if (!mesh)
126 {
127 return EXIT_FAILURE;
128 }
129
130 if (mesh->getDimension() == 3)
131 {
132 WARN(
133 "Swapping coordinate values of 3D elements can result in incorrect "
134 "node-ordering.");
135 }
136
137 INFO("Exchange node coordinates from xyz to {:s}",
138 new_order_arg.getValue().data());
139 swapNodeCoordinateAxes(*mesh, new_order);
140
141 INFO("Save the new mesh into a file");
142 MeshLib::IO::writeMeshToFile(*mesh, output_arg.getValue());
143
144 return EXIT_SUCCESS;
145}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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)
static bool parseNewOrder(std::string const &str_order, std::array< int, 3 > &new_axes_indices)
static void swapNodeCoordinateAxes(MeshLib::Mesh const &mesh, std::array< int, 3 > const &new_axes_indices)

References INFO(), GitInfoLib::GitInfo::ogs_version, parseNewOrder(), MeshLib::IO::readMeshFromFile(), swapNodeCoordinateAxes(), WARN(), and MeshLib::IO::writeMeshToFile().

◆ parseNewOrder()

static bool parseNewOrder ( std::string const & str_order,
std::array< int, 3 > & new_axes_indices )
static

Definition at line 41 of file swapNodeCoordinateAxes.cpp.

43{
44 if (str_order.length() != 3)
45 {
46 ERR("Invalid argument for the new order. The argument should contain "
47 "three characters.");
48 return false;
49 }
50
51 new_axes_indices.fill(-1);
52
53 for (int i = 0; i < 3; i++)
54 {
55 if (str_order[i] == 'x')
56 {
57 new_axes_indices[i] = 0;
58 }
59 else if (str_order[i] == 'y')
60 {
61 new_axes_indices[i] = 1;
62 }
63 else if (str_order[i] == 'z')
64 {
65 new_axes_indices[i] = 2;
66 }
67 else
68 {
69 ERR("Invalid argument for the new order. The given argument "
70 "contains a character other than 'x', 'y', 'z'.");
71 return false;
72 }
73 }
74
75 bool isAxisSet[3] = {false};
76 for (int new_axes_indice : new_axes_indices)
77 {
78 if (isAxisSet[new_axes_indice])
79 {
80 ERR("Invalid argument for the new order. The argument contains "
81 "some character used more than once.");
82 return false;
83 }
84 isAxisSet[new_axes_indice] = true;
85 }
86
87 return true;
88}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45

References ERR().

Referenced by main().

◆ swapNodeCoordinateAxes()

static void swapNodeCoordinateAxes ( MeshLib::Mesh const & mesh,
std::array< int, 3 > const & new_axes_indices )
static

Definition at line 24 of file swapNodeCoordinateAxes.cpp.

26{
27 double new_coords[3] = {};
28 for (MeshLib::Node* node : mesh.getNodes())
29 {
30 for (int i = 0; i < 3; i++)
31 {
32 new_coords[i] = (*node)[new_axes_indices[i]];
33 }
34 for (int i = 0; i < 3; i++)
35 {
36 (*node)[i] = new_coords[i];
37 }
38 }
39}
std::vector< std::size_t > getNodes(GeoLib::Point const &pnt, std::vector< MeshLib::Node * > const &nodes, MeshLib::PropertyVector< int > const &mat_ids, std::pair< int, int > const &mat_limits, std::pair< double, double > const &elevation_limits, MeshLib::Mesh const &mesh)

References MeshLib::Mesh::getNodes().

Referenced by main().