int main (int argc, char* argv[]) { LOGOG_INITIALIZE(); logog::Cout* logog_cout (new logog::Cout); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); logog_cout->SetFormatter(*custom_format); TCLAP::CmdLine cmd("Converts VTK mesh into OGS mesh.", ' ', "0.1"); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", "the name of the file the mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); cmd.parse(argc, argv); MeshLib::Mesh* mesh (FileIO::BoostVtuInterface::readVTUFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); FileIO::Legacy::MeshIO meshIO; meshIO.setMesh(mesh); meshIO.writeToFile(mesh_out.getValue()); delete custom_format; delete logog_cout; LOGOG_SHUTDOWN(); return 0; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd( "Converts OGS mesh into VTK mesh.\n\n" "OpenGeoSys-6 software, version " + BaseLib::BuildInfo::ogs_version + ".\n" "Copyright (c) 2012-2019, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', BaseLib::BuildInfo::ogs_version); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", "the name of the file the mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); cmd.parse(argc, argv); std::unique_ptr<MeshLib::Mesh const> mesh( MeshLib::IO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); MeshLib::IO::VtuInterface vtu(mesh.get()); vtu.writeToFile(mesh_out.getValue()); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd("Tool extracts the surface of the given mesh.", ' ', "0.1"); TCLAP::ValueArg<std::string> mesh_in( "i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> mesh_out( "o", "mesh-output-file", "the name of the file the surface mesh should be written to", false, "", "file name of output mesh"); cmd.add(mesh_out); TCLAP::ValueArg<double> x("x", "x-component", "x component of the normal", false, 0, "floating point value"); cmd.add(x); TCLAP::ValueArg<double> y("y", "y-component", "y component of the normal", false, 0, "floating point value"); cmd.add(y); TCLAP::ValueArg<double> z("z", "z-component", "z component of the normal", false, -1.0, "floating point value"); cmd.add(z); TCLAP::ValueArg<double> angle_arg( "a", "angle", "angle between given normal and element normal", false, 90, "floating point value"); cmd.add(angle_arg); cmd.parse(argc, argv); std::unique_ptr<MeshLib::Mesh const> mesh( MeshLib::IO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %u nodes, %u elements.", mesh->getNNodes(), mesh->getNElements()); // extract surface MathLib::Vector3 const dir(x.getValue(), y.getValue(), z.getValue()); double const angle(angle_arg.getValue()); std::unique_ptr<MeshLib::Mesh> surface_mesh( MeshLib::MeshSurfaceExtraction::getMeshSurface( *mesh, dir, angle, "OriginalSubsurfaceNodeIDs")); std::string out_fname(mesh_out.getValue()); if (out_fname.empty()) out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu"; MeshLib::IO::writeMeshToFile(*surface_mesh, out_fname); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd("Converts OGS mesh into VTK mesh.", ' ', "0.1"); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", "the name of the file the mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); cmd.parse(argc, argv); std::unique_ptr<MeshLib::Mesh const> mesh( MeshLib::IO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); MeshLib::IO::VtuInterface vtu(mesh.get()); vtu.writeToFile(mesh_out.getValue()); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd("Converts VTK mesh into OGS mesh.", ' ', "0.1"); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", "the name of the file the mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); cmd.parse(argc, argv); MeshLib::Mesh* mesh (MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); MeshLib::IO::Legacy::MeshIO meshIO; meshIO.setMesh(mesh); meshIO.writeToFile(mesh_out.getValue()); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { LOGOG_INITIALIZE(); logog::Cout* logog_cout (new logog::Cout); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); logog_cout->SetFormatter(*custom_format); TCLAP::CmdLine cmd("Remove mesh elements.", ' ', "0.1"); // Bounding box params TCLAP::ValueArg<double> zLargeArg("", "z-max", "largest allowed extent in z-dimension", false, std::numeric_limits<double>::max(), "value"); cmd.add(zLargeArg); TCLAP::ValueArg<double> zSmallArg("", "z-min", "smallest allowed extent in z-dimension", false, -1 * std::numeric_limits<double>::max(), "value"); cmd.add(zSmallArg); TCLAP::ValueArg<double> yLargeArg("", "y-max", "largest allowed extent in y-dimension", false, std::numeric_limits<double>::max(), "value"); cmd.add(yLargeArg); TCLAP::ValueArg<double> ySmallArg("", "y-min", "smallest allowed extent in y-dimension", false, -1 * std::numeric_limits<double>::max(), "value"); cmd.add(ySmallArg); TCLAP::ValueArg<double> xLargeArg("", "x-max", "largest allowed extent in x-dimension", false, std::numeric_limits<double>::max(), "value"); cmd.add(xLargeArg); TCLAP::ValueArg<double> xSmallArg("", "x-min", "smallest allowed extent in x-dimension", false, -1 * std::numeric_limits<double>::max(), "value"); cmd.add(xSmallArg); // Non-bounding-box params TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements", false); cmd.add(zveArg); TCLAP::MultiArg<std::string> eleTypeArg("t", "element-type", "element type to be removed", false, "element type"); cmd.add(eleTypeArg); TCLAP::MultiArg<unsigned> matIDArg("m", "material-id", "material id", false, "material id"); cmd.add(matIDArg); // I/O params TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", "the name of the file the mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); cmd.parse(argc, argv); MeshLib::Mesh const*const mesh (FileIO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); MeshLib::ElementSearch ex(*mesh); // search elements IDs to be removed if (zveArg.isSet()) { const std::size_t n_removed_elements = ex.searchByContent(); INFO("%d zero volume elements found.", n_removed_elements); } if (eleTypeArg.isSet()) { const std::vector<std::string> eleTypeNames = eleTypeArg.getValue(); for (auto typeName : eleTypeNames) { const MeshLib::MeshElemType type = MeshLib::String2MeshElemType(typeName); if (type == MeshLib::MeshElemType::INVALID) continue; const std::size_t n_removed_elements = ex.searchByElementType(type); INFO("%d %s elements found.", n_removed_elements, typeName.c_str()); } } if (matIDArg.isSet()) { const std::vector<unsigned> vec_matID = matIDArg.getValue(); for (auto matID : vec_matID) { const std::size_t n_removed_elements = ex.searchByMaterialID(matID); INFO("%d elements with material ID %d found.", n_removed_elements, matID); } } if (xSmallArg.isSet() || xLargeArg.isSet() || ySmallArg.isSet() || yLargeArg.isSet() || zSmallArg.isSet() || zLargeArg.isSet()) { bool aabb_error (false); if (xSmallArg.getValue() >= xLargeArg.getValue()) { ERR ("Minimum x-extent larger than maximum x-extent."); aabb_error = true; } if (ySmallArg.getValue() >= yLargeArg.getValue()) { ERR ("Minimum y-extent larger than maximum y-extent."); aabb_error = true; } if (zSmallArg.getValue() >= zLargeArg.getValue()) { ERR ("Minimum z-extent larger than maximum z-extent."); aabb_error = true; } if (aabb_error) return 1; std::array<MathLib::Point3d, 2> extent({{ MathLib::Point3d(std::array<double,3>{{xSmallArg.getValue(), ySmallArg.getValue(), zSmallArg.getValue()}}), MathLib::Point3d(std::array<double,3>{{xLargeArg.getValue(), yLargeArg.getValue(), zLargeArg.getValue()}})}}); const std::size_t n_removed_elements = ex.searchByBoundingBox( GeoLib::AABB(extent.begin(), extent.end())); INFO("%d elements found.", n_removed_elements); } // remove the elements and create a new mesh object. MeshLib::Mesh const*const new_mesh = MeshLib::removeElements(*mesh, ex.getSearchedElementIDs(), mesh->getName()); // write into a file FileIO::Legacy::MeshIO meshIO; meshIO.setMesh(new_mesh); meshIO.writeToFile(mesh_out.getValue()); delete custom_format; delete logog_cout; LOGOG_SHUTDOWN(); return 0; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd("Computes ids of mesh nodes that are in polygonal " "regions and resides on the top surface. The polygonal regions have to " "be given in a gml- or gli-file. The found mesh nodes and the associated" " area are written as txt and csv data." "The documentation is available at https://docs.opengeosys.org/docs/tools/model-preparation/computesurfacenodeidsinpolygonalregion", ' ', "0.1"); TCLAP::ValueArg<std::string> mesh_in("m", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> geo_in("g", "geo-file", "the name of the gml file containing the polygons", true, "", "file name of input geometry"); cmd.add(geo_in); cmd.parse(argc, argv); std::unique_ptr<MeshLib::Mesh const> mesh(FileIO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %u nodes, %u elements.", mesh->getNNodes(), mesh->getNElements()); GeoLib::GEOObjects geo_objs; FileIO::readGeometryFromFile(geo_in.getValue(), geo_objs); std::vector<std::string> geo_names; geo_objs.getGeometryNames(geo_names); INFO("Geometry \"%s\" read: %u points, %u polylines.", geo_names[0].c_str(), geo_objs.getPointVec(geo_names[0])->size(), geo_objs.getPolylineVec(geo_names[0])->size()); MathLib::Vector3 const dir(0.0, 0.0, -1.0); double angle(90); auto computeElementTopSurfaceAreas = [](MeshLib::Mesh const& mesh, MathLib::Vector3 const& d, double angle) { std::unique_ptr<MeshLib::Mesh> surface_mesh( MeshLib::MeshSurfaceExtraction::getMeshSurface(mesh, d, angle)); return MeshLib::MeshSurfaceExtraction::getSurfaceAreaForNodes( *surface_mesh.get()); }; std::vector<double> areas(computeElementTopSurfaceAreas(*mesh, dir, angle)); std::vector<GeoLib::Point*> all_sfc_pnts( MeshLib::MeshSurfaceExtraction::getSurfaceNodes(*mesh, dir, angle) ); std::for_each(all_sfc_pnts.begin(), all_sfc_pnts.end(), [](GeoLib::Point* p) { (*p)[2] = 0.0; }); std::vector<MeshLib::Node*> const& mesh_nodes(mesh->getNodes()); GeoLib::PolylineVec const* ply_vec( geo_objs.getPolylineVecObj(geo_names[0]) ); std::vector<GeoLib::Polyline*> const& plys(*(ply_vec->getVector())); for (std::size_t j(0); j<plys.size(); j++) { if (! plys[j]->isClosed()) { continue; } std::string polygon_name; ply_vec->getNameOfElement(plys[j], polygon_name); if (polygon_name.empty()) polygon_name = "Polygon-" + std::to_string(j); // create Polygon from Polyline GeoLib::Polygon const& polygon(*(plys[j])); // ids of mesh nodes on surface that are within the given polygon std::vector<std::pair<std::size_t, double>> ids_and_areas; for (std::size_t k(0); k<all_sfc_pnts.size(); k++) { GeoLib::Point const& pnt(*(all_sfc_pnts[k])); if (polygon.isPntInPolygon(pnt)) { ids_and_areas.push_back(std::make_pair(pnt.getID(), areas[k])); } } if (ids_and_areas.empty()) { ERR("Polygonal part of surface \"%s\" doesn't contains nodes. No " "output will be generated.", polygon_name.c_str()); continue; } std::string const out_path(BaseLib::extractPath(geo_in.getValue())); std::string id_and_area_fname(out_path + polygon_name); std::string csv_fname(out_path + polygon_name); id_and_area_fname += std::to_string(j) + ".txt"; csv_fname += std::to_string(j) + ".csv"; INFO("Polygonal part of surface \"%s\" contains %ul nodes. Writting to" " files \"%s\" and \"%s\".", polygon_name.c_str(), ids_and_areas.size(), id_and_area_fname.c_str(), csv_fname.c_str() ); writeToFile(id_and_area_fname, csv_fname, ids_and_areas, mesh_nodes); } std::for_each(all_sfc_pnts.begin(), all_sfc_pnts.end(), std::default_delete<GeoLib::Point>()); return 0; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd("Maps geometric objects to the surface of a given mesh." "The documentation is available at https://docs.opengeosys.org/docs/tools/model-preparation/map-geometric-object-to-the-surface-of-a-mesh", ' ', "0.1"); TCLAP::ValueArg<std::string> mesh_in("m", "mesh-file", "the name of the file containing the mesh", true, "", "file name"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> input_geometry_fname("i", "input-geometry", "the name of the file containing the input geometry", true, "", "file name"); cmd.add(input_geometry_fname); TCLAP::ValueArg<bool> additional_insert_mapping("a", "additional-insert-mapping", "if true advanced mapping algorithm will be applied, i.e. a new " "geometry will be created and possibly new points will be inserted.", false, true, "boolean value"); cmd.add(additional_insert_mapping); TCLAP::ValueArg<std::string> output_geometry_fname("o", "output-geometry", "the name of the file containing the input geometry", true, "", "file name"); cmd.add(output_geometry_fname); cmd.parse(argc, argv); // *** read geometry GeoLib::GEOObjects geometries; { GeoLib::IO::BoostXmlGmlInterface xml_io(geometries); if (xml_io.readFile(input_geometry_fname.getValue())) { INFO("Read geometry from file \"%s\".", input_geometry_fname.getValue().c_str()); } else { return EXIT_FAILURE; } } std::string geo_name; { std::vector<std::string> geo_names; geometries.getGeometryNames(geo_names); geo_name = geo_names[0]; } MeshGeoToolsLib::GeoMapper geo_mapper(geometries, geo_name); // *** read mesh std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(mesh_in.getValue())); if (additional_insert_mapping.getValue()) { geo_mapper.advancedMapOnMesh(*mesh); } else { geo_mapper.mapOnMesh(mesh.get()); } { GeoLib::IO::BoostXmlGmlInterface xml_io(geometries); xml_io.setNameForExport(geo_name); xml_io.writeToFile(output_geometry_fname.getValue()); } return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd( "Append line elements into a mesh.\n\n" "OpenGeoSys-6 software, version " + BaseLib::BuildInfo::ogs_version + ".\n" "Copyright (c) 2012-2019, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', BaseLib::BuildInfo::ogs_version); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", "the name of the file the mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); TCLAP::ValueArg<std::string> geoFileArg("g", "geo-file", "the name of the geometry file which contains polylines", true, "", "the name of the geometry file"); cmd.add(geoFileArg); TCLAP::ValueArg<std::string> gmsh_path_arg("g", "gmsh-path", "the path to the gmsh binary", false, "", "path as string"); cmd.add(gmsh_path_arg); // parse arguments cmd.parse(argc, argv); // read GEO objects GeoLib::GEOObjects geo_objs; FileIO::readGeometryFromFile(geoFileArg.getValue(), geo_objs, gmsh_path_arg.getValue()); std::vector<std::string> geo_names; geo_objs.getGeometryNames (geo_names); if (geo_names.empty ()) { ERR("No geometries found."); return EXIT_FAILURE; } const GeoLib::PolylineVec* ply_vec (geo_objs.getPolylineVecObj(geo_names[0])); if (!ply_vec) { ERR("Could not find polylines in geometry '%s'.", geo_names.front().c_str()); return EXIT_FAILURE; } // read a mesh MeshLib::Mesh const*const mesh (MeshLib::IO::readMeshFromFile(mesh_in.getValue())); if (!mesh) { ERR("Mesh file '%s' not found", mesh_in.getValue().c_str()); return EXIT_FAILURE; } INFO("Mesh read: %d nodes, %d elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); // add line elements std::unique_ptr<MeshLib::Mesh> new_mesh = MeshGeoToolsLib::appendLinesAlongPolylines(*mesh, *ply_vec); INFO("Mesh created: %d nodes, %d elements.", new_mesh->getNumberOfNodes(), new_mesh->getNumberOfElements()); MeshLib::IO::writeMeshToFile(*new_mesh, mesh_out.getValue()); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { LOGOG_INITIALIZE(); logog::Cout* logog_cout (new logog::Cout); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); logog_cout->SetFormatter(*custom_format); TCLAP::CmdLine cmd("Append line elements into a mesh.", ' ', "0.1"); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", "the name of the file the mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); TCLAP::ValueArg<std::string> geoFileArg("g", "geo-file", "the name of the geometry file which contains polylines", true, "", "the name of the geometry file"); cmd.add(geoFileArg); // parse arguments cmd.parse(argc, argv); // read GEO objects GeoLib::GEOObjects geo_objs; FileIO::BoostXmlGmlInterface xml(geo_objs); xml.readFile(geoFileArg.getValue()); std::vector<std::string> geo_names; geo_objs.getGeometryNames (geo_names); if (geo_names.empty ()) { std::cout << "no geometries found" << std::endl; return -1; } const GeoLib::PolylineVec* ply_vec (geo_objs.getPolylineVecObj(geo_names[0])); if (!ply_vec) { std::cout << "could not found polylines" << std::endl; return -1; } // read a mesh MeshLib::Mesh const*const mesh (FileIO::readMeshFromFile(mesh_in.getValue())); if (!mesh) { ERR("Mesh file %s not found", mesh_in.getValue().c_str()); return 1; } INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); // add line elements std::unique_ptr<MeshLib::Mesh> new_mesh = MeshGeoToolsLib::appendLinesAlongPolylines(*mesh, *ply_vec); INFO("Mesh created: %d nodes, %d elements.", new_mesh->getNNodes(), new_mesh->getNElements()); // write into a file FileIO::Legacy::MeshIO meshIO; meshIO.setMesh(new_mesh.get()); meshIO.writeToFile(mesh_out.getValue()); delete custom_format; delete logog_cout; LOGOG_SHUTDOWN(); return 1; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd("Edit material IDs of mesh elements.", ' ', "0.1"); TCLAP::SwitchArg replaceArg("r", "replace", "replace material IDs", false); TCLAP::SwitchArg condenseArg("c", "condense", "condense material IDs", false); TCLAP::SwitchArg specifyArg("s", "specify", "specify material IDs by element types (-e)", false); std::vector<TCLAP::Arg*> vec_xors; vec_xors.push_back(&replaceArg); vec_xors.push_back(&condenseArg); vec_xors.push_back(&specifyArg); cmd.xorAdd(vec_xors); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", "the name of the file the mesh will be written to", true, "", "file name"); cmd.add(mesh_out); TCLAP::MultiArg<unsigned> matIDArg("m", "current-material-id", "current material id to be replaced", false, "number"); cmd.add(matIDArg); TCLAP::ValueArg<unsigned> newIDArg("n", "new-material-id", "new material id", false, 0, "number"); cmd.add(newIDArg); std::vector<std::string> eleList(MeshLib::getMeshElemTypeStringsShort()); TCLAP::ValuesConstraint<std::string> allowedVals(eleList); TCLAP::ValueArg<std::string> eleTypeArg("e", "element-type", "element type", false, "", &allowedVals); cmd.add(eleTypeArg); cmd.parse(argc, argv); if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet()) { INFO("Please select editing mode: -r or -c or -s"); return 0; } else if (replaceArg.isSet() && condenseArg.isSet()) { INFO("Please select only one editing mode: -r or -c or -s"); return 0; } else if (replaceArg.isSet()) { if (!matIDArg.isSet() || !newIDArg.isSet()) { INFO("current and new material IDs must be provided for replacement"); return 0; } } else if (specifyArg.isSet()) { if (!eleTypeArg.isSet() || !newIDArg.isSet()) { INFO("element type and new material IDs must be provided to specify elements"); return 0; } } std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); if (condenseArg.isSet()) { INFO("Condensing material ID..."); MeshLib::ElementValueModification::condense(*mesh); } else if (replaceArg.isSet()) { INFO("Replacing material ID..."); const auto vecOldID = matIDArg.getValue(); const unsigned newID = newIDArg.getValue(); for (auto oldID : vecOldID) { INFO("%d -> %d", oldID, newID); MeshLib::ElementValueModification::replace(*mesh, oldID, newID, true); } } else if (specifyArg.isSet()) { INFO("Specifying material ID..."); const std::string eleTypeName(eleTypeArg.getValue()); const MeshLib::MeshElemType eleType = MeshLib::String2MeshElemType(eleTypeName); const unsigned newID = newIDArg.getValue(); unsigned cnt = MeshLib::ElementValueModification::setByElementType(*mesh, eleType, newID); INFO("updated %d elements", cnt); } MeshLib::IO::writeMeshToFile(*mesh, mesh_out.getValue()); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd("The tool computes the area per node of the surface mesh" " and writes the information as txt and csv data.", ' ', "0.1"); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> id_prop_name("", "id-prop-name", "the name of the property containing the id information", false, "OriginalSubsurfaceNodeIDs", "property name"); cmd.add(id_prop_name); TCLAP::ValueArg<std::string> out_base_fname("p", "output-base-name", "the path and base file name the output will be written to", false, "", "output path and base name as one string"); cmd.add(out_base_fname); cmd.parse(argc, argv); std::unique_ptr<MeshLib::Mesh> surface_mesh( MeshLib::IO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %u nodes, %u elements.", surface_mesh->getNNodes(), surface_mesh->getNElements()); // ToDo check if mesh is read correct and if the mesh is a surface mesh // check if a node property containing the subsurface ids is available boost::optional<MeshLib::PropertyVector<std::size_t> const&> orig_node_ids( surface_mesh->getProperties().getPropertyVector<std::size_t>( id_prop_name.getValue())); // if the node property is not available generate it if (!orig_node_ids) { boost::optional<MeshLib::PropertyVector<std::size_t>&> node_ids( surface_mesh->getProperties().createNewPropertyVector<std::size_t>( id_prop_name.getValue(), MeshLib::MeshItemType::Node, 1)); if (!node_ids) { ERR("Fatal error: could not create property."); return EXIT_FAILURE; } node_ids->resize(surface_mesh->getNNodes()); std::iota(node_ids->begin(), node_ids->end(), 0); orig_node_ids = node_ids; } std::vector<double> areas( MeshLib::MeshSurfaceExtraction::getSurfaceAreaForNodes(*surface_mesh)); // pack area and node id together std::vector<std::pair<std::size_t, double>> ids_and_areas; std::transform(orig_node_ids->cbegin(), orig_node_ids->cend(), areas.cbegin(), std::back_inserter(ids_and_areas), std::make_pair<std::size_t const&, double const&>); // generate file names for output std::string path(out_base_fname.getValue()); if (path.empty()) path = BaseLib::dropFileExtension(mesh_in.getValue()); std::string const id_and_area_fname(path+".txt"); std::string const csv_fname(path+".csv"); writeToFile(id_and_area_fname, csv_fname, ids_and_areas, surface_mesh->getNodes()); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { LOGOG_INITIALIZE(); logog::Cout* logog_cout (new logog::Cout); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); logog_cout->SetFormatter(*custom_format); TCLAP::CmdLine cmd("Remove mesh elements.", ' ', "0.1"); TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", "the name of the file containing the input mesh", true, "", "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", "the name of the file the mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements", false); cmd.add(zveArg); TCLAP::MultiArg<std::string> eleTypeArg("t", "element-type", "element type to be removed", false, "element type"); cmd.add(eleTypeArg); TCLAP::MultiArg<unsigned> matIDArg("m", "material-id", "material id", false, "material id"); cmd.add(matIDArg); cmd.parse(argc, argv); MeshLib::Mesh* mesh (FileIO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); // search elements IDs to be removed std::vector<std::size_t> vec_elementIDs_removed; if (zveArg.isSet()) { std::vector<std::size_t> vec_matched = searchByZeroContent(mesh->getElements()); updateUnion(vec_matched, vec_elementIDs_removed); INFO("%d zero volume elements found.", vec_matched.size()); } if (eleTypeArg.isSet()) { std::vector<std::string> eleTypeNames = eleTypeArg.getValue(); for (auto typeName : eleTypeNames) { MeshElemType type = String2MeshElemType(typeName); if (type == MeshElemType::INVALID) continue; std::vector<std::size_t> vec_matched = searchByElementType(mesh->getElements(), type); updateUnion(vec_matched, vec_elementIDs_removed); INFO("%d %s elements found.", vec_matched.size(), typeName.c_str()); } } if (matIDArg.isSet()) { std::vector<unsigned> vec_matID = matIDArg.getValue(); for (auto matID : vec_matID) { std::vector<std::size_t> vec_matched = searchByMaterialID(mesh->getElements(), matID); updateUnion(vec_matched, vec_elementIDs_removed); INFO("%d elements with material ID %d found.", vec_matched.size(), matID); } } // remove the elements INFO("Removing total %d elements...", vec_elementIDs_removed.size()); std::vector<MeshLib::Element*> tmp_eles = excludeElements(mesh->getElements(), vec_elementIDs_removed); INFO("%d elements remained.", tmp_eles.size()); std::vector<MeshLib::Node*> new_nodes; std::vector<MeshLib::Element*> new_eles; copyNodesElements(mesh->getNodes(), tmp_eles, new_nodes, new_eles); // create a new mesh object. Unsued nodes are removed while construction MeshLib::Mesh* new_mesh(new MeshLib::Mesh(mesh->getName(), new_nodes, new_eles)); // write into a file FileIO::Legacy::MeshIO meshIO; meshIO.setMesh(new_mesh); meshIO.writeToFile(mesh_out.getValue()); delete custom_format; delete logog_cout; LOGOG_SHUTDOWN(); return 0; }