Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
periodicconstraints.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUFEM_CONSTRAINTS_PERIODICCONSTRAINTS_HH
8#define DUNE_FUFEM_CONSTRAINTS_PERIODICCONSTRAINTS_HH
9
10#include <type_traits>
11#include <variant>
12#include <vector>
13#include <tuple>
14
16
19
22
23
24
25namespace Dune::Fufem {
26
63template<class BV, class V, class MI, class C, class PrimaryBasis, class PrimaryPatch, class SecondaryBasis, class SecondaryPatch, class SecondaryToPrimary>
66 const PrimaryBasis& primaryBasis,
67 const PrimaryPatch& primaryPatch,
68 const SecondaryBasis& secondaryBasis,
69 const SecondaryPatch& secondaryPatch,
70 const SecondaryToPrimary& secondaryToPrimary)
71{
72 using Constraints = AffineConstraints<BV, V, MI, C>;
73 using Coefficient = typename Constraints::Coefficient;
74 using ElementSeed = typename SecondaryBasis::GridView::Grid::template Codim<0>::EntitySeed;
75 using GlobalCoordinate = typename SecondaryBasis::GridView::Grid::template Codim<0>::Geometry::GlobalCoordinate;
76
78
79 // Interpolation weights smaller than the tolerance will be ignored
80 const auto tol = 1e-5;
81
82 auto localIsConstrained = std::vector<bool>();
83 auto interpolationValues = std::vector<Coefficient>();
84
85 auto primaryLocalView = primaryBasis.localView();
86 auto secondaryLocalView = secondaryBasis.localView();
87 auto secondaryFaceDOFs = Dune::Functions::subEntityDOFs(secondaryBasis);
88
90
91 auto secondaryFaces = std::vector<Face>();
92 for(const auto& secondaryIntersection : secondaryPatch)
93 secondaryFaces.push_back(Face(
94 secondaryIntersection.inside().seed(),
95 secondaryIntersection.indexInInside(),
96 secondaryIntersection.geometry().center()));
97
98 for(const auto& primaryIntersection : primaryPatch)
99 {
100 auto primaryCenter = primaryIntersection.geometry().center();
101 const auto& primaryElement = primaryIntersection.inside();
102
103 for(const auto& secondaryFace : secondaryFaces)
104 {
105 const auto& [secondaryElementSeed, secondaryFaceIndex, secondaryCenter] = secondaryFace;
106 const auto& secondaryElement = secondaryBasis.gridView().grid().entity(secondaryElementSeed);
107
108 if ((primaryCenter - secondaryToPrimary(secondaryCenter)).two_norm() < tol)
109 {
110 primaryLocalView.bind(primaryElement);
111 if (primaryLocalView.tree().size() == 0)
112 break;
113 secondaryLocalView.bind(secondaryElement);
114 if (secondaryLocalView.tree().size() == 0)
115 continue;
116 secondaryFaceDOFs.bind(secondaryLocalView, secondaryFaceIndex, 1);
117
118 const auto& primaryGeometry = primaryElement.geometry();
119 const auto& secondaryGeometry = secondaryElement.geometry();
120 auto localSecondaryToPrimary = [&](auto xLocalSecondary) {
121 auto xGlobal = secondaryGeometry.global(xLocalSecondary);
122 return primaryGeometry.local(secondaryToPrimary(xGlobal));
123 };
124
125 computeLocalInterpolationConstraints(primaryLocalView, secondaryLocalView, localSecondaryToPrimary, secondaryFaceDOFs, constraints);
126
127 break;
128 }
129 }
130 }
131 constraints.resolveDependencies();
132}
133
134
135
170template<class BV, class V, class MI, class C, class Basis, class PrimaryPatch, class SecondaryPatch, class SecondaryToPrimary>
173 const Basis& basis,
174 const PrimaryPatch& primaryPatch,
175 const SecondaryPatch& secondaryPatch,
176 const SecondaryToPrimary& secondaryToPrimary)
177{
178 computePeriodicConstraints(constraints, basis, primaryPatch, basis, secondaryPatch, secondaryToPrimary);
179}
180
181
182
183} // namespace Dune::Fufem
184
185
186
187#endif // DUNE_FUFEM_CONSTRAINTS_PERIODICCONSTRAINTS_HH
auto subEntityDOFs(const T &)
void computePeriodicConstraints(AffineConstraints< BV, V, MI, C > &constraints, const PrimaryBasis &primaryBasis, const PrimaryPatch &primaryPatch, const SecondaryBasis &secondaryBasis, const SecondaryPatch &secondaryPatch, const SecondaryToPrimary &secondaryToPrimary)
Compute constraints for periodic boundary conditions.
Definition periodicconstraints.hh:64
void computeLocalInterpolationConstraints(const PrimaryLocalView &primaryLocalView, const SecondaryLocalView &secondaryLocalView, const SecondaryToPrimary &localSecondaryToPrimary, const SecondaryDOFs &secondaryDOFs, Constraints &constraints)
Compute local constraints from interpolating between local views.
Definition localinterpolationconstraints.hh:61
Definition dunefunctionsboundaryfunctionalassembler.hh:29
Class to handle affine constraints on a subset of DOFs.
Definition affineconstraints.hh:201
void resolveDependencies()
Resolve dependencies of constrained DOFs on other constrained DOFs.
Definition affineconstraints.hh:756
Class representing a face.
Definition facehierarchy.hh:120
T forward(T... args)