19#include <dune/functions/backends/istlvectorbackend.hh>
20#include <dune/functions/functionspacebases/boundarydofs.hh>
21#include <dune/functions/functionspacebases/flatmultiindex.hh>
22#include <dune/functions/functionspacebases/subspacebasis.hh>
26#include <autodiff/forward/real/real.hpp>
31template <
class K,
int N>
43template <Concepts::EigenVector T>
65template <
typename B,
typename FC = std::vector<
bool>>
69 using Basis = std::remove_cvref_t<B>;
72 using BackendType =
decltype(Dune::Functions::istlVectorBackend(std::declval<FlagsType&>()));
76 dirichletFlagsBackend_{dirichletFlags_} {
77 dirichletFlagsBackend_.resize(basis_);
78 std::fill(dirichletFlags_.begin(), dirichletFlags_.end(),
false);
79 inhomogeneousBoundaryVectorDummy_.setZero(
static_cast<Eigen::Index
>(basis_.size()));
91 template <
typename F,
typename TreePath = Dune::TypeTree::Hybr
idTreePath<>>
93 using namespace Dune::Functions;
94 using SubSpaceLocalView =
95 typename std::remove_cvref_t<decltype(subspaceBasis(basis_, std::forward<TreePath>(treePath)))>::LocalView;
98 auto lambda = [&](
auto&& indexGlobal) { f(dirichletFlagsBackend_, indexGlobal); };
99 Dune::Functions::forEachBoundaryDOF(subspaceBasis(basis_, std::forward<TreePath>(treePath)), lambda);
100 }
else if constexpr (Concepts::IsFunctorWithArgs<F, BackendType, int, SubSpaceLocalView>) {
101 auto lambda = [&](
auto&& localIndex,
auto&& localView) { f(dirichletFlagsBackend_, localIndex, localView); };
102 Dune::Functions::forEachBoundaryDOF(subspaceBasis(basis_, std::forward<TreePath>(treePath)), lambda);
103 }
else if constexpr (Concepts::IsFunctorWithArgs<F,
BackendType, int, SubSpaceLocalView,
104 typename Basis::GridView::Intersection>) {
105 auto lambda = [&](
auto&& localIndex,
auto&& localView,
auto&& intersection) {
106 f(dirichletFlagsBackend_, localIndex, localView, intersection);
108 Dune::Functions::forEachBoundaryDOF(subspaceBasis(basis_, std::forward<TreePath>(treePath)), lambda);
110 static_assert(Dune::AlwaysFalse<F>(),
"fixBoundaryDOFs: A function with this signature is not supported");
122 template <
typename F>
124 f(basis_, dirichletFlagsBackend_);
133 template <
typename MultiIndex>
134 requires(not std::integral<MultiIndex>)
136 dirichletFlagsBackend_[i] = flag;
147 requires(std::same_as<typename Basis::MultiIndex, Dune::Functions::FlatMultiIndex<size_t>>)
149 dirichletFlags_[i] = flag;
156 std::fill(dirichletFlags_.begin(), dirichletFlags_.end(),
false);
157 inhomogeneousBoundaryVectorDummy_.setZero(
static_cast<Eigen::Index
>(basis_.size()));
161 const auto&
basis()
const {
return basis_; }
164 template <
typename MultiIndex>
165 requires(not std::integral<MultiIndex>)
167 return dirichletFlagsBackend_[multiIndex];
172 requires(std::same_as<typename Basis::MultiIndex, Dune::Functions::FlatMultiIndex<size_t>>)
174 return dirichletFlags_[i];
178 auto fixedDOFsize()
const {
return std::ranges::count(dirichletFlags_,
true); }
181 auto size()
const {
return dirichletFlags_.size(); }
195 template <
typename F>
197 auto derivativeLambda = [&](
const auto& globalCoord,
const double& lambda) {
198 autodiff::real lambdaDual = lambda;
200 return derivative(f(globalCoord, lambdaDual));
202 dirichletFunctions_.push_back({f, derivativeLambda});
215 inhomogeneousBoundaryVectorDummy_.setZero();
216 xIh.resizeLike(inhomogeneousBoundaryVectorDummy_);
218 for (
auto& f : dirichletFunctions_) {
220 basis_, inhomogeneousBoundaryVectorDummy_,
221 [&](
const auto& globalCoord) {
return f.value(globalCoord, lambda); }, dirichletFlagsBackend_);
222 xIh += inhomogeneousBoundaryVectorDummy_;
236 inhomogeneousBoundaryVectorDummy_.setZero();
237 xIh.resizeLike(inhomogeneousBoundaryVectorDummy_);
239 for (
auto& f : dirichletFunctions_) {
241 basis_, inhomogeneousBoundaryVectorDummy_,
242 [&](
const auto& globalCoord) {
return f.derivative(globalCoord, lambda); }, dirichletFlagsBackend_);
243 xIh += inhomogeneousBoundaryVectorDummy_;
248 Eigen::VectorXd inhomogeneousBoundaryVectorDummy_;
252 struct DirichletFunctions
254 using Signature = std::function<Eigen::Vector<double, worldDimension>(
257 Signature derivative;
259 std::vector<DirichletFunctions> dirichletFunctions_;
Definition: assemblermanipulatorbuildingblocks.hh:22
Definition: utils/dirichletvalues.hh:30
Definition: utils/dirichletvalues.hh:32
A helper struct to derive the SizeType of the underlying container.
Definition: utils/dirichletvalues.hh:41
Eigen::Index SizeType
Definition: utils/dirichletvalues.hh:46
std::vector< bool >::size_type SizeType
Definition: utils/dirichletvalues.hh:52
Class for handling Dirichlet boundary conditions in Ikarus.
Definition: utils/dirichletvalues.hh:67
auto size() const
Definition: utils/dirichletvalues.hh:181
void setSingleDOF(const MultiIndex i, bool flag)
Fixes and unfixes (set boolean value to true or false) a specific degree of freedom.
Definition: utils/dirichletvalues.hh:135
bool isConstrained(const MultiIndex &multiIndex) const
Definition: utils/dirichletvalues.hh:166
bool isConstrained(std::size_t i) const
Definition: utils/dirichletvalues.hh:171
void setSingleDOF(std::size_t i, bool flag)
Fixes or unfixes (set boolean value to true or false) a specific degree of freedom.
Definition: utils/dirichletvalues.hh:146
std::remove_cvref_t< B > Basis
Definition: utils/dirichletvalues.hh:69
void fixBoundaryDOFs(F &&f, TreePath &&treePath={})
Function to fix (set boolean values to true or false) degrees of freedom on the boundary.
Definition: utils/dirichletvalues.hh:92
decltype(Dune::Functions::istlVectorBackend(std::declval< FlagsType & >())) BackendType
Definition: utils/dirichletvalues.hh:72
void evaluateInhomogeneousBoundaryConditionDerivative(Eigen::VectorXd &xIh, const double &lambda)
Function to evaluate all stored inhomogeneous Dirichlet boundary derivative functions.
Definition: utils/dirichletvalues.hh:235
static constexpr int worldDimension
Definition: utils/dirichletvalues.hh:71
void fixDOFs(F &&f)
Function to fix (set boolean values to true or false) degrees of freedom.
Definition: utils/dirichletvalues.hh:123
FC FlagsType
Definition: utils/dirichletvalues.hh:70
void reset()
Resets all degrees of freedom.
Definition: utils/dirichletvalues.hh:155
void storeInhomogeneousBoundaryCondition(F &&f)
Function to insert a function for inhomogeneous Dirichlet boundary conditions.
Definition: utils/dirichletvalues.hh:196
void evaluateInhomogeneousBoundaryCondition(Eigen::VectorXd &xIh, const double &lambda)
Function to evaluate all stored inhomogeneous Dirichlet boundary functions.
Definition: utils/dirichletvalues.hh:214
typename DeriveSizeType< FlagsType >::SizeType SizeType
Definition: utils/dirichletvalues.hh:73
const auto & basis() const
Definition: utils/dirichletvalues.hh:161
auto fixedDOFsize() const
Definition: utils/dirichletvalues.hh:178
DirichletValues(const B &basis)
Definition: utils/dirichletvalues.hh:74
auto & container() const
Definition: utils/dirichletvalues.hh:184
Concept defining the requirements for functors with arguments.
Definition: concepts.hh:347