version 3.11-dev
dirichletconstraints.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DIRICHLET_CONSTRAINTS_HH
13#define DUMUX_DIRICHLET_CONSTRAINTS_HH
14
15#include <concepts>
16#include <unordered_map>
17
19
20namespace Dumux {
21
22template<class Info, class Values>
24{
25 using ConstraintInfo = Info;
26 using ConstraintValues = Values;
27
29 { return info_; }
30
31 const ConstraintValues& values() const
32 { return values_; }
33
36};
37
38template<class DirichletConstraintInfo, class DirichletValues, class IndexType>
39struct DirichletConstraintData : public ConstraintData<DirichletConstraintInfo, DirichletValues>
40{
41 using GridIndexType = IndexType;
42
44 { return dofIdx_; }
45
47};
48
55template<class Data>
57{
58 using GridIndexType = typename Data::GridIndexType;
59 using DirichletConstraintInfo = typename Data::ConstraintInfo;
60 using DirichletValues = typename Data::ConstraintValues;
61
62public:
69 template<class Problem, typename DirichletFunction>
70 void update(const Problem& problem, const DirichletFunction& dirichletFunction)
71 {
72 constraints_.clear();
73
74 auto fvGeometry = localView(problem.gridGeometry());
75 for (const auto& element : elements(problem.gridGeometry().gridView()))
76 {
77 fvGeometry.bind(element);
78 for (const auto& intersection : intersections(problem.gridGeometry().gridView(), element))
79 {
80 if(!intersection.boundary() || intersection.neighbor())
81 continue;
82
83 const auto& bcTypes = problem.boundaryTypes(fvGeometry, intersection);
84 if (bcTypes.hasDirichlet())
85 {
86 for (const auto& localDof : localDofs(fvGeometry, intersection))
87 {
88 DirichletConstraintInfo info;
89 // set the Dirichlet constraints
90 for (int eqIdx = 0; eqIdx < DirichletValues::size(); ++eqIdx)
91 if (bcTypes.isDirichlet(eqIdx))
92 info.set(bcTypes.eqToDirichletIndex(eqIdx), eqIdx);
93
94 auto dirichletValues = dirichletFunction(fvGeometry, intersection, localDof);
95 constraints_.push_back(Data{std::move(info), std::move(dirichletValues), localDof.dofIndex()});
96 }
97 }
98 }
99 }
100 }
101
102 auto begin() const
103 { return constraints_.cbegin(); }
104
105 auto end() const
106 { return constraints_.cend(); }
107
108private:
109 std::vector<Data> constraints_;
110};
111
112static_assert(std::ranges::range<DirichletConstraints<DirichletConstraintData<int, int, int>>>);
113
114} // namespace Dumux
115
116#endif
Constraints related to Dirichlet boundaries. This class generates global constraints based on Dirichl...
Definition: dirichletconstraints.hh:57
auto end() const
Definition: dirichletconstraints.hh:105
auto begin() const
Definition: dirichletconstraints.hh:102
void update(const Problem &problem, const DirichletFunction &dirichletFunction)
Update the boundary types for all element intersections.
Definition: dirichletconstraints.hh:70
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
Defines the index types used for grid and local indices.
Definition: adapt.hh:17
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition: localdof.hh:50
Definition: dirichletconstraints.hh:24
Info ConstraintInfo
Definition: dirichletconstraints.hh:25
const ConstraintValues & values() const
Definition: dirichletconstraints.hh:31
ConstraintValues values_
Definition: dirichletconstraints.hh:35
ConstraintInfo info_
Definition: dirichletconstraints.hh:34
Values ConstraintValues
Definition: dirichletconstraints.hh:26
const ConstraintInfo & constraintInfo() const
Definition: dirichletconstraints.hh:28
Definition: dirichletconstraints.hh:40
IndexType GridIndexType
Definition: dirichletconstraints.hh:41
GridIndexType dofIndex() const
Definition: dirichletconstraints.hh:43
GridIndexType dofIdx_
Definition: dirichletconstraints.hh:46