Commit bc96d1dc authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Cleanup DiscreteFunctions

parent b749d3f8
...@@ -11,6 +11,11 @@ namespace AMDiS ...@@ -11,6 +11,11 @@ namespace AMDiS
struct matrix {}; struct matrix {};
struct unknown {}; struct unknown {};
// tags representing interpolation strategies
struct average {};
struct assign {};
struct defaulted {};
} // end namespace tag } // end namespace tag
} // end namespace AMDiS } // end namespace AMDiS
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <amdis/common/FakeContainer.hpp> #include <amdis/common/FakeContainer.hpp>
#include <amdis/common/FieldMatVec.hpp> #include <amdis/common/FieldMatVec.hpp>
#include <amdis/common/Logical.hpp> #include <amdis/common/Logical.hpp>
#include <amdis/common/Tags.hpp>
#include <amdis/functions/FunctionFromCallable.hpp> #include <amdis/functions/FunctionFromCallable.hpp>
#include <amdis/functions/HierarchicNodeToRangeMap.hpp> #include <amdis/functions/HierarchicNodeToRangeMap.hpp>
#include <amdis/functions/NodeIndices.hpp> #include <amdis/functions/NodeIndices.hpp>
...@@ -22,14 +23,6 @@ ...@@ -22,14 +23,6 @@
namespace AMDiS namespace AMDiS
{ {
namespace tag
{
struct average {};
struct assign {};
struct defaulted {};
} // end namespace tag
namespace Impl namespace Impl
{ {
template <class B, class Vec, class GF, class TP, class C, class BV, class NTRE, class Assign> template <class B, class Vec, class GF, class TP, class C, class BV, class NTRE, class Assign>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <dune/functions/gridfunctions/gridviewentityset.hh> #include <dune/functions/gridfunctions/gridviewentityset.hh>
#include <dune/typetree/childextraction.hh> #include <dune/typetree/childextraction.hh>
#include <amdis/LinearAlgebra.hpp> #include <amdis/common/Tags.hpp>
#include <amdis/typetree/FiniteElementType.hpp> #include <amdis/typetree/FiniteElementType.hpp>
#include <amdis/typetree/RangeType.hpp> #include <amdis/typetree/RangeType.hpp>
#include <amdis/typetree/TreePath.hpp> #include <amdis/typetree/TreePath.hpp>
...@@ -32,18 +32,17 @@ namespace AMDiS ...@@ -32,18 +32,17 @@ namespace AMDiS
class DiscreteFunction; class DiscreteFunction;
#if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION #if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
template <class Coeff, class GB, class TreePath = Dune::TypeTree::HybridTreePath<>> template <class Coeff, class GB, class TreePath = RootTreePath>
DiscreteFunction(Coeff&, GB const&, TreePath = {}) DiscreteFunction(Coeff&, GB const&, TreePath = {})
-> DiscreteFunction<Coeff, GB, TreePath>; -> DiscreteFunction<Coeff, GB, TreePath_t<TreePath>>;
#endif #endif
/// A Generator for a mutable \ref DiscreteFunction /// A Generator for a mutable \ref DiscreteFunction
template <class Coeff, class GB, class Path, template <class Coeff, class GB, class Path = RootTreePath,
class = void_t<decltype(std::declval<GB>().localView())> > class = void_t<decltype(std::declval<GB>().localView())> >
auto makeDiscreteFunction(Coeff& coefficients, GB const& basis, Path const& path) auto makeDiscreteFunction(Coeff& coefficients, GB const& basis, Path const& path = {})
{ {
auto treePath = makeTreePath(path); return DiscreteFunction<Coeff, GB, TreePath_t<Path>>{coefficients, basis, path};
return DiscreteFunction<Coeff, GB, decltype(treePath)>{coefficients, basis, treePath};
} }
...@@ -61,8 +60,9 @@ namespace AMDiS ...@@ -61,8 +60,9 @@ namespace AMDiS
public: public:
/// Constructor. Stores a pointer to the mutable `dofvector`. /// Constructor. Stores a pointer to the mutable `dofvector`.
DiscreteFunction(Coefficients& dofVector, GlobalBasis const& basis, TreePath const& treePath = {}) template <class Path = TreePath>
: Super(dofVector, basis, treePath) DiscreteFunction(Coefficients& dofVector, GlobalBasis const& basis, Path const& path = {})
: Super(dofVector, basis, path)
, mutableCoeff_(&dofVector) , mutableCoeff_(&dofVector)
{} {}
...@@ -117,7 +117,10 @@ namespace AMDiS ...@@ -117,7 +117,10 @@ namespace AMDiS
} }
/// Return the mutable DOFVector /// Return the mutable DOFVector
Coefficients& coefficients() { return *mutableCoeff_; } Coefficients& coefficients()
{
return *mutableCoeff_;
}
/// Return the const DOFVector /// Return the const DOFVector
using Super::coefficients; using Super::coefficients;
...@@ -125,8 +128,8 @@ namespace AMDiS ...@@ -125,8 +128,8 @@ namespace AMDiS
template <class Path = RootTreePath> template <class Path = RootTreePath>
auto child(Path const& path = {}) auto child(Path const& path = {})
{ {
auto&& tp = makeTreePath(path); auto tp = cat(this->treePath_, makeTreePath(path));
return makeDiscreteFunction(*mutableCoeff_, this->basis(), cat(this->treePath_,tp)); return makeDiscreteFunction(*mutableCoeff_, this->basis(), tp);
} }
using Super::child; using Super::child;
...@@ -142,7 +145,7 @@ namespace AMDiS ...@@ -142,7 +145,7 @@ namespace AMDiS
private: private:
using Coefficients = std::remove_const_t<Coeff>; using Coefficients = std::remove_const_t<Coeff>;
using GlobalBasis = GB; using GlobalBasis = GB;
using ValueType = typename Coeff::value_type; using ValueType = typename Coefficients::value_type;
using Tree = typename GlobalBasis::LocalView::Tree; using Tree = typename GlobalBasis::LocalView::Tree;
using SubTree = typename Dune::TypeTree::ChildForTreePath<Tree, TreePath>; using SubTree = typename Dune::TypeTree::ChildForTreePath<Tree, TreePath>;
...@@ -177,12 +180,13 @@ namespace AMDiS ...@@ -177,12 +180,13 @@ namespace AMDiS
public: public:
/// Constructor. Stores a pointer to the dofVector and a copy of the treePath. /// Constructor. Stores a pointer to the dofVector and a copy of the treePath.
DiscreteFunction(Coefficients const& coefficients, GlobalBasis const& basis, TreePath const& treePath = {}) template <class Path = TreePath>
DiscreteFunction(Coefficients const& coefficients, GlobalBasis const& basis, Path const& path = {})
: coefficients_(&coefficients) : coefficients_(&coefficients)
, basis_(&basis) , basis_(&basis)
, treePath_(treePath) , treePath_(makeTreePath(path))
, entitySet_(basis_->gridView()) , entitySet_(basis_->gridView())
, nodeToRangeEntry_(Dune::Functions::makeDefaultNodeToRangeMap(*basis_, treePath)) , nodeToRangeEntry_(Dune::Functions::makeDefaultNodeToRangeMap(*basis_, treePath_))
{} {}
/// \brief Evaluate DiscreteFunction in global coordinates. NOTE: expensive /// \brief Evaluate DiscreteFunction in global coordinates. NOTE: expensive
...@@ -221,8 +225,8 @@ namespace AMDiS ...@@ -221,8 +225,8 @@ namespace AMDiS
template <class Path = RootTreePath> template <class Path = RootTreePath>
auto child(Path const& path = {}) const auto child(Path const& path = {}) const
{ {
auto&& tp = makeTreePath(path); auto tp = cat(this->treePath_, makeTreePath(path));
return makeDiscreteFunction(*coefficients_, *basis_, cat(this->treePath_,tp)); return makeDiscreteFunction(*coefficients_, *basis_, tp);
} }
protected: protected:
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <amdis/functions/Interpolate.hpp> #include <amdis/functions/Interpolate.hpp>
#include <amdis/gridfunctions/GridFunction.hpp> #include <amdis/gridfunctions/GridFunction.hpp>
#include <amdis/linearalgebra/VectorFacade.hpp>
namespace AMDiS { namespace AMDiS {
......
#pragma once #pragma once
#include <amdis/Output.hpp>
#include <amdis/common/DerivativeTraits.hpp> #include <amdis/common/DerivativeTraits.hpp>
#include <amdis/common/FieldMatVec.hpp> #include <amdis/common/FieldMatVec.hpp>
#include <amdis/functions/NodeIndices.hpp>
#include <amdis/utility/LocalBasisCache.hpp> #include <amdis/utility/LocalBasisCache.hpp>
#include <amdis/utility/LocalToGlobalAdapter.hpp> #include <amdis/utility/LocalToGlobalAdapter.hpp>
#include <dune/common/ftraits.hh> #include <dune/common/ftraits.hh>
namespace AMDiS { namespace AMDiS {
namespace Impl {
// specialization of Coeff has gather method
template <class Coeff, class LocalView, class LocalCoeff,
class = decltype(std::declval<Coeff>().gather(std::declval<LocalView>(), std::declval<LocalCoeff&>()))>
void gather(Coeff const& coeff, LocalView const& localView, LocalCoeff& localCoeff, Dune::PriorityTag<2>)
{
coeff.gather(localView, localCoeff);
}
// fallback implementation
template <class Coeff, class LocalView, class LocalCoeff>
void gather(Coeff const& coeff, LocalView const& localView, LocalCoeff& localCoeff, Dune::PriorityTag<1>)
{
localCoeff.resize(localView.size());
auto it = localCoeff.begin();
for (auto const& idx : nodeIndices(localView))
*it++ = coeff[idx];
}
} // end namespace Impl
template <class Coeff, class GB, class TP> template <class Coeff, class GB, class TP>
class DiscreteFunction<Coeff const,GB,TP>::LocalFunction class DiscreteFunction<Coeff const,GB,TP>::LocalFunction
...@@ -42,8 +66,7 @@ public: ...@@ -42,8 +66,7 @@ public:
void bind(Element const& element) void bind(Element const& element)
{ {
localView_.bind(element); localView_.bind(element);
Impl::gather(globalFunction_.coefficients(), localView_, localCoefficients_, Dune::PriorityTag<4>{});
globalFunction_.coefficients().gather(localView_, localCoefficients_);
bound_ = true; bound_ = true;
} }
...@@ -173,7 +196,7 @@ public: ...@@ -173,7 +196,7 @@ public:
localView_.bind(element); localView_.bind(element);
geometry_.emplace(element.geometry()); geometry_.emplace(element.geometry());
globalFunction_.coefficients().gather(localView_, localCoefficients_); Impl::gather(globalFunction_.coefficients(), localView_, localCoefficients_, Dune::PriorityTag<4>{});
bound_ = true; bound_ = true;
} }
......
...@@ -139,6 +139,10 @@ namespace AMDiS ...@@ -139,6 +139,10 @@ namespace AMDiS
return Dune::TypeTree::hybridTreePath(); return Dune::TypeTree::hybridTreePath();
} }
/// Type of the generated treepath
template <class PreTreePath>
using TreePath_t = TYPEOF(makeTreePath(std::declval<PreTreePath>()));
#endif // DOXYGEN #endif // DOXYGEN
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment