OGS
swapNodeCoordinateAxes.cpp File Reference

Detailed Description

Definition in file swapNodeCoordinateAxes.cpp.

#include <tclap/CmdLine.h>
#include <mpi.h>
#include <array>
#include <memory>
#include <string>
#include "BaseLib/Logging.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 93 of file swapNodeCoordinateAxes.cpp.

94{
95 TCLAP::CmdLine cmd(
96 "Swap node coordinate values.\n\n"
97 "OpenGeoSys-6 software, version " +
99 ".\n"
100 "Copyright (c) 2012-2024, OpenGeoSys Community "
101 "(http://www.opengeosys.org)",
103 TCLAP::ValueArg<std::string> input_arg(
104 "i", "input-mesh-file", "input mesh file", true, "", "string");
105 cmd.add(input_arg);
106 TCLAP::ValueArg<std::string> output_arg(
107 "o", "output-mesh-file", "output mesh file", true, "", "string");
108 cmd.add(output_arg);
109 TCLAP::ValueArg<std::string> new_order_arg(
110 "n", "new-order",
111 "the new order of swapped coordinate values (e.g. 'xzy' for converting "
112 "XYZ values to XZY values)",
113 true, "", "string");
114 cmd.add(new_order_arg);
115 cmd.parse(argc, argv);
116
117#ifdef USE_PETSC
118 MPI_Init(&argc, &argv);
119#endif
120
121 const std::string str_order = new_order_arg.getValue();
122 std::array<int, 3> new_order = {{}};
123 if (!parseNewOrder(str_order, new_order))
124 {
125#ifdef USE_PETSC
126 MPI_Finalize();
127#endif
128 return EXIT_FAILURE;
129 }
130
131 std::unique_ptr<MeshLib::Mesh> mesh(
132 MeshLib::IO::readMeshFromFile(input_arg.getValue()));
133 if (!mesh)
134 {
135#ifdef USE_PETSC
136 MPI_Finalize();
137#endif
138 return EXIT_FAILURE;
139 }
140
141 if (mesh->getDimension() == 3)
142 {
143 WARN(
144 "Swapping coordinate values of 3D elements can result in incorrect "
145 "node-ordering.");
146 }
147
148 INFO("Exchange node coordinates from xyz to {:s}",
149 new_order_arg.getValue().data());
150 swapNodeCoordinateAxes(*mesh, new_order);
151
152 INFO("Save the new mesh into a file");
153 MeshLib::IO::writeMeshToFile(*mesh, output_arg.getValue());
154
155#ifdef USE_PETSC
156 MPI_Finalize();
157#endif
158 return EXIT_SUCCESS;
159}
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 44 of file swapNodeCoordinateAxes.cpp.

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

29{
30 double new_coords[3] = {};
31 for (MeshLib::Node* node : mesh.getNodes())
32 {
33 for (int i = 0; i < 3; i++)
34 {
35 new_coords[i] = (*node)[new_axes_indices[i]];
36 }
37 for (int i = 0; i < 3; i++)
38 {
39 (*node)[i] = new_coords[i];
40 }
41 }
42}
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().