OGS
ProjectData.cpp File Reference
#include "ProjectData.h"
#include <pybind11/eval.h>
#include <spdlog/fmt/ranges.h>
#include <algorithm>
#include <boost/algorithm/string/predicate.hpp>
#include <cctype>
#include <range/v3/algorithm/contains.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/adjacent_remove_if.hpp>
#include <set>
#include "BaseLib/Algorithm.h"
#include "BaseLib/ConfigTree.h"
#include "BaseLib/FileTools.h"
#include "BaseLib/Logging.h"
#include "BaseLib/StringTools.h"
#include "GeoLib/GEOObjects.h"
#include "GeoLib/IO/AsciiRasterInterface.h"
#include "GeoLib/IO/NetCDFRasterReader.h"
#include "GeoLib/Raster.h"
#include "InfoLib/CMakeInfo.h"
#include "MaterialLib/MPL/CreateMedium.h"
#include "MaterialLib/Utils/MediaCreation.h"
#include "MathLib/Curve/CreatePiecewiseLinearCurve.h"
#include "MathLib/LinAlg/EigenLis/LinearSolverOptionsParser.h"
#include "MeshGeoToolsLib/ConstructMeshesFromGeometries.h"
#include "MeshGeoToolsLib/CreateSearchLength.h"
#include "MeshGeoToolsLib/SearchLength.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/MeshEnums.h"
#include "MeshLib/NodePartitionedMesh.h"
#include "MeshLib/Utils/SetMeshSpaceDimension.h"
#include "MeshToolsLib/OverwriteMeshFieldDataByMaterialIDs.h"
#include "NumLib/ODESolver/ConvergenceCriterion.h"
#include "ParameterLib/Utils.h"
#include "ProcessLib/CreateJacobianAssembler.h"
#include "ProcessLib/DeactivatedSubdomain.h"
#include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "ParameterLib/ConstantParameter.h"
#include "ParameterLib/CreateCoordinateSystem.h"
#include "ProcessLib/CreateTimeLoop.h"
#include "ProcessLib/TimeLoop.h"
Include dependency graph for ProjectData.cpp:

Go to the source code of this file.

Namespaces

namespace  anonymous_namespace{ProjectData.cpp}

Functions

void parseOverwriteMeshData (BaseLib::ConfigTree const &project_config, std::vector< MeshToolsLib::InitialConditionDataSet > &data_initial_conditions, std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
void anonymous_namespace{ProjectData.cpp}::readGeometry (std::string const &fname, GeoLib::GEOObjects &geo_objects, std::string const &dir_first, std::string const &dir_second)
std::unique_ptr< MeshLib::Meshanonymous_namespace{ProjectData.cpp}::readSingleMesh (BaseLib::ConfigTree const &mesh_config_parameter, std::string const &directory)
std::vector< std::unique_ptr< MeshLib::Mesh > > anonymous_namespace{ProjectData.cpp}::readMeshes (BaseLib::ConfigTree const &config, std::string const &directory)
std::vector< GeoLib::NamedRasteranonymous_namespace{ProjectData.cpp}::readRasters (BaseLib::ConfigTree const &config, GeoLib::MinMaxPoints const &min_max_points)

Function Documentation

◆ parseOverwriteMeshData()

void parseOverwriteMeshData ( BaseLib::ConfigTree const & project_config,
std::vector< MeshToolsLib::InitialConditionDataSet > & data_initial_conditions,
std::vector< std::unique_ptr< MeshLib::Mesh > > const & meshes,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters )

Handles <remove>, <set>, and <take_original> sub-elements of

Input File Parameter
prj__overwrite_mesh_data.

For <remove>: field_name, mesh_name, mesh_item_type For <set>/<take_original>: field_name, mesh_name, mesh_item_type, material_ids, parameter_name

Input File Parameter
prj__overwrite_mesh_data
Input File Parameter
prj__overwrite_mesh_data__remove__field_name
Input File Parameter
prj__overwrite_mesh_data__remove__mesh
Input File Parameter
prj__overwrite_mesh_data__remove__mesh_item_type
Input File Parameter
prj__overwrite_mesh_data__take_original__field_name
Input File Parameter
Input File Parameter
prj__overwrite_mesh_data__take_original__mesh
Input File Parameter
Input File Parameter
prj__overwrite_mesh_data__take_original__mesh_item_type
Input File Parameter
Input File Parameter
prj__overwrite_mesh_data__take_original__material_ids
Input File Parameter
prj__overwrite_mesh_data__set__field_name
Input File Parameter
prj__overwrite_mesh_data__set__mesh
Input File Parameter
prj__overwrite_mesh_data__set__mesh_item_type
Input File Parameter
prj__overwrite_mesh_data__set__material_ids
Input File Parameter
prj__overwrite_mesh_data__set__parameter_name

Definition at line 54 of file ProjectData.cpp.

59{
60 auto const overwrite_mesh_data_config =
62 project_config.getConfigSubtreeOptional("overwrite_mesh_data");
63 if (!overwrite_mesh_data_config)
64 {
65 return;
66 }
67
68 for (auto const& [tag, config] :
69 overwrite_mesh_data_config->getAllChildren())
70 {
71 if (tag == "remove")
72 {
73 auto const field_name =
75 config->getConfigParameter<std::string>("field_name");
77 auto const mesh_name = config->getConfigParameter<std::string>(
78 "mesh", meshes[0]->getName());
79 auto& mesh = MeshLib::findMeshByName(meshes, mesh_name);
80 auto const mesh_item_type = MeshLib::string2MeshItemType(
82 config->getConfigParameter<std::string>("mesh_item_type"));
83
84 MeshLib::Properties& properties = mesh.getProperties();
85 if (properties.template hasPropertyVector<double>(field_name,
86 mesh_item_type))
87 {
88 DBUG("remove property: {}", field_name);
89 properties.removePropertyVector(field_name);
90 }
91 continue;
92 }
93
94 if (tag == "set" || tag == "take_original")
95 {
96 // The "take_original" element shares the parsing code below with
97 // "set", so its parameters are documented separately here.
102 auto const field_name =
104 config->getConfigParameter<std::string>("field_name");
106 auto const mesh_name = config->getConfigParameter<std::string>(
107 "mesh", meshes[0]->getName());
108 auto& mesh = MeshLib::findMeshByName(meshes, mesh_name);
109 auto const mesh_item_type = MeshLib::string2MeshItemType(
111 config->getConfigParameter<std::string>("mesh_item_type"));
112
113 // string2MeshItemType() also accepts 'edge' and 'face', but the
114 // overwrite only supports node, cell and integration-point data.
115 // Reject the unsupported types here so the user gets a clear error
116 // at project-file parsing time instead of a fatal later during the
117 // overwrite.
118 if (mesh_item_type != MeshLib::MeshItemType::Node &&
119 mesh_item_type != MeshLib::MeshItemType::Cell &&
121 {
122 OGS_FATAL(
123 "overwrite_mesh_data: <{:s}> with mesh_item_type '{:s}' is "
124 "not supported. Only 'node', 'cell' and "
125 "'integration_point' "
126 "can be overwritten.",
127 tag, MeshLib::toString(mesh_item_type));
128 }
129
130 // Genuine multi-rank PETSc partition: each rank holds only a local
131 // mesh slice. Material-id selection and node writes not implemented
132 // there. Single-thread wrapper (serial / 1 rank) covers whole mesh,
133 // so allowed.
134 auto const* const partitioned_mesh =
135 dynamic_cast<MeshLib::NodePartitionedMesh const*>(&mesh);
136 bool const is_partition =
137 partitioned_mesh && !partitioned_mesh->isForSingleThread();
138
139 if (is_partition && mesh_item_type == MeshLib::MeshItemType::Node)
140 {
141 OGS_FATAL(
142 "overwrite_mesh_data: <{:s}> modifying node data is not "
143 "implemented for partitioned (PETSc) meshes.",
144 tag);
145 }
146
147 auto const selected_material_ids_string =
149 config->getConfigParameter<std::string>("material_ids", "0");
150 auto const* const material_ids = MeshLib::materialIDs(mesh);
151
152 std::vector<std::size_t> element_ids_for_selected_materials;
153 if (material_ids == nullptr)
154 {
155 // The mesh has no MaterialIDs: treat it as a single material-0
156 // region rather than injecting a permanent MaterialIDs
157 // property (which would leak into the output and into any
158 // downstream code that branches on materialIDs() being
159 // present).
160 if (selected_material_ids_string != "0" &&
161 selected_material_ids_string != "*")
162 {
163 OGS_FATAL(
164 "overwrite_mesh_data: mesh '{:s}' has no MaterialIDs, "
165 "so material_ids='{:s}' cannot be resolved. Only '0' "
166 "or '*' are valid in this case.",
167 mesh_name, selected_material_ids_string);
168 }
169 element_ids_for_selected_materials =
170 ranges::views::iota(std::size_t{0},
171 mesh.getNumberOfElements()) |
172 ranges::to<std::vector>;
173 }
174 else
175 {
176 // Specific material subset: depends on material ids, cannot
177 // resolve against partition-local subset. "*" (whole mesh)
178 // exempt.
179 if (is_partition && selected_material_ids_string != "*")
180 {
181 OGS_FATAL(
182 "overwrite_mesh_data: <{:s}> material-id-based "
183 "selection (material_ids='{:s}') is not implemented "
184 "for "
185 "partitioned (PETSc) meshes.",
186 tag, selected_material_ids_string);
187 }
188 std::set<int> const selected_material_ids =
190 selected_material_ids_string, material_ids, ' ',
191 /*validate=*/true) |
192 ranges::to<std::set<int>>();
193 element_ids_for_selected_materials =
194 ranges::views::iota(std::size_t{0}, material_ids->size()) |
195 ranges::views::filter(
196 [&](std::size_t const i)
197 {
198 return selected_material_ids.contains(
199 (*material_ids)[i]);
200 }) |
201 ranges::to<std::vector>;
202 }
203
204 // For \c set, get parameter_name; for \c take_original, it's
205 // empty
206 auto const& parameter_name =
207 tag == "set"
209 ? config->getConfigParameterOptional<std::string>(
210 "parameter_name")
211 : std::optional<std::string>{};
212
213 if (tag == "set" && !parameter_name)
214 {
215 OGS_FATAL(
216 "\"set\" element requires a parameter_name attribute.");
217 }
218
219 auto const parameter =
220 !parameter_name || parameter_name->empty()
221 ? static_cast<ParameterLib::Parameter<double>*>(nullptr)
222 : &ParameterLib::findParameter<double>(
223 *parameter_name, parameters, 0, nullptr);
224 data_initial_conditions.emplace_back(
225 field_name,
226 std::move(element_ids_for_selected_materials),
227 nullptr,
228 &mesh,
229 parameter,
230 mesh_item_type);
231 continue;
232 }
233
234 OGS_FATAL(
235 "Unknown element <{:s}> in <overwrite_mesh_data>. Expected one of "
236 "<remove>, <set>, or <take_original>.",
237 tag);
238 }
239}
#define OGS_FATAL(...)
Definition Error.h:10
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
void removePropertyVector(std::string_view name)
Definition Properties.cpp:8
std::vector< int > parseMaterialIdString(std::string const &material_id_string, MeshLib::PropertyVector< int > const *const material_ids, char const separator, bool const validate)
Mesh & findMeshByName(std::vector< std::unique_ptr< Mesh > > const &meshes, std::string_view const name)
Definition Mesh.cpp:356
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:260
static constexpr char const * toString(const MeshItemType t)
Returns a char array for a specific MeshItemType.
Definition MeshEnums.h:26
MeshItemType string2MeshItemType(const std::string &s)
OGS_NO_DANGLING Parameter< ParameterDataType > & findParameter(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase > > const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)

References MeshLib::Cell, DBUG(), MeshLib::findMeshByName(), ParameterLib::findParameter(), BaseLib::ConfigTree::getConfigSubtreeOptional(), MeshLib::IntegrationPoint, MeshLib::NodePartitionedMesh::isForSingleThread(), MeshLib::materialIDs(), MeshLib::Node, OGS_FATAL, MaterialLib::parseMaterialIdString(), MeshLib::Properties::removePropertyVector(), MeshLib::string2MeshItemType(), and MeshLib::toString().