diff --git a/Applications/Utils/FileConverter/CMakeLists.txt b/Applications/Utils/FileConverter/CMakeLists.txt index ec0b9d4c72d625257d02759f82a866e3def4143c..452da058b22e22843c84fc5336c7cee2e6564c2f 100644 --- a/Applications/Utils/FileConverter/CMakeLists.txt +++ b/Applications/Utils/FileConverter/CMakeLists.txt @@ -15,15 +15,6 @@ if (QT4_FOUND) target_link_libraries(ConvertSHPToGLI FileIO) - add_executable(generateBCandGLI generateBCandGLI.cpp ) - target_link_libraries(generateBCandGLI FileIO) - - add_executable(generateBCFromPolyline generateBCFromPolyline.cpp ) - target_link_libraries(generateBCFromPolyline FileIO) - - set_target_properties(generateBCandGLI generateBCFromPolyline - PROPERTIES FOLDER Utilities) - add_executable(FEFLOW2OGS FEFLOW2OGS.cpp) set_target_properties(FEFLOW2OGS PROPERTIES FOLDER Utilities) target_link_libraries(FEFLOW2OGS FileIO) @@ -68,7 +59,7 @@ install(TARGETS generateMatPropsFromMatID GMSH2OGS OGS2VTK VTK2OGS VTK2TIN RUNTIME DESTINATION bin COMPONENT ogs_converter) if(QT4_FOUND) - install(TARGETS ConvertSHPToGLI generateBCandGLI generateBCFromPolyline generateBCandGLI + install(TARGETS ConvertSHPToGLI FEFLOW2OGS RUNTIME DESTINATION bin COMPONENT ogs_converter) endif() diff --git a/Applications/Utils/FileConverter/generateBCFromPolyline.cpp b/Applications/Utils/FileConverter/generateBCFromPolyline.cpp deleted file mode 100644 index e54afee9119123d23c9d1a84255bf3a6db3c396f..0000000000000000000000000000000000000000 --- a/Applications/Utils/FileConverter/generateBCFromPolyline.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/** - * \file - * \author Thomas Fischer - * \date 2011-03-08 - * \brief Implementation of the generateBCFromPolyline tool. - * - * \copyright - * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -#include <fstream> - -#include <QString> - -// GeoLib -#include "GEOObjects.h" -#include "PolylineVec.h" - -// OGS -#include "Applications/ApplicationsLib/ProjectData.h" - -// FileIO -#include "XmlIO/Qt/XmlGmlInterface.h" - -int main (int argc, char* argv[]) -{ - if (argc == 1) - { - std::cout << "Usage: " << argv[0] << " gml-file" << std::endl; - std::cout << "\tgives you the name of all polylines in the file" << std::endl; - std::cout << "Usage: " << argv[0] << " gml-file polyline-to-convert" << std::endl; - std::cout << "\tcreates for the given polyline points boundary conditions" << - std::endl; - return -1; - } - - GeoLib::GEOObjects geo_objs; - FileIO::XmlGmlInterface xml(geo_objs); - std::string fname (argv[1]); - xml.readFile(QString::fromStdString (fname)); - - 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; - } - const std::size_t n_ply (ply_vec->size()); - - std::vector<std::size_t> ply_pnt_ids; - for (std::size_t k(0); k < n_ply; k++) - { - std::string ply_name; - if (ply_vec->getNameOfElementByID(k, ply_name)) - { - if (argc == 2) - std::cout << "polyline " << k << ": " << ply_name << std::endl; - else if (ply_name.find (argv[2]) != std::string::npos) - { - std::cout << "found polyline " << ply_name << std::endl; - GeoLib::Polyline const* ply (ply_vec->getElementByName(ply_name)); - const std::size_t n_ply_pnts (ply->getNumberOfPoints()); - for (std::size_t j(0); j < n_ply_pnts; j++) - ply_pnt_ids.push_back (ply->getPointID(j)); - } - } - } - - if (argc == 2) - return 0; - - std::vector<GeoLib::Point*> const* geo_pnts (geo_objs.getPointVec(geo_names[0])); - // write gli file and bc file - std::ofstream gli_out ("TB.gli"); - std::ofstream bc_out ("TB.bc"); - bc_out << "// file generated by " << argv[0] << "\n"; - if (gli_out && bc_out) - { - gli_out << "#POINTS" << "\n"; - for (std::size_t k(0); k < ply_pnt_ids.size(); k++) - { - gli_out << k << " " << *((*geo_pnts)[ply_pnt_ids[k]]) << " $NAME PLYPNT" << - argv[2] << k << "\n"; - // boundary condition - bc_out << "#BOUNDARY_CONDITION" << "\n"; - bc_out << "\t$PCS_TYPE" << "\n" << "\t\tGROUNDWATER_FLOW" << "\n"; - bc_out << "\t$PRIMARY_VARIABLE" << "\n" << "\t\tHEAD" << "\n"; - bc_out << "\t$GEO_TYPE" << "\n" << "\t\tPOINT PLYPNT" << argv[2] << - k << "\n"; - bc_out << "\t$DIS_TYPE" << "\n" << "\t\tCONSTANT " << - (*((*geo_pnts)[ply_pnt_ids[k]]))[2] << "\n"; - } - gli_out << "#STOP" << "\n"; - bc_out << "#STOP" << "\n"; - gli_out.close (); - bc_out.close (); - } -} diff --git a/Applications/Utils/FileConverter/generateBCandGLI.cpp b/Applications/Utils/FileConverter/generateBCandGLI.cpp deleted file mode 100644 index 76c8bc780bbd32c5b32e587399f9c0b7a9a7f711..0000000000000000000000000000000000000000 --- a/Applications/Utils/FileConverter/generateBCandGLI.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/** - * \file - * \author Thomas Fischer - * \date 2011-03-01 - * \brief Implementation of the generateBCandGLI tool. - * - * \copyright - * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -// STL -#include <algorithm> -#include <fstream> - -// Qt -#include <QString> - -// GeoLib -#include "GEOObjects.h" -#include "SurfaceVec.h" -#include "GeoLib/Triangle.h" - -#include "Applications/ApplicationsLib/ProjectData.h" - -// FileIO -#include "XmlIO/Qt/XmlGmlInterface.h" - -int main (int argc, char* argv[]) -{ - if (argc == 1) - { - std::cout << "Usage: " << argv[0] << " gml-file" << std::endl; - return -1; - } - GeoLib::GEOObjects geo_objs; - FileIO::XmlGmlInterface xml(geo_objs); - std::string fname (argv[1]); - xml.readFile(QString::fromStdString (fname)); - - 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::SurfaceVec* sfc_vec (geo_objs.getSurfaceVecObj(geo_names[0])); - if (!sfc_vec) - { - std::cout << "could not found surfaces" << std::endl; - return -1; - } - const std::size_t n_sfc (sfc_vec->size()); - - std::vector<std::size_t> sfc_pnt_ids; - for (std::size_t k(0); k < n_sfc; k++) - { - std::string sfc_name; - if (sfc_vec->getNameOfElementByID(k, sfc_name)) - if (sfc_name.find ("Terrain") != std::string::npos) - { - std::cout << k << ": " << sfc_name << std::endl; - GeoLib::Surface const* sfc (sfc_vec->getElementByName(sfc_name)); - const std::size_t n_triangles (sfc->getNTriangles()); - for (std::size_t j(0); j < n_triangles; j++) - { - GeoLib::Triangle const* tri ((*sfc)[j]); - for (std::size_t i(0); i < 3; i++) - sfc_pnt_ids.push_back ((*tri)[i]); - } - } - } - - // make entries unique - std::cout << "make points unique ... " << std::flush; - std::sort (sfc_pnt_ids.begin(), sfc_pnt_ids.end()); - std::vector<std::size_t>::iterator it (sfc_pnt_ids.begin()); - while (it != sfc_pnt_ids.end()) - { - std::vector<std::size_t>::iterator next (it); - ++next; - if (next != sfc_pnt_ids.end()) - { - if (*it == *next) - it = sfc_pnt_ids.erase (it); - else - ++it; - } - else - ++it; - } - std::cout << "done" << std::endl; - - std::vector<GeoLib::Point*> const* geo_pnts (geo_objs.getPointVec(geo_names[0])); - // write gli file and bc file - std::ofstream gli_out ("TB.gli"); - std::ofstream bc_out ("TB.bc"); - bc_out << "// file generated by " << argv[0] << "\n"; - if (gli_out && bc_out) - { - gli_out << "#POINTS" << "\n"; - for (std::size_t k(0); k < sfc_pnt_ids.size(); k++) - { - gli_out << k << " " << *((*geo_pnts)[sfc_pnt_ids[k]]) << " $NAME " << k << - "\n"; - // boundary condition - bc_out << "#BOUNDARY_CONDITION" << "\n"; - bc_out << "\t$PCS_TYPE" << "\n" << "\t\tGROUNDWATER_FLOW" << "\n"; - bc_out << "\t$PRIMARY_VARIABLE" << "\n" << "\t\tHEAD" << "\n"; - bc_out << "\t$GEO_TYPE" << "\n" << "\t\tPOINT " << k << "\n"; - bc_out << "\t$DIS_TYPE" << "\n" << "\t\tCONSTANT " << - (*((*geo_pnts)[sfc_pnt_ids[k]]))[2] << "\n"; - } - gli_out << "#STOP" << "\n"; - bc_out << "#STOP" << "\n"; - gli_out.close (); - bc_out.close (); - } -} diff --git a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp index c03d32fb1586195798dd03c490804c9810ea10d9..82239b3fa14e7bc642d782e12d242a55d89d9e29 100644 --- a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp +++ b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp @@ -65,30 +65,61 @@ void convertMeshNodesToGeometry(std::vector<MeshLib::Node*> const& nodes, geometry_sets.addPointVec(std::move(pnts), geo_name, pnt_names); } -void writeBCsAndGeometry(GeoLib::GEOObjects & geometry_sets, - std::string & geo_name, bool write_gml) +void writeGroundwaterFlowPointBC(std::ostream& bc_out, + std::string const& pnt_name, double head_value) +{ + bc_out << "#BOUNDARY_CONDITION\n"; + bc_out << " $PCS_TYPE\n"; + bc_out << " GROUNDWATER_FLOW\n"; + bc_out << " $PRIMARY_VARIABLE\n"; + bc_out << " HEAD\n"; + bc_out << " $GEO_TYPE\n"; + bc_out << " POINT " << pnt_name << "\n"; + bc_out << " $DIS_TYPE\n"; + bc_out << " CONSTANT " << head_value << "\n"; +} + +void writeLiquidFlowPointBC(std::ostream & bc_out, std::string const& pnt_name) +{ + bc_out << "#BOUNDARY_CONDITION\n"; + bc_out << " $PCS_TYPE\n"; + bc_out << " LIQUID_FLOW\n"; + bc_out << " $PRIMARY_VARIABLE\n"; + bc_out << " PRESSURE1\n"; + bc_out << " $GEO_TYPE\n"; + bc_out << " POINT " << pnt_name << "\n"; + bc_out << " $DIS_TYPE\n"; + bc_out << " CONSTANT 0.0\n"; +} + +// geometry_sets contains the geometric points the boundary conditions will be +// set on, geo_name is the name the geometry can be accessed with, out_fname is +// the base file name the gli and bc as well as the gml file will be written to. +void writeBCsAndGeometry(GeoLib::GEOObjects& geometry_sets, + std::string& geo_name, std::string const& out_fname, + std::string const& bc_type, bool write_gml) { if (write_gml) { INFO("write points to \"%s.gml\".", geo_name.c_str()); - FileIO::writeGeometryToFile(geo_name, geometry_sets, geo_name+".gml"); + FileIO::writeGeometryToFile(geo_name, geometry_sets, out_fname+".gml"); } - FileIO::writeGeometryToFile(geo_name, geometry_sets, geo_name+".gli"); + FileIO::writeGeometryToFile(geo_name, geometry_sets, out_fname+".gli"); + + bool liquid_flow(false); + if (bc_type == "LIQUID_FLOW") + liquid_flow = true; + GeoLib::PointVec const* pnt_vec_objs(geometry_sets.getPointVecObj(geo_name)); std::vector<GeoLib::Point*> const& pnts(*(pnt_vec_objs->getVector())); - std::ofstream bc_out (geo_name+".bc"); + std::ofstream bc_out (out_fname+".bc"); for (std::size_t k(0); k<pnts.size(); k++) { std::string const& pnt_name(pnt_vec_objs->getItemNameByID(k)); if (!pnt_name.empty()) { - bc_out << "#BOUNDARY_CONDITION\n"; - bc_out << " $PCS_TYPE\n"; - bc_out << " LIQUID_FLOW\n"; - bc_out << " $PRIMARY_VARIABLE\n"; - bc_out << " PRESSURE1\n"; - bc_out << " $GEO_TYPE\n"; - bc_out << " POINT " << pnt_name << "\n"; - bc_out << " $DIS_TYPE\n"; - bc_out << " CONSTANT 0.0\n"; + if (liquid_flow) + writeLiquidFlowPointBC(bc_out, pnt_name); + else + writeGroundwaterFlowPointBC(bc_out, pnt_name, (*pnts[k])[2]); } } bc_out << "#STOP\n"; @@ -103,22 +134,40 @@ int main (int argc, char* argv[]) "Creates boundary conditions for mesh nodes along polylines.", ' ', "0.1"); - TCLAP::ValueArg<std::string> mesh_arg("m", "mesh-file", - "the name of the file containing the mesh", true, - "", "file name"); - cmd.add(mesh_arg); - TCLAP::ValueArg<std::string> geometry_fname("g", "geometry", - "the name of the file containing the input geometry", true, - "", "file name"); - cmd.add(geometry_fname); 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 @@ -237,6 +286,9 @@ int main (int argc, char* argv[]) geometry_sets.addPointVec(std::move(surface_pnts), surface_name, name_id_map, 1e-6); // write the BCs and the merged geometry set to file - writeBCsAndGeometry(geometry_sets, surface_name, gml_arg.getValue()); + 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; }