AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
PeriodicBC.hpp
1#pragma once
2
3#include <map>
4#include <optional>
5#include <utility>
6#include <vector>
7
8#include <dune/common/concept.hh>
9#include <dune/functions/functionspacebases/concepts.hh>
10#include <dune/functions/functionspacebases/subspacebasis.hh>
11
12#include <amdis/BoundaryCondition.hpp>
13#include <amdis/BoundarySubset.hpp>
14#include <amdis/common/ConceptsBase.hpp>
15#include <amdis/common/FieldMatVec.hpp>
16#include <amdis/common/TypeTraits.hpp>
17#include <amdis/typetree/TreePath.hpp>
18
19
20namespace AMDiS
21{
23 template <class ct, int dow>
25 {
26 using WorldMatrix = FieldMatrix<ct, dow, dow>;
27 using WorldVector = FieldVector<ct, dow>;
28
30 WorldMatrix matrix_;
31
33 WorldVector shift_;
34
35 WorldVector evaluate(WorldVector const& x) const
36 {
37 WorldVector y = shift_;
38 matrix_.umv(x, y);
39 return y;
40 }
41
42 WorldVector evaluateInverse(WorldVector const& y) const
43 {
44 WorldVector ys = y - shift_;
45 WorldVector x;
46 matrix_.mtv(ys, x);
47 return x;
48 }
49 };
50
51
53
60 template <class Basis, class TP>
62 {
63 using SubspaceBasis = Dune::Functions::SubspaceBasis<Basis, TP>;
64
65 public:
66 using Domain = typename SubspaceBasis::GridView::template Codim<0>::Geometry::GlobalCoordinate;
67 using MultiIndex = typename SubspaceBasis::MultiIndex;
69 using Intersection = typename SubspaceBasis::GridView::Intersection;
70
71 public:
73 PeriodicBC(SubspaceBasis basis, BoundarySubset<Intersection> boundarySubset,
74 FaceTrafo faceTrafo)
75 : basis_(std::move(basis))
76 , boundarySubset_(std::move(boundarySubset))
77 , faceTrafo_(std::move(faceTrafo))
78 {}
79
81
86 void init();
87
89
94 template <class Mat, class Sol, class Rhs>
95 void apply(Mat& matrix, Sol& solution, Rhs& rhs);
96
98 auto const& associations() const
99 {
100 return associations_;
101 }
102
104 auto const& periodicNodes() const
105 {
106 return periodicNodes_;
107 }
108
109 protected:
110 void initAssociations();
111 void initAssociations2();
112
113 // Get the coordinates of the DOFs
114 template <class Node>
115 auto coords(Node const& node, std::vector<std::size_t> const& localIndices) const;
116
117 private:
118 SubspaceBasis basis_;
119 BoundarySubset<Intersection> boundarySubset_;
120 FaceTrafo faceTrafo_;
121
122 std::vector<bool> periodicNodes_;
123 std::map<std::size_t, std::size_t> associations_;
124 std::optional<bool> hasConnectedIntersections_;
125 };
126
127 namespace Impl {
128 template <class Basis>
129 using FaceTrafo = FaceTransformation<
130 typename Basis::GridView::template Codim<0>::Geometry::GlobalCoordinate::field_type,
131 Basis::GridView::template Codim<0>::Geometry::GlobalCoordinate::dimension>;
132 }
133
134
136 template <class B, class TP>
137 auto makePeriodicBC(Dune::Functions::SubspaceBasis<B, TP> basis,
138 BoundarySubset<typename B::GridView::Intersection> boundarySubset,
139 Impl::FaceTrafo<B> trafo)
140 {
141 using BcType = PeriodicBC<B, TP>;
142 return BcType(std::move(basis), std::move(boundarySubset), std::move(trafo));
143 }
144
146 template <class B, class TP,
147 REQUIRES(Concepts::GlobalBasis<B>)>
148 auto makePeriodicBC(B const& basis, TP const& tp,
149 BoundarySubset<typename B::GridView::Intersection> boundarySubset,
150 Impl::FaceTrafo<B> trafo)
151 {
152 return makePeriodicBC(Dune::Functions::subspaceBasis(basis, tp),
153 std::move(boundarySubset), std::move(trafo));
154 }
155
157 template <class B,
158 REQUIRES(Concepts::GlobalBasis<B>)>
159 auto makePeriodicBC(B const& basis,
160 BoundarySubset<typename B::GridView::Intersection> boundarySubset,
161 Impl::FaceTrafo<B> trafo)
162 {
163 return makePeriodicBC(basis, makeTreePath(), std::move(boundarySubset),
164 std::move(trafo));
165 }
166
167} // end namespace AMDiS
168
169#include "PeriodicBC.inc.hpp"
Implements a periodic boundary condition.
Definition: PeriodicBC.hpp:62
void init()
Compute the pairs of associated boundary DOFs.
Definition: PeriodicBC.inc.hpp:18
auto const & associations() const
Return the map of DOF associations.
Definition: PeriodicBC.hpp:98
void apply(Mat &matrix, Sol &solution, Rhs &rhs)
Move matrix rows (and columns) of dependant DOFs to the corresponding master DOFs.
Definition: PeriodicBC.inc.hpp:235
auto const & periodicNodes() const
Return the boolean boundary indicator.
Definition: PeriodicBC.hpp:104
PeriodicBC(SubspaceBasis basis, BoundarySubset< Intersection > boundarySubset, FaceTrafo faceTrafo)
Create the BoundaryCondition and store the face transformation in a local variable.
Definition: PeriodicBC.hpp:73
constexpr bool MultiIndex
A multi-index type.
Definition: Concepts.hpp:149
Affine transformation x := A*x + b.
Definition: PeriodicBC.hpp:25
WorldMatrix matrix_
orthogonal (rotation) matrix
Definition: PeriodicBC.hpp:30
WorldVector shift_
Shift vector.
Definition: PeriodicBC.hpp:33