OGS
createNeumannBc.cpp File Reference

Detailed Description

Definition in file createNeumannBc.cpp.

#include <tclap/CmdLine.h>
#include <fstream>
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/TCLAPArguments.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
Include dependency graph for createNeumannBc.cpp:

Go to the source code of this file.

Functions

std::vector< double > getSurfaceIntegratedValuesForNodes (const MeshLib::Mesh &mesh, std::string const &prop_name)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ getSurfaceIntegratedValuesForNodes()

std::vector< double > getSurfaceIntegratedValuesForNodes ( const MeshLib::Mesh & mesh,
std::string const & prop_name )

Returns a vector of values where each value is associated with a particular node. Since a node is part of elements, it is possible to assign an area per element to this node. Each value of the return vector is the sum of the assigned area (per element) multiplied by the property value of the element.

Parameters
mesha surface mesh containing a property prop_name assigned to cells
prop_namename of the cell based property within the mesh
Returns
vector of integration values associated to the surface mesh nodes

Definition at line 34 of file createNeumannBc.cpp.

36{
37 if (mesh.getDimension() != 2)
38 {
39 ERR("Error in "
40 "MeshSurfaceExtraction::getSurfaceIntegratedValuesForNodes() - "
41 "Given mesh is no surface mesh (dimension != 2).");
42 return std::vector<double>();
43 }
44
45 if (!mesh.getProperties().existsPropertyVector<double>(prop_name))
46 {
47 ERR("Need element property, but the property '{:s}' is not available.",
48 prop_name);
49 return std::vector<double>();
50 }
51 auto const* const elem_pv = mesh.getProperties().getPropertyVector<double>(
52 prop_name, MeshLib::MeshItemType::Cell, 1);
53
54 std::vector<double> integrated_node_area_vec;
55 double total_area(0);
56
57 for (auto const* node : mesh.getNodes())
58 {
59 double integrated_node_area(0);
60 for (auto const& connected_elem :
61 mesh.getElementsConnectedToNode(*node))
62 {
63 double const area = connected_elem->getContent() /
64 connected_elem->getNumberOfBaseNodes();
65 integrated_node_area += area * (*elem_pv)[connected_elem->getID()];
66 total_area += area;
67 }
68
69 integrated_node_area_vec.push_back(integrated_node_area);
70 }
71
72 INFO("Total surface area: {:g}", total_area);
73
74 return integrated_node_area_vec;
75}
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 INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:90
Properties & getProperties()
Definition Mesh.h:136
bool existsPropertyVector(std::string_view name) const
PropertyVector< T > const * getPropertyVector(std::string_view name) const

References MeshLib::Cell, ERR(), MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElementsConnectedToNode(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), and INFO().

Referenced by main().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 77 of file createNeumannBc.cpp.

78{
79 TCLAP::CmdLine cmd(
80 "Integrates the given element property and outputs an OGS-5 direct "
81 "Neumann boundary condition. The mesh has to contain a property "
82 "'bulk_node_ids' that stores the original subsurface mesh node ids. "
83 "Such surface meshes can be created using the OGS-6 tool "
84 "ExtractSurface.\n\n"
85 "OpenGeoSys-6 software, version " +
87 ".\n"
88 "Copyright (c) 2012-2025, OpenGeoSys Community "
89 "(http://www.opengeosys.org)",
91
92 TCLAP::ValueArg<std::string> in_mesh(
93 "i",
94 "in-mesh",
95 "Input (.vtu | .msh). The surface mesh input file that has an element "
96 "property for the Neumann boundary condition",
97 true,
98 "",
99 "INPUT_FILE");
100 cmd.add(in_mesh);
101
102 TCLAP::ValueArg<std::string> property_in_arg(
103 "p",
104 "property-in-name",
105 "name of an element property used for the computation of the Neumann "
106 "boundary condition",
107 true,
108 "",
109 "PROP_IN_NAME");
110 cmd.add(property_in_arg);
111
112 TCLAP::ValueArg<std::string> property_out_arg(
113 "",
114 "property-out-name",
115 "name of the node based property used for the output of the Neumann "
116 "boundary condition",
117 true,
118 "",
119 "PROP_OUT_NAME");
120 cmd.add(property_out_arg);
121
122 TCLAP::ValueArg<std::string> result_file(
123 "o",
124 "result-out",
125 "Output (.txt). The output file name the result will be written to",
126 true,
127 "",
128 "OUTPUT_FILE");
129 cmd.add(result_file);
130 auto log_level_arg = BaseLib::makeLogLevelArg();
131 cmd.add(log_level_arg);
132 cmd.parse(argc, argv);
133
134 BaseLib::MPI::Setup mpi_setup(argc, argv);
135 BaseLib::initOGSLogger(log_level_arg.getValue());
136
137 // read surface mesh
138 std::unique_ptr<MeshLib::Mesh> surface_mesh(
139 MeshLib::IO::readMeshFromFile(in_mesh.getValue()));
140
141 auto const* const node_id_pv =
143 {
144 try
145 {
146 return surface_mesh->getProperties().getPropertyVector<std::size_t>(
149 }
150 catch (std::runtime_error const& e)
151 {
152 WARN("{:s}", e.what());
153 return nullptr;
154 }
155 }();
156 if (!node_id_pv)
157 {
158 return EXIT_FAILURE;
159 }
160
161 std::vector<double> integrated_values = getSurfaceIntegratedValuesForNodes(
162 *surface_mesh, property_in_arg.getValue());
163 std::vector<std::pair<std::size_t, double>> direct_values;
164 direct_values.reserve(surface_mesh->getNumberOfNodes());
165
166 for (auto const* node : surface_mesh->getNodes())
167 {
168 auto const id(node->getID());
169 auto const subsurface_node_id((*node_id_pv)[id]);
170 auto const val(integrated_values[id]);
171 direct_values.emplace_back(subsurface_node_id, val);
172 }
173
174 auto* const pv =
175 surface_mesh->getProperties().createNewPropertyVector<double>(
176 property_out_arg.getValue(), MeshLib::MeshItemType::Node,
177 surface_mesh->getNodes().size(), 1);
178 for (std::size_t k(0); k < surface_mesh->getNodes().size(); ++k)
179 {
180 (*pv)[k] = direct_values[k].second;
181 }
182
183 MeshLib::IO::writeMeshToFile(*surface_mesh, result_file.getValue());
184
185 std::ofstream result_out(result_file.getValue() + ".txt");
186 result_out.precision(std::numeric_limits<double>::max_digits10);
187 for (auto const& p : direct_values)
188 {
189 result_out << p.first << " " << p.second << "\n";
190 }
191
192 return EXIT_SUCCESS;
193}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:42
std::vector< double > getSurfaceIntegratedValuesForNodes(const MeshLib::Mesh &mesh, std::string const &prop_name)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition Properties.h:191

References MeshLib::getBulkIDString(), getSurfaceIntegratedValuesForNodes(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), MeshLib::Node, GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), WARN(), and MeshLib::IO::writeMeshToFile().