Loading [MathJax]/extensions/tex2jax.js
OGS
IntegrationPointMetaData.cpp
Go to the documentation of this file.
1
11
12#include <spdlog/fmt/ranges.h>
13
14#include <nlohmann/json.hpp>
15#include <range/v3/algorithm/find.hpp>
16#include <range/v3/iterator/operations.hpp>
17#include <range/v3/range/conversion.hpp>
18#include <range/v3/view/filter.hpp>
19#include <range/v3/view/transform.hpp>
20#include <unordered_set>
21
22#include "BaseLib/Error.h"
23
24using nlohmann::json;
25
26namespace MeshLib
27{
28
30 std::string_view const json_string)
31{
32 json const meta_data = json::parse(json_string);
33
34 fields_ = meta_data["integration_point_arrays"] |
35 ranges::views::transform(
36 [](auto const& md)
37 {
39 md["name"], md["number_of_components"],
40 md["integration_order"]};
41 }) |
42 ranges::to<std::vector>;
43
45}
46
48 std::string const& field_name) const
49{
50 auto it = ranges::find(
52
53 if (it == fields_.end())
54 {
55 OGS_FATAL("No integration point meta data with name '{:s}' found.",
56 field_name);
57 }
58 return *it;
59}
60
62{
63 json json_meta_data;
64 json_meta_data["integration_point_arrays"] = json::array();
65
66 for (auto const& field : fields_)
67 {
68 json_meta_data["integration_point_arrays"].push_back(
69 {{"name", field.field_name},
70 {"number_of_components", field.n_components},
71 {"integration_order", field.integration_order}});
72 }
73
74 return json_meta_data.dump();
75}
76
78{
79 std::unordered_set<std::string> seen;
80
81 auto const duplicates =
82 fields_ |
83 ranges::views::transform(
85 ranges::views::filter([&seen](std::string const& name)
86 { return !seen.insert(name).second; }) |
87 ranges::to<std::vector>;
88
89 if (!duplicates.empty())
90 {
91 OGS_FATAL("Duplicate integration point meta data names found: {:s}.",
92 fmt::join(duplicates, ", "));
93 }
94}
95
97 std::optional<IntegrationPointMetaData> const& ip_meta_data,
98 std::string const& field_name)
99{
100 if (!ip_meta_data)
101 {
102 OGS_FATAL(
103 "The required 'IntegrationPointMetaData' array is not available in "
104 "the vtk field data but is needed to evaluate the integration "
105 "point property '{:s}'.",
106 field_name);
107 }
108 return (*ip_meta_data)[field_name];
109}
110} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:26
IntegrationPointMetaData(std::string_view const json_string)
Constructs integration point meta data from a JSON encoded string.
std::string toJsonString() const
Converts integration point meta data to a JSON string.
IntegrationPointMetaDataSingleField const & operator[](std::string const &field_name) const
std::vector< IntegrationPointMetaDataSingleField > fields_
IntegrationPointMetaDataSingleField getIntegrationPointMetaDataSingleField(std::optional< IntegrationPointMetaData > const &ip_meta_data, std::string const &field_name)