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
138 std::unique_ptr<MeshLib::Mesh> surface_mesh(
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
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>(
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
187
188 std::ofstream result_out(result_file.getValue() + ".txt");
189 result_out.precision(std::numeric_limits<double>::max_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)
std::vector< double > getSurfaceIntegratedValuesForNodes(const MeshLib::Mesh &mesh, std::string const &prop_name)
GITINFOLIB_EXPORT const std::string ogs_version
constexpr int size(int const displacement_dim)
Vectorized tensor size for given displacement dimension.
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)