diff --git a/amdis/DOFVector.hpp b/amdis/DOFVector.hpp index ebd5e2c75bd833e35b4ed91f30190725b83188e8..060254029454f1872abab49fef4014290d0d432c 100644 --- a/amdis/DOFVector.hpp +++ b/amdis/DOFVector.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include namespace AMDiS @@ -86,50 +85,11 @@ namespace AMDiS {} /// Return the global basis - std::shared_ptr const& basis() const { return basis_; } - - /// Transform the DOFVector into a DiscreteFunction - template - auto discreteFunction(Indices... ii) - { - return DiscreteFunction{coefficients(), *basis_, makeTreePath(ii...)}; - } - - /// Transform the DOFVector into a DiscreteFunction - template - 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 - void interpolate_noalias(Expr&& expr, Tag strategy = {}) - { - discreteFunction().interpolate_noalias(FWD(expr), strategy); - } - - /// Interpolation of GridFunction to DOFVector. - /// See \ref DiscreteFunction::interpolate - template - void interpolate(Expr&& expr, Tag strategy = {}) + std::shared_ptr const& basis() const { - discreteFunction().interpolate(FWD(expr), strategy); + return basis_; } - /// Interpolation of GridFunction to DOFVector. - /// See \ref DiscreteFunction::interpolate - template - DOFVector& operator<<(Expr&& expr) - { - discreteFunction().interpolate(FWD(expr)); - return *this; - } - - Coefficients const& coefficients() const { return static_cast(*this); @@ -250,20 +210,6 @@ namespace AMDiS return {FWD(basis), op}; } - /// A Generator for a mutable \ref DiscreteFunction - template - auto discreteFunction(DOFVector& dofVec, Indices... ii) - { - return dofVec.discreteFunction(ii...); - } - - /// A Generator for a mutable \ref DiscreteFunction - template - auto discreteFunction(DOFVector const& dofVec, Indices... ii) - { - return dofVec.discreteFunction(ii...); - } - } // end namespace AMDiS #include diff --git a/amdis/ProblemInstat.hpp b/amdis/ProblemInstat.hpp index 55148dcdd873fe9a7f47a9d1943b1cb06ad9b983..896c5ba29d0ad0d15f22a5ee6ec05c29e741cce5 100644 --- a/amdis/ProblemInstat.hpp +++ b/amdis/ProblemInstat.hpp @@ -67,7 +67,7 @@ namespace AMDiS { test_exit_dbg(bool(oldSolution_), "OldSolution need to be created. Call initialize with INIT_UH_OLD."); - return oldSolution_->discreteFunction(ii...); + return valueOf(*oldSolution_, ii...); } /// Implementation of \ref ProblemTimeInterface::transferInitialSolution(). diff --git a/amdis/ProblemStat.hpp b/amdis/ProblemStat.hpp index 8d806cd9b269b00584cb3f484460dc74963bbd0a..494d33a617614b4863ed986fdb601ec772939606 100644 --- a/amdis/ProblemStat.hpp +++ b/amdis/ProblemStat.hpp @@ -372,7 +372,7 @@ namespace AMDiS auto solution(Indices... ii) { 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 @@ -380,7 +380,7 @@ namespace AMDiS auto solution(Indices... ii) const { assert(bool(solution_) && "You have to call initialize() before."); - return solution_->discreteFunction(ii...); + return valueOf(*solution_, ii...); } diff --git a/amdis/common/DerivativeTraits.hpp b/amdis/common/DerivativeTraits.hpp index e86e0ff698edb9a21fcbd5d7e98f0b0683d969b3..f4b11c1a072e9797b8edb04ec9f37f708fee9362 100644 --- a/amdis/common/DerivativeTraits.hpp +++ b/amdis/common/DerivativeTraits.hpp @@ -15,44 +15,56 @@ namespace AMDiS { namespace tag { + struct jacobian {}; struct gradient {}; struct divergence {}; struct partial { std::size_t comp = 0; }; // register possible types for derivative traits - struct derivative_type : gradient, divergence, partial {}; + struct derivative_type : jacobian, gradient, divergence, partial {}; } template struct DerivativeTraits; template - struct DerivativeTraits + struct DerivativeTraits : public Dune::Functions::DefaultDerivativeTraits {}; template - struct DerivativeTraits + struct DerivativeTraits + : public Dune::Functions::DefaultDerivativeTraits + {}; + + template + struct DerivativeTraits), tag::gradient> { - using Range = R; + using Range = Dune::FieldVector; }; - template - struct DerivativeTraits + template + struct DerivativeTraits(Dune::FieldVector), tag::gradient> { - // error + using Range = Dune::FieldVector; }; - template - struct DerivativeTraits(D), tag::divergence> + template + struct DerivativeTraits), tag::partial> + { + using Range = R; + }; + + template + struct DerivativeTraits(Dune::FieldVector), tag::divergence> { using Range = K; }; - template - struct DerivativeTraits(D), tag::divergence> + template + struct DerivativeTraits(FieldVector), tag::divergence> { using Range = Dune::FieldVector; }; -} // end namespace AMDiS \ No newline at end of file +} // end namespace AMDiS diff --git a/amdis/gridfunctions/AnalyticGridFunction.hpp b/amdis/gridfunctions/AnalyticGridFunction.hpp index 6c28fcf0d3324cb0ffb490a20735be3619973399..ae06b72acdc3443f80b30e4752ad21f7cedb0d67 100644 --- a/amdis/gridfunctions/AnalyticGridFunction.hpp +++ b/amdis/gridfunctions/AnalyticGridFunction.hpp @@ -28,7 +28,7 @@ namespace AMDiS /// The range type of the LocalFunction using Range = R; - /// This LocalFunction has its own \ref derivative() function + /// This LocalFunction has its own \ref derivativeOf() function enum { hasDerivative = true }; private: @@ -100,12 +100,12 @@ namespace AMDiS * - The functor F must fulfill the concept \ref Concepts::HasDerivative **/ template - auto derivative(AnalyticLocalFunction const& lf, Type const& type) + auto derivativeOf(AnalyticLocalFunction const& lf, Type const& type) { static_assert(Concepts::HasDerivative, "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::RawSignature; using DerivativeSignature = typename DerivativeTraits::Range(D); @@ -220,12 +220,12 @@ namespace AMDiS * - Functor F must fulfill the concept \ref Concepts::HasDerivative **/ template - auto derivative(AnalyticGridFunction const& gf, Type const& type) + auto derivativeOf(AnalyticGridFunction const& gf, Type const& type) { static_assert(Concepts::HasDerivative, "No derivative(F,DerivativeType) defined for Functor of AnalyticLocalFunction."); - auto df = derivative(gf.fct(), type); + auto df = derivativeOf(gf.fct(), type); return AnalyticGridFunction{df, gf.entitySet().gridView()}; } diff --git a/amdis/gridfunctions/ConstantGridFunction.hpp b/amdis/gridfunctions/ConstantGridFunction.hpp index ba8d3af4fe73265266c729530059e4cf9804b2ba..f5dafef51cd6e545b83aee5ff1fed0111e0fba43 100644 --- a/amdis/gridfunctions/ConstantGridFunction.hpp +++ b/amdis/gridfunctions/ConstantGridFunction.hpp @@ -30,7 +30,7 @@ namespace AMDiS /// The range type of the LocalFunction using Range = R; - /// This LocalFunction has its own \ref derivative() function + /// This LocalFunction has its own \ref derivativeOf() function enum { hasDerivative = true }; private: diff --git a/amdis/gridfunctions/CoordsGridFunction.hpp b/amdis/gridfunctions/CoordsGridFunction.hpp index 36e9b887f04b10b3cac8ee8621a7fd66f9840796..ed657d093168f7612eb2d95354e7acc0236e7ed2 100644 --- a/amdis/gridfunctions/CoordsGridFunction.hpp +++ b/amdis/gridfunctions/CoordsGridFunction.hpp @@ -49,7 +49,7 @@ namespace AMDiS return Dune::DiagonalMatrix{T(1)}; } }; - friend Derivative derivative(CoordsFunction const& /*f*/, tag::gradient) + friend Derivative derivativeOf(CoordsFunction const& /*f*/, tag::gradient) { return Derivative{}; } @@ -106,7 +106,7 @@ namespace AMDiS int comp_; }; - friend Derivative derivative(Self const& f, tag::gradient) + friend Derivative derivativeOf(Self const& f, tag::gradient) { return Derivative{f.comp_}; } diff --git a/amdis/gridfunctions/Derivative.hpp b/amdis/gridfunctions/Derivative.hpp index 6d9cb3e43a3e4174957d42f4c333ad3af76f8086..0db991fa32eae33a1e9b7da1fd57583cbb1795b4 100644 --- a/amdis/gridfunctions/Derivative.hpp +++ b/amdis/gridfunctions/Derivative.hpp @@ -11,7 +11,7 @@ namespace AMDiS /// The derivative of a localfunction as localfunction itself template )> - auto derivative(LocalFunction const& lf, Type const& type) + auto derivativeOf(LocalFunction const& lf, Type const& type) -> decltype(lf.makeDerivative(type)) { return lf.makeDerivative(type); @@ -28,13 +28,13 @@ namespace AMDiS struct HasDerivative { template - auto require(F&& f, T&& t) -> decltype( derivative(f,t) ); + auto require(F&& f, T&& t) -> decltype( derivativeOf(f,t) ); }; struct HasLocalFunctionDerivative { template - auto require(F&& f, T&& t) -> decltype( derivative(localFunction(f),t) ); + auto require(F&& f, T&& t) -> decltype( derivativeOf(localFunction(f),t) ); }; struct HasPartial @@ -46,7 +46,7 @@ namespace AMDiS } // end namespace Definition - /// \brief GridFunction GF has free function derivative(F) + /// \brief GridFunction GF has free function derivativeOf(F,type) template constexpr bool HasDerivative = models; @@ -54,7 +54,7 @@ namespace AMDiS using HasDerivative_t = models_t; - /// \brief GridFunction GF has free function derivative(localFunction(F)) + /// \brief GridFunction GF has free function derivativeOf(localFunction(F)) template constexpr bool HasLocalFunctionDerivative = models; diff --git a/amdis/gridfunctions/DerivativeGridFunction.hpp b/amdis/gridfunctions/DerivativeGridFunction.hpp index 660f4a642ad1fd76503b4b242dcee43fb9a2c569..9cae9b4b02e23599d5e2ac8607a160216663ac11 100644 --- a/amdis/gridfunctions/DerivativeGridFunction.hpp +++ b/amdis/gridfunctions/DerivativeGridFunction.hpp @@ -48,7 +48,7 @@ namespace AMDiS using RawSignature = typename Dune::Functions::SignatureTraits::RawSignature; using Traits = DerivativeTraits; - using LocalFunction = TYPEOF( derivative(localFunction(std::declval()), std::declval()) ) ; + using LocalFunction = TYPEOF( derivativeOf(localFunction(std::declval()), std::declval()) ) ; using LocalFctRange = typename Traits::Range; using LocalFctDomain = typename GridFunction::EntitySet::LocalCoordinate; @@ -96,7 +96,7 @@ namespace AMDiS /// Return the derivative-localFunction of the GridFunction. LocalFunction makeLocalFunction() const { - return derivative(localFunction(gridFct_), type_); + return derivativeOf(localFunction(gridFct_), type_); } /// Return the \ref EntitySet of the \ref GridFunction. @@ -111,26 +111,26 @@ namespace AMDiS }; - /// \fn derivative + /// \fn derivativeOf /// \brief Create a GridFunction representing the derivative of the given /// Gridfunction. /** * A GridFunction can be differentiated if the corresponding LocalFunction - * provides a free function derivative() + * provides a free function derivativeOf() * * **Requirements:** * - 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. * - The localFunction of the GridFct models Concepts::HasDerivative. **/ template ()) ), REQUIRES(not GridFct::hasDerivative)> - auto derivative(GridFct const& gridFct, Type const& type) + auto derivativeOf(GridFct const& gridFct, Type const& type) { static_assert(Concepts::HasDerivative, - "derivative(LocalFunction,type) not defined!"); + "derivativeOf(LocalFunction,type) not defined!"); return DerivativeGridFunction{gridFct, type}; } @@ -146,7 +146,7 @@ namespace AMDiS template 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 #endif - /// \fn gradientAtQP + /// \fn gradientOf /// \brief Generator function for DerivativeGridFunction expressions. /// \relates DerivativeGridFunction /** @@ -172,25 +172,25 @@ namespace AMDiS * See \ref DerivativeGridFunction. * * **Examples:** - * - gradientAtQP(prob.solution(_0)) - * - gradientAtQP(X(0) + X(1) + prob.solution(_0)) + * - gradientOf(prob.solution(_0)) + * - gradientOf(X(0) + X(1) + prob.solution(_0)) **/ template - auto gradientAtQP(Expr const& expr) + auto gradientOf(Expr const& expr) { return DerivativePreGridFunction{expr}; } /// Generates a Gridfunction representing the divergence of a vector-valued GridFunction. template - auto divergenceAtQP(Expr const& expr) + auto divergenceOf(Expr const& expr) { return DerivativePreGridFunction{expr}; } /// Generates a Gridfunction representing the partial derivative of a GridFunction. template - auto partialAtQP(Expr const& expr, std::size_t i) + auto partialDerivativeOf(Expr const& expr, std::size_t i) { return DerivativePreGridFunction{expr, tag::partial{i}}; } diff --git a/amdis/gridfunctions/DiscreteFunction.hpp b/amdis/gridfunctions/DiscreteFunction.hpp index 08581abc332b034420f26cdc6dc8c5a9b4c6a922..462d3336149c479ff01440d25d3eeb298da87ca7 100644 --- a/amdis/gridfunctions/DiscreteFunction.hpp +++ b/amdis/gridfunctions/DiscreteFunction.hpp @@ -32,12 +32,6 @@ namespace AMDiS class DiscreteFunction; - // deduction guide - template - DiscreteFunction(Coeff&, GB const&, Path const& path) - -> DiscreteFunction; - - /// A mutable view on the subspace of a DOFVector, \relates DiscreteFunction template class DiscreteFunction @@ -72,7 +66,7 @@ namespace AMDiS /** * **Example:** *  - * auto v = discreteFunction(prob.solutionVector(),0); + * auto v = valueOf(prob.solutionVector(),0); * v.interpolate_noalias([](auto const& x) { return x[0]; }); *  **/ @@ -83,11 +77,11 @@ namespace AMDiS /** * **Example:** *  - * auto v = discreteFunction(prob.solutionVector(),0); + * auto v = valueOf(prob.solutionVector(),0); * v.interpolate(v + [](auto const& x) { return x[0]; }); *  * 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 void interpolate(Expr&& expr, Tag strategy = {}); @@ -261,6 +255,33 @@ namespace AMDiS DiscreteFunction(DV&, Path...) -> DiscreteFunction,std::decay_t,TP>; + + // grid functions representing the DOFVector + // ----------------------------------------- + + /// A Generator for the childs of a mutable \ref DiscreteFunction + template + auto valueOf(DiscreteFunction& df, Indices... ii) + { + return df.child(ii...); + } + + /// A Generator for the childs of a const \ref DiscreteFunction + template + auto valueOf(DiscreteFunction const& df, Indices... ii) + { + return df.child(ii...); + } + + /// A Generator to transform a DOFVector into a \ref DiscreteFunction + template ().coefficients()), + class = decltype(std::declval().basis())> + auto valueOf(DV& dofVec, Indices... ii) + { + return DiscreteFunction{dofVec.coefficients(), *dofVec.basis(), makeTreePath(ii...)}; + } + } // end namespace AMDiS #include "DiscreteLocalFunction.inc.hpp" diff --git a/amdis/gridfunctions/FunctorGridFunction.hpp b/amdis/gridfunctions/FunctorGridFunction.hpp index 18a5a502b54338c67f9cf56ba1e77b3641621574..b24b0025dcc86f569204b6c50d7f1f9b3e639940 100644 --- a/amdis/gridfunctions/FunctorGridFunction.hpp +++ b/amdis/gridfunctions/FunctorGridFunction.hpp @@ -113,14 +113,14 @@ namespace AMDiS /// \brief Derivative of the LocalFunction of a FunctorGridFunction, utilizing /// the chain-rule. Only available if the functor provides partial derivatives. /** - * \f$d_x(f(lf(x)...)) = \sum_i d_i(f)[lf(x)...] * derivative(lf[i]) \f$ + * \f$d_x(f(lf(x)...)) = \sum_i d_i(f)[lf(x)...] * derivativeOf(lf[i]) \f$ * * **Requirements:** * - The Functor F must model Concepts::HasPartial **/ template )> - auto derivative(FunctorLocalFunction const& lf, Type const& type) + auto derivativeOf(FunctorLocalFunction const& lf, Type const& type) { auto index_seq = std::index_sequence_for{}; @@ -133,10 +133,10 @@ namespace AMDiS using std::get; auto const& lgfs_i = *get(lf.localFcts()); - return makeFunctorGridFunction(Operation::Multiplies{}, di_f, derivative(lgfs_i, type)); + return makeFunctorGridFunction(Operation::Multiplies{}, di_f, derivativeOf(lgfs_i, type)); }; - // sum_i [ d_i(f)[lgfs...] * derivative(lgfs_i) + // sum_i [ d_i(f)[lgfs...] * derivativeOf(lgfs_i) auto gridFct = Tools::apply([&](auto const... _i) { return makeFunctorGridFunction(Operation::Plus{}, term_i(_i)...); diff --git a/amdis/gridfunctions/GridFunction.hpp b/amdis/gridfunctions/GridFunction.hpp index 4b35dcc4a88222a1f3d024db9e79ef872a7aa3fb..f7fb4a1607f2e942a7eb0ba9044f63a48b6b347f 100644 --- a/amdis/gridfunctions/GridFunction.hpp +++ b/amdis/gridfunctions/GridFunction.hpp @@ -145,9 +145,9 @@ namespace AMDiS * - have the free-function \ref localFunction() to obtain a LocalFunction * - its LocalFunctions have the free-function \ref order() to obtain the * polynomial order of the Expression (if available) - * - its LocalFunctions have the free-function \ref derivative() to + * - its LocalFunctions have the free-function \ref derivativeOf() to * differentiate the Expression with respect to global Coordinates. - * A derivative Expression can be created, using \ref gradientAtQP() that + * A derivative Expression can be created, using \ref gradientOf() that * can be converted to a GridFunction afterwards. **/ template diff --git a/amdis/io/FileWriterCreator.hpp b/amdis/io/FileWriterCreator.hpp index 65c1b7f3f9016f6ab4731992b8fa5adf66634d52..4dca105e8b782e86d11439304d77d3d627206af0 100644 --- a/amdis/io/FileWriterCreator.hpp +++ b/amdis/io/FileWriterCreator.hpp @@ -46,7 +46,7 @@ namespace AMDiS std::unique_ptr create(std::string type, std::string prefix, Indices... ii) const { - auto data = discreteFunction(*systemVector_, ii...); + auto data = valueOf(*systemVector_, ii...); return create_impl(std::move(type), std::move(prefix), data, Dune::PriorityTag<42>{}); } diff --git a/docs/reference/DOFVector.md b/docs/reference/DOFVector.md index f49842d6c65f034d4508dde98922e3d1ce80abcd..74aea54bb604c3b0abcdf38898995782f6a48cb5 100644 --- a/docs/reference/DOFVector.md +++ b/docs/reference/DOFVector.md @@ -55,19 +55,10 @@ The value_type is often the same as T, but might be just something similar, Function | Descriptions --------------------------------|--------------------------------------------- [*(constructor)*](#function-dofvectordofvector) | Construct the DOFVector -[child](#function-dofvectorchild) | Return a DiscreteFunction of a given sub-space [backup](#function-dofvectorbackup) | Write DOFVector to file [restore](#function-dofvectorrestore) | Read backup data from file [dataTransfer](#function-dofvectordataTransfer) | Return the associated DataTransfer object -### Interpolation functions - - Function | Descriptions ---------------------------------|--------------------------------------------- -[interpolate](#function-dofvectorinterpolate) | Interpolation of GridFunction to DOFVector -[interpolate_noalias](#function-dofvectorinterpolate) | Interpolation of GridFunction to DOFVector assuming no aliasing -[operator<<](#function-dofvectorinterpolate) | Operator for the interpolation - ??? seealso "Functions inherited from [VectorFacade](../MatVecFacade/#class-vectorfacade)" Function | Descriptions --------------------------------|--------------------------------------------- @@ -126,37 +117,6 @@ DOFVector> vec2(std::move(basis2)); - Generator function to construct a DOFVector: [makeDOFVector()](#function-makedofvector) -## function DOFVector::discreteFunction - -c++ -template -auto discreteFunction(Indices... ii) // (1) - -template -auto discreteFunction(Indices... ii) const // (2) - - -(1) Creates a mutable DiscreteFunction representing the sub-space w.r.t. the passed tree-path. The path {ii...} thereby -refers to the hierarchic global basis. - -(2) Creates a constant DiscreteFunction representing the sub-space w.r.t. the passed tree-path. The path {ii...} thereby -refers to the hierarchic global basis. - -#### Arguments -Indices... ii -: Components of the tree-path identifying the basis node - -#### Example -c++ -DOFVector vec(basis); - -auto vec_ = vec.discreteFunction(); -auto vec_0 = vec.discreteFunction(_0); -auto vec_10 = vec.discreteFunction(_1,0); -auto vec_10_b = discreteFunction(vec,_1,0); - - - ## function DOFVector::backup c++ void backup(std::string const& filename); @@ -182,42 +142,6 @@ Reads a backup of the DOFVector from file previously created using the [backup() : The filename of the backup file to read from. -## function DOFVector::interpolate,interpolate_noalias,operator<< {: #function-dofvectorinterpolate } -c++ -// (1) -template -void interpolate_noalias(Expr&& expr, Tag strategy) - -// (2) -template -void interpolate(Expr&& expr, Tag strategy) - -// (3) -template -DOFVector& operator<<(Expr&& expr) - - -(1) Interpolation of a GridFunction (or Expression) to the DOFVector, assuming that there is no -reference to this DOFVector in the expression (no aliasing). - -(2) Interpolation of a GridFunction (or Expression) to the DOFVector, allowing aliasing. - -(3) Operator notation of (2) using averaging strategy. - -In case *aliasing* is allowed, a temporary DOFVector is created first as copy of *this* and the interpolation -performed on the temporary using *noalias* interpolation (1). Then, this tempoary is moved back to *this*. - -#### Arguments -Expr expr -: An Expression representing a GridFunction - -Tag strategy -: An interpolation strategy, either tag::average or tag::assign. - The average strategy accumulates interpolation values on each dof and takes the average by - dividing by the number of assignees. The assign strategy diretly assigns an interpolation - value to a dof that might be overwritten in a subsequent interpolation step. - - ## function makeDOFVector Defined in header [](https://gitlab.mn.tu-dresden.de/amdis/amdis-core/blob/master/amdis/DOFVector.hpp) @@ -398,11 +322,13 @@ Returns the const (1) or mutable (2) sub-range view of the stored DOFVector. c++ ParallelGlobalBasis basis(gridView, power<3>(lagrange<1>())); auto vec = makeDOFVector(basis); -auto df = discreteFunction(vec); +auto df = valueOf(vec); auto df1 = df.child(); auto df2 = df.child(0); auto df3 = df.child(_0); +auto df4 = valueOf(df,0); +auto df5 = valueOf(vec,0); // df4 == df5  @@ -460,12 +386,9 @@ Note, the range type of the expression must be compatible with the Range type ParallelGlobalBasis basis(gridView, power<3>(lagrange<1>())); auto vec = makeDOFVector(basis); -auto df1 = vec.discreteFunction(); -auto df2 = vec.discreteFunction(0); - // Range type is FieldVector -df1 << [](FieldVector const& x) -> FieldVector { return x; }; +valueOf(vec) << [](FieldVector const& x) -> FieldVector { return x; }; // Range type is double -df2 += 42.0; +valueOf(vec,0) += 42.0;  diff --git a/docs/reference/GridFunctions.md b/docs/reference/GridFunctions.md index 4dc85fcc24aca4b851075a4311c28f086627471c..493e298ad85ec8307f99a3fac7781bc088e7055e 100644 --- a/docs/reference/GridFunctions.md +++ b/docs/reference/GridFunctions.md @@ -118,7 +118,7 @@ auto value = integrate(Expression, prob.gridView()); Function | Descriptions -------------------------------------------|--------------------------------------------- [evalAtQP(f)](#function-evalatqp) | Evaluates a functor in global coordinates. -[gradientAtQP(gf)](#function-gradientatqp) | Differentiate a grid function w.r.t. global coords +[gradientOf(gf)](#function-gradientof) | Differentiate a grid function w.r.t. global coords [invokeAtQP(f,gf_0,gf_1...)](#function-invokeatqp) | Apply a functor to the evaluated grid functions [X()](#function-x), [X(comp)](#function-x) | Return (component of) the global coordinate constant | Any (constant) scalar value or FieldVector or FieldMatrix @@ -189,12 +189,12 @@ global coordinates (2). dow is the world dimension. -## function gradientAtQP() +## function gradientOf() Defined in header [](https://gitlab.mn.tu-dresden.de/amdis/amdis-core/blob/master/amdis/gridfunctions/DerivativeGridFunction.hpp) c++ template -auto gradientAtQP(Expr const& expr); +auto gradientOf(Expr const& expr);  Creates a GridFunction representing the gradient w.r.t. global coordinates of the @@ -207,13 +207,13 @@ wrapped expression. #### Requirements * The GridFunction of gf = makeGridFunction(expr, gridView)with some GridView models Concepts::GridFunction and its LocalFunction has a derivative, i.e. - the expression derivative(localFunction(gf)) does not fail. + the expression derivativeOf(localFunction(gf),tag::gradient{}) does not fail. #### Examples We assume there is a ProblemStat with the name prob. c++ -gradientAtQP(prob.solution(_0)) -gradientAtQP(X(0) + X(1) + prob.solution(_0)) +gradientOf(prob.solution(_0)) +gradientOf(X(0) + X(1) + prob.solution(_0))  @@ -242,9 +242,9 @@ locally it is evaluated $ f(g_0(x), g_1(x), ...) $ * g_i models concept Concepts::GridFunction !!! note - The composition of grid functions can be differentiated using [gradientAtQP()](#function-gradientatqp) + The composition of grid functions can be differentiated using [gradientOf()](#function-gradientatqp) if all the grid functions are differentiable and the functor is differentiable, i.e. - there exist valid functions derivative(g_i) and partial(f, i). + there exist valid functions derivativeOf(g_i,type) and partial(f, i). #### Examples `c++ diff --git a/examples/ellipt.cc b/examples/ellipt.cc index 0deafb2203b4a92684802b47ee8cf09e15e603b3..c5558632654a6104f13983721c3e86e9f71f0f48 100644 --- a/examples/ellipt.cc +++ b/examples/ellipt.cc @@ -68,7 +68,7 @@ int main(int argc, char** argv) double errorL2 = integrate(sqr(g - prob.solution()), prob.gridView(), 6); errL2.push_back(std::sqrt(errorL2)); - double errorH1 = errorL2 + integrate(unary_dot(grad_g - gradientAtQP(prob.solution())), prob.gridView(), 6); + double errorH1 = errorL2 + integrate(unary_dot(grad_g - gradientOf(prob.solution())), prob.gridView(), 6); errH1.push_back(std::sqrt(errorH1)); } diff --git a/examples/navier_stokes.cc b/examples/navier_stokes.cc index da6ec48b5eacb69cc3488054549b3dce245ec8ee..f03c5de48ebd182d0afe2a95b34f79156821043a 100644 --- a/examples/navier_stokes.cc +++ b/examples/navier_stokes.cc @@ -57,7 +57,7 @@ int main(int argc, char** argv) // <(u * nabla)u_i^old, v_i> auto opNonlin1 = makeOperator(tag::testvec_trialvec{}, - density * trans(gradientAtQP(prob.solution(_v)))); + density * trans(gradientOf(prob.solution(_v)))); prob.addMatrixOperator(opNonlin1, _v, _v); for (std::size_t i = 0; i < WORLDDIM; ++i) { @@ -69,7 +69,7 @@ int main(int argc, char** argv) // <(u^old * grad(u_i^old)), v_i> auto opNonlin3 = makeOperator(tag::testvec{}, - trans(gradientAtQP(prob.solution(_v))) * prob.solution(_v)); + trans(gradientOf(prob.solution(_v))) * prob.solution(_v)); prob.addVectorOperator(opNonlin3, _v); // define boundary values diff --git a/test/BackupRestoreTest.cpp b/test/BackupRestoreTest.cpp index e5c97eb8d52afcd2b8b9080ad3f48008d4325417..e5d07185848654962518eaad5c4ef260655ffede 100644 --- a/test/BackupRestoreTest.cpp +++ b/test/BackupRestoreTest.cpp @@ -25,6 +25,7 @@ using namespace AMDiS; template void test(Factory factory) { + using namespace Dune::Indices; using Param = TaylorHoodBasis; using Problem = ProblemStat; @@ -40,8 +41,8 @@ void test(Factory factory) prob.initialize(INIT_ALL); prob.globalRefine(2); - prob.solution(Dune::Indices::_0) << [](auto const& x) { return x; }; - prob.solution(Dune::Indices::_1) << [](auto const& x) { return two_norm(x); }; + prob.solution(_0) << [](auto const& x) { return x; }; + prob.solution(_1) << [](auto const& x) { return two_norm(x); }; num_elements = prob.grid()->size(0); num_vertices = prob.grid()->size(Grid::dimension); @@ -59,15 +60,15 @@ void test(Factory factory) AMDIS_TEST_EQ(num_vertices, prob.grid()->size(Grid::dimension)); DOFVector vec(prob.globalBasis()); - vec.discreteFunction(Dune::Indices::_0) << [](auto const& x) { return x; }; - vec.discreteFunction(Dune::Indices::_1) << [](auto const& x) { return two_norm(x); }; + valueOf(vec,_0) << [](auto const& x) { return x; }; + valueOf(vec,_1) << [](auto const& x) { return two_norm(x); }; double error0 = std::sqrt(integrate( - unary_dot(prob.solution(Dune::Indices::_0) - vec.discreteFunction(Dune::Indices::_0)), prob.gridView())); + unary_dot(prob.solution(_0) - valueOf(vec,_0)), prob.gridView())); AMDIS_TEST(error0 < 1.e-10); double error1 = std::sqrt(integrate( - pow<2>(prob.solution(Dune::Indices::_1) - vec.discreteFunction(Dune::Indices::_1)), prob.gridView())); + pow<2>(prob.solution(_1) - valueOf(vec,_1)), prob.gridView())); AMDIS_TEST(error1 < 1.e-10); } } diff --git a/test/DOFVectorTest.cpp b/test/DOFVectorTest.cpp index c786f1306a12116303687d9f76482ed8b23eb2eb..93aaa667cad37f82631e8bfc190be3f5223682bd 100644 --- a/test/DOFVectorTest.cpp +++ b/test/DOFVectorTest.cpp @@ -44,16 +44,6 @@ void test_dofvector(DOFVector& vec) if (vec.localSize() > 1) AMDIS_TEST_EQ(min, T(0)); AMDIS_TEST_EQ(max, T(1)); - - // interpolate constant function on DOFVector - vec << T(2); - AMDIS_TEST_EQ(vec.at(MultiIndex{0}), T(2)); - - vec.interpolate(T(3)); - AMDIS_TEST_EQ(vec.at(MultiIndex{0}), T(3)); - - vec.interpolate_noalias(T(4)); - AMDIS_TEST_EQ(vec.at(MultiIndex{0}), T(4)); } int main(int argc, char** argv) diff --git a/test/DiscreteFunctionTest.cpp b/test/DiscreteFunctionTest.cpp index 55ee59f903559e48dacd83db81d8798b964a7142..27ef7a67dcbf5d8e6cfe07347a90b653060e9db7 100644 --- a/test/DiscreteFunctionTest.cpp +++ b/test/DiscreteFunctionTest.cpp @@ -54,9 +54,9 @@ int main(int argc, char** argv) auto U1 = *prob.solutionVector(); auto U2 = *prob.solutionVector(); - auto u0 = discreteFunction(U0); - auto u1 = discreteFunction(U1); - auto u2 = discreteFunction(U2); + auto u0 = valueOf(U0); + auto u1 = valueOf(U1); + auto u2 = valueOf(U2); // Test const and mutable construction auto const& U_c = *prob.solutionVector(); @@ -65,8 +65,8 @@ int main(int argc, char** argv) DiscreteFunction u0_c(U_c.coefficients(), *U_c.basis(), makeTreePath()); DiscreteFunction u0_m(U_m.coefficients(), *U_m.basis(), makeTreePath()); - auto u1_c = discreteFunction(U_c); - auto u1_m = discreteFunction(U_m); + auto u1_c = valueOf(U_c); + auto u1_m = valueOf(U_m); // sub-range view on DiscreteFunction auto su1_c = u1_c.child(); @@ -113,9 +113,9 @@ int main(int argc, char** argv) AMDIS_TEST( comp(U0, U1) ); AMDIS_TEST( comp(U0, U2) ); - auto du0 = derivative(u0, tag::gradient{}); + auto du0 = derivativeOf(u0, tag::gradient{}); auto localFct = localFunction(u0); - auto dlocalFct = derivative(localFct, tag::gradient{}); + auto dlocalFct = derivativeOf(localFct, tag::gradient{}); for (auto const& e : elements(prob.gridView())) { localFct.bind(e); @@ -139,29 +139,29 @@ int main(int argc, char** argv) } auto V0 = makeDOFVector(prob.globalBasis()); - auto v0 = discreteFunction(V0); + auto v0 = valueOf(V0); v0 << expr1; - // test discreteFunction + // test DiscreteFunction std::integral_constant _0; auto tp = makeTreePath(0); auto W0 = *prob.solutionVector(); auto W1 = *prob.solutionVector(); auto W2 = *prob.solutionVector(); - auto w0 = discreteFunction(W0, 0); - auto w1 = discreteFunction(W1, _0); - auto w2 = discreteFunction(W2, tp); + auto w0 = valueOf(W0, 0); + auto w1 = valueOf(W1, _0); + auto w2 = valueOf(W2, tp); - // test discreteFunction with (pre)treepath argument + // test DiscreteFunction with (pre)treepath argument auto expr = [](auto const& x) { return 1 + x[0] + x[1]; }; auto W3 = *prob.solutionVector(); auto W4 = *prob.solutionVector(); auto W5 = *prob.solutionVector(); auto W7 = *prob.solutionVector(); auto W8 = *prob.solutionVector(); - auto w3 = discreteFunction(W3, 0); - auto w4 = discreteFunction(W4, _0); - auto w5 = discreteFunction(W5, tp); + auto w3 = valueOf(W3, 0); + auto w4 = valueOf(W4, _0); + auto w5 = valueOf(W5, tp); auto w6 = prob.solution(tp); auto& W6 = *prob.solutionVector(); w3 << expr; @@ -173,9 +173,9 @@ int main(int argc, char** argv) AMDIS_TEST( comp(W3, W6) ); // test interpolation on subbasis - auto w7 = discreteFunction(W7); - auto w8_0 = discreteFunction(W8, 0); - auto w8_1 = discreteFunction(W8, 1); + auto w7 = valueOf(W7); + auto w8_0 = valueOf(W8, 0); + auto w8_1 = valueOf(W8, 1); w7 << expr; w8_0 << expr; w8_1 << expr; diff --git a/test/ExpressionsTest.cpp b/test/ExpressionsTest.cpp index 0559d4f9edb9e6a4cab140afeeef0a2261908f4f..54eac90c1d04a3401cc7b51fb2f53ece732e8d38 100644 --- a/test/ExpressionsTest.cpp +++ b/test/ExpressionsTest.cpp @@ -45,26 +45,21 @@ int main(int argc, char** argv) // derivative of expressions - auto diff4 = gradientAtQP(expr4); - // auto diff5 = gradientAtQP(expr5); - auto diff6 = gradientAtQP(expr6); - - // auto diff7 = gradientAtQP(expr7); - auto diff8 = gradientAtQP(expr8); - - auto diff9 = gradientAtQP(expr9); + auto diff4 = gradientOf(expr4); + // auto diff5 = gradientOf(expr5); + auto diff6 = gradientOf(expr6); + // auto diff7 = gradientOf(expr7); + auto diff8 = gradientOf(expr8); + auto diff9 = gradientOf(expr9); // --------------------------------- u.interpolate(expr1); u.interpolate(expr2); u.interpolate(expr3); - u.interpolate(expr4); u.interpolate(expr6); - u.interpolate(expr8); - u.interpolate(expr9); // --------------------------------- @@ -79,12 +74,9 @@ int main(int argc, char** argv) auto op6 = invokeAtQP([](double v) { return 2*v; }, op5); - u.interpolate(two_norm(diff4)); u.interpolate(two_norm(diff6)); - u.interpolate(two_norm(diff8)); - u.interpolate(two_norm(diff9)); // --------------------------------- diff --git a/test/GradientTest.cpp b/test/GradientTest.cpp index f5e566d5e4f2148c55777e82601a832f0dc153f1..9cfd1bd2ce7b24f8c13122951be6d52de00627ac 100644 --- a/test/GradientTest.cpp +++ b/test/GradientTest.cpp @@ -29,28 +29,28 @@ void test() auto uVector = makeDOFVector(basis); - auto u = discreteFunction(uVector); - auto u_0 = discreteFunction(uVector, 0); - auto u_1 = discreteFunction(uVector, 1); + auto u = valueOf(uVector); + auto u_0 = valueOf(uVector, 0); + auto u_1 = valueOf(uVector, 1); // eval a functor at global coordinates (at quadrature points) u_0 << evalAtQP([](auto const& x) { return x[0] + x[1]; }); u_1 << evalAtQP([](auto const& x) { return -2*x[0] + 3*x[1]; }); // test gradient - AMDIS_TEST_APPROX((std::sqrt(integrate(unary_dot(gradientAtQP(u_0)), gridView))), std::sqrt(2.0)); - AMDIS_TEST_APPROX((std::sqrt(integrate(unary_dot(gradientAtQP(u_1)), gridView))), std::sqrt(13.0)); + AMDIS_TEST_APPROX((std::sqrt(integrate(unary_dot(gradientOf(u_0)), gridView))), std::sqrt(2.0)); + AMDIS_TEST_APPROX((std::sqrt(integrate(unary_dot(gradientOf(u_1)), gridView))), std::sqrt(13.0)); // test divergence - AMDIS_TEST_APPROX((integrate(divergenceAtQP(u), gridView)), 4.0); + AMDIS_TEST_APPROX((integrate(divergenceOf(u), gridView)), 4.0); // test partial derivative - double d0u_0 = integrate(partialAtQP(u_0,0), gridView); - double d1u_1 = integrate(partialAtQP(u_1,1), gridView); + double d0u_0 = integrate(partialDerivativeOf(u_0,0), gridView); + double d1u_1 = integrate(partialDerivativeOf(u_1,1), gridView); AMDIS_TEST_APPROX(d0u_0, 1.0); AMDIS_TEST_APPROX(d1u_1, 3.0); - auto gf_d0u_0 = makeGridFunction(partialAtQP(u_0,0), gridView); + auto gf_d0u_0 = makeGridFunction(partialDerivativeOf(u_0,0), gridView); auto lf_d0u_0 = localFunction(gf_d0u_0); for (auto const& e : elements(gridView)) { lf_d0u_0.bind(e); @@ -62,29 +62,29 @@ void test() u_0 << evalAtQP([](auto const& x) { return std::sin(x[0]) + std::cos(x[1]); }); u_1 << evalAtQP([](auto const& x) { return -std::sin(x[0]) * std::cos(x[1]); }); - AMDIS_TEST_APPROX((integrate(divergenceAtQP(u), gridView)), - (integrate(partialAtQP(u_0,0) + partialAtQP(u_1,1), gridView))); + AMDIS_TEST_APPROX((integrate(divergenceOf(u), gridView)), + (integrate(partialDerivativeOf(u_0,0) + partialDerivativeOf(u_1,1), gridView))); auto vVector(uVector); - auto v = discreteFunction(vVector); - auto v_0 = discreteFunction(vVector, 0); - auto v_1 = discreteFunction(vVector, 1); + auto v = valueOf(vVector); + auto v_0 = valueOf(vVector, 0); + auto v_1 = valueOf(vVector, 1); // test gradient v << evalAtQP([](auto const& x) { return Dune::FieldVector{std::cos(x[0]), -std::sin(x[1])}; }); - AMDIS_TEST((std::sqrt(integrate(unary_dot(v - gradientAtQP(u_0)), gridView))) < 0.05); + AMDIS_TEST((std::sqrt(integrate(unary_dot(v - gradientOf(u_0)), gridView))) < 0.05); // test divergence v_0 << evalAtQP([](auto const& x) { return std::cos(x[0]) + std::sin(x[0])*std::sin(x[1]); }); - AMDIS_TEST((integrate(v_0 - divergenceAtQP(u), gridView)) < 0.05); + AMDIS_TEST((integrate(v_0 - divergenceOf(u), gridView)) < 0.05); // test partial derivative v_0 << evalAtQP([](auto const& x) { return std::cos(x[0]); }); v_1 << evalAtQP([](auto const& x) { return std::sin(x[0])*std::sin(x[1]); }); - AMDIS_TEST((integrate(v_0 - partialAtQP(u_0,0), gridView)) < 0.05); - AMDIS_TEST((integrate(v_1 - partialAtQP(u_1,1), gridView)) < 0.05); + AMDIS_TEST((integrate(v_0 - partialDerivativeOf(u_0,0), gridView)) < 0.05); + AMDIS_TEST((integrate(v_1 - partialDerivativeOf(u_1,1), gridView)) < 0.05); } int main(int argc, char** argv)