OGS
queryMesh.cpp File Reference

Detailed Description

Definition in file queryMesh.cpp.

#include <tclap/CmdLine.h>
#include <array>
#include <memory>
#include <sstream>
#include <string>
#include "BaseLib/FileTools.h"
#include "BaseLib/MPI.h"
#include "BaseLib/StringTools.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
Include dependency graph for queryMesh.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 26 of file queryMesh.cpp.

27{
28 TCLAP::CmdLine cmd(
29 "Query mesh information.\n\n"
30 "OpenGeoSys-6 software, version " +
32 ".\n"
33 "Copyright (c) 2012-2024, OpenGeoSys Community "
34 "(http://www.opengeosys.org)",
36 TCLAP::UnlabeledValueArg<std::string> mesh_arg(
37 "mesh-file", "input mesh file", true, "", "string");
38 cmd.add(mesh_arg);
39 TCLAP::MultiArg<std::size_t> eleId_arg("e", "element-id", "element ID",
40 false, "number");
41 cmd.add(eleId_arg);
42 TCLAP::MultiArg<std::size_t> nodeId_arg("n", "node-id", "node ID", false,
43 "number");
44 cmd.add(nodeId_arg);
45 TCLAP::SwitchArg showNodeWithMaxEle_arg(
46 "", "show-node-with-max-elements",
47 "show a node having the max number of connected elements", false);
48 cmd.add(showNodeWithMaxEle_arg);
49
50 cmd.parse(argc, argv);
51
52 BaseLib::MPI::Setup mpi_setup(argc, argv);
53
54 const std::string filename(mesh_arg.getValue());
55
56 // read the mesh file
57 auto const mesh =
58 std::unique_ptr<MeshLib::Mesh>(MeshLib::IO::readMeshFromFile(
59 filename, true /* compute_element_neighbors */));
60 if (!mesh)
61 {
62 return EXIT_FAILURE;
63 }
64
65 std::vector<std::size_t> selected_node_ids;
66 if (showNodeWithMaxEle_arg.getValue())
67 {
68 auto itr = std::max_element(
69 mesh->getNodes().begin(), mesh->getNodes().end(),
70 [&mesh](MeshLib::Node* i, MeshLib::Node* j)
71 {
72 return mesh->getElementsConnectedToNode(*i).size() <
73 mesh->getElementsConnectedToNode(*j).size();
74 });
75 if (itr != mesh->getNodes().end())
76 {
77 MeshLib::Node* node = *itr;
78 selected_node_ids.push_back(node->getID());
79 }
80 }
81 selected_node_ids.insert(selected_node_ids.end(),
82 nodeId_arg.getValue().begin(),
83 nodeId_arg.getValue().end());
84
85 auto const materialIds = materialIDs(*mesh);
86 for (auto ele_id : eleId_arg.getValue())
87 {
88 std::stringstream out;
89 out << std::scientific
90 << std::setprecision(std::numeric_limits<double>::max_digits10);
91 out << "--------------------------------------------------------"
92 << std::endl;
93 auto* ele = mesh->getElement(ele_id);
94 out << "# Element " << ele->getID() << std::endl;
95 out << "Type : " << CellType2String(ele->getCellType()) << std::endl;
96 if (materialIds)
97 {
98 out << "Mat ID : " << (*materialIds)[ele_id] << std::endl;
99 }
100 out << "Nodes: " << std::endl;
101 for (unsigned i = 0; i < ele->getNumberOfNodes(); i++)
102 {
103 out << ele->getNode(i)->getID() << " " << *ele->getNode(i)
104 << std::endl;
105 }
106 out << "Content: " << ele->getContent() << std::endl;
107 out << "Neighbors: ";
108 for (unsigned i = 0; i < ele->getNumberOfNeighbors(); i++)
109 {
110 if (ele->getNeighbor(i))
111 {
112 out << ele->getNeighbor(i)->getID() << " ";
113 }
114 else
115 {
116 out << "none ";
117 }
118 }
119 out << std::endl;
120 INFO("{:s}", out.str());
121 }
122
123 auto const& connections = MeshLib::calculateNodesConnectedByElements(*mesh);
124 for (auto node_id : selected_node_ids)
125 {
126 std::stringstream out;
127 out << std::scientific
128 << std::setprecision(std::numeric_limits<double>::max_digits10);
129 out << "--------------------------------------------------------"
130 << std::endl;
131 MeshLib::Node const* node = mesh->getNode(node_id);
132 out << "# Node " << node->getID() << std::endl;
133 out << "Coordinates: " << *node << std::endl;
134 out << "Connected elements ("
135 << mesh->getElementsConnectedToNode(*node).size() << "): ";
136 for (auto ele : mesh->getElementsConnectedToNode(*node))
137 {
138 out << ele->getID() << " ";
139 }
140 out << std::endl;
141 out << "Connected nodes (" << connections[node->getID()].size()
142 << "): ";
143 for (auto nd : connections[node->getID()])
144 {
145 out << nd->getID() << " ";
146 }
147 out << std::endl;
148 INFO("{:s}", out.str());
149 }
150 return EXIT_SUCCESS;
151}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
std::string getValue(std::string const &line, std::string const &val_name, bool is_string)
std::size_t getID() const
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
std::vector< std::vector< Node * > > calculateNodesConnectedByElements(Mesh const &mesh)
Definition Mesh.cpp:308
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:268
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.

References MeshLib::calculateNodesConnectedByElements(), MathLib::Point3dWithID::getID(), INFO(), GitInfoLib::GitInfo::ogs_version, and MeshLib::IO::readMeshFromFile().