dune-assembler 2.12
Loading...
Searching...
No Matches
localviewpair.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_ASSEMBLER_LOCALVIEWPAIR_HH
5#define DUNE_ASSEMBLER_LOCALVIEWPAIR_HH
6
7#include <type_traits>
8
11
12namespace Dune::Assembler {
13
22template <Concepts::LocalView RowLocalView, Concepts::LocalView ColLocalView>
24{
25 using RowBasis = typename RowLocalView::GlobalBasis;
26 using ColBasis = typename ColLocalView::GlobalBasis;
27
29
30 // create a reference to the first local view of the bases and the local views
31 // are identical, otherwise return a reference to the second local view.
32 template <class LV1, class LV2>
33 static auto& refColLocalView (LV1& first, LV2& second, bool same) noexcept
34 {
35 if constexpr (std::is_same_v<LV1,LV2>)
36 return same ? first : second;
37 else
38 return second;
39 }
40
41public:
43 LocalViewPair (RowBasis const& rowBasis, ColBasis const& colBasis)
44 : rowLocalView_(rowBasis.localView())
45 , colLocalViewStorage_(colBasis.localView())
47 (void*)(&rowBasis) == (void*)(&colBasis)))
48 {}
49
59
69
71 template <class Element>
72 void bind (const Element& element)
73 {
74 rowLocalView_.bind(element);
75 if (not same())
76 colLocalView_.bind(element);
77 }
78
80 void unbind ()
81 {
82 rowLocalView_.unbind();
83 if (not same())
84 colLocalView_.unbind();
85 }
86
88 template <std::size_t I>
89 friend auto const& get (const LocalViewPair& pair) noexcept
90 {
91 if constexpr (I == 0)
92 return pair.rowLocalView_;
93 else
94 return pair.colLocalView_;
95 }
96
101 [[nodiscard]] bool same () const
102 {
103 return ((void*)(&rowLocalView_) == (void*)(&colLocalView_));
104 }
105
106protected:
107 RowLocalView rowLocalView_;
109 ColLocalView& colLocalView_;
110};
111
112template <Concepts::GlobalBasis RowBasis, Concepts::GlobalBasis ColBasis>
113LocalViewPair(const RowBasis&, const ColBasis&)
115
116} // end namespace Dune::Assembler
117
118#endif // DUNE_ASSEMBLER_LOCALVIEWPAIR_HH
STL namespace.
Definition localboundaryintersectionmatrixassembler.hh:9
const IndexPair * pair(const std::size_t &local) const
A pair of local views constructed from a pair of global bases.
Definition localviewpair.hh:24
LocalViewPair(RowBasis const &rowBasis, ColBasis const &colBasis)
Construct local view for a given global finite element basis.
Definition localviewpair.hh:43
bool same() const
Return whether both local views refer to the same object.
Definition localviewpair.hh:101
friend auto const & get(const LocalViewPair &pair) noexcept
Return a reference to the first (I == 0) or second (I == 1) local view.
Definition localviewpair.hh:89
void bind(const Element &element)
Bind the views to a grid element.
Definition localviewpair.hh:72
ColLocalView & colLocalView_
Definition localviewpair.hh:109
LocalViewPair(LocalViewPair &&other)
Move-construct a LocalView pair. This needs to reset the reference for the second local view.
Definition localviewpair.hh:64
void unbind()
Unbind from the current element.
Definition localviewpair.hh:80
LocalViewPair(const LocalViewPair &other)
Copy-construct a LocalView pair. This needs to reset the reference for the second local view.
Definition localviewpair.hh:54
RowLocalView rowLocalView_
Definition localviewpair.hh:107
ColLocalView colLocalViewStorage_
Definition localviewpair.hh:108