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
26 field_data.assign(ip_values | ranges::views::join);
27
28 return {writer.name(), writer.numberOfComponents(),
29 writer.integrationOrder()};
30}
31
35 MeshLib::Mesh& mesh, MeshLib::IntegrationPointMetaData const& ip_meta_data)
36{
37 // Store the field data.
39 mesh, "IntegrationPointMetaData",
41 dictionary.assign(ip_meta_data.toJsonString());
42}
43
44namespace MeshLib
45{
47 MeshLib::Mesh& mesh,
48 std::vector<std::unique_ptr<IntegrationPointWriter>> const&
49 integration_point_writer)
50{
51 auto meta_data = IntegrationPointMetaData{
52 integration_point_writer |
53 ranges::views::transform(
54 [&](auto const& ip_writer)
55 { return addIntegrationPointData(mesh, *ip_writer); })};
56
57 if (!meta_data.empty())
58 {
60 }
61}
62
63std::optional<IntegrationPointMetaData> getIntegrationPointMetaData(
64 MeshLib::Properties const& properties)
65{
66 if (!properties.existsPropertyVector<char>("IntegrationPointMetaData"))
67 {
68 return std::nullopt;
69 }
70 auto const& mesh_property_ip_meta_data =
71 *properties.template getPropertyVector<char>(
72 "IntegrationPointMetaData");
73
74 if (mesh_property_ip_meta_data.getMeshItemType() !=
76 {
77 OGS_FATAL("IntegrationPointMetaData array must be field data.");
78 }
79
80 // Find the current integration point data entry and extract the
81 // meta data.
82 return IntegrationPointMetaData{std::string_view{
83 mesh_property_ip_meta_data.data(), mesh_property_ip_meta_data.size()}};
84}
85} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:10
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:89
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