OGS
CellAverageAlgorithm.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 "CellAverageData.h"
8
9namespace ProcessLib
10{
11namespace detail
12{
13void computeCellAverages(CellAverageData& cell_average_data,
14 std::string const& name, unsigned const num_comp,
15 auto&& flattened_ip_data_accessor,
16 auto const& local_assemblers)
17{
18 auto& prop_vec =
19 cell_average_data.getOrCreatePropertyVector(name, num_comp);
20
21 for (std::size_t i = 0; i < local_assemblers.size(); ++i)
22 {
23 auto const& loc_asm = *local_assemblers[i];
24 auto const& ip_data = flattened_ip_data_accessor(loc_asm);
25 assert(ip_data.size() % num_comp == 0);
26 auto const num_ips =
27 static_cast<Eigen::Index>(ip_data.size() / num_comp);
28 Eigen::Map<const Eigen::MatrixXd> ip_data_mapped{ip_data.data(),
29 num_comp, num_ips};
30
31 Eigen::Map<Eigen::VectorXd>{&prop_vec[i * num_comp], num_comp} =
32 ip_data_mapped.rowwise().mean();
33 }
34}
35} // namespace detail
36
37template <int dim, typename LAIntf>
39 CellAverageData& cell_average_data,
40 std::vector<std::unique_ptr<LAIntf>> const& local_assemblers)
41{
42 auto const callback = [&cell_average_data, &local_assemblers](
43 std::string const& name,
44 unsigned const num_comp,
45 auto&& flattened_ip_data_accessor)
46 {
47 detail::computeCellAverages(cell_average_data, name, num_comp,
48 flattened_ip_data_accessor,
49 local_assemblers);
50 };
51
53 LAIntf>(
54 LAIntf::getReflectionDataForOutput(), callback);
55}
56} // namespace ProcessLib
void forEachReflectedFlattenedIPDataAccessor(ReflData const &reflection_data, Callback const &callback)
void computeCellAverages(CellAverageData &cell_average_data, std::string const &name, unsigned const num_comp, auto &&flattened_ip_data_accessor, auto const &local_assemblers)
void computeCellAverages(CellAverageData &cell_average_data, std::vector< std::unique_ptr< LAIntf > > const &local_assemblers)
MeshLib::PropertyVector< double > & getOrCreatePropertyVector(std::string const &name, unsigned const num_comp)