version 0.4.7
fehelper.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2025 The Ikarus Developers ikarus@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
6#include <functional>
7#include <optional>
8
9#include <dune/localfefunctions/manifolds/realTuple.hh>
10
12
27template <typename Traits, typename Vector, typename ST>
29 const Vector& x, const typename Traits::LocalView& localView,
30 const std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>& dx = std::nullopt) {
31 constexpr int worldDim = Traits::worlddim;
32 const auto& fe = localView.tree().child(0).finiteElement();
33 Dune::BlockVector<Dune::RealTuple<ST, worldDim>> localX(fe.size());
34 if (dx) {
35 for (auto i = 0U; i < localX.size(); ++i)
36 for (auto j = 0U; j < worldDim; ++j)
37 localX[i][j] =
38 dx.value().get()[i * worldDim + j] + x[localView.index(localView.tree().child(j).localIndex(i))[0]];
39 } else {
40 for (auto i = 0U; i < localX.size(); ++i)
41 for (auto j = 0U; j < worldDim; ++j)
42 localX[i][j] = x[localView.index(localView.tree().child(j).localIndex(i))[0]];
43 }
44
45 return localX;
46}
47
61template <typename Traits, typename Vector, typename ST>
63 const Vector& x, const typename Traits::LocalView& localView, auto&& treePath,
64 const std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>& dx = std::nullopt) {
65 constexpr int worldDim = Traits::worlddim;
66 const auto& fe = localView.tree().child(treePath).finiteElement();
67 Dune::BlockVector<Dune::RealTuple<ST, 1>> localX(fe.size());
68 if (dx) {
69 for (auto i = 0U; i < localX.size(); ++i) {
70 auto iIdx = localView.index(localView.tree().child(treePath).localIndex(i))[0];
71 localX[i][0] = dx.value().get()[iIdx] + x[iIdx];
72 }
73 } else {
74 for (auto i = 0U; i < localX.size(); ++i)
75 localX[i][0] = x[localView.index(localView.tree().child(treePath).localIndex(i))[0]];
76 }
77
78 return localX;
79}
80
94template <typename Traits, typename Vector, typename ST>
96 const Vector& x, const typename Traits::LocalView& localView, auto&& treePath,
97 const std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>& dx = std::nullopt) {
98 constexpr int worldDim = Traits::worlddim;
99 const auto& fe = localView.tree().child(treePath).child(0).finiteElement();
100 Dune::BlockVector<Dune::RealTuple<ST, worldDim>> localX(fe.size());
101 if (dx) {
102 for (auto i = 0U; i < localX.size(); ++i)
103 for (auto j = 0U; j < worldDim; ++j) {
104 auto ijIndx = localView.index(localView.tree().child(treePath).child(j).localIndex(i))[0];
105 localX[i][j] = dx.value().get()[ijIndx] + x[ijIndx];
106 }
107 } else {
108 for (auto i = 0U; i < localX.size(); ++i)
109 for (auto j = 0U; j < worldDim; ++j)
110 localX[i][j] = x[localView.index(localView.tree().child(treePath).child(j).localIndex(i))[0]];
111 }
112
113 return localX;
114}
115
116namespace Impl {
127 template <typename LocalView, typename Node>
128 void leafNodeIndices(const LocalView& localView, const Node& node,
129 std::vector<typename LocalView::MultiIndex>& globalIndices) {
130 const auto& fe = node.finiteElement();
131 for (size_t i = 0; i < fe.size(); ++i)
132 globalIndices.push_back(localView.index(node.localIndex(i)));
133 }
134
145 template <typename LocalView, typename Node>
146 void powerNodeIndices(const LocalView& localView, const Node& node,
147 std::vector<typename LocalView::MultiIndex>& globalIndices) {
148 const auto& fe = node.child(0).finiteElement();
149 const int childrenSize = node.degree();
150 for (size_t i = 0; i < fe.size(); ++i)
151 for (int j = 0; j < childrenSize; ++j)
152 globalIndices.push_back(localView.index(node.child(j).localIndex(i)));
153 }
154} // namespace Impl
155
164template <typename LocalView>
165void globalIndicesFromLocalView(const LocalView& localView,
166 std::vector<typename LocalView::MultiIndex>& globalIndices) {
167 assert(localView.bound());
168 globalIndices.clear();
169 using namespace Dune::Indices;
170 using namespace FEHelper::Impl;
171
172 auto leafOpFunc = [&](auto&& node, [[maybe_unused]] auto&& treePath) {
173 leafNodeIndices(localView, node, globalIndices);
174 };
175
176 auto powerOpFunc = [&](auto&& node, [[maybe_unused]] auto&& treePath) {
177 powerNodeIndices(localView, node, globalIndices);
178 };
179
180 utils::forEachLeafOrPowerLeafNode(localView.tree(), Dune::TypeTree::hybridTreePath(), powerOpFunc, leafOpFunc);
181}
182
194template <typename FiniteElement>
195void globalIndices(const FiniteElement& fe, std::vector<typename FiniteElement::LocalView::MultiIndex>& globalIndices) {
197}
198} // namespace Ikarus::FEHelper
Contains functions to traverse through a tree to its different nodes.
Definition: fehelper.hh:13
auto localSolutionBlockVectorComposite(const Vector &x, const typename Traits::LocalView &localView, auto &&treePath, const std::optional< std::reference_wrapper< const Eigen::VectorX< ST > > > &dx=std::nullopt)
Gets the local solution Dune block vector for a particular power node child of a composite basis.
Definition: fehelper.hh:95
void globalIndicesFromLocalView(const LocalView &localView, std::vector< typename LocalView::MultiIndex > &globalIndices)
Get the global indices for the provided local view of an element.
Definition: fehelper.hh:165
void globalIndices(const FiniteElement &fe, std::vector< typename FiniteElement::LocalView::MultiIndex > &globalIndices)
Get the global indices for the provided finite element.
Definition: fehelper.hh:195
auto localSolutionBlockVector(const Vector &x, const typename Traits::LocalView &localView, const std::optional< std::reference_wrapper< const Eigen::VectorX< ST > > > &dx=std::nullopt)
Gets the local solution Dune block vector for a power basis.
Definition: fehelper.hh:28
auto localSolutionBlockVectorScalar(const Vector &x, const typename Traits::LocalView &localView, auto &&treePath, const std::optional< std::reference_wrapper< const Eigen::VectorX< ST > > > &dx=std::nullopt)
Gets the local solution Dune block vector for a scalar (or leaf) node of a power basis.
Definition: fehelper.hh:62
void forEachLeafOrPowerLeafNode(T &&tree, TreePath &&treePath, PowerFunc &&powerFunc, LeafFunc &&leafFunc)
A function which loops over all the nodes of a tree and performs different actions for a power node (...
Definition: traversal.hh:31