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