AMDiS 2.11-git
The Adaptive Multi-Dimensional Simulation Toolbox
 
Loading...
Searching...
No Matches
BlockedBasisMapping.hpp
1#pragma once
2
3#include <memory>
4#include <type_traits>
5#include <vector>
6
7#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
8#include <amdis/functions/BasisMapping.hpp>
9#include <amdis/functions/BlockedBasis.hpp>
10#include <amdis/functions/FlatBasis.hpp>
11
12namespace AMDiS
13{
15 template <class RowBasis, class ColBasis>
17 {
18 // RowBasis and ColBasis must be flat bases
19 static_assert(std::is_same_v<FlatBasis_t<RowBasis>,RowBasis>);
20 static_assert(std::is_same_v<FlatBasis_t<ColBasis>,ColBasis>);
21
22 // Define a blocked rowbasis
23 using RowBlockedBasis = BlockedBasis_t<RowBasis>;
24
25 // Define a blocked colbasis
26 using ColBlockedBasis = BlockedBasis_t<ColBasis>;
27
28 // Since the source basis is flat, we can use a vector as storage backend for the mapping
29 using RowMapping = BasisMapping<RowBasis, RowBlockedBasis,
30 std::vector<typename RowBlockedBasis::MultiIndex>>;
31 using ColMapping = BasisMapping<ColBasis, ColBlockedBasis,
32 std::vector<typename ColBlockedBasis::MultiIndex>>;
33
34 public:
35 BlockedBasisMapping(std::shared_ptr<RowBasis> const& rowBasis,
36 std::shared_ptr<ColBasis> const& colBasis)
37 : rowMapping_(rowBasis, std::make_shared<RowBlockedBasis>(blockedBasis(*rowBasis)))
38 , colMapping_(colBasis, std::make_shared<ColBlockedBasis>(blockedBasis(*colBasis)))
39 {}
40
41 BlockedBasisMapping(std::shared_ptr<RowBasis> const& rowBasis)
42 : BlockedBasisMapping(rowBasis, rowBasis)
43 {}
44
46 template <class Index>
47 typename RowBlockedBasis::MultiIndex const& row(Index const& index) const
48 {
49 return rowMapping_(index);
50 }
51
53 template <class Index>
54 typename ColBlockedBasis::MultiIndex const& col(Index const& index) const
55 {
56 return colMapping_(index);
57 }
58
60 decltype(auto) rowSizeInfo() const
61 {
62 return rowMapping_.sizeInfo();
63 }
64
66 decltype(auto) colSizeInfo() const
67 {
68 return colMapping_.sizeInfo();
69 }
70
71 private:
72 RowMapping rowMapping_;
73 ColMapping colMapping_;
74 };
75
76
77#ifndef DOXYGEN
78 // Specialization for row-basis == col-basis:
79 // Construct only one mapping for the indices
80 template <class Basis>
81 class BlockedBasisMapping<Basis, Basis>
82 {
83 // Basis must be flat basis
84 static_assert(std::is_same_v<FlatBasis_t<Basis>,Basis>);
85
86 // Define a blocked basis
87 using BBasis = BlockedBasis_t<Basis>;
88 using Mapping = BasisMapping<Basis, BBasis,
89 std::vector<typename BBasis::MultiIndex>>;
90
91 public:
92 BlockedBasisMapping(std::shared_ptr<Basis> const& basis)
93 : mapping_(basis, std::make_shared<BBasis>(blockedBasis(*basis)))
94 {}
95
96 BlockedBasisMapping(std::shared_ptr<Basis> const& rowBasis, std::shared_ptr<Basis> const& /*colBasis*/)
97 : BlockedBasisMapping(rowBasis)
98 {}
99
101 template <class Index>
102 typename BBasis::MultiIndex const& row(Index const& index) const
103 {
104 return mapping_(index);
105 }
106
108 template <class Index>
109 typename BBasis::MultiIndex const& col(Index const& index) const
110 {
111 return mapping_(index);
112 }
113
115 decltype(auto) rowSizeInfo() const
116 {
117 return mapping_.sizeInfo();
118 }
119
121 decltype(auto) colSizeInfo() const
122 {
123 return mapping_.sizeInfo();
124 }
125
126 private:
127 Mapping mapping_;
128 };
129#endif
130
131} // end namespace AMDiS
TargetBasis const & sizeInfo() const
Return the target basis as a size info object.
Definition BasisMapping.hpp:91
BBasis::MultiIndex const & col(Index const &index) const
Map the index in the flat basis into a multi-index in the blocked basis.
Definition BlockedBasisMapping.hpp:109
decltype(auto) rowSizeInfo() const
Get the size info (typically the basis itself) for the mapping.
Definition BlockedBasisMapping.hpp:115
BBasis::MultiIndex const & row(Index const &index) const
Map the index in the flat basis into a multi-index in the blocked basis.
Definition BlockedBasisMapping.hpp:102
decltype(auto) colSizeInfo() const
Get the size info (typically the basis itself) for the mapping.
Definition BlockedBasisMapping.hpp:121
Mapping of a pair of flat bases to the corresponding outer-level blocked bases.
Definition BlockedBasisMapping.hpp:17
decltype(auto) rowSizeInfo() const
Get the size info (typically the basis itself) for the row-mapping.
Definition BlockedBasisMapping.hpp:60
ColBlockedBasis::MultiIndex const & col(Index const &index) const
Map the index in the flat col-basis into a multi-index in the blocked col-basis.
Definition BlockedBasisMapping.hpp:54
decltype(auto) colSizeInfo() const
Get the size info (typically the basis itself) for the col-mapping.
Definition BlockedBasisMapping.hpp:66
RowBlockedBasis::MultiIndex const & row(Index const &index) const
Map the index in the flat row-basis into a multi-index in the blocked row-basis.
Definition BlockedBasisMapping.hpp:47