Commit 4e38a30a authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'feature/basis_nodes' into 'master'

Add range over node indices

See merge request !102
parents 09aba8bc 6f44dd6d
#pragma once
#include <dune/common/rangeutilities.hh>
#include <dune/functions/functionspacebases/concepts.hh>
#include <amdis/typetree/MultiIndex.hpp>
#include <amdis/utility/MappedRangeView.hpp>
namespace AMDiS
{
/// Returns a range over (flat) DOF indices on a node, given by the localView
template <class LocalView, class Node>
auto nodeIndices(LocalView const& localView, Node const& node)
{
using namespace Dune::Functions;
static_assert(Dune::models<Concept::LocalView<typename LocalView::GlobalBasis>, LocalView>(), "");
static_assert(Dune::models<Concept::BasisTree<typename LocalView::GridView>, Node>(), "");
return mappedRangeView(Dune::range(node.size()), [&](std::size_t j) -> std::size_t {
return flatMultiIndex(localView.index(node.localIndex(j)));
});
}
/// Returns a range over (flat) DOF indices on the basis tree, given by the localView
template <class LocalView>
auto nodeIndices(LocalView const& localView)
{
using namespace Dune::Functions;
static_assert(Dune::models<Concept::LocalView<typename LocalView::GlobalBasis>, LocalView>(), "");
return mappedRangeView(Dune::range(localView.size()), [&](std::size_t i) -> std::size_t {
return flatMultiIndex(localView.index(i));
});
}
/// Returns the number of DOF indices on a node, given by the localView
template <class LocalView, class Node>
std::size_t nodeIndexCount(LocalView const& /*localView*/, Node const& node)
{
return node.size();
}
/// Returns the number of DOF indices on the basis tree, given by the localView
template <class LocalView>
std::size_t nodeIndexCount(LocalView const& localView)
{
return localView.size();
}
} // end namespace AMDiS
......@@ -34,4 +34,16 @@ namespace AMDiS
#endif
}
// dune version independent creation of node from preBasis
template <class PB, class TP>
auto makeNodeIndexSet(PB const& preBasis, TP const& treePath)
{
#if DUNE_VERSION_LT(DUNE_FUNCTIONS,2,7)
return preBasis.indexSet(treePath);
#else
DUNE_UNUSED_PARAMETER(treePath);
return preBasis.makeIndexSet();
#endif
}
} // end namespace AMDiS
......@@ -87,6 +87,9 @@ dune_add_test(SOURCES MultiTypeVectorTest.cpp
dune_add_test(SOURCES MultiTypeMatrixTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES NodeIndicesTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES OperationsTest.cpp
LINK_LIBRARIES amdis)
......
#include <dune/grid/yaspgrid.hh>
#include <dune/functions/functionspacebases/compositebasis.hh>
#include <dune/functions/functionspacebases/powerbasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <amdis/functions/NodeIndices.hpp>
#include "Tests.hpp"
int main()
{
using namespace AMDiS;
using namespace Dune::Functions::BasisFactory;
// create grid
Dune::YaspGrid<2> grid({1.0, 1.0}, {1, 1});
auto gridView = grid.leafGridView();
// create basis
auto taylorHoodBasis = makeBasis(
gridView,
composite(
power<2>(lagrange<2>(), flatInterleaved()),
lagrange<1>(),
flatLexicographic()
));
auto localView = taylorHoodBasis.localView();
for (auto const& e : elements(gridView)) {
localView.bind(e);
std::size_t numDofs = 2*(3*3) + (2*2);
std::size_t numNodeIndices = nodeIndexCount(localView);
AMDIS_TEST_EQ(numNodeIndices, numDofs);
std::size_t num = 0;
for (std::size_t dof : nodeIndices(localView)) {
DUNE_UNUSED_PARAMETER(dof);
num++;
}
AMDIS_TEST_EQ(num, numDofs);
auto node = localView.tree();
numNodeIndices = nodeIndexCount(localView, node);
AMDIS_TEST_EQ(numNodeIndices, numDofs);
// count the number of velocity dofs
std::size_t numVelDofs = 2*(3*3);
auto v_node = Dune::TypeTree::child(node, Dune::Indices::_0);
std::size_t numVelNodeIndices = nodeIndexCount(localView, v_node);
AMDIS_TEST_EQ(numVelNodeIndices, numVelDofs);
num = 0;
for (std::size_t dof : nodeIndices(localView, v_node)) {
DUNE_UNUSED_PARAMETER(dof);
num++;
}
AMDIS_TEST_EQ(num, numVelDofs);
// count the number of pressure dofs
std::size_t numPDofs = 2*2;
auto p_node = Dune::TypeTree::child(node, Dune::Indices::_1);
std::size_t numPNodeIndices = nodeIndexCount(localView, p_node);
AMDIS_TEST_EQ(numPNodeIndices, numPDofs);
num = 0;
for (std::size_t dof : nodeIndices(localView, p_node)) {
DUNE_UNUSED_PARAMETER(dof);
num++;
}
AMDIS_TEST_EQ(num, numPDofs);
}
return report_errors();
}
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