scvftoscvboundarytypes.hh 3.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
 *   See the file COPYING for full copying permissions.                      *
 *                                                                           *
 *   This program is free software: you can redistribute it and/or modify    *
 *   it under the terms of the GNU General Public License as published by    *
 *   the Free Software Foundation, either version 2 of the License, or       *
 *   (at your option) any later version.                                     *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 *****************************************************************************/
/*!
 * \file
 * \brief Convert intersection boundary types to vertex boundary types
 */
#ifndef DUMUX_SCVF_TO_SCV_BCTYPES_HH
#define DUMUX_SCVF_TO_SCV_BCTYPES_HH

#include <vector>
27
#include <dune/common/exceptions.hh>
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <dumux/discretization/methods.hh>

namespace Dumux
{

/*!
 * \ingroup BoxModel
 * \brief Convert intersection boundary types to vertex boundary types
 */
template<class BoundaryTypes, DiscretizationMethods discMethod>
class ScvfToScvBoundaryTypes
{
public:
    ScvfToScvBoundaryTypes() = default;

    template<class Problem>
    void computeBoundaryTypes(const Problem& problem)
    {
        // only do something for box
        if (discMethod == DiscretizationMethods::Box)
        {
            const auto& fvGridGeometry = problem.fvGridGeometry();
            scvBoundaryTypes.resize(fvGridGeometry.vertexMapper().size());
            // set all equations to Neumann by default
            for (std::size_t vIdx = 0; vIdx < scvBoundaryTypes.size(); vIdx++)
                scvBoundaryTypes[vIdx].setAllNeumann();

            for (const auto& element : elements(fvGridGeometry.gridView()))
            {
                // iterate over the scvfs
                auto fvGeometry = localView(fvGridGeometry);
                fvGeometry.bindElement(element);

                for (const auto& scvf : scvfs(fvGeometry))
                {
                    if (!scvf.boundary())
                        continue;

                    const auto bcTypes = problem.boundaryTypes(element, scvf);
                    if (!bcTypes.hasDirichlet())
                        continue;

                    // get the inside scv belonging to this scvf and set possible Dirichlet boundary conditions
                    const auto& scv = fvGeometry.scv(scvf.insideScvIdx());
                    for (int pvIdx = 0; pvIdx < bcTypes.size(); ++pvIdx)
                        if (bcTypes.isDirichlet(pvIdx))
                            scvBoundaryTypes[scv.dofIndex()].setDirichlet(pvIdx);
                }
            }
        }
    }

    //! get the boundary types of the scv
    template<class SubControlVolume>
    const BoundaryTypes& boundaryTypes(const SubControlVolume& scv) const
    {
        if (discMethod == DiscretizationMethods::Box)
            return scvBoundaryTypes[scv.dofIndex()];
        else
            DUNE_THROW(Dune::InvalidStateException, "Only use this for the box discretization!");
    }

private:
    std::vector<BoundaryTypes> scvBoundaryTypes;
};

} // end namespace Dumux

#endif