version 3.8
common/boundarytypes.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-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_BOUNDARY_TYPES_HH
13#define DUMUX_BOUNDARY_TYPES_HH
14
15#include <algorithm>
16#include <array>
17
18namespace Dumux {
19
24template <int numEq>
26{
27public:
29 { reset(); }
30
32 static constexpr int size()
33 { return numEq; }
34
42 void reset()
43 {
44 for (int eqIdx=0; eqIdx < numEq; ++eqIdx)
45 resetEq(eqIdx);
46 }
47
51 void resetEq(int eqIdx)
52 {
53 boundaryInfo_[eqIdx].visited = false;
54
55 boundaryInfo_[eqIdx].isDirichlet = false;
56 boundaryInfo_[eqIdx].isNeumann = false;
57 boundaryInfo_[eqIdx].isOutflow = false;
58 boundaryInfo_[eqIdx].isCouplingDirichlet = false;
59 boundaryInfo_[eqIdx].isCouplingNeumann = false;
60
61 eq2pvIdx_[eqIdx] = eqIdx;
62 pv2eqIdx_[eqIdx] = eqIdx;
63 }
64
71 bool isSet(int eqIdx) const
72 { return boundaryInfo_[eqIdx].visited; }
73
80 void checkWellPosed() const
81 {
82 // if this fails, at least one condition is missing.
83 for (int i=0; i < numEq; ++i)
84 assert(boundaryInfo_[i].visited);
85 }
86
91 {
92 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
93 setNeumann(eqIdx);
94 }
95
100 {
101 for (int eqIdx = 0; eqIdx < numEq; ++ eqIdx)
102 setDirichlet(eqIdx);
103 }
104
109 {
110 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
112 }
113
118 {
119 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
120 setCouplingNeumann(eqIdx);
121 }
122
128 void setNeumann(int eqIdx)
129 {
130 resetEq(eqIdx);
131 boundaryInfo_[eqIdx].visited = true;
132 boundaryInfo_[eqIdx].isNeumann = true;
133 }
134
144 void setDirichlet(int pvIdx, int eqIdx)
145 {
146 resetEq(eqIdx);
147 boundaryInfo_[eqIdx].visited = true;
148 boundaryInfo_[eqIdx].isDirichlet = true;
149
150 // update the equation <-> primary variable mapping
151 eq2pvIdx_[eqIdx] = pvIdx;
152 pv2eqIdx_[pvIdx] = eqIdx;
153 }
154
159 void setCouplingDirichlet(int eqIdx)
160 {
161 resetEq(eqIdx);
162 boundaryInfo_[eqIdx].visited = true;
163 boundaryInfo_[eqIdx].isCouplingDirichlet = true;
164 boundaryInfo_[eqIdx].isDirichlet = true;
165 }
166
171 void setCouplingNeumann(int eqIdx)
172 {
173 resetEq(eqIdx);
174 boundaryInfo_[eqIdx].visited = true;
175 boundaryInfo_[eqIdx].isCouplingNeumann = true;
176 boundaryInfo_[eqIdx].isNeumann = true;
177 }
178
189 void setDirichlet(int pvIdx)
190 {
191 setDirichlet(pvIdx, pvIdx);
192 }
193
200 bool isDirichlet(unsigned eqIdx) const
201 { return boundaryInfo_[eqIdx].isDirichlet ||
202 boundaryInfo_[eqIdx].isCouplingDirichlet;
203 }
204
209 bool hasOnlyDirichlet() const
210 {
211 return std::all_of(boundaryInfo_.begin(),
212 boundaryInfo_.end(),
213 [](const BoundaryInfo& b){ return b.isDirichlet ||
214 b.isCouplingDirichlet; }
215 );
216 }
217
222 bool hasDirichlet() const
223 {
224 return std::any_of(boundaryInfo_.begin(),
225 boundaryInfo_.end(),
226 [](const BoundaryInfo& b){ return b.isDirichlet ||
227 b.isCouplingDirichlet; }
228 );
229 }
230
237 bool isNeumann(unsigned eqIdx) const
238 {
239 return boundaryInfo_[eqIdx].isNeumann ||
240 boundaryInfo_[eqIdx].isCouplingNeumann;
241 }
242
247 bool hasOnlyNeumann() const
248 {
249 return std::all_of(boundaryInfo_.begin(),
250 boundaryInfo_.end(),
251 [](const BoundaryInfo& b){ return b.isNeumann ||
252 b.isCouplingNeumann; }
253 );
254 }
255
260 bool hasNeumann() const
261 {
262 return std::any_of(boundaryInfo_.begin(),
263 boundaryInfo_.end(),
264 [](const BoundaryInfo& b){ return b.isNeumann ||
265 b.isCouplingNeumann; }
266 );
267 }
268
275 bool isCouplingDirichlet(unsigned eqIdx) const
276 { return boundaryInfo_[eqIdx].isCouplingDirichlet; }
277
283 {
284 return std::any_of(boundaryInfo_.begin(),
285 boundaryInfo_.end(),
286 [](const BoundaryInfo& b){ return b.isCouplingDirichlet; }
287 );
288 }
289
296 bool isCouplingNeumann(unsigned eqIdx) const
297 { return boundaryInfo_[eqIdx].isCouplingNeumann; }
298
304 {
305 return std::any_of(boundaryInfo_.begin(),
306 boundaryInfo_.end(),
307 [](const BoundaryInfo& b){ return b.isCouplingNeumann; }
308 );
309 }
310
317 bool isCoupling(unsigned eqIdx) const
318 {
319 return boundaryInfo_[eqIdx].isCouplingDirichlet
320 || boundaryInfo_[eqIdx].isCouplingNeumann;
321 }
322
327 bool hasCoupling() const
328 {
329 for (int i = 0; i < numEq; ++i)
330 if (isCoupling(i))
331 return true;
332 return false;
333 }
334
343 unsigned dirichletToEqIndex(unsigned pvIdx) const
344 { return pv2eqIdx_[pvIdx]; }
345
354 unsigned eqToDirichletIndex(unsigned eqIdx) const
355 { return eq2pvIdx_[eqIdx]; }
356
357protected:
360 bool visited : 1;
361 bool isDirichlet : 1;
362 bool isNeumann : 1;
363 bool isOutflow : 1;
366 };
367
368 std::array<BoundaryInfo, numEq> boundaryInfo_;
369 std::array<unsigned int, numEq> eq2pvIdx_, pv2eqIdx_;
370};
371
372} // end namespace Dumux
373
374#endif
Class to specify the type of a boundary.
Definition: common/boundarytypes.hh:26
void setAllCouplingDirichlet()
Set all boundary conditions to Dirichlet-like coupling.
Definition: common/boundarytypes.hh:108
void setAllNeumann()
Set all boundary conditions to Neumann.
Definition: common/boundarytypes.hh:90
bool isNeumann(unsigned eqIdx) const
Returns true if an equation is used to specify a Neumann condition.
Definition: common/boundarytypes.hh:237
void setAllDirichlet()
Set all boundary conditions to Dirichlet.
Definition: common/boundarytypes.hh:99
void reset()
Reset the boundary types for all equations.
Definition: common/boundarytypes.hh:42
bool hasOnlyDirichlet() const
Returns true if all equations are used to specify a Dirichlet condition.
Definition: common/boundarytypes.hh:209
BoundaryTypes()
Definition: common/boundarytypes.hh:28
bool isSet(int eqIdx) const
Returns true if the boundary types for a given equation has been specified.
Definition: common/boundarytypes.hh:71
bool isDirichlet(unsigned eqIdx) const
Returns true if an equation is used to specify a Dirichlet condition.
Definition: common/boundarytypes.hh:200
void resetEq(int eqIdx)
Reset the boundary types for one equation.
Definition: common/boundarytypes.hh:51
bool hasNeumann() const
Returns true if some equation is used to specify a Neumann condition.
Definition: common/boundarytypes.hh:260
void setDirichlet(int pvIdx)
Set a Dirichlet boundary condition for a single primary variable.
Definition: common/boundarytypes.hh:189
unsigned eqToDirichletIndex(unsigned eqIdx) const
Returns the index of the primary variable which should be used for the Dirichlet condition given an e...
Definition: common/boundarytypes.hh:354
void checkWellPosed() const
Make sure the boundary conditions are well-posed.
Definition: common/boundarytypes.hh:80
bool isCouplingNeumann(unsigned eqIdx) const
Returns true if an equation is used to specify an Neumann coupling condition.
Definition: common/boundarytypes.hh:296
bool hasCoupling() const
Returns true if some equation is used to specify a coupling condition.
Definition: common/boundarytypes.hh:327
bool hasOnlyNeumann() const
Returns true if all equations are used to specify a Neumann condition.
Definition: common/boundarytypes.hh:247
void setDirichlet(int pvIdx, int eqIdx)
Set a Dirichlet boundary condition for a single primary variable.
Definition: common/boundarytypes.hh:144
std::array< BoundaryInfo, numEq > boundaryInfo_
Definition: common/boundarytypes.hh:368
std::array< unsigned int, numEq > eq2pvIdx_
Definition: common/boundarytypes.hh:369
void setCouplingNeumann(int eqIdx)
Set a boundary condition for a single equation to a Neumann-like coupling condition.
Definition: common/boundarytypes.hh:171
unsigned dirichletToEqIndex(unsigned pvIdx) const
Returns the index of the equation which should be used for the Dirichlet condition of the pvIdx's pri...
Definition: common/boundarytypes.hh:343
bool isCouplingDirichlet(unsigned eqIdx) const
Returns true if an equation is used to specify an Dirichlet coupling condition.
Definition: common/boundarytypes.hh:275
bool hasDirichlet() const
Returns true if some equation is used to specify a Dirichlet condition.
Definition: common/boundarytypes.hh:222
void setCouplingDirichlet(int eqIdx)
Set a boundary condition for a single equation to a Dirichlet-like coupling condition.
Definition: common/boundarytypes.hh:159
bool isCoupling(unsigned eqIdx) const
Returns true if an equation is used to specify a coupling condition.
Definition: common/boundarytypes.hh:317
void setAllCouplingNeumann()
Set all boundary conditions to Neumann-like coupling.
Definition: common/boundarytypes.hh:117
bool hasCouplingDirichlet() const
Returns true if some equation is used to specify an Dirichlet coupling condition.
Definition: common/boundarytypes.hh:282
bool hasCouplingNeumann() const
Returns true if some equation is used to specify an Neumann coupling condition.
Definition: common/boundarytypes.hh:303
std::array< unsigned int, numEq > pv2eqIdx_
Definition: common/boundarytypes.hh:369
static constexpr int size()
we have a boundary condition for each equation
Definition: common/boundarytypes.hh:32
void setNeumann(int eqIdx)
Set a Neumann boundary condition for a single equation.
Definition: common/boundarytypes.hh:128
Definition: adapt.hh:17
use bitfields to minimize the size
Definition: common/boundarytypes.hh:359
bool isNeumann
Definition: common/boundarytypes.hh:362
bool isOutflow
Definition: common/boundarytypes.hh:363
bool isDirichlet
Definition: common/boundarytypes.hh:361
bool visited
Definition: common/boundarytypes.hh:360
bool isCouplingDirichlet
Definition: common/boundarytypes.hh:364
bool isCouplingNeumann
Definition: common/boundarytypes.hh:365