12#include <tclap/CmdLine.h>
42 std::size_t n_corrected_elements = 0;
43 std::size_t
const nElements(elements.size());
44 for (std::size_t i = 0; i < nElements; ++i)
46 if (!forced && elements[i]->testElementNodeOrder())
50 n_corrected_elements++;
52 const unsigned nElemNodes(elements[i]->getNumberOfBaseNodes());
53 std::vector<MeshLib::Node*> nodes(elements[i]->
getNodes(),
54 elements[i]->
getNodes() + nElemNodes);
56 switch (elements[i]->getGeomType())
59 for (std::size_t j = 0; j < 4; ++j)
61 elements[i]->setNode(j, nodes[(j + 1) % 4]);
65 elements[i]->setNode(0, nodes[1]);
66 elements[i]->setNode(1, nodes[0]);
67 elements[i]->setNode(2, nodes[3]);
68 elements[i]->setNode(3, nodes[2]);
71 for (std::size_t j = 0; j < 3; ++j)
73 elements[i]->setNode(j, nodes[j + 3]);
74 elements[i]->setNode(j + 3, nodes[j]);
78 for (std::size_t j = 0; j < 4; ++j)
80 elements[i]->setNode(j, nodes[j + 4]);
81 elements[i]->setNode(j + 4, nodes[j]);
85 for (std::size_t j = 0; j < nElemNodes; ++j)
87 elements[i]->setNode(j, nodes[nElemNodes - j - 1]);
92 INFO(
"Corrected {:d} elements.", n_corrected_elements);
100 std::size_t
const nElements(elements.size());
101 for (std::size_t i = 0; i < nElements; ++i)
103 const unsigned nElemNodes(elements[i]->getNumberOfBaseNodes());
104 std::vector<MeshLib::Node*> nodes(elements[i]->
getNodes(),
105 elements[i]->
getNodes() + nElemNodes);
107 for (std::size_t j = 0; j < nElemNodes; ++j)
111 for (std::size_t k = 0; k < 3; ++k)
113 elements[i]->setNode(k, nodes[k + 3]);
114 elements[i]->setNode(k + 3, nodes[k]);
125 std::vector<MeshLib::Node*> base_nodes;
126 std::vector<MeshLib::Node*> nonlinear_nodes;
129 for (
unsigned i = 0; i < e->getNumberOfBaseNodes(); i++)
131 base_nodes.push_back(
const_cast<MeshLib::Node*
>(e->getNode(i)));
133 for (
unsigned i = e->getNumberOfBaseNodes(); i < e->getNumberOfNodes();
136 nonlinear_nodes.push_back(
146 std::vector<MeshLib::Node*>& allnodes =
147 const_cast<std::vector<MeshLib::Node*>&
>(mesh.
getNodes());
150 allnodes.insert(allnodes.end(), base_nodes.begin(), base_nodes.end());
151 allnodes.insert(allnodes.end(), nonlinear_nodes.begin(),
152 nonlinear_nodes.end());
157int main(
int argc,
char* argv[])
160 "Reorders mesh nodes in elements to make old or incorrectly ordered "
161 "meshes compatible with OGS6.\n"
162 "Three options are available:\n"
163 "Method 0: Reversing order of nodes for all elements.\n"
164 "Method 1: Reversing order of nodes unless it's perceived correct by "
165 "OGS6 standards. This is the default selection.\n"
166 "Method 2: Fixing node ordering issues between VTK and OGS6 (only "
167 "applies to prism-elements)\n"
168 "Method 3: Re-ordering of mesh node vector such that all base nodes "
169 "are sorted before all nonlinear nodes.\n\n"
170 "OpenGeoSys-6 software, version " +
173 "Copyright (c) 2012-2025, OpenGeoSys Community "
174 "(http://www.opengeosys.org)",
177 std::vector<int> method_ids{0, 1, 2, 3};
178 TCLAP::ValuesConstraint<int> allowed_values(method_ids);
179 TCLAP::ValueArg<int> method_arg(
"m",
"method",
180 "reordering method selection",
false, 1,
183 TCLAP::ValueArg<std::string> output_mesh_arg(
184 "o",
"output_mesh",
"Output (.vtu). The name of the output mesh file",
185 true,
"",
"OUTPUT_FILE");
186 cmd.add(output_mesh_arg);
187 TCLAP::ValueArg<std::string> input_mesh_arg(
189 "Input (.vtu | .vtk | .msh). The name of the input mesh file",
true,
"",
191 cmd.add(input_mesh_arg);
193 cmd.add(log_level_arg);
194 cmd.parse(argc, argv);
199 std::unique_ptr<MeshLib::Mesh> mesh(
207 INFO(
"Reordering nodes... ");
208 if (!method_arg.isSet() || method_arg.getValue() < 2)
210 bool const forced = (method_arg.getValue() == 0);
212 const_cast<std::vector<MeshLib::Element*>&
>(mesh->getElements()),
215 else if (method_arg.getValue() == 2)
218 const_cast<std::vector<MeshLib::Element*>&
>(mesh->getElements()));
220 else if (method_arg.getValue() == 3)
227 INFO(
"VTU file written.");
Definition of the Element class.
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)
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Mesh class.
int main(int argc, char *argv[])
void fixVtkInconsistencies(std::vector< MeshLib::Element * > &elements)
void reverseNodeOrder(std::vector< MeshLib::Element * > &elements, bool const forced)
Reverses order of nodes. In particular, this fixes issues between OGS5 and OGS6 meshes.
void reorderNonlinearNodes(MeshLib::Mesh &mesh)
Orders the base nodes of each elements before its non-linear nodes.
Definition of the Node class.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
void resetNodeIDs()
Resets the IDs of all mesh-nodes to their position in the node vector.
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
void makeVectorUnique(std::vector< T > &v)
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)
bool idsComparator(T const a, T const b)
Definition of readMeshFromFile function.