69{
70 TCLAP::CmdLine cmd(
71 "Integrates line elements representing boreholes into a pre-existing "
72 "3D mesh. Corresponding nodes matching the (x,y)-coordinates given in "
73 "the gml-file are found in the mesh and connected from top to bottom "
74 "via line elements. Each borehole (i.e. all points at a given "
75 "(x,y)-location but at different depths) is assigned a unique material "
76 "ID. Vertical limits of boreholes can be specified via Material IDs "
77 "and/or elevation. Point not matching any mesh nodes or located outside"
78 " the mesh are ignored.\n\n"
79 "OpenGeoSys-6 software, version " +
81 ".\n"
82 "Copyright (c) 2012-2026, OpenGeoSys Community "
83 "(http://www.opengeosys.org)",
85
86 double const dmax = std::numeric_limits<double>::max();
87 TCLAP::ValueArg<double> max_elevation_arg(
88 "", "max-elevation",
89 "Maximum elevation for an integrated borehole, "
90 "(min = 0)",
91 false, 0, "MAX_ELEVATION");
92 cmd.add(max_elevation_arg);
93 TCLAP::ValueArg<double> min_elevation_arg(
94 "", "min-elevation",
95 "Minimum elevation for an integrated borehole, "
96 "(min = 0)",
97 false, 0, "MIN_ELEVATION");
98 cmd.add(min_elevation_arg);
99 TCLAP::ValueArg<int> max_id_arg(
100 "", "max-id", "Maximum MaterialID for an integrated borehole", false,
101 -1, "MAX_ID");
102 cmd.add(max_id_arg);
103 TCLAP::ValueArg<int> min_id_arg(
104 "", "min-id", "Minimum MaterialID for an integrated borehole", false,
105 -1, "MIN_ID");
106 cmd.add(min_id_arg);
107 TCLAP::ValueArg<std::string> geo_arg(
108 "g", "geo", "Input (.gml). Name of the geometry file", true, "",
109 "INPUT_FILE");
110 cmd.add(geo_arg);
111 TCLAP::ValueArg<std::string> output_arg(
112 "o", "output", "Output (.vtu). Name of the mesh file", true, "",
113 "OUTPUT_FILE");
114 cmd.add(output_arg);
115 TCLAP::ValueArg<std::string> input_arg(
116 "i", "input", "Input (.vtu). Name of the mesh file", true, "",
117 "INPUT_FILE");
118 cmd.add(input_arg);
120 cmd.add(log_level_arg);
121 cmd.parse(argc, argv);
122
125
126 std::pair<int, int> mat_limits(0, std::numeric_limits<int>::max());
127 std::pair<double, double> elevation_limits(
128 std::numeric_limits<double>::lowest(), dmax);
129
130 if (min_id_arg.isSet() != max_id_arg.isSet())
131 {
132 ERR(
"If minimum MaterialID is set, maximum ID must be set, too (and "
133 "vice versa).");
134 return EXIT_FAILURE;
135 }
136 if (min_id_arg.isSet() && max_id_arg.isSet())
137 {
138 mat_limits =
139 std::make_pair(min_id_arg.getValue(), max_id_arg.getValue());
140 }
141 if (mat_limits.first > mat_limits.second)
142 {
143 std::swap(mat_limits.first, mat_limits.second);
144 }
145 if (min_id_arg.isSet() && (mat_limits.first < 0 || mat_limits.second < 0))
146 {
147 ERR(
"Specified MaterialIDs must have non-negative values.");
148 return EXIT_FAILURE;
149 }
150 if (min_elevation_arg.isSet() != max_elevation_arg.isSet())
151 {
152 ERR(
"If minimum elevation is set, maximum elevation must be set, too "
153 "(and vice versa).");
154 return EXIT_FAILURE;
155 }
156 if (min_elevation_arg.isSet() && max_elevation_arg.isSet())
157 {
158 elevation_limits = std::make_pair(min_elevation_arg.getValue(),
159 max_elevation_arg.getValue());
160 }
161 if (elevation_limits.first > elevation_limits.second)
162 {
163 std::swap(elevation_limits.first, elevation_limits.second);
164 }
165
166 std::string const& mesh_name = input_arg.getValue();
167 std::string const& output_name = output_arg.getValue();
168 std::string const& geo_name = geo_arg.getValue();
169
172 if (!xml_io.readFile(geo_name))
173 {
174 ERR(
"Failed to read geometry file `{:s}'.", geo_name);
175 return EXIT_FAILURE;
176 }
177 std::vector<GeoLib::Point*> const& points =
179
180 std::unique_ptr<MeshLib::Mesh> const mesh(
182 if (mesh == nullptr)
183 {
184 ERR(
"Failed to read input mesh file `{:s}'.", mesh_name);
185 return EXIT_FAILURE;
186 }
187 if (mesh->getDimension() != 3)
188 {
189 ERR(
"Method can only be applied to 3D meshes.");
190 return EXIT_FAILURE;
191 }
192
193 auto const& nodes = mesh->getNodes();
195 if (mat_ids == nullptr)
196 {
197 ERR(
"Mesh is required to have MaterialIDs");
198 return EXIT_FAILURE;
199 }
200
201 auto const& elems = mesh->getElements();
205 std::copy(mat_ids->cbegin(), mat_ids->cend(),
206 std::back_inserter(*new_mat_ids));
207 int const max_id = *std::max_element(mat_ids->begin(), mat_ids->end());
209 std::size_t const n_points = points.size();
210 std::vector<MeshLib::Element*> new_elems =
212
213 for (std::size_t i = 0; i < n_points; ++i)
214 {
215 std::vector<std::size_t>
const& line_nodes =
getNodes(
216 *points[i], nodes, *mat_ids, mat_limits, elevation_limits, *mesh);
217 std::size_t const n_line_nodes = line_nodes.size();
218 if (n_line_nodes < 2)
219 {
220 continue;
221 }
222 for (std::size_t j = 0; j < n_line_nodes - 1; ++j)
223 {
225 {new_nodes[line_nodes[j]], new_nodes[line_nodes[j + 1]]},
226 elems.size()));
227 new_mat_ids->push_back(max_id + i + 1);
228 }
229 }
230
232 true , props);
234 vtu.writeToFile(output_name);
235 return EXIT_SUCCESS;
236}
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 ERR(fmt::format_string< Args... > fmt, Args &&... args)
Container class for geometric objects.
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
const std::vector< Point * > * getPointVec(const std::string &name) const
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
std::vector< Node * > copyNodeVector(const std::vector< Node * > &nodes)
Creates a deep copy of a Node vector.
PropertyVector< int > const * materialIDs(Mesh const &mesh)
TemplateElement< MeshLib::LineRule2 > Line
std::vector< Element * > copyElementVector(std::vector< Element * > const &elements, std::vector< Node * > const &new_nodes, std::vector< std::size_t > const *const node_id_map)