3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PERIODICBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PERIODICBASIS_HH
12#include <dune/functions/functionspacebases/concepts.hh>
13#include <dune/functions/functionspacebases/transformedindexbasis.hh>
16namespace Dune::Functions {
18namespace BasisFactory {
24namespace Experimental {
37 using IndexPairSet = std::set<std::pair<std::size_t,std::size_t>>;
53 indexPairSet_.insert(std::make_pair(a,b));
56 const auto& indexPairSet()
const
62 IndexPairSet indexPairSet_;
72class PeriodicIndexingTransformation
76 static constexpr std::size_t minIndexSize = 1;
77 static constexpr std::size_t maxIndexSize = 1;
79 template<
class RawPreBasis,
class IndexPairSet>
80 PeriodicIndexingTransformation(
const RawPreBasis& rawPreBasis,
const IndexPairSet& indexPairSet)
83 mappedIdx_.resize(rawPreBasis.size(), invalid);
86 for(
const auto& [a, b] : indexPairSet)
89 if (mappedIdx_[i] == invalid)
90 mappedIdx_[i] = numIndices_++;
91 mappedIdx_[b] = mappedIdx_[a];
93 for(; i<rawPreBasis.size(); ++i)
94 if (mappedIdx_[i] == invalid)
95 mappedIdx_[i] = numIndices_++;
98 template<
class MultiIndex,
class PreBasis>
99 void transformIndex(MultiIndex& multiIndex,
const PreBasis& preBasis)
const
101 multiIndex = {{ mappedIdx_[multiIndex[0]] }};
104 template<
class Prefix,
class PreBasis>
105 std::size_t size(
const Prefix& prefix,
const PreBasis& preBasis)
const
107 if (prefix.size() == 1)
112 template<
class PreBasis>
113 auto dimension(
const PreBasis& preBasis)
const
119 std::vector<std::size_t> mappedIdx_;
120 std::size_t numIndices_;
125template<
class RawPreBasisIndicator>
126class PeriodicPreBasisFactory
129 static const std::size_t requiredMultiIndexSize = 1;
131 PeriodicPreBasisFactory()
134 template<
class RPBI,
class PIS>
135 PeriodicPreBasisFactory(RPBI&& rawPreBasisIndicator, PIS&& periodicIndexSet) :
136 rawPreBasisIndicator_(
std::forward<RPBI>(rawPreBasisIndicator)),
137 periodicIndexSet_(
std::forward<PIS>(periodicIndexSet))
140 template<
class MultiIndex,
class GridView,
141 std::enable_if_t<models<Concept::GlobalBasis<GridView>,RawPreBasisIndicator>(),
int> = 0>
142 auto makePreBasis(
const GridView& gridView)
const
144 const auto& rawPreBasis = rawPreBasisIndicator_.preBasis();
145 using RawPreBasis = std::decay_t<
decltype(rawPreBasis)>;
146 PeriodicIndexingTransformation transformation(rawPreBasis, periodicIndexSet_.indexPairSet());
150 template<
class MultiIndex,
class GridView,
151 std::enable_if_t<models<Concept::PreBasis<GridView>,RawPreBasisIndicator>(),
int> = 0>
152 auto makePreBasis(
const GridView& gridView)
const
154 const auto& rawPreBasis = rawPreBasisIndicator_;
155 using RawPreBasis = std::decay_t<
decltype(rawPreBasis)>;
156 PeriodicIndexingTransformation transformation(rawPreBasis, periodicIndexSet_.indexPairSet());
160 template<
class MultiIndex,
class GridView,
161 std::enable_if_t<not models<Concept::GlobalBasis<GridView>,RawPreBasisIndicator>(),
int> = 0,
162 std::enable_if_t<not
models<Concept::PreBasis<GridView>,RawPreBasisIndicator>(),
int> = 0>
163 auto makePreBasis(
const GridView& gridView)
const
165 auto rawPreBasis = rawPreBasisIndicator_.template makePreBasis<MultiIndex>(gridView);
166 rawPreBasis.initializeIndices();
167 using RawPreBasis = std::decay_t<
decltype(rawPreBasis)>;
168 PeriodicIndexingTransformation transformation(rawPreBasis, periodicIndexSet_.indexPairSet());
173 RawPreBasisIndicator rawPreBasisIndicator_;
174 PeriodicIndexSet periodicIndexSet_;
194template<
class RawPreBasisIndicator,
class PIS>
196 RawPreBasisIndicator&& rawPreBasisIndicator,
197 PIS&& periodicIndexSet
200 return Impl::PeriodicPreBasisFactory<std::decay_t<RawPreBasisIndicator>>(
201 std::forward<RawPreBasisIndicator>(rawPreBasisIndicator),
202 std::forward<PIS>(periodicIndexSet));
Container storing identified indices for a periodic basis.
Definition: periodicbasis.hh:36
void unifyIndexPair(std::size_t a, std::size_t b)
Insert a pair of indices.
Definition: periodicbasis.hh:47
constexpr auto models()
Check if concept is modeled by given types.
Definition: concept.hh:182
auto periodic(RawPreBasisIndicator &&rawPreBasisIndicator, PIS &&periodicIndexSet)
Create a pre-basis factory that can create a periodic pre-basis.
Definition: periodicbasis.hh:195
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79