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
26template <typename Traits, typename ST>
28 const typename Traits::FERequirementType::SolutionVectorTypeRaw& x, const typename Traits::LocalView& localView,
29 const std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>& dx = std::nullopt) {
30 constexpr int worldDim = Traits::worlddim;
31 const auto& fe = localView.tree().child(0).finiteElement();
32 Dune::BlockVector<Dune::RealTuple<ST, worldDim>> localX(fe.size());
33 if (dx)
34 for (auto i = 0U; i < localX.size(); ++i)
35 for (auto j = 0U; j < worldDim; ++j)
36 localX[i][j] =
37 dx.value().get()[i * worldDim + j] + x[localView.index(localView.tree().child(j).localIndex(i))[0]];
38 else
39 for (auto i = 0U; i < localX.size(); ++i)
40 for (auto j = 0U; j < worldDim; ++j)
41 localX[i][j] = x[localView.index(localView.tree().child(j).localIndex(i))[0]];
42 return localX;
43}
44
45namespace Impl {
56 template <typename LocalView, typename Node>
57 void leafNodeIndices(const LocalView& localView, const Node& node,
58 std::vector<typename LocalView::MultiIndex>& globalIndices) {
59 const auto& fe = node.finiteElement();
60 for (size_t i = 0; i < fe.size(); ++i)
61 globalIndices.push_back(localView.index(node.localIndex(i)));
62 }
63
74 template <typename LocalView, typename Node>
75 void powerNodeIndices(const LocalView& localView, const Node& node,
76 std::vector<typename LocalView::MultiIndex>& globalIndices) {
77 const auto& fe = node.child(0).finiteElement();
78 const int childrenSize = node.degree();
79 for (size_t i = 0; i < fe.size(); ++i)
80 for (int j = 0; j < childrenSize; ++j)
81 globalIndices.push_back(localView.index(node.child(j).localIndex(i)));
82 }
83} // namespace Impl
84
93template <typename LocalView>
94void globalIndicesFromLocalView(const LocalView& localView,
95 std::vector<typename LocalView::MultiIndex>& globalIndices) {
96 assert(localView.bound());
97 globalIndices.clear();
98 using namespace Dune::Indices;
99 using namespace FEHelper::Impl;
100
101 auto leafOpFunc = [&](auto&& node, [[maybe_unused]] auto&& treePath) {
102 leafNodeIndices(localView, node, globalIndices);
103 };
104
105 auto powerOpFunc = [&](auto&& node, [[maybe_unused]] auto&& treePath) {
106 powerNodeIndices(localView, node, globalIndices);
107 };
108
109 utils::forEachLeafOrPowerLeafNode(localView.tree(), Dune::TypeTree::hybridTreePath(), powerOpFunc, leafOpFunc);
110}
111
123template <typename FiniteElement>
124void globalIndices(const FiniteElement& fe, std::vector<typename FiniteElement::LocalView::MultiIndex>& globalIndices) {
126}
127} // 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:94
void globalIndices(const FiniteElement &fe, std::vector< typename FiniteElement::LocalView::MultiIndex > &globalIndices)
Get the global indices for the provided finite element.
Definition: fehelper.hh:124
auto localSolutionBlockVector(const typename Traits::FERequirementType::SolutionVectorTypeRaw &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:27
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:30