45 const unsigned num_components,
48 std::vector<GlobalVector*>
const& x,
49 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_table)
51 auto const num_nodal_dof_result =
54 std::vector<GlobalIndexType> ghost_indices;
58 auto const& single_component_ghost_indices =
60 auto const single_component_ghost_indices_size =
61 single_component_ghost_indices.size();
62 ghost_indices.reserve(single_component_ghost_indices_size *
64 for (
unsigned i = 0; i < single_component_ghost_indices_size; ++i)
66 for (
unsigned c = 0; c < num_components; ++c)
68 ghost_indices.push_back(
69 single_component_ghost_indices[i] * num_components + c);
83 {num_nodal_dof_result, num_nodal_dof_result, &ghost_indices,
94 auto const size = extrapolatables.
size();
95 for (std::size_t i = 0; i < size; ++i)
108 const unsigned num_components,
111 std::vector<GlobalVector*>
const& x,
112 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_table)
126 if (
static_cast<std::size_t
>(num_element_dof_result) !=
127 extrapolatables.
size() * num_components)
129 OGS_FATAL(
"mismatch in number of D.o.F.");
132 auto const size = extrapolatables.
size();
133 for (std::size_t i = 0; i < size; ++i)
142 std::size_t
const element_index,
143 const unsigned num_components,
146 std::vector<GlobalVector*>
const& x,
147 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_table,
150 auto const& integration_point_values =
155 if (integration_point_values.empty())
160 auto const& N_0 = extrapolatables.
getShapeMatrix(element_index, 0);
161 auto const num_nodes =
static_cast<unsigned>(N_0.cols());
162 auto const num_values =
163 static_cast<unsigned>(integration_point_values.size());
165 if (num_values % num_components != 0)
168 "The number of computed integration point values is not divisible "
169 "by the number of num_components. Maybe the computed property is "
170 "not a {:d}-component vector for each integration point.",
175 const auto num_int_pts = num_values / num_components;
177 if (num_int_pts < num_nodes)
180 "Least squares is not possible if there are more nodes than "
181 "integration points.");
185 std::make_pair(num_nodes, num_int_pts),
CachedData{});
187 auto& cached_data = pair_it_inserted.first->second;
188 if (pair_it_inserted.second)
190 DBUG(
"Computing new singular value decomposition");
195 auto& interpolation_matrix = cached_data.A;
196 interpolation_matrix.resize(num_int_pts, num_nodes);
198 interpolation_matrix.row(0) = N_0;
199 for (
unsigned int_pt = 1; int_pt < num_int_pts; ++int_pt)
201 auto const& shp_mat =
203 assert(shp_mat.cols() == num_nodes);
206 interpolation_matrix.row(int_pt) = shp_mat;
215 Eigen::JacobiSVD<Eigen::MatrixXd> svd(
216 interpolation_matrix, Eigen::ComputeThinU | Eigen::ComputeThinV);
218 auto const& S = svd.singularValues();
219 auto const& U = svd.matrixU();
220 auto const& V = svd.matrixV();
223 auto const rank = svd.rank();
224 assert(rank == num_nodes);
227 cached_data.A_pinv.noalias() = V.leftCols(rank) *
228 S.head(rank).asDiagonal().inverse() *
229 U.leftCols(rank).transpose();
231 else if (cached_data.A.row(0) != N_0)
233 OGS_FATAL(
"The cached and the passed shapematrices differ.");
236 auto const& global_indices =
239 if (num_components == 1)
241 auto const integration_point_values_vec =
245 Eigen::VectorXd
const nodal_values =
246 cached_data.A_pinv * integration_point_values_vec;
251 counts.
add(global_indices,
252 std::vector<double>(global_indices.size(), 1.0));
257 integration_point_values, num_components, num_int_pts);
260 Eigen::MatrixXd
const nodal_values =
261 cached_data.A_pinv * integration_point_values_mat.transpose();
263 std::vector<GlobalIndexType> indices;
264 indices.reserve(num_components * global_indices.size());
267 for (
unsigned comp = 0; comp < num_components; ++comp)
269 transform(cbegin(global_indices), cend(global_indices),
270 back_inserter(indices),
271 [&](
auto const i) {
return num_components * i + comp; });
277 counts.
add(indices, std::vector<double>(indices.size(), 1.0));
282 std::size_t
const element_index,
283 const unsigned num_components,
286 std::vector<GlobalVector*>
const& x,
287 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_table)
292 auto const num_values =
static_cast<unsigned>(int_pt_vals.size());
293 if (num_values % num_components != 0)
296 "The number of computed integration point values is not divisible "
297 "by the number of num_components. Maybe the computed property is "
298 "not a {:d}-component vector for each integration point.",
303 const auto num_int_pts = num_values / num_components;
305 const auto& global_indices =
307 const auto num_nodes =
static_cast<unsigned>(global_indices.size());
309 auto const& interpolation_matrix =
312 Eigen::VectorXd nodal_vals_element(num_nodes);
313 auto const int_pt_vals_mat =
318 for (
unsigned comp = 0; comp < num_components; ++comp)
321 for (
unsigned i = 0; i < num_nodes; ++i)
324 auto const idx = num_components * global_indices[i] + comp;
328 double const residual = (interpolation_matrix * nodal_vals_element -
329 int_pt_vals_mat.row(comp).transpose())
335 auto const root_mean_square = std::sqrt(residual / num_int_pts);