version 0.4.1
fehelper.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@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
48namespace Impl {
59 template <typename LocalView, typename Node>
60 void leafNodeIndices(const LocalView& localView, const Node& node,
61 std::vector<typename LocalView::MultiIndex>& globalIndices) {
62 const auto& fe = node.finiteElement();
63 for (size_t i = 0; i < fe.size(); ++i)
64 globalIndices.push_back(localView.index(node.localIndex(i)));
65 }
66
77 template <typename LocalView, typename Node>
78 void powerNodeIndices(const LocalView& localView, const Node& node,
79 std::vector<typename LocalView::MultiIndex>& globalIndices) {
80 const auto& fe = node.child(0).finiteElement();
81 const int childrenSize = node.degree();
82 for (size_t i = 0; i < fe.size(); ++i)
83 for (int j = 0; j < childrenSize; ++j)
84 globalIndices.push_back(localView.index(node.child(j).localIndex(i)));
85 }
86} // namespace Impl
87
96template <typename LocalView>
97void globalIndicesFromLocalView(const LocalView& localView,
98 std::vector<typename LocalView::MultiIndex>& globalIndices) {
99 assert(localView.bound());
100 globalIndices.clear();
101 using namespace Dune::Indices;
102 using namespace FEHelper::Impl;
103
104 auto leafOpFunc = [&](auto&& node, [[maybe_unused]] auto&& treePath) {
105 leafNodeIndices(localView, node, globalIndices);
106 };
107
108 auto powerOpFunc = [&](auto&& node, [[maybe_unused]] auto&& treePath) {
109 powerNodeIndices(localView, node, globalIndices);
110 };
111
112 utils::forEachLeafOrPowerLeafNode(localView.tree(), Dune::TypeTree::hybridTreePath(), powerOpFunc, leafOpFunc);
113}
114
126template <typename FiniteElement>
127void globalIndices(const FiniteElement& fe, std::vector<typename FiniteElement::LocalView::MultiIndex>& globalIndices) {
129}
130} // namespace Ikarus::FEHelper
Contains functions to traverse through a tree to its different nodes.
Definition: fehelper.hh:13
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:97
void globalIndices(const FiniteElement &fe, std::vector< typename FiniteElement::LocalView::MultiIndex > &globalIndices)
Get the global indices for the provided finite element.
Definition: fehelper.hh:127
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.
Definition: fehelper.hh:28
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