OGS
MaterialSpatialDistributionMap.cpp
Go to the documentation of this file.
1
13
14#include <spdlog/fmt/bundled/core.h>
15#include <spdlog/fmt/bundled/ranges.h>
16
17#include <range/v3/view/map.hpp>
18
19#include "MeshLib/Mesh.h"
20
21namespace MaterialPropertyLib
22{
24{
25 return const_cast<Medium*>(
26 static_cast<MaterialSpatialDistributionMap const&>(*this).getMedium(
27 element_id));
28}
29
31 std::size_t const element_id) const
32{
33 auto const material_id =
34 material_ids_ == nullptr ? 0 : (*material_ids_)[element_id];
35
36 assert(!media_.empty());
37
38 if (auto const it = media_.find(material_id); it != media_.end())
39 {
40 return it->second.get();
41 }
42
43 //
44 // Error handling until end of the function.
45 //
46
47 if (material_ids_ == nullptr)
48 {
49 assert(material_id == 0);
50 ERR("No MaterialIDs given in the mesh therefore default material id = "
51 "0 is used.");
52 }
53 auto keys = media_ | ranges::views::keys;
54
55 if (media_.size() == 1)
56 {
57 ERR("Single medium for material id {} is defined.",
58 fmt::join(keys, ", "));
59 }
60 else
61 {
62 ERR("Media for material ids {} are defined.", fmt::join(keys, ", "));
63 }
64 OGS_FATAL("No medium for material id {} found for element {}.", material_id,
65 element_id);
66}
67
69 std::size_t const element_id) const
70{
71 auto const material_id =
72 material_ids_ == nullptr ? 0 : (*material_ids_)[element_id];
73 if (media_.find(material_id) == media_.end())
74 {
76 "There is no medium definition for element {:d} with material "
77 "ID {:d}. Please define a medium for each material.",
78 element_id, material_id);
79 }
80}
81
82} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
Definition of the Mesh class.
MeshLib::PropertyVector< int > const *const material_ids_
std::map< int, std::shared_ptr< Medium > > const & media_