Commit 51ab2756 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Rename gradientAtQp into gradientOf and similarly other expressions

parent 200b1e32
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include <amdis/common/Concepts.hpp> #include <amdis/common/Concepts.hpp>
#include <amdis/common/TypeTraits.hpp> #include <amdis/common/TypeTraits.hpp>
#include <amdis/functions/ParallelGlobalBasis.hpp> #include <amdis/functions/ParallelGlobalBasis.hpp>
#include <amdis/gridfunctions/DiscreteFunction.hpp>
#include <amdis/typetree/TreePath.hpp> #include <amdis/typetree/TreePath.hpp>
namespace AMDiS namespace AMDiS
...@@ -86,50 +85,11 @@ namespace AMDiS ...@@ -86,50 +85,11 @@ namespace AMDiS
{} {}
/// Return the global basis /// Return the global basis
std::shared_ptr<GlobalBasis const> const& basis() const { return basis_; } std::shared_ptr<GlobalBasis const> const& basis() const
/// Transform the DOFVector into a DiscreteFunction
template <class... Indices>
auto discreteFunction(Indices... ii)
{
return DiscreteFunction{coefficients(), *basis_, makeTreePath(ii...)};
}
/// Transform the DOFVector into a DiscreteFunction
template <class... Indices>
auto discreteFunction(Indices... ii) const
{
return DiscreteFunction{coefficients(), *basis_, makeTreePath(ii...)};
}
/// Interpolation of GridFunction to DOFVector, assuming that there is no
/// reference to this DOFVector in the expression.
/// See \ref DiscreteFunction::interpolate_noalias
template <class Expr, class Tag = tag::average>
void interpolate_noalias(Expr&& expr, Tag strategy = {})
{
discreteFunction().interpolate_noalias(FWD(expr), strategy);
}
/// Interpolation of GridFunction to DOFVector.
/// See \ref DiscreteFunction::interpolate
template <class Expr, class Tag = tag::average>
void interpolate(Expr&& expr, Tag strategy = {})
{ {
discreteFunction().interpolate(FWD(expr), strategy); return basis_;
} }
/// Interpolation of GridFunction to DOFVector.
/// See \ref DiscreteFunction::interpolate
template <class Expr>
DOFVector& operator<<(Expr&& expr)
{
discreteFunction().interpolate(FWD(expr));
return *this;
}
Coefficients const& coefficients() const Coefficients const& coefficients() const
{ {
return static_cast<Coefficients const&>(*this); return static_cast<Coefficients const&>(*this);
...@@ -250,20 +210,6 @@ namespace AMDiS ...@@ -250,20 +210,6 @@ namespace AMDiS
return {FWD(basis), op}; return {FWD(basis), op};
} }
/// A Generator for a mutable \ref DiscreteFunction
template <class GB, class T, class... Indices>
auto discreteFunction(DOFVector<GB,T>& dofVec, Indices... ii)
{
return dofVec.discreteFunction(ii...);
}
/// A Generator for a mutable \ref DiscreteFunction
template <class GB, class T, class... Indices>
auto discreteFunction(DOFVector<GB,T> const& dofVec, Indices... ii)
{
return dofVec.discreteFunction(ii...);
}
} // end namespace AMDiS } // end namespace AMDiS
#include <amdis/DOFVector.inc.hpp> #include <amdis/DOFVector.inc.hpp>
...@@ -67,7 +67,7 @@ namespace AMDiS ...@@ -67,7 +67,7 @@ namespace AMDiS
{ {
test_exit_dbg(bool(oldSolution_), test_exit_dbg(bool(oldSolution_),
"OldSolution need to be created. Call initialize with INIT_UH_OLD."); "OldSolution need to be created. Call initialize with INIT_UH_OLD.");
return oldSolution_->discreteFunction(ii...); return valueOf(*oldSolution_, ii...);
} }
/// Implementation of \ref ProblemTimeInterface::transferInitialSolution(). /// Implementation of \ref ProblemTimeInterface::transferInitialSolution().
......
...@@ -372,7 +372,7 @@ namespace AMDiS ...@@ -372,7 +372,7 @@ namespace AMDiS
auto solution(Indices... ii) auto solution(Indices... ii)
{ {
assert(bool(solution_) && "You have to call initialize() before."); assert(bool(solution_) && "You have to call initialize() before.");
return solution_->discreteFunction(ii...); return valueOf(*solution_, ii...);
} }
/// Return a const view to a solution component /// Return a const view to a solution component
...@@ -380,7 +380,7 @@ namespace AMDiS ...@@ -380,7 +380,7 @@ namespace AMDiS
auto solution(Indices... ii) const auto solution(Indices... ii) const
{ {
assert(bool(solution_) && "You have to call initialize() before."); assert(bool(solution_) && "You have to call initialize() before.");
return solution_->discreteFunction(ii...); return valueOf(*solution_, ii...);
} }
......
...@@ -15,42 +15,54 @@ namespace AMDiS ...@@ -15,42 +15,54 @@ namespace AMDiS
{ {
namespace tag namespace tag
{ {
struct jacobian {};
struct gradient {}; struct gradient {};
struct divergence {}; struct divergence {};
struct partial { std::size_t comp = 0; }; struct partial { std::size_t comp = 0; };
// register possible types for derivative traits // register possible types for derivative traits
struct derivative_type : gradient, divergence, partial {}; struct derivative_type : jacobian, gradient, divergence, partial {};
} }
template <class Sig, class Type> template <class Sig, class Type>
struct DerivativeTraits; struct DerivativeTraits;
template <class R, class D> template <class R, class D>
struct DerivativeTraits<R(D), tag::gradient> struct DerivativeTraits<R(D), tag::jacobian>
: public Dune::Functions::DefaultDerivativeTraits<R(D)> : public Dune::Functions::DefaultDerivativeTraits<R(D)>
{}; {};
template <class R, class D> template <class R, class D>
struct DerivativeTraits<R(D), tag::partial> struct DerivativeTraits<R(D), tag::gradient>
: public Dune::Functions::DefaultDerivativeTraits<R(D)>
{};
template <class K, int n>
struct DerivativeTraits<K(Dune::FieldVector<K,n>), tag::gradient>
{ {
using Range = R; using Range = Dune::FieldVector<K,n>;
}; };
template <class K, class D> template <class K, int n>
struct DerivativeTraits<K(D), tag::divergence> struct DerivativeTraits<Dune::FieldVector<K,1>(Dune::FieldVector<K,n>), tag::gradient>
{ {
// error using Range = Dune::FieldVector<K,n>;
}; };
template <class K, int n, class D> template <class R, class K, int n>
struct DerivativeTraits<Dune::FieldVector<K,n>(D), tag::divergence> struct DerivativeTraits<R(Dune::FieldVector<K,n>), tag::partial>
{
using Range = R;
};
template <class K, int n>
struct DerivativeTraits<Dune::FieldVector<K,n>(Dune::FieldVector<K,n>), tag::divergence>
{ {
using Range = K; using Range = K;
}; };
template <class K, int n, int m, class D> template <class K, int n, int m>
struct DerivativeTraits<Dune::FieldMatrix<K,n,m>(D), tag::divergence> struct DerivativeTraits<Dune::FieldMatrix<K,n,m>(FieldVector<K,n>), tag::divergence>
{ {
using Range = Dune::FieldVector<K,m>; using Range = Dune::FieldVector<K,m>;
}; };
......
...@@ -28,7 +28,7 @@ namespace AMDiS ...@@ -28,7 +28,7 @@ namespace AMDiS
/// The range type of the LocalFunction /// The range type of the LocalFunction
using Range = R; using Range = R;
/// This LocalFunction has its own \ref derivative() function /// This LocalFunction has its own \ref derivativeOf() function
enum { hasDerivative = true }; enum { hasDerivative = true };
private: private:
...@@ -100,12 +100,12 @@ namespace AMDiS ...@@ -100,12 +100,12 @@ namespace AMDiS
* - The functor `F` must fulfill the concept \ref Concepts::HasDerivative * - The functor `F` must fulfill the concept \ref Concepts::HasDerivative
**/ **/
template <class R, class D, class LC, class F, class Type> template <class R, class D, class LC, class F, class Type>
auto derivative(AnalyticLocalFunction<R(D),LC,F> const& lf, Type const& type) auto derivativeOf(AnalyticLocalFunction<R(D),LC,F> const& lf, Type const& type)
{ {
static_assert(Concepts::HasDerivative<F,Type>, static_assert(Concepts::HasDerivative<F,Type>,
"No derivative(F,DerivativeType) defined for Functor F of AnalyticLocalFunction."); "No derivative(F,DerivativeType) defined for Functor F of AnalyticLocalFunction.");
auto df = derivative(lf.fct(), type); auto df = derivativeOf(lf.fct(), type);
using RawSignature = typename Dune::Functions::SignatureTraits<R(D)>::RawSignature; using RawSignature = typename Dune::Functions::SignatureTraits<R(D)>::RawSignature;
using DerivativeSignature = typename DerivativeTraits<RawSignature,Type>::Range(D); using DerivativeSignature = typename DerivativeTraits<RawSignature,Type>::Range(D);
...@@ -220,12 +220,12 @@ namespace AMDiS ...@@ -220,12 +220,12 @@ namespace AMDiS
* - Functor `F` must fulfill the concept \ref Concepts::HasDerivative<Type> * - Functor `F` must fulfill the concept \ref Concepts::HasDerivative<Type>
**/ **/
template <class F, class GV, class Type> template <class F, class GV, class Type>
auto derivative(AnalyticGridFunction<F,GV> const& gf, Type const& type) auto derivativeOf(AnalyticGridFunction<F,GV> const& gf, Type const& type)
{ {
static_assert(Concepts::HasDerivative<F,Type>, static_assert(Concepts::HasDerivative<F,Type>,
"No derivative(F,DerivativeType) defined for Functor of AnalyticLocalFunction."); "No derivative(F,DerivativeType) defined for Functor of AnalyticLocalFunction.");
auto df = derivative(gf.fct(), type); auto df = derivativeOf(gf.fct(), type);
return AnalyticGridFunction<decltype(df), GV>{df, gf.entitySet().gridView()}; return AnalyticGridFunction<decltype(df), GV>{df, gf.entitySet().gridView()};
} }
......
...@@ -30,7 +30,7 @@ namespace AMDiS ...@@ -30,7 +30,7 @@ namespace AMDiS
/// The range type of the LocalFunction /// The range type of the LocalFunction
using Range = R; using Range = R;
/// This LocalFunction has its own \ref derivative() function /// This LocalFunction has its own \ref derivativeOf() function
enum { hasDerivative = true }; enum { hasDerivative = true };
private: private:
......
...@@ -49,7 +49,7 @@ namespace AMDiS ...@@ -49,7 +49,7 @@ namespace AMDiS
return Dune::DiagonalMatrix<T,N>{T(1)}; return Dune::DiagonalMatrix<T,N>{T(1)};
} }
}; };
friend Derivative derivative(CoordsFunction const& /*f*/, tag::gradient) friend Derivative derivativeOf(CoordsFunction const& /*f*/, tag::gradient)
{ {
return Derivative{}; return Derivative{};
} }
...@@ -106,7 +106,7 @@ namespace AMDiS ...@@ -106,7 +106,7 @@ namespace AMDiS
int comp_; int comp_;
}; };
friend Derivative derivative(Self const& f, tag::gradient) friend Derivative derivativeOf(Self const& f, tag::gradient)
{ {
return Derivative{f.comp_}; return Derivative{f.comp_};
} }
......
...@@ -11,7 +11,7 @@ namespace AMDiS ...@@ -11,7 +11,7 @@ namespace AMDiS
/// The derivative of a localfunction as localfunction itself /// The derivative of a localfunction as localfunction itself
template <class LocalFunction, class Type, template <class LocalFunction, class Type,
REQUIRES(std::is_convertible_v<tag::derivative_type, Type>)> REQUIRES(std::is_convertible_v<tag::derivative_type, Type>)>
auto derivative(LocalFunction const& lf, Type const& type) auto derivativeOf(LocalFunction const& lf, Type const& type)
-> decltype(lf.makeDerivative(type)) -> decltype(lf.makeDerivative(type))
{ {
return lf.makeDerivative(type); return lf.makeDerivative(type);
...@@ -28,13 +28,13 @@ namespace AMDiS ...@@ -28,13 +28,13 @@ namespace AMDiS
struct HasDerivative struct HasDerivative
{ {
template <class F, class T> template <class F, class T>
auto require(F&& f, T&& t) -> decltype( derivative(f,t) ); auto require(F&& f, T&& t) -> decltype( derivativeOf(f,t) );
}; };
struct HasLocalFunctionDerivative struct HasLocalFunctionDerivative
{ {
template <class F, class T> template <class F, class T>
auto require(F&& f, T&& t) -> decltype( derivative(localFunction(f),t) ); auto require(F&& f, T&& t) -> decltype( derivativeOf(localFunction(f),t) );
}; };
struct HasPartial struct HasPartial
...@@ -46,7 +46,7 @@ namespace AMDiS ...@@ -46,7 +46,7 @@ namespace AMDiS
} // end namespace Definition } // end namespace Definition
/// \brief GridFunction GF has free function `derivative(F)` /// \brief GridFunction GF has free function `derivativeOf(F,type)`
template <class GF, class Type> template <class GF, class Type>
constexpr bool HasDerivative = models<Definition::HasDerivative(GF,Type)>; constexpr bool HasDerivative = models<Definition::HasDerivative(GF,Type)>;
...@@ -54,7 +54,7 @@ namespace AMDiS ...@@ -54,7 +54,7 @@ namespace AMDiS
using HasDerivative_t = models_t<Definition::HasDerivative(GF,Type)>; using HasDerivative_t = models_t<Definition::HasDerivative(GF,Type)>;
/// \brief GridFunction GF has free function `derivative(localFunction(F))` /// \brief GridFunction GF has free function `derivativeOf(localFunction(F))`
template <class GF, class Type> template <class GF, class Type>
constexpr bool HasLocalFunctionDerivative = models<Definition::HasLocalFunctionDerivative(GF,Type)>; constexpr bool HasLocalFunctionDerivative = models<Definition::HasLocalFunctionDerivative(GF,Type)>;
......
...@@ -48,7 +48,7 @@ namespace AMDiS ...@@ -48,7 +48,7 @@ namespace AMDiS
using RawSignature = typename Dune::Functions::SignatureTraits<GridFctRange(GridFctDomain)>::RawSignature; using RawSignature = typename Dune::Functions::SignatureTraits<GridFctRange(GridFctDomain)>::RawSignature;
using Traits = DerivativeTraits<RawSignature, Type>; using Traits = DerivativeTraits<RawSignature, Type>;
using LocalFunction = TYPEOF( derivative(localFunction(std::declval<GridFunction>()), std::declval<Type>()) ) ; using LocalFunction = TYPEOF( derivativeOf(localFunction(std::declval<GridFunction>()), std::declval<Type>()) ) ;
using LocalFctRange = typename Traits::Range; using LocalFctRange = typename Traits::Range;
using LocalFctDomain = typename GridFunction::EntitySet::LocalCoordinate; using LocalFctDomain = typename GridFunction::EntitySet::LocalCoordinate;
...@@ -96,7 +96,7 @@ namespace AMDiS ...@@ -96,7 +96,7 @@ namespace AMDiS
/// Return the derivative-localFunction of the GridFunction. /// Return the derivative-localFunction of the GridFunction.
LocalFunction makeLocalFunction() const LocalFunction makeLocalFunction() const
{ {
return derivative(localFunction(gridFct_), type_); return derivativeOf(localFunction(gridFct_), type_);
} }
/// Return the \ref EntitySet of the \ref GridFunction. /// Return the \ref EntitySet of the \ref GridFunction.
...@@ -111,26 +111,26 @@ namespace AMDiS ...@@ -111,26 +111,26 @@ namespace AMDiS
}; };
/// \fn derivative /// \fn derivativeOf
/// \brief Create a GridFunction representing the derivative of the given /// \brief Create a GridFunction representing the derivative of the given
/// Gridfunction. /// Gridfunction.
/** /**
* A GridFunction can be differentiated if the corresponding LocalFunction * A GridFunction can be differentiated if the corresponding LocalFunction
* provides a free function `derivative()` * provides a free function `derivativeOf()`
* *
* **Requirements:** * **Requirements:**
* - The type `GridFct` models the concept of a GridFunction * - The type `GridFct` models the concept of a GridFunction
* - The `GridFct` has no own `derivative()` function, i.e. it holds * - The `GridFct` has no own `derivativeOf()` function, i.e. it holds
* `GridFct::hasDerivative == false`. * `GridFct::hasDerivative == false`.
* - The localFunction of the `GridFct` models `Concepts::HasDerivative`. * - The localFunction of the `GridFct` models `Concepts::HasDerivative`.
**/ **/
template <class GridFct, class Type, template <class GridFct, class Type,
class LocalFct = decltype( localFunction(std::declval<GridFct>()) ), class LocalFct = decltype( localFunction(std::declval<GridFct>()) ),
REQUIRES(not GridFct::hasDerivative)> REQUIRES(not GridFct::hasDerivative)>
auto derivative(GridFct const& gridFct, Type const& type) auto derivativeOf(GridFct const& gridFct, Type const& type)
{ {
static_assert(Concepts::HasDerivative<LocalFct,Type>, static_assert(Concepts::HasDerivative<LocalFct,Type>,
"derivative(LocalFunction,type) not defined!"); "derivativeOf(LocalFunction,type) not defined!");
return DerivativeGridFunction<GridFct,Type>{gridFct, type}; return DerivativeGridFunction<GridFct,Type>{gridFct, type};
} }
...@@ -146,7 +146,7 @@ namespace AMDiS ...@@ -146,7 +146,7 @@ namespace AMDiS
template <class GridView> template <class GridView>
static auto create(Self const& self, GridView const& gridView) static auto create(Self const& self, GridView const& gridView)
{ {
return derivative(makeGridFunction(self.expr_, gridView), self.type_); return derivativeOf(makeGridFunction(self.expr_, gridView), self.type_);
} }
}; };
...@@ -163,7 +163,7 @@ namespace AMDiS ...@@ -163,7 +163,7 @@ namespace AMDiS
#endif #endif
/// \fn gradientAtQP /// \fn gradientOf
/// \brief Generator function for DerivativeGridFunction expressions. /// \brief Generator function for DerivativeGridFunction expressions.
/// \relates DerivativeGridFunction /// \relates DerivativeGridFunction
/** /**
...@@ -172,25 +172,25 @@ namespace AMDiS ...@@ -172,25 +172,25 @@ namespace AMDiS
* See \ref DerivativeGridFunction. * See \ref DerivativeGridFunction.
* *
* **Examples:** * **Examples:**
* - `gradientAtQP(prob.solution(_0))` * - `gradientOf(prob.solution(_0))`
* - `gradientAtQP(X(0) + X(1) + prob.solution(_0))` * - `gradientOf(X(0) + X(1) + prob.solution(_0))`
**/ **/
template <class Expr> template <class Expr>
auto gradientAtQP(Expr const& expr) auto gradientOf(Expr const& expr)
{ {
return DerivativePreGridFunction<Expr, tag::gradient>{expr}; return DerivativePreGridFunction<Expr, tag::gradient>{expr};
} }
/// Generates a Gridfunction representing the divergence of a vector-valued GridFunction. /// Generates a Gridfunction representing the divergence of a vector-valued GridFunction.
template <class Expr> template <class Expr>
auto divergenceAtQP(Expr const& expr) auto divergenceOf(Expr const& expr)
{ {
return DerivativePreGridFunction<Expr, tag::divergence>{expr}; return DerivativePreGridFunction<Expr, tag::divergence>{expr};
} }
/// Generates a Gridfunction representing the partial derivative of a GridFunction. /// Generates a Gridfunction representing the partial derivative of a GridFunction.
template <class Expr> template <class Expr>
auto partialAtQP(Expr const& expr, std::size_t i) auto partialDerivativeOf(Expr const& expr, std::size_t i)
{ {
return DerivativePreGridFunction<Expr, tag::partial>{expr, tag::partial{i}}; return DerivativePreGridFunction<Expr, tag::partial>{expr, tag::partial{i}};
} }
......
...@@ -32,12 +32,6 @@ namespace AMDiS ...@@ -32,12 +32,6 @@ namespace AMDiS
class DiscreteFunction; class DiscreteFunction;
// deduction guide
template <class Coeff, class GB, class Path>
DiscreteFunction(Coeff&, GB const&, Path const& path)
-> DiscreteFunction<Coeff, GB, TYPEOF(makeTreePath(path))>;
/// A mutable view on the subspace of a DOFVector, \relates DiscreteFunction /// A mutable view on the subspace of a DOFVector, \relates DiscreteFunction
template <class Coeff, class GB, class TreePath> template <class Coeff, class GB, class TreePath>
class DiscreteFunction class DiscreteFunction
...@@ -72,7 +66,7 @@ namespace AMDiS ...@@ -72,7 +66,7 @@ namespace AMDiS
/** /**
* **Example:** * **Example:**
* ``` * ```
* auto v = discreteFunction(prob.solutionVector(),0); * auto v = valueOf(prob.solutionVector(),0);
* v.interpolate_noalias([](auto const& x) { return x[0]; }); * v.interpolate_noalias([](auto const& x) { return x[0]; });
* ``` * ```
**/ **/
...@@ -83,11 +77,11 @@ namespace AMDiS ...@@ -83,11 +77,11 @@ namespace AMDiS
/** /**
* **Example:** * **Example:**
* ``` * ```
* auto v = discreteFunction(prob.solutionVector(),0); * auto v = valueOf(prob.solutionVector(),0);
* v.interpolate(v + [](auto const& x) { return x[0]; }); * v.interpolate(v + [](auto const& x) { return x[0]; });
* ``` * ```
* Allows to have a reference to the DOFVector in the expression, e.g. as * Allows to have a reference to the DOFVector in the expression, e.g. as
* \ref DiscreteFunction or \ref gradientAtQP() of a DiscreteFunction. * \ref DiscreteFunction or \ref gradientOf() of a DiscreteFunction.
**/ **/
template <class Expr, class Tag = tag::average> template <class Expr, class Tag = tag::average>
void interpolate(Expr&& expr, Tag strategy = {}); void interpolate(Expr&& expr, Tag strategy = {});
...@@ -261,6 +255,33 @@ namespace AMDiS ...@@ -261,6 +255,33 @@ namespace AMDiS
DiscreteFunction(DV&, Path...) DiscreteFunction(DV&, Path...)
-> DiscreteFunction<std::remove_reference_t<Coeff>,std::decay_t<GB>,TP>; -> DiscreteFunction<std::remove_reference_t<Coeff>,std::decay_t<GB>,TP>;
// grid functions representing the DOFVector