int main(int argc, char* argv[]) { ApplicationsLib::LogogSetup logo_setup; TCLAP::CmdLine cmd( "Converts a geometry defined on a given mesh to distinct meshes.\n\n" "OpenGeoSys-6 software, version " + BaseLib::BuildInfo::git_describe + ".\n" "Copyright (c) 2012-2018, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', BaseLib::BuildInfo::git_describe); TCLAP::ValueArg<double> search_length_arg( "s", "searchlength", "search length determining radius for the node search algorithm. " "Non-negative floating point number (default 1e-16) ", false, 1e-16, "float"); cmd.add(search_length_arg); TCLAP::ValueArg<std::string> geometry_arg("g", "geometry", "the file name the geometry", true, "", "geometry file name"); cmd.add(geometry_arg); TCLAP::ValueArg<std::string> mesh_arg( "m", "mesh", "the file name of the mesh where the geometry is defined", true, "", "mesh file name"); cmd.add(mesh_arg); cmd.parse(argc, argv); std::unique_ptr<MeshLib::Mesh> mesh{ MeshLib::IO::readMeshFromFile(mesh_arg.getValue())}; auto const geo_objects = readGeometry(geometry_arg.getValue()); double const search_length = search_length_arg.getValue(); auto const extracted_meshes = constructAdditionalMeshesFromGeoObjects( *geo_objects, *mesh, std::make_unique<MeshGeoToolsLib::SearchLength>(search_length)); for (auto const& m_ptr : extracted_meshes) { MeshLib::IO::writeMeshToFile(*m_ptr, m_ptr->getName() + ".vtu"); } return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd( "Checks if the subdomain meshes are part of the bulk mesh and writes " "the 'bulk_node_ids' and the 'bulk_element_ids' in each of them.\n\n" "OpenGeoSys-6 software, version " + BaseLib::BuildInfo::git_describe + ".\n" "Copyright (c) 2012-2019, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', BaseLib::BuildInfo::git_describe); TCLAP::ValueArg<bool> force_overwrite_arg( "f", "force", "Overwrites the existing subdomain meshes. (default: do not " "overwrite.)", false, false, "true/false"); cmd.add(force_overwrite_arg); TCLAP::ValueArg<std::string> output_prefix_arg( "o", "output_prefix", "Prefix the subdomain meshes' filenames with the output prefix/path.", false, "", "path"); cmd.add(output_prefix_arg); TCLAP::ValueArg<double> search_length_arg( "s", "searchlength", "search length determining radius for the node search algorithm. " "Non-negative floating point number (default 1e-16) ", false, 1e-16, "float"); cmd.add(search_length_arg); TCLAP::ValueArg<std::string> bulk_mesh_arg( "m", "mesh", "the file name of the bulk mesh", true, "", "mesh file"); cmd.add(bulk_mesh_arg); // All the remaining arguments are used as file names for boundary/subdomain // meshes. TCLAP::UnlabeledMultiArg<std::string> subdomain_meshes_filenames_arg( "subdomain_meshes_filenames", "mesh file names.", true, "subdomain mesh file"); cmd.add(subdomain_meshes_filenames_arg); cmd.parse(argc, argv); // // The bulk mesh. // std::unique_ptr<MeshLib::Mesh> bulk_mesh{ MeshLib::IO::readMeshFromFile(bulk_mesh_arg.getValue())}; if (bulk_mesh == nullptr) { OGS_FATAL("Could not read bulk mesh from '%s'", bulk_mesh_arg.getValue().c_str()); } // // Read the subdomain meshes. // auto const subdomain_meshes = readMeshes(subdomain_meshes_filenames_arg.getValue()); // // Bulk mesh node searcher. // auto const& mesh_node_searcher = MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeSearcher( *bulk_mesh, std::make_unique<MeshGeoToolsLib::SearchLength>( search_length_arg.getValue())); // // Identify the subdomains in the bulk mesh. // for (auto& mesh_ptr : subdomain_meshes) { // If force overwrite is set or the output is to different mesh than // the input mesh. bool const overwrite_property_vectors = force_overwrite_arg.getValue() || !output_prefix_arg.getValue().empty(); identifySubdomainMesh(*mesh_ptr, *bulk_mesh, mesh_node_searcher, overwrite_property_vectors); } // // Output after the successful subdomain mesh identification. // for (auto const& mesh_ptr : subdomain_meshes) { MeshLib::IO::writeMeshToFile( *mesh_ptr, output_prefix_arg.getValue() + mesh_ptr->getName() + ".vtu"); } return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd( "Creates boundary conditions for mesh nodes along polylines." "The documentation is available at https://docs.opengeosys.org/docs/tools/model-preparation/create-boundary-conditions-along-a-polyline", ' ', "0.1"); TCLAP::ValueArg<bool> gml_arg("", "gml", "if switched on write found nodes to file in gml format", false, 0, "bool"); cmd.add(gml_arg); TCLAP::ValueArg<std::string> output_base_fname("o", "output-base-file-name", "the base name of the file the output (geometry (gli) and boundary"\ "condition (bc)) will be written to", true, "", "file name"); cmd.add(output_base_fname); TCLAP::ValueArg<std::string> bc_type("t", "type", "the process type the boundary condition will be written for "\ "currently LIQUID_FLOW (primary variable PRESSURE1) and "\ "GROUNDWATER_FLOW (primary variable HEAD, default) are supported", true, "", "process type as string (LIQUID_FLOW or GROUNDWATER_FLOW (default))"); cmd.add(bc_type); TCLAP::ValueArg<double> search_length_arg("s", "search-length", "The size of the search length. The default value is " "std::numeric_limits<double>::epsilon()", false, std::numeric_limits<double>::epsilon(), "floating point number"); cmd.add(search_length_arg); TCLAP::ValueArg<std::string> geometry_fname("i", "input-geometry", "the name of the file containing the input geometry", true, "", "file name"); cmd.add(geometry_fname); TCLAP::ValueArg<std::string> mesh_arg("m", "mesh-file", "the name of the file containing the mesh", true, "", "file name"); cmd.add(mesh_arg); cmd.parse(argc, argv); // *** read mesh INFO("Reading mesh \"%s\" ... ", mesh_arg.getValue().c_str()); MeshLib::Mesh * subsurface_mesh(FileIO::readMeshFromFile(mesh_arg.getValue())); INFO("done."); INFO("Extracting top surface of mesh \"%s\" ... ", mesh_arg.getValue().c_str()); const MathLib::Vector3 dir(0,0,-1); double const angle(90); std::unique_ptr<MeshLib::Mesh> surface_mesh( MeshLib::MeshSurfaceExtraction::getMeshSurface(*subsurface_mesh, dir, angle)); INFO("done."); delete subsurface_mesh; subsurface_mesh = nullptr; // *** read geometry GeoLib::GEOObjects geometries; FileIO::readGeometryFromFile(geometry_fname.getValue(), geometries); std::string geo_name; { std::vector<std::string> geo_names; geometries.getGeometryNames(geo_names); geo_name = geo_names[0]; } // *** check if the data is usable // *** get vector of polylines std::vector<GeoLib::Polyline*> const* plys(geometries.getPolylineVec(geo_name)); if (!plys) { ERR("Could not get vector of polylines out of geometry \"%s\".", geo_name.c_str()); return -1; } MeshGeoToolsLib::SearchLength search_length_strategy; if (search_length_arg.isSet()) { search_length_strategy = MeshGeoToolsLib::SearchLength(search_length_arg.getValue()); } GeoLib::GEOObjects geometry_sets; MeshGeoToolsLib::MeshNodeSearcher mesh_searcher(*surface_mesh, search_length_strategy); for(std::size_t k(0); k<plys->size(); k++) { std::vector<std::size_t> ids (mesh_searcher.getMeshNodeIDsAlongPolyline(*((*plys)[k]))); if (ids.empty()) continue; std::string geo_name("Polyline-"+std::to_string(k)); convertMeshNodesToGeometry(surface_mesh->getNodes(), ids, geo_name, geometry_sets); } // merge all together std::vector<std::string> geo_names; geometry_sets.getGeometryNames(geo_names); if (geo_names.empty()) { ERR("Did not find mesh nodes along polylines."); return -1; } std::string merge_name("AllMeshNodesAlongPolylines"); if (geometry_sets.mergeGeometries(geo_names, merge_name) == 2) merge_name = geo_names[0]; GeoLib::PointVec const* pnt_vec(geometry_sets.getPointVecObj(merge_name)); std::vector<GeoLib::Point*> const* merged_pnts(pnt_vec->getVector()); std::vector<GeoLib::Point> pnts_with_id; const std::size_t n_merged_pnts(merged_pnts->size()); for(std::size_t k(0); k<n_merged_pnts; ++k) { pnts_with_id.emplace_back(*((*merged_pnts)[k]), k); } std::sort(pnts_with_id.begin(), pnts_with_id.end(), [](GeoLib::Point const& p0, GeoLib::Point const& p1) { return p0 < p1; } ); double const eps (std::numeric_limits<double>::epsilon()); auto surface_pnts = std::unique_ptr<std::vector<GeoLib::Point*>>( new std::vector<GeoLib::Point*>); std::map<std::string, std::size_t> *name_id_map( new std::map<std::string, std::size_t> ); // insert first point surface_pnts->push_back( new GeoLib::Point(pnts_with_id[0], surface_pnts->size())); std::string element_name; pnt_vec->getNameOfElementByID(0, element_name); name_id_map->insert( std::pair<std::string, std::size_t>(element_name,0) ); for (std::size_t k(1); k < n_merged_pnts; ++k) { const GeoLib::Point& p0 (pnts_with_id[k-1]); const GeoLib::Point& p1 (pnts_with_id[k]); if (std::abs (p0[0] - p1[0]) > eps || std::abs (p0[1] - p1[1]) > eps) { surface_pnts->push_back(new GeoLib::Point(pnts_with_id[k], surface_pnts->size())); std::string element_name; pnt_vec->getNameOfElementByID(k, element_name); name_id_map->insert( std::pair<std::string, std::size_t>(element_name, surface_pnts->size()-1) ); } } std::string surface_name(BaseLib::dropFileExtension(mesh_arg.getValue())+"-MeshNodesAlongPolylines"); geometry_sets.addPointVec(std::move(surface_pnts), surface_name, name_id_map, 1e-6); // write the BCs and the merged geometry set to file std::string const base_fname( BaseLib::dropFileExtension(output_base_fname.getValue())); writeBCsAndGeometry(geometry_sets, surface_name, base_fname, bc_type.getValue(), gml_arg.getValue()); return 0; }