Loading [MathJax]/extensions/tex2jax.js
3.4
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
120 [[deprecated("Will be removed after release 3.4")]]
122 {
123 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
124 setOutflow(eqIdx);
125 }
126
131 {
132 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
134 }
135
140 {
141 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
142 setCouplingNeumann(eqIdx);
143 }
144
150 void setNeumann(int eqIdx)
151 {
152 resetEq(eqIdx);
153 boundaryInfo_[eqIdx].visited = true;
154 boundaryInfo_[eqIdx].isNeumann = true;
155 }
156
166 void setDirichlet(int pvIdx, int eqIdx)
167 {
168 resetEq(eqIdx);
169 boundaryInfo_[eqIdx].visited = true;
170 boundaryInfo_[eqIdx].isDirichlet = true;
171
172 // update the equation <-> primary variable mapping
173 eq2pvIdx_[eqIdx] = pvIdx;
174 pv2eqIdx_[pvIdx] = eqIdx;
175 }
176
183 [[deprecated("Will be removed after release 3.4")]]
184 void setOutflow(int eqIdx)
185 {
186 resetEq(eqIdx);
187 boundaryInfo_[eqIdx].visited = true;
188 boundaryInfo_[eqIdx].isOutflow = true;
189 }
190
195 void setCouplingDirichlet(int eqIdx)
196 {
197 resetEq(eqIdx);
198 boundaryInfo_[eqIdx].visited = true;
199 boundaryInfo_[eqIdx].isCouplingDirichlet = true;
200 boundaryInfo_[eqIdx].isDirichlet = true;
201 }
202
207 void setCouplingNeumann(int eqIdx)
208 {
209 resetEq(eqIdx);
210 boundaryInfo_[eqIdx].visited = true;
211 boundaryInfo_[eqIdx].isCouplingNeumann = true;
212 boundaryInfo_[eqIdx].isNeumann = true;
213 }
214
225 void setDirichlet(int pvIdx)
226 {
227 setDirichlet(pvIdx, pvIdx);
228 }
229
236 bool isDirichlet(unsigned eqIdx) const
237 { return boundaryInfo_[eqIdx].isDirichlet ||
238 boundaryInfo_[eqIdx].isCouplingDirichlet;
239 }
240
245 bool hasOnlyDirichlet() const
246 {
247 return std::all_of(boundaryInfo_.begin(),
248 boundaryInfo_.end(),
249 [](const BoundaryInfo& b){ return b.isDirichlet ||
250 b.isCouplingDirichlet; }
251 );
252 }
253
258 bool hasDirichlet() const
259 {
260 return std::any_of(boundaryInfo_.begin(),
261 boundaryInfo_.end(),
262 [](const BoundaryInfo& b){ return b.isDirichlet ||
263 b.isCouplingDirichlet; }
264 );
265 }
266
273 bool isNeumann(unsigned eqIdx) const
274 {
275 return boundaryInfo_[eqIdx].isNeumann ||
276 boundaryInfo_[eqIdx].isCouplingNeumann;
277 }
278
283 bool hasOnlyNeumann() const
284 {
285 return std::all_of(boundaryInfo_.begin(),
286 boundaryInfo_.end(),
287 [](const BoundaryInfo& b){ return b.isNeumann ||
288 b.isCouplingNeumann; }
289 );
290 }
291
296 bool hasNeumann() const
297 {
298 return std::any_of(boundaryInfo_.begin(),
299 boundaryInfo_.end(),
300 [](const BoundaryInfo& b){ return b.isNeumann ||
301 b.isCouplingNeumann; }
302 );
303 }
304
311 [[deprecated("Will be removed after release 3.4")]]
312 bool isOutflow(unsigned eqIdx) const
313 { return boundaryInfo_[eqIdx].isOutflow; }
314
319 [[deprecated("Will be removed after release 3.4")]]
320 bool hasOutflow() const
321 {
322 return std::any_of(boundaryInfo_.begin(),
323 boundaryInfo_.end(),
324 [](const BoundaryInfo& b){ return b.isOutflow; }
325 );
326 }
327
334 bool isCouplingDirichlet(unsigned eqIdx) const
335 { return boundaryInfo_[eqIdx].isCouplingDirichlet; }
336
342 {
343 return std::any_of(boundaryInfo_.begin(),
344 boundaryInfo_.end(),
345 [](const BoundaryInfo& b){ return b.isCouplingDirichlet; }
346 );
347 }
348
355 bool isCouplingNeumann(unsigned eqIdx) const
356 { return boundaryInfo_[eqIdx].isCouplingNeumann; }
357
363 {
364 return std::any_of(boundaryInfo_.begin(),
365 boundaryInfo_.end(),
366 [](const BoundaryInfo& b){ return b.isCouplingNeumann; }
367 );
368 }
369
376 bool isCoupling(unsigned eqIdx) const
377 {
378 return boundaryInfo_[eqIdx].isCouplingDirichlet
379 || boundaryInfo_[eqIdx].isCouplingNeumann;
380 }
381
386 bool hasCoupling() const
387 {
388 for (int i = 0; i < numEq; ++i)
389 if (isCoupling(i))
390 return true;
391 return false;
392 }
393
402 unsigned dirichletToEqIndex(unsigned pvIdx) const
403 { return pv2eqIdx_[pvIdx]; }
404
413 unsigned eqToDirichletIndex(unsigned eqIdx) const
414 { return eq2pvIdx_[eqIdx]; }
415
416protected:
419 bool visited : 1;
420 bool isDirichlet : 1;
421 bool isNeumann : 1;
422 bool isOutflow : 1;
425 };
426
427 std::array<BoundaryInfo, numEq> boundaryInfo_;
428 std::array<unsigned int, numEq> eq2pvIdx_, pv2eqIdx_;
429};
430
431} // end namespace Dumux
432
433#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:130
void setAllNeumann()
Set all boundary conditions to Neumann.
Definition: common/boundarytypes.hh:102
bool isOutflow(unsigned eqIdx) const
Returns true if an equation is used to specify an outflow condition.
Definition: common/boundarytypes.hh:312
bool isNeumann(unsigned eqIdx) const
Returns true if an equation is used to specify a Neumann condition.
Definition: common/boundarytypes.hh:273
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:245
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:236
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:296
void setDirichlet(int pvIdx)
Set a Dirichlet boundary condition for a single primary variable.
Definition: common/boundarytypes.hh:225
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:413
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:355
bool hasCoupling() const
Returns true if some equation is used to specify a coupling condition.
Definition: common/boundarytypes.hh:386
bool hasOnlyNeumann() const
Returns true if all equations are used to specify a Neumann condition.
Definition: common/boundarytypes.hh:283
void setDirichlet(int pvIdx, int eqIdx)
Set a Dirichlet boundary condition for a single primary variable.
Definition: common/boundarytypes.hh:166
std::array< BoundaryInfo, numEq > boundaryInfo_
Definition: common/boundarytypes.hh:427
std::array< unsigned int, numEq > eq2pvIdx_
Definition: common/boundarytypes.hh:428
void setCouplingNeumann(int eqIdx)
Set a boundary condition for a single equation to a Neumann-like coupling condition.
Definition: common/boundarytypes.hh:207
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:402
void setAllOutflow()
Set all boundary conditions to Neumann.
Definition: common/boundarytypes.hh:121
bool isCouplingDirichlet(unsigned eqIdx) const
Returns true if an equation is used to specify an Dirichlet coupling condition.
Definition: common/boundarytypes.hh:334
void setOutflow(int eqIdx)
Set a Neumann boundary condition for a single equation.
Definition: common/boundarytypes.hh:184
bool hasDirichlet() const
Returns true if some equation is used to specify a Dirichlet condition.
Definition: common/boundarytypes.hh:258
void setCouplingDirichlet(int eqIdx)
Set a boundary condition for a single equation to a Dirichlet-like coupling condition.
Definition: common/boundarytypes.hh:195
bool hasOutflow() const
Returns true if some equation is used to specify an outflow condition.
Definition: common/boundarytypes.hh:320
bool isCoupling(unsigned eqIdx) const
Returns true if an equation is used to specify a coupling condition.
Definition: common/boundarytypes.hh:376
void setAllCouplingNeumann()
Set all boundary conditions to Neumann-like coupling.
Definition: common/boundarytypes.hh:139
bool hasCouplingDirichlet() const
Returns true if some equation is used to specify an Dirichlet coupling condition.
Definition: common/boundarytypes.hh:341
bool hasCouplingNeumann() const
Returns true if some equation is used to specify an Neumann coupling condition.
Definition: common/boundarytypes.hh:362
std::array< unsigned int, numEq > pv2eqIdx_
Definition: common/boundarytypes.hh:428
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:150
use bitfields to minimize the size
Definition: common/boundarytypes.hh:418
bool isNeumann
Definition: common/boundarytypes.hh:421
bool isOutflow
Definition: common/boundarytypes.hh:422
bool isDirichlet
Definition: common/boundarytypes.hh:420
bool visited
Definition: common/boundarytypes.hh:419
bool isCouplingDirichlet
Definition: common/boundarytypes.hh:423
bool isCouplingNeumann
Definition: common/boundarytypes.hh:424