Commit ed807839 authored by Carsten Gräser's avatar Carsten Gräser

Merge branch 'feature/merge-localindexset-into-localview' into 'master'

Feature/merge localindexset into localview

See merge request staging/dune-functions!118
parents 8c642b88 c5594d71
......@@ -185,6 +185,7 @@ struct LocalView
template<class V>
auto require(const V& localView) -> decltype(
requireType<typename V::size_type>(),
requireType<typename V::MultiIndex>(),
requireType<typename V::GlobalBasis>(),
requireType<typename V::Tree>(),
requireType<typename V::GridView>(),
......@@ -197,6 +198,7 @@ struct LocalView
const_cast<V&>(localView).unbind(),
requireConvertible<typename V::Tree>(localView.tree()),
requireConvertible<typename V::size_type>(localView.size()),
requireConvertible<typename V::MultiIndex>(localView.index(std::declval<typename V::size_type>())),
requireConvertible<typename V::size_type>(localView.maxSize()),
requireConvertible<typename V::GlobalBasis>(localView.globalBasis()),
requireConcept<BasisTree<typename V::GridView>>(localView.tree()),
......
......@@ -22,22 +22,15 @@ public:
using NodeIndexSet = NIS;
/** \brief Type used for global numbering of the basis vectors */
using MultiIndex = typename NodeIndexSet::MultiIndex;
using size_type = std::size_t;
using MultiIndex = typename LocalView::MultiIndex;
using size_type = typename LocalView::size_type;
private:
template<typename NodeIndexSet>
using hasIndices = decltype(std::declval<NodeIndexSet>().indices(std::declval<std::vector<MultiIndex>>().begin()));
public:
DefaultLocalIndexSet(const NodeIndexSet& nodeIndexSet) :
nodeIndexSet_(nodeIndexSet)
DefaultLocalIndexSet() :
localView_(nullptr)
{}
DefaultLocalIndexSet(NodeIndexSet&& nodeIndexSet) :
nodeIndexSet_(nodeIndexSet)
DefaultLocalIndexSet(const NodeIndexSet& nodeIndexSet) :
localView_(nullptr)
{}
/** \brief Bind the index set to a LocalView
......@@ -45,17 +38,6 @@ public:
void bind(const LocalView& localView)
{
localView_ = &localView;
nodeIndexSet_.bind(localView_->tree());
indices_.resize(size());
Hybrid::ifElse(
Std::is_detected<hasIndices,NodeIndexSet>{},
[&](auto id) {
id(nodeIndexSet_).indices(indices_.begin());
},
[&](auto id) {
for (size_type i = 0 ; i < this->size() ; ++i)
indices_[i] = id(nodeIndexSet_).index(i);
});
}
/** \brief Bind the index set to a SubspaceLocalView
......@@ -71,20 +53,19 @@ public:
void unbind()
{
localView_ = nullptr;
nodeIndexSet_.unbind();
}
/** \brief Size of subtree rooted in this node (element-local)
*/
size_type size() const
{
return nodeIndexSet_.size();
return localView_->size();
}
//! Maps from subtree index set [0..size-1] to a globally unique multi index in global basis
MultiIndex index(size_type i) const
{
return indices_[i];
return localView_->index(i);
}
/** \brief Return the local view that we are attached to
......@@ -97,9 +78,6 @@ public:
protected:
const LocalView* localView_;
NodeIndexSet nodeIndexSet_;
std::vector<MultiIndex> indices_;
};
......
......@@ -7,6 +7,7 @@
#include <tuple>
#include <dune/common/concept.hh>
#include <dune/common/hybridutilities.hh>
#include <dune/functions/functionspacebases/concepts.hh>
......@@ -23,6 +24,9 @@ class DefaultLocalView
{
using PrefixPath = TypeTree::HybridTreePath<>;
// Node index set provided by PreBasis
using NodeIndexSet = typename GB::PreBasis::template IndexSet<PrefixPath>;
public:
//! The global FE basis that this is a view on
......@@ -40,10 +44,21 @@ public:
//! Tree of local finite elements / local shape function sets
using Tree = typename GlobalBasis::PreBasis::template Node<PrefixPath>;
/** \brief Type used for global numbering of the basis vectors */
using MultiIndex = typename NodeIndexSet::MultiIndex;
private:
template<typename NodeIndexSet_>
using hasIndices = decltype(std::declval<NodeIndexSet_>().indices(std::declval<std::vector<MultiIndex>>().begin()));
public:
/** \brief Construct local view for a given global finite element basis */
DefaultLocalView(const GlobalBasis& globalBasis) :
globalBasis_(&globalBasis),
tree_(globalBasis_->preBasis().node(PrefixPath()))
tree_(globalBasis_->preBasis().node(PrefixPath())),
nodeIndexSet_(globalBasis_->preBasis().template indexSet<PrefixPath>())
{
static_assert(models<Concept::BasisTree<GridView>, Tree>(), "Tree type passed to DefaultLocalView does not model the BasisNode concept.");
initializeTree(tree_);
......@@ -58,6 +73,17 @@ public:
{
element_ = e;
bindTree(tree_, element_);
nodeIndexSet_.bind(tree_);
indices_.resize(size());
Hybrid::ifElse(
Std::is_detected<hasIndices,NodeIndexSet>{},
[&](auto id) {
id(nodeIndexSet_).indices(indices_.begin());
},
[&](auto id) {
for (size_type i = 0 ; i < this->size() ; ++i)
indices_[i] = id(nodeIndexSet_).index(i);
});
}
/** \brief Return the grid element that the view is bound to
......@@ -74,7 +100,9 @@ public:
* Calling this method should only be a hint that the view can be unbound.
*/
void unbind()
{}
{
nodeIndexSet_.unbind();
}
/** \brief Return the local ansatz tree associated to the bound entity
*
......@@ -103,6 +131,12 @@ public:
return globalBasis_->preBasis().maxNodeSize();
}
//! Maps from subtree index set [0..size-1] to a globally unique multi index in global basis
MultiIndex index(size_type i) const
{
return indices_[i];
}
/** \brief Return the global basis that we are a view on
*/
const GlobalBasis& globalBasis() const
......@@ -119,6 +153,8 @@ protected:
const GlobalBasis* globalBasis_;
Element element_;
Tree tree_;
NodeIndexSet nodeIndexSet_;
std::vector<MultiIndex> indices_;
};
......
......@@ -52,6 +52,9 @@ public:
//! Tree of local finite elements / local shape function sets
using Tree = typename TypeTree::ChildForTreePath<RootTree, PrefixPath>;
/** \brief Type used for global numbering of the basis vectors */
using MultiIndex = typename RootLocalView::MultiIndex;
/** \brief Construct local view for a given global finite element basis */
SubspaceLocalView(const GlobalBasis& globalBasis, const PrefixPath& prefixPath) :
globalBasis_(&globalBasis),
......@@ -115,6 +118,12 @@ public:
return rootLocalView_.maxSize();
}
//! Maps from subtree index set [0..size-1] to a globally unique multi index in global basis
MultiIndex index(size_type i) const
{
return rootLocalView_.index(i);
}
/** \brief Return the global basis that we are a view on
*/
const GlobalBasis& globalBasis() const
......
Markdown is supported
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