7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PERIODICBASIS_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PERIODICBASIS_HH
16#include <dune/functions/functionspacebases/concepts.hh>
17#include <dune/functions/functionspacebases/containerdescriptors.hh>
18#include <dune/functions/functionspacebases/transformedindexbasis.hh>
21namespace Dune::Functions {
23namespace BasisFactory {
29namespace Experimental {
42 using IndexPairSet = std::set<std::pair<std::size_t,std::size_t>>;
58 indexPairSet_.insert(std::make_pair(a,b));
61 const auto& indexPairSet()
const
67 IndexPairSet indexPairSet_;
77class PeriodicIndexingTransformation
81 static constexpr std::size_t minIndexSize = 1;
82 static constexpr std::size_t maxIndexSize = 1;
84 template<
class RawPreBasis,
class IndexPairSet>
85 PeriodicIndexingTransformation(
const RawPreBasis& rawPreBasis,
const IndexPairSet& indexPairSet)
87 static_assert(RawPreBasis::maxMultiIndexSize==1,
"PeriodicIndexingTransformation is only implemented for flat multi-indices");
89 mappedIdx_.resize(rawPreBasis.size(), invalid);
92 for(
const auto& [a, b] : indexPairSet)
95 if (mappedIdx_[i] == invalid)
96 mappedIdx_[i] = numIndices_++;
97 mappedIdx_[b] = mappedIdx_[a];
99 for(; i<rawPreBasis.size(); ++i)
100 if (mappedIdx_[i] == invalid)
101 mappedIdx_[i] = numIndices_++;
104 template<
class MultiIndex,
class PreBasis>
105 void transformIndex(MultiIndex& multiIndex,
const PreBasis& preBasis)
const
107 multiIndex = {{ mappedIdx_[multiIndex[0]] }};
110 template<
class Prefix,
class PreBasis>
111 std::size_t
size(
const Prefix& prefix,
const PreBasis& preBasis)
const
113 if (prefix.size() == 1)
118 template<
class PreBasis>
119 auto dimension(
const PreBasis& preBasis)
const
125 template<
class PreBasis>
126 auto containerDescriptor(
const PreBasis& preBasis)
const
128 return Dune::Functions::containerDescriptor(preBasis);
132 std::vector<std::size_t> mappedIdx_;
133 std::size_t numIndices_;
138template<
class RawPreBasisIndicator>
139class PeriodicPreBasisFactory
142 PeriodicPreBasisFactory()
145 template<
class RPBI,
class PIS>
146 PeriodicPreBasisFactory(RPBI&& rawPreBasisIndicator, PIS&& periodicIndexSet) :
147 rawPreBasisIndicator_(
std::forward<RPBI>(rawPreBasisIndicator)),
148 periodicIndexSet_(
std::forward<PIS>(periodicIndexSet))
151 template<
class GridView,
152 std::enable_if_t<models<Concept::GlobalBasis<GridView>,RawPreBasisIndicator>(),
int> = 0>
153 auto operator()(
const GridView& gridView)
const
155 const auto& rawPreBasis = rawPreBasisIndicator_.preBasis();
156 auto transformation = PeriodicIndexingTransformation(rawPreBasis, periodicIndexSet_.indexPairSet());
160 template<
class GridView,
161 std::enable_if_t<models<Concept::PreBasis<GridView>,RawPreBasisIndicator>(),
int> = 0>
162 auto operator()(
const GridView& gridView)
const
164 const auto& rawPreBasis = rawPreBasisIndicator_;
165 auto transformation = PeriodicIndexingTransformation(rawPreBasis, periodicIndexSet_.indexPairSet());
169 template<
class GridView,
170 std::enable_if_t<not models<Concept::GlobalBasis<GridView>,RawPreBasisIndicator>(),
int> = 0,
171 std::enable_if_t<not
models<Concept::PreBasis<GridView>,RawPreBasisIndicator>(),
int> = 0>
172 auto operator()(
const GridView& gridView)
const
174 auto rawPreBasis = rawPreBasisIndicator_(gridView);
175 rawPreBasis.initializeIndices();
176 auto transformation = PeriodicIndexingTransformation(rawPreBasis, periodicIndexSet_.indexPairSet());
181 RawPreBasisIndicator rawPreBasisIndicator_;
182 PeriodicIndexSet periodicIndexSet_;
202template<
class RawPreBasisIndicator,
class PIS>
204 RawPreBasisIndicator&& rawPreBasisIndicator,
205 PIS&& periodicIndexSet
208 return Impl::PeriodicPreBasisFactory<std::decay_t<RawPreBasisIndicator>>(
209 std::forward<RawPreBasisIndicator>(rawPreBasisIndicator),
210 std::forward<PIS>(periodicIndexSet));
Container storing identified indices for a periodic basis.
Definition: periodicbasis.hh:41
void unifyIndexPair(std::size_t a, std::size_t b)
Insert a pair of indices.
Definition: periodicbasis.hh:52
constexpr auto models()
Check if concept is modeled by given types.
Definition: concept.hh:184
auto periodic(RawPreBasisIndicator &&rawPreBasisIndicator, PIS &&periodicIndexSet)
Create a pre-basis factory that can create a periodic pre-basis.
Definition: periodicbasis.hh:203
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75