OGS
IntegrationPointMetaData.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <spdlog/fmt/ranges.h>
7
8#include <nlohmann/json.hpp>
9#include <range/v3/algorithm/find.hpp>
10#include <range/v3/iterator/operations.hpp>
11#include <range/v3/range/conversion.hpp>
12#include <range/v3/view/transform.hpp>
13
14#include "BaseLib/Algorithm.h"
15#include "BaseLib/Error.h"
16
17using nlohmann::json;
18
19namespace MeshLib
20{
21
23 std::string_view const json_string)
24{
25 json const meta_data = json::parse(json_string);
26
27 fields_ = meta_data["integration_point_arrays"] |
28 ranges::views::transform(
29 [](auto const& md)
30 {
32 md["name"], md["number_of_components"],
33 md["integration_order"]};
34 }) |
35 ranges::to<std::vector>;
36
38}
39
41 std::string const& field_name) const
42{
43 auto it = ranges::find(
45
46 if (it == fields_.end())
47 {
48 OGS_FATAL("No integration point meta data with name '{:s}' found.",
49 field_name);
50 }
51 return *it;
52}
53
55{
56 json json_meta_data;
57 json_meta_data["integration_point_arrays"] = json::array();
58
59 for (auto const& field : fields_)
60 {
61 json_meta_data["integration_point_arrays"].push_back(
62 {{"name", field.field_name},
63 {"number_of_components", field.n_components},
64 {"integration_order", field.integration_order}});
65 }
66
67 return json_meta_data.dump();
68}
69
71{
72 auto const duplicates = BaseLib::getDuplicates(
73 fields_ | ranges::views::transform(
75
76 if (!duplicates.empty())
77 {
78 OGS_FATAL("Duplicate integration point meta data names found: {:s}.",
79 fmt::join(duplicates, ", "));
80 }
81}
82
84 std::optional<IntegrationPointMetaData> const& ip_meta_data,
85 std::string const& field_name)
86{
87 if (!ip_meta_data)
88 {
90 "The required 'IntegrationPointMetaData' array is not available in "
91 "the vtk field data but is needed to evaluate the integration "
92 "point property '{:s}'.",
93 field_name);
94 }
95 return (*ip_meta_data)[field_name];
96}
97} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:10
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_
std::vector< ranges::range_value_t< Range > > getDuplicates(Range &&range)
Definition Algorithm.h:178
IntegrationPointMetaDataSingleField getIntegrationPointMetaDataSingleField(std::optional< IntegrationPointMetaData > const &ip_meta_data, std::string const &field_name)