3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_BOUNDARY_TYPES_HH
25#define DUMUX_BOUNDARY_TYPES_HH
26
27#include <algorithm>
28#include <array>
29
30namespace Dumux {
31
36template <int numEq>
38{
39public:
41 { reset(); }
42
44 static constexpr int size()
45 { return numEq; }
46
54 void reset()
55 {
56 for (int eqIdx=0; eqIdx < numEq; ++eqIdx)
57 resetEq(eqIdx);
58 }
59
63 void resetEq(int eqIdx)
64 {
65 boundaryInfo_[eqIdx].visited = false;
66
67 boundaryInfo_[eqIdx].isDirichlet = false;
68 boundaryInfo_[eqIdx].isNeumann = false;
69 boundaryInfo_[eqIdx].isOutflow = false;
70 boundaryInfo_[eqIdx].isCouplingDirichlet = false;
71 boundaryInfo_[eqIdx].isCouplingNeumann = false;
72
73 eq2pvIdx_[eqIdx] = eqIdx;
74 pv2eqIdx_[eqIdx] = eqIdx;
75 }
76
83 bool isSet(int eqIdx) const
84 { return boundaryInfo_[eqIdx].visited; }
85
92 void checkWellPosed() const
93 {
94 // if this fails, at least one condition is missing.
95 for (int i=0; i < numEq; ++i)
96 assert(boundaryInfo_[i].visited);
97 }
98
103 {
104 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
105 setNeumann(eqIdx);
106 }
107
112 {
113 for (int eqIdx = 0; eqIdx < numEq; ++ eqIdx)
114 setDirichlet(eqIdx);
115 }
116
121 {
122 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
124 }
125
130 {
131 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
132 setCouplingNeumann(eqIdx);
133 }
134
140 void setNeumann(int eqIdx)
141 {
142 resetEq(eqIdx);
143 boundaryInfo_[eqIdx].visited = true;
144 boundaryInfo_[eqIdx].isNeumann = true;
145 }
146
156 void setDirichlet(int pvIdx, int eqIdx)
157 {
158 resetEq(eqIdx);
159 boundaryInfo_[eqIdx].visited = true;
160 boundaryInfo_[eqIdx].isDirichlet = true;
161
162 // update the equation <-> primary variable mapping
163 eq2pvIdx_[eqIdx] = pvIdx;
164 pv2eqIdx_[pvIdx] = eqIdx;
165 }
166
171 void setCouplingDirichlet(int eqIdx)
172 {
173 resetEq(eqIdx);
174 boundaryInfo_[eqIdx].visited = true;
175 boundaryInfo_[eqIdx].isCouplingDirichlet = true;
176 boundaryInfo_[eqIdx].isDirichlet = true;
177 }
178
183 void setCouplingNeumann(int eqIdx)
184 {
185 resetEq(eqIdx);
186 boundaryInfo_[eqIdx].visited = true;
187 boundaryInfo_[eqIdx].isCouplingNeumann = true;
188 boundaryInfo_[eqIdx].isNeumann = true;
189 }
190
201 void setDirichlet(int pvIdx)
202 {
203 setDirichlet(pvIdx, pvIdx);
204 }
205
212 bool isDirichlet(unsigned eqIdx) const
213 { return boundaryInfo_[eqIdx].isDirichlet ||
214 boundaryInfo_[eqIdx].isCouplingDirichlet;
215 }
216
221 bool hasOnlyDirichlet() const
222 {
223 return std::all_of(boundaryInfo_.begin(),
224 boundaryInfo_.end(),
225 [](const BoundaryInfo& b){ return b.isDirichlet ||
226 b.isCouplingDirichlet; }
227 );
228 }
229
234 bool hasDirichlet() const
235 {
236 return std::any_of(boundaryInfo_.begin(),
237 boundaryInfo_.end(),
238 [](const BoundaryInfo& b){ return b.isDirichlet ||
239 b.isCouplingDirichlet; }
240 );
241 }
242
249 bool isNeumann(unsigned eqIdx) const
250 {
251 return boundaryInfo_[eqIdx].isNeumann ||
252 boundaryInfo_[eqIdx].isCouplingNeumann;
253 }
254
259 bool hasOnlyNeumann() const
260 {
261 return std::all_of(boundaryInfo_.begin(),
262 boundaryInfo_.end(),
263 [](const BoundaryInfo& b){ return b.isNeumann ||
264 b.isCouplingNeumann; }
265 );
266 }
267
272 bool hasNeumann() const
273 {
274 return std::any_of(boundaryInfo_.begin(),
275 boundaryInfo_.end(),
276 [](const BoundaryInfo& b){ return b.isNeumann ||
277 b.isCouplingNeumann; }
278 );
279 }
280
287 bool isCouplingDirichlet(unsigned eqIdx) const
288 { return boundaryInfo_[eqIdx].isCouplingDirichlet; }
289
295 {
296 return std::any_of(boundaryInfo_.begin(),
297 boundaryInfo_.end(),
298 [](const BoundaryInfo& b){ return b.isCouplingDirichlet; }
299 );
300 }
301
308 bool isCouplingNeumann(unsigned eqIdx) const
309 { return boundaryInfo_[eqIdx].isCouplingNeumann; }
310
316 {
317 return std::any_of(boundaryInfo_.begin(),
318 boundaryInfo_.end(),
319 [](const BoundaryInfo& b){ return b.isCouplingNeumann; }
320 );
321 }
322
329 bool isCoupling(unsigned eqIdx) const
330 {
331 return boundaryInfo_[eqIdx].isCouplingDirichlet
332 || boundaryInfo_[eqIdx].isCouplingNeumann;
333 }
334
339 bool hasCoupling() const
340 {
341 for (int i = 0; i < numEq; ++i)
342 if (isCoupling(i))
343 return true;
344 return false;
345 }
346
355 unsigned dirichletToEqIndex(unsigned pvIdx) const
356 { return pv2eqIdx_[pvIdx]; }
357
366 unsigned eqToDirichletIndex(unsigned eqIdx) const
367 { return eq2pvIdx_[eqIdx]; }
368
369protected:
372 bool visited : 1;
373 bool isDirichlet : 1;
374 bool isNeumann : 1;
375 bool isOutflow : 1;
378 };
379
380 std::array<BoundaryInfo, numEq> boundaryInfo_;
381 std::array<unsigned int, numEq> eq2pvIdx_, pv2eqIdx_;
382};
383
384} // end namespace Dumux
385
386#endif
Definition: adapt.hh:29
Class to specify the type of a boundary.
Definition: common/boundarytypes.hh:38
void setAllCouplingDirichlet()
Set all boundary conditions to Dirichlet-like coupling.
Definition: common/boundarytypes.hh:120
void setAllNeumann()
Set all boundary conditions to Neumann.
Definition: common/boundarytypes.hh:102
bool isNeumann(unsigned eqIdx) const
Returns true if an equation is used to specify a Neumann condition.
Definition: common/boundarytypes.hh:249
void setAllDirichlet()
Set all boundary conditions to Dirichlet.
Definition: common/boundarytypes.hh:111
void reset()
Reset the boundary types for all equations.
Definition: common/boundarytypes.hh:54
bool hasOnlyDirichlet() const
Returns true if all equations are used to specify a Dirichlet condition.
Definition: common/boundarytypes.hh:221
BoundaryTypes()
Definition: common/boundarytypes.hh:40
bool isSet(int eqIdx) const
Returns true if the boundary types for a given equation has been specified.
Definition: common/boundarytypes.hh:83
bool isDirichlet(unsigned eqIdx) const
Returns true if an equation is used to specify a Dirichlet condition.
Definition: common/boundarytypes.hh:212
void resetEq(int eqIdx)
Reset the boundary types for one equation.
Definition: common/boundarytypes.hh:63
bool hasNeumann() const
Returns true if some equation is used to specify a Neumann condition.
Definition: common/boundarytypes.hh:272
void setDirichlet(int pvIdx)
Set a Dirichlet boundary condition for a single primary variable.
Definition: common/boundarytypes.hh:201
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:366
void checkWellPosed() const
Make sure the boundary conditions are well-posed.
Definition: common/boundarytypes.hh:92
bool isCouplingNeumann(unsigned eqIdx) const
Returns true if an equation is used to specify an Neumann coupling condition.
Definition: common/boundarytypes.hh:308
bool hasCoupling() const
Returns true if some equation is used to specify a coupling condition.
Definition: common/boundarytypes.hh:339
bool hasOnlyNeumann() const
Returns true if all equations are used to specify a Neumann condition.
Definition: common/boundarytypes.hh:259
void setDirichlet(int pvIdx, int eqIdx)
Set a Dirichlet boundary condition for a single primary variable.
Definition: common/boundarytypes.hh:156
std::array< BoundaryInfo, numEq > boundaryInfo_
Definition: common/boundarytypes.hh:380
std::array< unsigned int, numEq > eq2pvIdx_
Definition: common/boundarytypes.hh:381
void setCouplingNeumann(int eqIdx)
Set a boundary condition for a single equation to a Neumann-like coupling condition.
Definition: common/boundarytypes.hh:183
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:355
bool isCouplingDirichlet(unsigned eqIdx) const
Returns true if an equation is used to specify an Dirichlet coupling condition.
Definition: common/boundarytypes.hh:287
bool hasDirichlet() const
Returns true if some equation is used to specify a Dirichlet condition.
Definition: common/boundarytypes.hh:234
void setCouplingDirichlet(int eqIdx)
Set a boundary condition for a single equation to a Dirichlet-like coupling condition.
Definition: common/boundarytypes.hh:171
bool isCoupling(unsigned eqIdx) const
Returns true if an equation is used to specify a coupling condition.
Definition: common/boundarytypes.hh:329
void setAllCouplingNeumann()
Set all boundary conditions to Neumann-like coupling.
Definition: common/boundarytypes.hh:129
bool hasCouplingDirichlet() const
Returns true if some equation is used to specify an Dirichlet coupling condition.
Definition: common/boundarytypes.hh:294
bool hasCouplingNeumann() const
Returns true if some equation is used to specify an Neumann coupling condition.
Definition: common/boundarytypes.hh:315
std::array< unsigned int, numEq > pv2eqIdx_
Definition: common/boundarytypes.hh:381
static constexpr int size()
we have a boundary condition for each equation
Definition: common/boundarytypes.hh:44
void setNeumann(int eqIdx)
Set a Neumann boundary condition for a single equation.
Definition: common/boundarytypes.hh:140
use bitfields to minimize the size
Definition: common/boundarytypes.hh:371
bool isNeumann
Definition: common/boundarytypes.hh:374
bool isOutflow
Definition: common/boundarytypes.hh:375
bool isDirichlet
Definition: common/boundarytypes.hh:373
bool visited
Definition: common/boundarytypes.hh:372
bool isCouplingDirichlet
Definition: common/boundarytypes.hh:376
bool isCouplingNeumann
Definition: common/boundarytypes.hh:377