OGS 6.2.1-97-g73d1aeda3
CreateMaterialSpatialDistributionMap.cpp
Go to the documentation of this file.
1 
14 #include "MeshLib/Mesh.h"
15 
16 namespace MaterialPropertyLib
17 {
18 std::unique_ptr<MaterialSpatialDistributionMap>
20  std::map<int, std::unique_ptr<Medium>> const& media,
21  MeshLib::Mesh const& mesh)
22 {
23  auto const material_ids = materialIDs(mesh);
24 
25  int const max_material_id =
26  !material_ids
27  ? 0
28  : *std::max_element(begin(*material_ids), end(*material_ids));
29 
30  if (max_material_id > static_cast<int>(media.size() - 1))
31  {
32  OGS_FATAL(
33  "The maximum value of MaterialIDs in mesh is %d. As the given "
34  "number of porous media definitions in the project file is %d, the "
35  "maximum value of MaterialIDs in mesh must be %d (index starts "
36  "with zero).",
37  max_material_id, media.size(), max_material_id - 1);
38  }
39 
40  if (max_material_id < static_cast<int>(media.size() - 1))
41  WARN(
42  "There are %d porous medium definitions in the project file but "
43  "only %d different values in the MaterialIDs vector/data_array in "
44  "the mesh.",
45  media.size(), max_material_id - 1);
46 
47  return std::make_unique<MaterialSpatialDistributionMap>(media,
48  material_ids);
49 }
50 } // namespace MaterialPropertyLib
std::unique_ptr< MaterialSpatialDistributionMap > createMaterialSpatialDistributionMap(std::map< int, std::unique_ptr< Medium >> const &media, MeshLib::Mesh const &mesh)
Definition of the Mesh class.
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:403
#define OGS_FATAL(fmt,...)
Definition: Error.h:63