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