Commit 6f44dd6d authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

add nodeIndexCount and test of nodeIndex range

parent d2dcaa71
#pragma once #pragma once
#include <dune/common/rangeutilities.hh> #include <dune/common/rangeutilities.hh>
#include <dune/functions/functionspacebases/concepts.hh>
#include <amdis/typetree/MultiIndex.hpp> #include <amdis/typetree/MultiIndex.hpp>
#include <amdis/utility/MappedRangeView.hpp> #include <amdis/utility/MappedRangeView.hpp>
namespace AMDiS namespace AMDiS
{ {
/// Returns a range over the DOF indices on a node, given by the localView /// Returns a range over (flat) DOF indices on a node, given by the localView
template <class LocalView, class Node> template <class LocalView, class Node>
auto nodeIndices(LocalView const& localView, Node const& node) auto nodeIndices(LocalView const& localView, Node const& node)
{ {
return mappedRangeView(Dune::range(node.size()), [&](std::size_t j) { 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))); return flatMultiIndex(localView.index(node.localIndex(j)));
}); });
} }
/// Returns a range over the DOF indices on the basis tree, given by the localView /// Returns a range over (flat) DOF indices on the basis tree, given by the localView
template <class LocalView> template <class LocalView>
auto nodeIndices(LocalView const& localView) auto nodeIndices(LocalView const& localView)
{ {
return mappedRangeView(Dune::range(localView.size()), [&](std::size_t i) { 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)); 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 } // end namespace AMDiS
...@@ -84,6 +84,9 @@ dune_add_test(SOURCES MultiTypeVectorTest.cpp ...@@ -84,6 +84,9 @@ dune_add_test(SOURCES MultiTypeVectorTest.cpp
dune_add_test(SOURCES MultiTypeMatrixTest.cpp dune_add_test(SOURCES MultiTypeMatrixTest.cpp
LINK_LIBRARIES amdis) LINK_LIBRARIES amdis)
dune_add_test(SOURCES NodeIndicesTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES OperationsTest.cpp dune_add_test(SOURCES OperationsTest.cpp
LINK_LIBRARIES amdis) 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