OGS
SetOrGetIntegrationPointData.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <Eigen/Core>
7#include <span>
8#include <vector>
9
11#include "TransposeInPlace.h"
12
13namespace ProcessLib
14{
15
16template <int DisplacementDim, typename IntegrationPointDataVector,
17 typename IpData, typename MemberType>
18std::vector<double> const& getIntegrationPointDimMatrixData(
19 IntegrationPointDataVector const& ip_data_vector,
20 MemberType IpData::*const member, std::vector<double>& cache)
21{
23 ip_data_vector,
24 [member](IpData const& ip_data) -> auto const&
25 { return ip_data.*member; },
26 cache);
27}
28
29template <int DisplacementDim, typename IntegrationPointDataVector,
30 typename Accessor>
31std::vector<double> const& getIntegrationPointDimMatrixData(
32 IntegrationPointDataVector const& ip_data_vector, Accessor&& accessor,
33 std::vector<double>& cache)
34{
35 using AccessorResult = decltype(std::declval<Accessor>()(
36 std::declval<IntegrationPointDataVector>()[0]));
37 static_assert(std::is_lvalue_reference_v<AccessorResult>,
38 "The ip data accessor should return a reference. This check "
39 "prevents accidental copies.");
40
41 auto const n_integration_points = ip_data_vector.size();
42 constexpr int size = DisplacementDim * DisplacementDim;
43
44 cache.clear();
45 auto cache_mat = MathLib::createZeroedMatrix<
46 Eigen::Matrix<double, size, Eigen::Dynamic, Eigen::RowMajor>>(
47 cache, size, n_integration_points);
48
49 for (unsigned ip = 0; ip < n_integration_points; ++ip)
50 {
51 auto const& dim_matix = accessor(ip_data_vector[ip]);
52 cache_mat.col(ip) = dim_matix.template reshaped<Eigen::RowMajor>();
53 }
54
55 return cache;
56}
57
58template <int DisplacementDim, typename IntegrationPointDataVector,
59 typename IpData, typename MemberType>
60std::vector<double> const& getIntegrationPointKelvinVectorData(
61 IntegrationPointDataVector const& ip_data_vector,
62 MemberType IpData::*const member, std::vector<double>& cache)
63{
65 ip_data_vector,
66 [member](IpData const& ip_data) -> auto const&
67 { return ip_data.*member; },
68 cache);
69}
70
71template <int DisplacementDim, typename IntegrationPointDataVector,
72 typename Accessor>
73std::vector<double> const& getIntegrationPointKelvinVectorData(
74 IntegrationPointDataVector const& ip_data_vector, Accessor&& accessor,
75 std::vector<double>& cache)
76{
77 using AccessorResult = decltype(std::declval<Accessor>()(
78 std::declval<IntegrationPointDataVector>()[0]));
79 static_assert(std::is_lvalue_reference_v<AccessorResult>,
80 "The ip data accessor should return a reference. This check "
81 "prevents accidental copies.");
82
83 constexpr int kelvin_vector_size =
85 auto const n_integration_points = ip_data_vector.size();
86
87 cache.clear();
88 auto cache_mat = MathLib::createZeroedMatrix<Eigen::Matrix<
89 double, kelvin_vector_size, Eigen::Dynamic, Eigen::RowMajor>>(
90 cache, kelvin_vector_size, n_integration_points);
91
92 for (unsigned ip = 0; ip < n_integration_points; ++ip)
93 {
94 auto const& kelvin_vector = accessor(ip_data_vector[ip]);
95 cache_mat.col(ip) =
97 }
98
99 return cache;
100}
101
106template <int DisplacementDim, typename IntegrationPointDataVector,
107 typename MemberType>
109 IntegrationPointDataVector const& ip_data_vector, MemberType member)
110{
111 constexpr int kelvin_vector_size =
113
115 [&](std::vector<double>& values)
116 {
118 ip_data_vector, member, values);
119 ;
120 });
121}
122
123template <int DisplacementDim, typename IntegrationPointDataVector,
124 typename IpData, typename MemberType>
126 double const* values,
127 IntegrationPointDataVector& ip_data_vector,
128 MemberType IpData::*const member)
129{
131 values, ip_data_vector,
132 [member](IpData& ip_data) -> auto& { return ip_data.*member; });
133}
134
135template <int DisplacementDim, typename IntegrationPointDataVector,
136 typename Accessor>
138 double const* values,
139 IntegrationPointDataVector& ip_data_vector,
140 Accessor&& accessor)
141{
142 using AccessorResult = decltype(std::declval<Accessor>()(
143 std::declval<IntegrationPointDataVector>()[0]));
144 static_assert(std::is_lvalue_reference_v<AccessorResult>,
145 "The ip data accessor must return a reference.");
146
147 constexpr int kelvin_vector_size =
149 auto const n_integration_points = ip_data_vector.size();
150
151 auto kelvin_vector_values =
152 Eigen::Map<Eigen::Matrix<double, kelvin_vector_size, Eigen::Dynamic,
153 Eigen::ColMajor> const>(
154 values, kelvin_vector_size, n_integration_points);
155
156 for (unsigned ip = 0; ip < n_integration_points; ++ip)
157 {
158 accessor(ip_data_vector[ip]) =
160 kelvin_vector_values.col(ip));
161 }
162
163 return n_integration_points;
164}
165
166template <typename IntegrationPointDataVector, typename IpData,
167 typename MemberType>
168std::vector<double> const& getIntegrationPointScalarData(
169 IntegrationPointDataVector const& ip_data_vector,
170 MemberType IpData::*const member, std::vector<double>& cache)
171{
173 ip_data_vector,
174 [member](IpData const& ip_data) -> auto const&
175 { return ip_data.*member; },
176 cache);
177}
178
179template <typename IntegrationPointDataVector, typename Accessor>
180std::vector<double> const& getIntegrationPointScalarData(
181 IntegrationPointDataVector const& ip_data_vector, Accessor&& accessor,
182 std::vector<double>& cache)
183{
184 using AccessorResult = decltype(std::declval<Accessor>()(
185 std::declval<IntegrationPointDataVector>()[0]));
186 static_assert(std::is_lvalue_reference_v<AccessorResult>,
187 "The ip data accessor should return a reference. This check "
188 "prevents accidental copies.");
189
190 auto const n_integration_points = ip_data_vector.size();
191
192 cache.clear();
193 auto cache_mat = MathLib::createZeroedMatrix<
194 Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor>>(
195 cache, 1, n_integration_points);
196
197 for (unsigned ip = 0; ip < n_integration_points; ++ip)
198 {
199 cache_mat[ip] = accessor(ip_data_vector[ip]);
200 }
201
202 return cache;
203}
204
205template <typename IntegrationPointDataVector, typename IpData,
206 typename MemberType>
208 double const* values,
209 IntegrationPointDataVector& ip_data_vector,
210 MemberType IpData::*const member)
211{
212 return setIntegrationPointScalarData(values, ip_data_vector,
213 [member](IpData& ip_data) -> auto&
214 { return ip_data.*member; });
215}
216
217template <typename IntegrationPointDataVector, typename Accessor>
219 double const* values,
220 IntegrationPointDataVector& ip_data_vector,
221 Accessor&& accessor)
222{
223 using AccessorResult = decltype(std::declval<Accessor>()(
224 std::declval<IntegrationPointDataVector>()[0]));
225 static_assert(std::is_lvalue_reference_v<AccessorResult>,
226 "The ip data accessor must return a reference.");
227
228 auto const n_integration_points = ip_data_vector.size();
229
230 for (unsigned ip = 0; ip < n_integration_points; ++ip)
231 {
232 accessor(ip_data_vector[ip]) = values[ip];
233 }
234 return n_integration_points;
235}
236
237template <typename IntegrationPointDataVector, typename MemberType,
238 typename MaterialStateVariables>
240 IntegrationPointDataVector const& ip_data_vector,
241 MemberType member,
242 std::function<std::span<double>(MaterialStateVariables&)>
243 get_values_span,
244 int const n_components)
245{
246 std::vector<double> result;
247 result.reserve(ip_data_vector.size() * n_components);
248
249 for (auto& ip_data : ip_data_vector)
250 {
251 auto const values_span = get_values_span(*(ip_data.*member));
252 assert(values_span.size() == static_cast<std::size_t>(n_components));
253
254 result.insert(end(result), values_span.begin(), values_span.end());
255 }
256
257 return result;
258}
259
260template <typename IntegrationPointDataVector, typename MemberType,
261 typename MaterialStateVariables>
263 double const* values,
264 IntegrationPointDataVector& ip_data_vector,
265 MemberType member,
266 std::function<std::span<double>(MaterialStateVariables&)>
267 get_values_span)
268{
269 auto const n_integration_points = ip_data_vector.size();
270
271 std::size_t position = 0;
272 for (auto const& ip_data : ip_data_vector)
273 {
274 auto const values_span = get_values_span(*(ip_data.*member));
275 std::copy_n(values + position, values_span.size(), values_span.begin());
276 position += values_span.size();
277 }
278 return n_integration_points;
279}
280} // namespace ProcessLib
Eigen::Matrix< double, 4, 1 > kelvinVectorToSymmetricTensor(Eigen::Matrix< double, 4, 1, Eigen::ColMajor, 4, 1 > const &v)
constexpr int kelvin_vector_dimensions(int const displacement_dim)
Kelvin vector dimensions for given displacement dimension.
Eigen::Matrix< double, Eigen::MatrixBase< Derived >::RowsAtCompileTime, 1 > symmetricTensorToKelvinVector(Eigen::MatrixBase< Derived > const &v)
Eigen::Map< Matrix > createZeroedMatrix(std::vector< double > &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
std::vector< double > const & getIntegrationPointScalarData(IntegrationPointDataVector const &ip_data_vector, MemberType IpData::*const member, std::vector< double > &cache)
std::size_t setIntegrationPointDataMaterialStateVariables(double const *values, IntegrationPointDataVector &ip_data_vector, MemberType member, std::function< std::span< double >(MaterialStateVariables &)> get_values_span)
std::vector< double > transposeInPlace(StoreValuesFunction const &store_values_function)
std::vector< double > getIntegrationPointDataMaterialStateVariables(IntegrationPointDataVector const &ip_data_vector, MemberType member, std::function< std::span< double >(MaterialStateVariables &)> get_values_span, int const n_components)
std::vector< double > const & getIntegrationPointDimMatrixData(IntegrationPointDataVector const &ip_data_vector, MemberType IpData::*const member, std::vector< double > &cache)
std::vector< double > const & getIntegrationPointKelvinVectorData(IntegrationPointDataVector const &ip_data_vector, MemberType IpData::*const member, std::vector< double > &cache)
std::size_t setIntegrationPointKelvinVectorData(double const *values, IntegrationPointDataVector &ip_data_vector, MemberType IpData::*const member)
std::size_t setIntegrationPointScalarData(double const *values, IntegrationPointDataVector &ip_data_vector, MemberType IpData::*const member)