OGS
IntegrationPointWriter.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 <range/v3/view/join.hpp>
7
8#include "MeshLib/Mesh.h"
10
16{
17 auto const& ip_values = writer.values(/*t, x, dof_table*/);
18 assert(ip_values.size() == mesh.getNumberOfElements());
19
20 // create field data and fill it with nodal values, and an offsets cell
21 // array indicating where the cell's integration point data starts.
24 writer.numberOfComponents());
25 field_data.clear();
26
27 ranges::copy(ip_values | ranges::views::join,
28 std::back_inserter(field_data));
29
30 return {writer.name(), writer.numberOfComponents(),
31 writer.integrationOrder()};
32}
33
37 MeshLib::Mesh& mesh, MeshLib::IntegrationPointMetaData const& ip_meta_data)
38{
39 // Store the field data.
40 std::string const json_string = ip_meta_data.toJsonString();
42 mesh, "IntegrationPointMetaData",
44 dictionary.clear();
45 std::copy(json_string.begin(), json_string.end(),
46 std::back_inserter(dictionary));
47}
48
49namespace MeshLib
50{
52 MeshLib::Mesh& mesh,
53 std::vector<std::unique_ptr<IntegrationPointWriter>> const&
54 integration_point_writer)
55{
56 auto meta_data = IntegrationPointMetaData{
57 integration_point_writer |
58 ranges::views::transform(
59 [&](auto const& ip_writer)
60 { return addIntegrationPointData(mesh, *ip_writer); })};
61
62 if (!meta_data.empty())
63 {
65 }
66}
67
68std::optional<IntegrationPointMetaData> getIntegrationPointMetaData(
69 MeshLib::Properties const& properties)
70{
71 if (!properties.existsPropertyVector<char>("IntegrationPointMetaData"))
72 {
73 return std::nullopt;
74 }
75 auto const& mesh_property_ip_meta_data =
76 *properties.template getPropertyVector<char>(
77 "IntegrationPointMetaData");
78
79 if (mesh_property_ip_meta_data.getMeshItemType() !=
81 {
82 OGS_FATAL("IntegrationPointMetaData array must be field data.");
83 }
84
85 // Find the current integration point data entry and extract the
86 // meta data.
87 return IntegrationPointMetaData{std::string_view{
88 mesh_property_ip_meta_data.data(), mesh_property_ip_meta_data.size()}};
89}
90} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:19
static MeshLib::IntegrationPointMetaDataSingleField addIntegrationPointData(MeshLib::Mesh &mesh, MeshLib::IntegrationPointWriter const &writer)
static void addIntegrationPointMetaDataSingleField(MeshLib::Mesh &mesh, MeshLib::IntegrationPointMetaData const &ip_meta_data)
Description of the stored integration point meta data for all fields.
std::string toJsonString() const
Converts integration point meta data to a JSON string.
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
bool existsPropertyVector(std::string_view name) const
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
std::optional< IntegrationPointMetaData > getIntegrationPointMetaData(MeshLib::Properties const &properties)
void addIntegrationPointDataToMesh(MeshLib::Mesh &mesh, std::vector< std::unique_ptr< IntegrationPointWriter > > const &integration_point_writer)
std::vector< std::vector< double > > values() const