OGS
createNeumannBc.cpp File Reference

Detailed Description

Definition in file createNeumannBc.cpp.

#include <tclap/CmdLine.h>
#include <mpi.h>
#include <fstream>
#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 35 of file createNeumannBc.cpp.

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

79{
80 TCLAP::CmdLine cmd(
81 "Integrates the given element property and outputs an OGS-5 direct "
82 "Neumann boundary condition. The mesh has to contain a property "
83 "'bulk_node_ids' that stores the original subsurface mesh node ids. "
84 "Such surface meshes can be created using the OGS-6 tool "
85 "ExtractSurface.\n\n"
86 "OpenGeoSys-6 software, version " +
88 ".\n"
89 "Copyright (c) 2012-2024, OpenGeoSys Community "
90 "(http://www.opengeosys.org)",
92
93 TCLAP::ValueArg<std::string> in_mesh(
94 "i",
95 "in-mesh",
96 "the surface mesh that has an element property for the Neumann "
97 "boundary condition",
98 true,
99 "",
100 "filename for surface mesh input");
101 cmd.add(in_mesh);
102
103 TCLAP::ValueArg<std::string> property_in_arg(
104 "p",
105 "property-in-name",
106 "name of an element property used for the computation of the Neumann "
107 "boundary condition",
108 true,
109 "",
110 "string (property name)");
111 cmd.add(property_in_arg);
112
113 TCLAP::ValueArg<std::string> property_out_arg(
114 "",
115 "property-out-name",
116 "name of the node based property used for the output of the Neumann "
117 "boundary condition",
118 true,
119 "",
120 "string (property name)");
121 cmd.add(property_out_arg);
122
123 TCLAP::ValueArg<std::string> result_file(
124 "o",
125 "result-out",
126 "the file name the result will be written to ",
127 true,
128 "",
129 "output file name");
130 cmd.add(result_file);
131 cmd.parse(argc, argv);
132
133#ifdef USE_PETSC
134 MPI_Init(&argc, &argv);
135#endif
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#ifdef USE_PETSC
159 MPI_Finalize();
160#endif
161 return EXIT_FAILURE;
162 }
163
164 std::vector<double> integrated_values = getSurfaceIntegratedValuesForNodes(
165 *surface_mesh, property_in_arg.getValue());
166 std::vector<std::pair<std::size_t, double>> direct_values;
167 direct_values.reserve(surface_mesh->getNumberOfNodes());
168
169 for (auto const* node : surface_mesh->getNodes())
170 {
171 auto const id(node->getID());
172 auto const subsurface_node_id((*node_id_pv)[id]);
173 auto const val(integrated_values[id]);
174 direct_values.emplace_back(subsurface_node_id, val);
175 }
176
177 auto* const pv =
178 surface_mesh->getProperties().createNewPropertyVector<double>(
179 property_out_arg.getValue(), MeshLib::MeshItemType::Node, 1);
180 pv->resize(surface_mesh->getNodes().size());
181 for (std::size_t k(0); k < surface_mesh->getNodes().size(); ++k)
182 {
183 (*pv)[k] = direct_values[k].second;
184 }
185
186 MeshLib::IO::writeMeshToFile(*surface_mesh, result_file.getValue());
187
188 std::ofstream result_out(result_file.getValue() + ".txt");
189 result_out.precision(std::numeric_limits<double>::digits10);
190 for (auto const& p : direct_values)
191 {
192 result_out << p.first << " " << p.second << "\n";
193 }
194
195#ifdef USE_PETSC
196 MPI_Finalize();
197#endif
198 return EXIT_SUCCESS;
199}
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().