19#include <dune/functions/backends/istlvectorbackend.hh>
20#include <dune/functions/functionspacebases/boundarydofs.hh>
24#include <autodiff/forward/real/real.hpp>
29 template <
class K,
int N>
45 template <
typename Basis_,
typename FlagsType_ = std::vector<
bool>>
48 using Basis = std::remove_cvref_t<Basis_>;
51 using BackendType =
decltype(Dune::Functions::istlVectorBackend(std::declval<FlagsType&>()));
52 explicit DirichletValues(
const Basis_& p_basis) : basis_{p_basis}, dirichletFlagsBackend{dirichletFlags} {
53 dirichletFlagsBackend.resize(basis_);
54 std::fill(dirichletFlags.begin(), dirichletFlags.end(),
false);
55 inhomogeneousBoundaryVectorDummy.setZero(
static_cast<Eigen::Index
>(basis_.size()));
69 auto lambda = [&](
auto&& indexGlobal) { f(dirichletFlagsBackend, indexGlobal); };
70 Dune::Functions::forEachBoundaryDOF(basis_, lambda);
72 auto lambda = [&](
auto&& localIndex,
auto&& localView) { f(dirichletFlagsBackend, localIndex, localView); };
73 Dune::Functions::forEachBoundaryDOF(basis_, lambda);
75 typename Basis::GridView::Intersection>) {
76 auto lambda = [&](
auto&& localIndex,
auto&& localView,
auto&& intersection) {
77 f(dirichletFlagsBackend, localIndex, localView, intersection);
79 Dune::Functions::forEachBoundaryDOF(basis_, lambda);
93 f(basis_, dirichletFlagsBackend);
101 void fixIthDOF(
typename Basis::MultiIndex i) { dirichletFlagsBackend[i] =
true; }
104 const auto&
basis()
const {
return basis_; }
107 template <
typename MultiIndex>
108 requires(not std::integral<MultiIndex>) [[nodiscard]]
bool isConstrained(
const MultiIndex& multiIndex)
const {
109 return dirichletFlagsBackend[multiIndex];
113 [[nodiscard]]
bool isConstrained(std::size_t i)
const {
return dirichletFlags[i]; }
116 auto fixedDOFsize()
const {
return std::ranges::count(dirichletFlags,
true); }
119 auto size()
const {
return dirichletFlags.size(); }
133 template <
typename F>
135 auto derivativeLambda = [&](
const auto& globalCoord,
const double& lambda) {
136 autodiff::real lambdaDual = lambda;
138 return derivative(f(globalCoord, lambdaDual));
140 dirichletFunctions.push_back({f, derivativeLambda});
153 inhomogeneousBoundaryVectorDummy.setZero();
154 xIh.resizeLike(inhomogeneousBoundaryVectorDummy);
156 for (
auto& f : dirichletFunctions) {
158 basis_, inhomogeneousBoundaryVectorDummy,
159 [&](
const auto& globalCoord) {
return f.value(globalCoord, lambda); }, dirichletFlagsBackend);
160 xIh += inhomogeneousBoundaryVectorDummy;
174 inhomogeneousBoundaryVectorDummy.setZero();
175 xIh.resizeLike(inhomogeneousBoundaryVectorDummy);
177 for (
auto& f : dirichletFunctions) {
179 basis_, inhomogeneousBoundaryVectorDummy,
180 [&](
const auto& globalCoord) {
return f.derivative(globalCoord, lambda); }, dirichletFlagsBackend);
181 xIh += inhomogeneousBoundaryVectorDummy;
186 Eigen::VectorXd inhomogeneousBoundaryVectorDummy;
190 struct DirichletFunctions {
191 using Signature = std::function<Eigen::Vector<double, worldDimension>(
194 Signature derivative;
196 std::vector<DirichletFunctions> dirichletFunctions;
Definition: simpleassemblers.hh:21
Definition: resultevaluators.hh:17
Definition: resultevaluators.hh:20
Wrapper class for a hierarchical basis constructed from a pre-basis.
Definition: utils/basis.hh:29
Class for handling Dirichlet boundary conditions in Ikarus.
Definition: utils/dirichletvalues.hh:46
auto fixedDOFsize() const
Definition: utils/dirichletvalues.hh:116
decltype(Dune::Functions::istlVectorBackend(std::declval< FlagsType & >())) BackendType
Definition: utils/dirichletvalues.hh:51
DirichletValues(const Basis_ &p_basis)
Definition: utils/dirichletvalues.hh:52
void fixBoundaryDOFs(F &&f)
Function to fix (set boolean values to true or false) degrees of freedom on the boundary.
Definition: utils/dirichletvalues.hh:67
FlagsType_ FlagsType
Definition: utils/dirichletvalues.hh:49
std::remove_cvref_t< Basis_ > Basis
Definition: utils/dirichletvalues.hh:48
const auto & basis() const
Definition: utils/dirichletvalues.hh:104
void storeInhomogeneousBoundaryCondition(F &&f)
Function to insert a function for inhomogeneous Dirichlet boundary conditions.
Definition: utils/dirichletvalues.hh:134
bool isConstrained(const MultiIndex &multiIndex) const
Definition: utils/dirichletvalues.hh:108
static constexpr int worldDimension
Definition: utils/dirichletvalues.hh:50
void evaluateInhomogeneousBoundaryCondition(Eigen::VectorXd &xIh, const double &lambda)
Function to evaluate all stored inhomogeneous Dirichlet boundary functions.
Definition: utils/dirichletvalues.hh:152
bool isConstrained(std::size_t i) const
Definition: utils/dirichletvalues.hh:113
void fixDOFs(F &&f)
Function to fix (set boolean values to true or false) degrees of freedom.
Definition: utils/dirichletvalues.hh:92
void evaluateInhomogeneousBoundaryConditionDerivative(Eigen::VectorXd &xIh, const double &lambda)
Function to evaluate all stored inhomogeneous Dirichlet boundary derivative functions.
Definition: utils/dirichletvalues.hh:173
auto size() const
Definition: utils/dirichletvalues.hh:119
auto & container() const
Definition: utils/dirichletvalues.hh:122
void fixIthDOF(typename Basis::MultiIndex i)
Function to fix (set boolean values to true or false) of degrees of freedom.
Definition: utils/dirichletvalues.hh:101
Concept defining the requirements for functors with arguments.
Definition: concepts.hh:369