OGS
createNeumannBc.cpp File Reference

Detailed Description

Definition in file createNeumannBc.cpp.

#include <tclap/CmdLine.h>
#include <fstream>
#include "BaseLib/MPI.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 32 of file createNeumannBc.cpp.

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

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

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