13#ifndef FUNCTIONAL_AUX_HH
14#define FUNCTIONAL_AUX_HH
18#include <dune/common/fvector.hh>
19#include <dune/common/fmatrix.hh>
61 template <ProblemType Type>
102 template <
int row,
int col>
151 template <
int row,
int col>
165 template <
class Cell>
168 return 2*shapeFunctionOrder;
181 template <
class Face>
196 template <
int ,
int >
199 return -10*std::numeric_limits<double>::epsilon();
211 template <
class TestVars,
int row>
230 template <
class TestVars,
int row,
class AnsatzVars,
int col>
239 template <
class Functional,
int n>
242 static constexpr bool ok = (!Functional::template D2<n,n>::present)
243 || Functional::template D2<n,n>::symmetric;
248 template <
class Functional>
251 static constexpr bool pass =
true;
255 template <
class Functional,
int n>
265 template <
int a,
int b>
268 static constexpr bool value = a<b;
271 template <
int a,
int b>
274 static constexpr bool value = a==b;
286 template <
class AnsatzVars,
class TestVars>
290 using Scalar =
typename AnsatzVars::Scalar;
292 template <
class Entity>
295 template <
class Position,
class Evaluators>
303 template <
int row,
int dim>
309 template <
int row,
int col,
int dim>
310 Dune::FieldMatrix <Scalar,TestVars::template components<row>,AnsatzVars::template components<row>>
333 template <
class Functional,
class Cache,
class ScalarT =
typename Functional::Scalar>
344 template <
int row>
using TestComponents = std::integral_constant<int,TestVars::template Components<row>::m>;
345 template <
int row>
using AnsatzComponents = std::integral_constant<int,AnsatzVars::template Components<row>::m>;
349 template <
int row,
int dimw>
352 return static_cast<Cache const*
>(
this)->
template d1_impl<row>(arg);
355 template <
int row,
int dimw>
362 template <int row, int dimw, class enable = typename std::enable_if_t<Functional_Aux_Detail::LessThan<1,TestComponents<row>::value>::value>>
365 Vector<row> result(0);
368 for(
int i=0; i<TestComponents<row>::value; ++i)
380 template <
int row,
int col,
int dim>
383 return static_cast<Cache const*
>(
this)->
template d2_impl<row,col>(arg1,arg2);
386 template <
int row,
int col,
int dim,
387 class enable1 =
typename std::enable_if_t<Functional_Aux_Detail::LessThan<1,TestComponents<row>::value>::value>,
388 class enable2 =
typename std::enable_if_t<Functional_Aux_Detail::LessThan<1,AnsatzComponents<row>::value>::value>
396 template <
int row,
int col,
int dim,
int m2,
397 class enable1 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,TestComponents<row>::value>::value>
::type,
398 class enable2 =
typename std::enable_if<Functional_Aux_Detail::Equals<m2,AnsatzComponents<col>::value>::value>
::type,
399 class enable3 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,AnsatzComponents<col>::value>::value>
::type
403 Vector<row> result(0);
405 for(
int i=0; i<AnsatzComponents<row>::value; ++i)
417 template <
int row,
int col,
int dim,
int m1,
418 class enable1 =
typename std::enable_if<Functional_Aux_Detail::Equals<m1,TestComponents<row>::value>::value>
::type,
419 class enable2 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,TestComponents<row>::value>::value>
::type,
420 class enable3 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,AnsatzComponents<col>::value>::value>
::type
424 Vector<row> result(0);
426 for(
int i=0; i<AnsatzComponents<row>::value; ++i)
438 template <
int row,
int col,
int dim>
441 Matrix<row,col> result(0);
444 for(
int i=0; i<TestComponents<row>::value; ++i)
448 for(
int j=0; j<AnsatzComponents<col>::value; ++j)
462 template <
int row,
int col,
int dim>
465 return static_cast<Cache const*
>(
this)->
template b2_impl<row,col>(arg1,arg2);
468 template <
int row,
int col,
int dim,
469 class enable1 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,TestComponents<row>::value>::value>
::type,
470 class enable2 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,AnsatzComponents<row>::value>::value>
::type
478 template <
int row,
int col,
int dim,
int m2,
479 class enable1 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,TestComponents<row>::value>::value>
::type,
480 class enable2 =
typename std::enable_if<Functional_Aux_Detail::Equals<m2,AnsatzComponents<col>::value>::value>
::type,
481 class enable3 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,AnsatzComponents<col>::value>::value>
::type
485 Vector<row> result(0);
487 for(
int i=0; i<AnsatzComponents<row>::value; ++i)
499 template <
int row,
int col,
int dim,
int m1,
500 class enable1 =
typename std::enable_if<Functional_Aux_Detail::Equals<m1,TestComponents<row>::value>::value>
::type,
501 class enable2 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,TestComponents<row>::value>::value>
::type,
502 class enable3 =
typename std::enable_if<Functional_Aux_Detail::LessThan<1,AnsatzComponents<col>::value>::value>
::type
506 Vector<row> result(0);
508 for(
int i=0; i<AnsatzComponents<row>::value; ++i)
520 template <
int row,
int col,
int dim>
523 Matrix<row,col> result(0);
526 for(
int i=0; i<TestComponents<row>::value; ++i)
530 for(
int j=0; j<AnsatzComponents<col>::value; ++j)
546 namespace Functional_Aux_Detail
551 template <
class Functional>
552 constexpr std::true_type hasInnerBoundaryCacheImpl(
typename Functional::InnerBoundaryCache*);
555 template <
class Functional>
556 constexpr std::false_type hasInnerBoundaryCacheImpl(...);
564 template <
class Functional>
566 decltype(Functional_Aux_Detail::hasInnerBoundaryCacheImpl<Functional>(
nullptr))::value;
575 template <
class Functional,
class Linearization,
bool hasInnerBoundaryCache>
576 struct InnerBoundaryPolicyImpl
580 template <
class Functional,
class Linearization>
581 struct InnerBoundaryPolicyImpl<Functional,Linearization,true>
583 using InnerBoundaryCache =
typename Functional::InnerBoundaryCache;
586 InnerBoundaryCache createInnerBoundaryCache(
int flags)
const
588 return InnerBoundaryCache(
static_cast<Linearization const*
>(
this)->getFunctional(),
589 static_cast<Linearization const*
>(
this)->getOrigin(),flags);
592 template <
class Face>
593 bool considerFace(
Face const& face)
const
595 return static_cast<Linearization const*
>(
this)->getFunctional().considerFace(face);
599 template <
class Functional,
class Linearization>
600 using InnerBoundaryPolicy = InnerBoundaryPolicyImpl<Functional,Linearization,hasInnerBoundaryCache<Functional>>;
620 template<
class Functional_>
621 class LinearizationAt :
public Functional_Aux_Detail::InnerBoundaryPolicy<Functional_,LinearizationAt<Functional_>>
627 typedef typename Functional::Scalar
Scalar;
676 struct D1:
public Functional::template
D1<row> {};
679 template <
int row,
int col>
680 struct D2:
public Functional::template
D2<row,col> {};
683 template <
class Cell>
686 return f.integrationOrder(cell,shapeFunctionOrder,boundary);
689 template <
int row,
int col>
712 return f.derivatives();
727 template<
class Functional>
756 template<
class Functional_>
758 :
public Functional_Aux_Detail::InnerBoundaryPolicy<Functional_,
759 LinearizationDifferenceAt<Functional_>>
765 typedef typename Functional::Scalar
Scalar;
787 :
f(f_),
u1(u1_),
u2(u2_) {};
793 : dc1(
f,
u1,flags), dc2(
f,
u2,flags) {}
795 template <
class Cell>
796 void moveTo(
Cell const& entity) { dc1.moveTo(entity); dc2.moveTo(entity); }
798 template <
class Position,
class Evaluators>
799 void evaluateAt(Position
const& x,
Evaluators const& evaluators) { dc1.evaluateAt(x,evaluators); dc2.evaluateAt(x,evaluators); }
803 template<
int row,
int dim>
810 template<
int row,
int col,
int dim>
819 typename Functional::DomainCache dc1, dc2;
826 : bc1(
f,
u1,flags), bc2(
f,
u2,flags) {}
828 template <
class FaceIterator>
829 void moveTo(FaceIterator
const& entity) { bc1.moveTo(entity); bc2.moveTo(entity); }
831 template <
class Position,
class Evaluators>
832 void evaluateAt(Position
const& x,
Evaluators const& evaluators) { bc1.evaluateAt(x,evaluators); bc2.evaluateAt(x,evaluators); }
836 template<
int row,
int dim>
843 template<
int row,
int col,
int dim>
851 typename Functional::BoundaryCache bc1, bc2;
870 struct D1:
public Functional::template
D1<row> {};
873 template <
int row,
int col>
874 struct D2:
public Functional::template
D2<row,col> {};
877 template <
class Cell>
895 template<
class Functional>
897 typename Functional::OriginVars::VariableSet
const & u1,
898 typename Functional::OriginVars::VariableSet
const & u2)
917 template <
class Functional>
929 typename Functional::AnsatzVars::VariableSet
const& u_,
930 typename Functional::AnsatzVars::VariableSet
const& uJ_,
931 typename Functional::AnsatzVars::VariableSet
const& du_):
936 return typename Functional::DomainCache(this->
f,this->
u,uJ,du,flags);
941 return typename Functional::BoundaryCache(this->
f,this->
u,uJ,du,flags);
945 typename Functional::AnsatzVars::VariableSet
const& uJ;
946 typename Functional::AnsatzVars::VariableSet
const& du;
949 template <
class Functional>
961 typename Functional::AnsatzVars::VariableSet
const& u_,
962 typename Functional::AnsatzVars::VariableSet
const& uJ_,
963 typename Functional::AnsatzVars::VariableSet
const& du_):
968 return typename Functional::DomainCache(this->
f,this->
u,uJ,du,flags);
973 return typename Functional::BoundaryCache(this->
f,this->
u,uJ,du,flags);
978 return typename Functional::InnerBoundaryCache(this->
f,this->
u,uJ,du,flags);
982 typename Functional::AnsatzVars::VariableSet
const& uJ;
983 typename Functional::AnsatzVars::VariableSet
const& du;
990 template<
class Functional>
992 typename Functional::AnsatzVars::VariableSet
const&
u,
993 typename Functional::AnsatzVars::VariableSet
const& uJ,
994 typename Functional::AnsatzVars::VariableSet
const& du)
Provides implementations of d1 and d2 for (possibly mixed) use of scalar and power spaces.
Matrix< row, col > d2(VariationalArg< Scalar, dim > const &scalarArg1, VariationalArg< Scalar, dim > const &scalarArg2) const
scalar argument for multi-component variables
Scalar b2_local(VariationalArg< Scalar, dim, TestComponents< row >::value > const &arg1, VariationalArg< Scalar, dim, AnsatzComponents< col >::value > const &arg2) const
forward to implementation via CRTP
Scalar d2_local(VariationalArg< Scalar, dim, TestComponents< row >::value > const &arg1, VariationalArg< Scalar, dim, AnsatzComponents< col >::value > const &arg2) const
forward to implementation via CRTP
Matrix< row, col > b2(VariationalArg< Scalar, dim > const &scalarArg1, VariationalArg< Scalar, dim > const &scalarArg2) const
scalar argument for multi-component variables
Scalar d1_local(VariationalArg< Scalar, dimw, TestComponents< row >::value > const &arg) const
forward to implementation via CRTP
Vector< row > d1(VariationalArg< Scalar, dimw > const &scalarArg) const
scalar argument for multi-component variables
typename Functional::AnsatzVars AnsatzVars
Vector< row > b2(VariationalArg< Scalar, dim > const &scalarArg, VariationalArg< Scalar, dim, m2 > const &arg2) const
scalar argument for multi-component variables
typename Functional::TestVars TestVars
Dune::FieldVector< Scalar, 1 > d1(VariationalArg< Scalar, dimw, TestComponents< row >::value > const &arg) const
Dune::FieldMatrix< Scalar, 1, 1 > d2(VariationalArg< Scalar, dim, TestComponents< row >::value > const &arg1, VariationalArg< Scalar, dim, AnsatzComponents< col >::value > const &arg2) const
Vector< row > b2(VariationalArg< Scalar, dim, m1 > const &arg1, VariationalArg< Scalar, dim > const &scalarArg) const
scalar argument for multi-component variables
Vector< row > d2(VariationalArg< Scalar, dim, m1 > const &arg1, VariationalArg< Scalar, dim > const &scalarArg) const
scalar argument for multi-component variables
Vector< row > d2(VariationalArg< Scalar, dim > const &scalarArg, VariationalArg< Scalar, dim, m2 > const &arg2) const
scalar argument for multi-component variables
Dune::FieldMatrix< Scalar, 1, 1 > b2(VariationalArg< Scalar, dim, TestComponents< row >::value > const &arg1, VariationalArg< Scalar, dim, AnsatzComponents< col >::value > const &arg2) const
Convenience base class for the easy definition of variational functionals and weak formulations.
bool considerFace(Face const &) const
Default implementation for which faces are to be considered for assembly in case an InnerBoundaryCach...
bool inDomain(T const &) const
int integrationOrder(Cell const &, int shapeFunctionOrder, bool) const
Default implementation specifying the integration order.
static constexpr ProblemType type
double makePositiveThreshold() const
Defines the eigenvalue threshold when enforcing positivity of local stiffness matrices.
Functional::DomainCache DomainCache
DomainCache createDomainCache(int flags) const
create a domain cache
PointOfLinearization const & getOrigin() const
Get point of linearization.
Functional::Scalar Scalar
Functional::OriginVars OriginVars
Functional::AnsatzVars AnsatzVars
int derivatives() const
Gives the highest derivative that arises in the weak formulation.
PointOfLinearization const & u
Functional::BoundaryCache BoundaryCache
LinearizationAt(Functional const &f_, PointOfLinearization const &u_)
Construct a linearization from a given functional.
static ProblemType const type
Functional const & getFunctional() const
Get functional.
Functional::TestVars TestVars
Functional::OriginVars::VariableSet PointOfLinearization
Type of variables around which the functional will be linearized.
auto makePositiveThreshold() const
int integrationOrder(Cell const &cell, int shapeFunctionOrder, bool boundary) const
integration order
BoundaryCache createBoundaryCache(int flags) const
create a boundary cache
void evaluateAt(Position const &x, Evaluators const &evaluators)
BoundaryCache(Functional const &f, PointOfLinearization const &u1, PointOfLinearization const &u2, int flags)
void moveTo(FaceIterator const &entity)
Dune::FieldVector< Scalar, TestVars::template Components< row >::m > d1(VariationalArg< Scalar, dim > const &arg) const
Dune::FieldMatrix< Scalar, TestVars::template Components< row >::m, AnsatzVars::template Components< col >::m > d2(VariationalArg< Scalar, dim > const &arg1, VariationalArg< Scalar, dim > const &arg2) const
DomainCache(Functional const &f, PointOfLinearization const &u1, PointOfLinearization const &u2, int flags)
void moveTo(Cell const &entity)
Dune::FieldVector< Scalar, TestVars::template Components< row >::m > d1(VariationalArg< Scalar, dim > const &arg) const
void evaluateAt(Position const &x, Evaluators const &evaluators)
Dune::FieldMatrix< Scalar, TestVars::template Components< row >::m, AnsatzVars::template Components< col >::m > d2(VariationalArg< Scalar, dim > const &arg1, VariationalArg< Scalar, dim > const &arg2) const
Proxy class for evaluating differences of linearizations of a nonlinear functional.
PointOfLinearization const & u1
PointOfLinearization const & u2
Functional::OriginVars::VariableSet PointOfLinearization
Type of variables around which the functional will be linearized.
Functional const & getFunctional() const
Get functional.
Functional::Scalar Scalar
int integrationOrder(Cell const &cell, int shapeFunctionOrder, bool boundary) const
integration order
LinearizationDifferenceAt(Functional const &f_, PointOfLinearization const &u1_, PointOfLinearization const &u2_)
Construct a difference of linearizations from a given functional.
Functional::OriginVars OriginVars
BoundaryCache createBoundaryCache(int flags) const
create a boundary cache
DomainCache createDomainCache(int flags) const
create a domain cache
static ProblemType const type
Functional::AnsatzVars AnsatzVars
Functional::TestVars TestVars
SemiLinearizationAt(Functional const &f_, typename Functional::AnsatzVars::VariableSet const &u_, typename Functional::AnsatzVars::VariableSet const &uJ_, typename Functional::AnsatzVars::VariableSet const &du_)
Constructor.
Functional::BoundaryCache createBoundaryCache(int flags) const
Functional::DomainCache createDomainCache(int flags) const
SemiLinearizationAt< Functional > semiLinearization(Functional const &f, typename Functional::AnsatzVars::VariableSet const &u, typename Functional::AnsatzVars::VariableSet const &uJ, typename Functional::AnsatzVars::VariableSet const &du)
Convenience routine for constructing semi-linearizations.
SemiLinearizationAtInner(Functional const &f_, typename Functional::AnsatzVars::VariableSet const &u_, typename Functional::AnsatzVars::VariableSet const &uJ_, typename Functional::AnsatzVars::VariableSet const &du_)
Constructor.
Functional::InnerBoundaryCache createInnerBoundaryCache(int flags) const
Functional::BoundaryCache createBoundaryCache(int flags) const
Functional::DomainCache createDomainCache(int flags) const
Base class simplifying the definition of domain and boundary caches.
Dune::FieldVector< Scalar, TestVars::template components< row > > d1(VariationalArg< Scalar, dim > const &arg) const
void evaluateAt(Position const &, Evaluators const &)
typename AnsatzVars::Scalar Scalar
Dune::FieldMatrix< Scalar, TestVars::template components< row >, AnsatzVars::template components< row > > d2(VariationalArg< Scalar, dim > const &, VariationalArg< Scalar, dim > const &) const
void moveTo(Entity const &)
FEFunctionSpace and FunctionSpaceElement and the like.
typename boost::fusion::result_of::as_vector< typename boost::fusion::result_of::transform< Spaces, GetEvaluatorTypes >::type >::type Evaluators
the heterogeneous sequence type of Evaluators for the given spaces
ProblemType
A type for describing the nature of a PDE problem.
constexpr bool hasInnerBoundaryCache
Checks whether InnerBoundaryCache is declared in Functional.
LinearizationAt< Functional > linearization(Functional const &f, typename Functional::OriginVars::VariableSet const &u)
Convenience routine: construct linearization without having to know the type of the functional.
typename GridView::Intersection Face
The type of faces in the grid view.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Dune::FieldMatrix< typename TestVars::Scalar, TestVars::template Components< row >::m, AnsatzVars::template Components< col >::m > D2Result
The return type of the d2() method of DomainCache and BoundaryCache.
Dune::FieldVector< typename TestVars::Scalar, TestVars::template Components< row >::m > D1Result
The return type of the d1() method of DomainCache and BoundaryCache.
LinearizationDifferenceAt< Functional > linearizationDifference(Functional const &f, typename Functional::OriginVars::VariableSet const &u1, typename Functional::OriginVars::VariableSet const &u2)
Convenience routine: construct linearization without having to know the type of the functional.
constexpr bool symmetryCheck
static constexpr bool pass
static constexpr bool pass
static bool const symmetric
static bool const present
static bool const constant
Static a priori default information about the right hand side blocks.
static constexpr bool present
Whether the block is to be assembled at all.
static constexpr int derivatives
The maximum ansatz and test function derivative occuring in this block.
Static a priori default information about the matrix blocks.
static constexpr bool constant
static constexpr bool makePositive
If this flag is true (and symmetric==true), the assembler will enforce positive semidefiniteness of a...
static constexpr int derivatives
The maximum ansatz and test function derivative occuring in this block.
static constexpr bool lumped
If this flag is true, only the diagonal of this block will be assembled and stored....
static constexpr bool symmetric
Whether the block is structurally symmetric (or hermitian). The default is true for diagonal blocks o...
static constexpr bool present
Whether the block is to be assembled and stored or not. The default value is the conservative one (bu...
A class that stores values, gradients, and Hessians of evaluated shape functions.
Dune::FieldMatrix< Scalar, components, dim > derivative
The shape function's spatial derivative, a components x dim matrix.
ValueType value
The shape function's value, a vector of dimension components