OGS
SelectSolidConstitutiveRelation.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <spdlog/fmt/ranges.h>
7
8#include <map>
9#include <range/v3/view/map.hpp>
10
12
13namespace MaterialLib
14{
15namespace Solids
16{
29template <typename SolidMaterialsMap>
31 SolidMaterialsMap const& constitutive_relations,
32 MeshLib::PropertyVector<int> const* const material_ids,
33 std::size_t const element_id)
34{
35 // Multiple constitutive relations and no material ids should not be valid.
36 if (constitutive_relations.size() > 1 && material_ids == nullptr)
37 {
39 "There are {} constitutive relations provided in the project file "
40 "but no MaterialIDs could be found in the mesh.",
41 constitutive_relations.size());
42 }
43
44 int const material_id = ((constitutive_relations.size() == 1 &&
45 constitutive_relations.begin()->first == 0) ||
46 material_ids == nullptr)
47 ? 0
48 : (*material_ids)[element_id];
49
50 auto const constitutive_relation = constitutive_relations.find(material_id);
51 if (constitutive_relation == end(constitutive_relations))
52 {
54 "No constitutive relation found for material id {:d} and element "
55 "{:d}. There are {:d} constitutive relations available, "
56 "corresponding to the ids: {}",
57 material_id, element_id, constitutive_relations.size(),
58 fmt::join(constitutive_relations | ranges::views::keys, " "));
59 }
60
61 if (constitutive_relation->second == nullptr)
62 {
64 "The constitutive relation found for material id {:d} and element "
65 "{:d} is a nullptr, which is impossible.",
66 material_id, element_id);
67 }
68
69 return *constitutive_relation->second;
70}
71} // namespace Solids
72} // namespace MaterialLib
#define OGS_FATAL(...)
Definition Error.h:19
auto & selectSolidConstitutiveRelation(SolidMaterialsMap const &constitutive_relations, MeshLib::PropertyVector< int > const *const material_ids, std::size_t const element_id)