12#include <tclap/CmdLine.h>
43 std::size_t n_corrected_elements = 0;
44 std::size_t
const nElements(elements.size());
45 for (std::size_t i = 0; i < nElements; ++i)
47 if (!forced && elements[i]->testElementNodeOrder())
51 n_corrected_elements++;
53 const unsigned nElemNodes(elements[i]->getNumberOfBaseNodes());
54 std::vector<MeshLib::Node*> nodes(elements[i]->
getNodes(),
55 elements[i]->
getNodes() + nElemNodes);
57 switch (elements[i]->getGeomType())
60 for (std::size_t j = 0; j < 4; ++j)
62 elements[i]->setNode(j, nodes[(j + 1) % 4]);
66 elements[i]->setNode(0, nodes[1]);
67 elements[i]->setNode(1, nodes[0]);
68 elements[i]->setNode(2, nodes[3]);
69 elements[i]->setNode(3, nodes[2]);
72 for (std::size_t j = 0; j < 3; ++j)
74 elements[i]->setNode(j, nodes[j + 3]);
75 elements[i]->setNode(j + 3, nodes[j]);
79 for (std::size_t j = 0; j < 4; ++j)
81 elements[i]->setNode(j, nodes[j + 4]);
82 elements[i]->setNode(j + 4, nodes[j]);
86 for (std::size_t j = 0; j < nElemNodes; ++j)
88 elements[i]->setNode(j, nodes[nElemNodes - j - 1]);
93 INFO(
"Corrected {:d} elements.", n_corrected_elements);
101 std::size_t
const nElements(elements.size());
102 for (std::size_t i = 0; i < nElements; ++i)
104 const unsigned nElemNodes(elements[i]->getNumberOfBaseNodes());
105 std::vector<MeshLib::Node*> nodes(elements[i]->
getNodes(),
106 elements[i]->
getNodes() + nElemNodes);
108 for (std::size_t j = 0; j < nElemNodes; ++j)
112 for (std::size_t k = 0; k < 3; ++k)
114 elements[i]->setNode(k, nodes[k + 3]);
115 elements[i]->setNode(k + 3, nodes[k]);
126 std::vector<MeshLib::Node*> base_nodes;
127 std::vector<MeshLib::Node*> nonlinear_nodes;
130 for (
unsigned i = 0; i < e->getNumberOfBaseNodes(); i++)
132 base_nodes.push_back(
const_cast<MeshLib::Node*
>(e->getNode(i)));
134 for (
unsigned i = e->getNumberOfBaseNodes(); i < e->getNumberOfNodes();
137 nonlinear_nodes.push_back(
147 std::vector<MeshLib::Node*>& allnodes =
148 const_cast<std::vector<MeshLib::Node*>&
>(mesh.
getNodes());
151 allnodes.insert(allnodes.end(), base_nodes.begin(), base_nodes.end());
152 allnodes.insert(allnodes.end(), nonlinear_nodes.begin(),
153 nonlinear_nodes.end());
158int main(
int argc,
char* argv[])
161 "Reorders mesh nodes in elements to make old or incorrectly ordered "
162 "meshes compatible with OGS6.\n"
163 "Three options are available:\n"
164 "Method 0: Reversing order of nodes for all elements.\n"
165 "Method 1: Reversing order of nodes unless it's perceived correct by "
166 "OGS6 standards. This is the default selection.\n"
167 "Method 2: Fixing node ordering issues between VTK and OGS6 (only "
168 "applies to prism-elements)\n"
169 "Method 3: Re-ordering of mesh node vector such that all base nodes "
170 "are sorted before all nonlinear nodes.\n\n"
171 "OpenGeoSys-6 software, version " +
174 "Copyright (c) 2012-2024, OpenGeoSys Community "
175 "(http://www.opengeosys.org)",
178 std::vector<int> method_ids{0, 1, 2, 3};
179 TCLAP::ValuesConstraint<int> allowed_values(method_ids);
180 TCLAP::ValueArg<int> method_arg(
"m",
"method",
181 "reordering method selection",
false, 1,
184 TCLAP::ValueArg<std::string> output_mesh_arg(
185 "o",
"output_mesh",
"the name of the output mesh file",
true,
"",
187 cmd.add(output_mesh_arg);
188 TCLAP::ValueArg<std::string> input_mesh_arg(
189 "i",
"input_mesh",
"the name of the input mesh file",
true,
"",
191 cmd.add(input_mesh_arg);
192 cmd.parse(argc, argv);
195 MPI_Init(&argc, &argv);
198 std::unique_ptr<MeshLib::Mesh> mesh(
209 INFO(
"Reordering nodes... ");
210 if (!method_arg.isSet() || method_arg.getValue() < 2)
212 bool const forced = (method_arg.getValue() == 0);
214 const_cast<std::vector<MeshLib::Element*>&
>(mesh->getElements()),
217 else if (method_arg.getValue() == 2)
220 const_cast<std::vector<MeshLib::Element*>&
>(mesh->getElements()));
222 else if (method_arg.getValue() == 3)
229 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.
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.