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
53
54 const std::string filename(mesh_arg.getValue());
55
56
57 auto const mesh =
59 filename, true ));
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(),
71 {
72 return mesh->getElementsConnectedToNode(*i).size() <
73 mesh->getElementsConnectedToNode(*j).size();
74 });
75 if (itr != mesh->getNodes().end())
76 {
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
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;
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
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;
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)
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.