OGS
SelectSolidConstitutiveRelation.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <spdlog/fmt/bundled/ranges.h>
13
14#include <map>
15#include <range/v3/view/map.hpp>
16
18
19namespace MaterialLib
20{
21namespace Solids
22{
35template <typename SolidMaterialsMap>
37 SolidMaterialsMap const& constitutive_relations,
38 MeshLib::PropertyVector<int> const* const material_ids,
39 std::size_t const element_id)
40{
41 // Multiple constitutive relations and no material ids should not be valid.
42 if (constitutive_relations.size() > 1 && material_ids == nullptr)
43 {
45 "There are {} constitutive relations provided in the project file "
46 "but no MaterialIDs could be found in the mesh.",
47 constitutive_relations.size());
48 }
49
50 int const material_id = ((constitutive_relations.size() == 1 &&
51 constitutive_relations.begin()->first == 0) ||
52 material_ids == nullptr)
53 ? 0
54 : (*material_ids)[element_id];
55
56 auto const constitutive_relation = constitutive_relations.find(material_id);
57 if (constitutive_relation == end(constitutive_relations))
58 {
60 "No constitutive relation found for material id {:d} and element "
61 "{:d}. There are {:d} constitutive relations available, "
62 "corresponding to the ids: {}",
63 material_id, element_id, constitutive_relations.size(),
64 fmt::join(constitutive_relations | ranges::views::keys, " "));
65 }
66
67 if (constitutive_relation->second == nullptr)
68 {
70 "The constitutive relation found for material id {:d} and element "
71 "{:d} is a nullptr, which is impossible.",
72 material_id, element_id);
73 }
74
75 return *constitutive_relation->second;
76}
77} // namespace Solids
78} // namespace MaterialLib
#define OGS_FATAL(...)
Definition Error.h:26
auto & selectSolidConstitutiveRelation(SolidMaterialsMap const &constitutive_relations, MeshLib::PropertyVector< int > const *const material_ids, std::size_t const element_id)