12 #include <tclap/CmdLine.h>
33 std::vector<std::size_t>
const& node_ids,
34 std::string& geo_name,
38 auto pnts = std::make_unique<std::vector<GeoLib::Point*>>();
39 auto pnt_names = std::make_unique<std::map<std::string, std::size_t>>();
41 for (std::size_t
id : node_ids)
44 pnt_names->insert(std::pair<std::string, std::size_t>(
45 geo_name +
"-PNT-" + std::to_string(cnt), cnt));
50 geometry_sets.
addPointVec(std::move(pnts), geo_name, std::move(pnt_names));
54 std::string
const& pnt_name,
double head_value)
56 bc_out <<
"#BOUNDARY_CONDITION\n";
57 bc_out <<
" $PCS_TYPE\n";
58 bc_out <<
" GROUNDWATER_FLOW\n";
59 bc_out <<
" $PRIMARY_VARIABLE\n";
61 bc_out <<
" $GEO_TYPE\n";
62 bc_out <<
" POINT " << pnt_name <<
"\n";
63 bc_out <<
" $DIS_TYPE\n";
64 bc_out <<
" CONSTANT " << head_value <<
"\n";
69 bc_out <<
"#BOUNDARY_CONDITION\n";
70 bc_out <<
" $PCS_TYPE\n";
71 bc_out <<
" LIQUID_FLOW\n";
72 bc_out <<
" $PRIMARY_VARIABLE\n";
73 bc_out <<
" PRESSURE1\n";
74 bc_out <<
" $GEO_TYPE\n";
75 bc_out <<
" POINT " << pnt_name <<
"\n";
76 bc_out <<
" $DIS_TYPE\n";
77 bc_out <<
" CONSTANT 0.0\n";
84 std::string
const& geo_name,
85 std::string
const& out_fname,
86 std::string
const& bc_type,
bool const write_gml)
90 INFO(
"write points to '{:s}.gml'.", geo_name);
96 bool liquid_flow(
false);
97 if (bc_type ==
"LIQUID_FLOW")
104 std::vector<GeoLib::Point*>
const& pnts(*(pnt_vec_objs->
getVector()));
105 std::ofstream bc_out(out_fname +
".bc");
106 for (std::size_t k(0); k < pnts.size(); k++)
109 if (!pnt_name.empty())
125 int main(
int argc,
char* argv[])
128 "Creates boundary conditions for mesh nodes along polylines."
129 "The documentation is available at "
130 "https://docs.opengeosys.org/docs/tools/model-preparation/"
131 "create-boundary-conditions-along-a-polyline.\n\n"
132 "OpenGeoSys-6 software, version " +
135 "Copyright (c) 2012-2021, OpenGeoSys Community "
136 "(http://www.opengeosys.org)",
138 TCLAP::SwitchArg gml_arg(
"",
"gml",
"Write found nodes to gml file.");
141 TCLAP::ValueArg<std::string> output_base_fname(
142 "o",
"output-base-file-name",
143 "the base name of the file the output (geometry (gli) and boundary "
144 "condition (bc)) will be written to",
145 true,
"",
"file name");
146 cmd.add(output_base_fname);
148 TCLAP::ValueArg<std::string> bc_type(
150 "the process type the boundary condition will be written for currently "
151 "LIQUID_FLOW (primary variable PRESSURE1) and GROUNDWATER_FLOW "
152 "(primary variable HEAD, default) are supported",
154 "process type as string (LIQUID_FLOW or GROUNDWATER_FLOW (default))");
157 TCLAP::ValueArg<double> search_length_arg(
158 "s",
"search-length",
159 "The size of the search length. The default value is "
160 "std::numeric_limits<double>::epsilon()",
161 false, std::numeric_limits<double>::epsilon(),
"floating point number");
162 cmd.add(search_length_arg);
164 TCLAP::ValueArg<std::string> geometry_fname(
165 "i",
"input-geometry",
166 "the name of the file containing the input geometry",
true,
"",
168 cmd.add(geometry_fname);
170 TCLAP::ValueArg<std::string> mesh_arg(
171 "m",
"mesh-file",
"the name of the file containing the mesh",
true,
"",
175 TCLAP::ValueArg<std::string> gmsh_path_arg(
"g",
"gmsh-path",
176 "the path to the gmsh binary",
177 false,
"",
"path as string");
178 cmd.add(gmsh_path_arg);
180 cmd.parse(argc, argv);
183 INFO(
"Reading mesh '{:s}' ... ", mesh_arg.getValue());
184 std::unique_ptr<MeshLib::Mesh> subsurface_mesh(
187 INFO(
"Extracting top surface of mesh '{:s}' ... ", mesh_arg.getValue());
188 Eigen::Vector3d
const dir({0, 0, -1});
189 double const angle(90);
190 std::unique_ptr<MeshLib::Mesh> surface_mesh(
194 subsurface_mesh.reset(
nullptr);
199 gmsh_path_arg.getValue());
205 std::vector<GeoLib::Polyline*>
const* plys(
209 ERR(
"Could not get vector of polylines out of geometry '{:s}'.",
214 auto search_length_strategy =
215 std::make_unique<MeshGeoToolsLib::SearchLength>();
216 if (search_length_arg.isSet())
218 search_length_strategy.reset(
224 *surface_mesh, std::move(search_length_strategy),
226 for (std::size_t k(0); k < plys->size(); k++)
233 std::string polyline_name(
"Polyline-" + std::to_string(k));
240 if (geo_names.empty())
242 ERR(
"Did not find mesh nodes along polylines.");
246 std::string merge_name(
"AllMeshNodesAlongPolylines");
249 merge_name = geo_names[0];
253 std::vector<GeoLib::Point*>
const* merged_pnts(pnt_vec->
getVector());
255 std::vector<GeoLib::Point> pnts_with_id;
256 const std::size_t n_merged_pnts(merged_pnts->size());
257 for (std::size_t k(0); k < n_merged_pnts; ++k)
259 pnts_with_id.emplace_back(*((*merged_pnts)[k]), k);
262 std::sort(pnts_with_id.begin(), pnts_with_id.end(),
264 { return p0 < p1; });
266 double const eps(std::numeric_limits<double>::epsilon());
267 auto surface_pnts = std::make_unique<std::vector<GeoLib::Point*>>();
268 auto name_id_map = std::make_unique<std::map<std::string, std::size_t>>();
271 surface_pnts->push_back(
274 std::string element_name;
277 std::pair<std::string, std::size_t>(element_name, 0));
279 for (std::size_t k(1); k < n_merged_pnts; ++k)
283 if (std::abs(p0[0] - p1[0]) > eps || std::abs(p0[1] - p1[1]) > eps)
285 surface_pnts->push_back(
287 std::string element_name;
289 name_id_map->insert(std::pair<std::string, std::size_t>(
290 element_name, surface_pnts->size() - 1));
295 "-MeshNodesAlongPolylines");
296 geometry_sets.
addPointVec(std::move(surface_pnts), surface_name,
297 std::move(name_id_map), 1e-6);
300 std::string
const base_fname(
303 bc_type.getValue(), gml_arg.getValue());
int main(int argc, char *argv[])
void writeGroundwaterFlowPointBC(std::ostream &bc_out, std::string const &pnt_name, double head_value)
void writeBCsAndGeometry(GeoLib::GEOObjects &geometry_sets, std::string const &geo_name, std::string const &out_fname, std::string const &bc_type, bool const write_gml)
void convertMeshNodesToGeometry(std::vector< MeshLib::Node * > const &nodes, std::vector< std::size_t > const &node_ids, std::string &geo_name, GeoLib::GEOObjects &geometry_sets)
void writeLiquidFlowPointBC(std::ostream &bc_out, std::string const &pnt_name)
Definition of the GEOObjects class.
Definition of the Point class.
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
Definition of the Mesh class.
Definition of the Node class.
Container class for geometric objects.
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
const PointVec * getPointVecObj(const std::string &name) const
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
This class manages pointers to Points in a std::vector along with a name. It also handles the deletin...
std::string const & getItemNameByID(std::size_t id) const
const std::vector< T * > * getVector() const
bool getNameOfElementByID(std::size_t id, std::string &element_name) const
std::string dropFileExtension(std::string const &filename)
void readGeometryFromFile(std::string const &fname, GeoLib::GEOObjects &geo_objs, std::string const &gmsh_path)
void writeGeometryToFile(std::string const &geo_name, GeoLib::GEOObjects &geo_objs, std::string const &fname)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
Definition of readMeshFromFile function.