cclocalresidual.hh 5.57 KB
Newer Older
1
2
3
4
5
6
7
// -*- 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    *
8
 *   the Free Software Foundation, either version 3 of the License, or       *
9
10
11
12
13
14
15
16
17
18
19
20
 *   (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
21
22
23
 * \ingroup Assembly
 * \ingroup CCDiscretization
 * \brief Calculates the element-wise residual for cell-centered discretization schemes
24
25
26
27
 */
#ifndef DUMUX_CC_LOCAL_RESIDUAL_HH
#define DUMUX_CC_LOCAL_RESIDUAL_HH

28
#include <dumux/common/reservedblockvector.hh>
29
#include <dumux/common/properties.hh>
30
#include <dumux/common/numeqvector.hh>
31
#include <dumux/assembly/fvlocalresidual.hh>
32
#include <dumux/discretization/extrusion.hh>
33

34
35
namespace Dumux {

36
/*!
37
38
39
 * \ingroup Assembly
 * \ingroup CCDiscretization
 * \brief Calculates the element-wise residual for the cell-centered discretization schemes
40
41
 */
template<class TypeTag>
42
class CCLocalResidual : public FVLocalResidual<TypeTag>
43
{
44
    using ParentType = FVLocalResidual<TypeTag>;
45
    using Problem = GetPropType<TypeTag, Properties::Problem>;
46
    using Element = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView::template Codim<0>::Entity;
47
    using NumEqVector = Dumux::NumEqVector<GetPropType<TypeTag, Properties::PrimaryVariables>>;
48
49
50
    using ElementBoundaryTypes = GetPropType<TypeTag, Properties::ElementBoundaryTypes>;
    using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
    using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
51
52
53
    using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
    using FVElementGeometry = typename GridGeometry::LocalView;
    using Extrusion = Extrusion_t<GridGeometry>;
54
    using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
55

56
public:
57
    using ElementResidualVector = typename ParentType::ElementResidualVector;
58
    using ParentType::ParentType;
59

60
    //! evaluate the flux residual for a sub control volume face and add to residual
61
62
63
64
65
66
67
68
    void evalFlux(ElementResidualVector& residual,
                  const Problem& problem,
                  const Element& element,
                  const FVElementGeometry& fvGeometry,
                  const ElementVolumeVariables& elemVolVars,
                  const ElementBoundaryTypes& elemBcTypes,
                  const ElementFluxVariablesCache& elemFluxVarsCache,
                  const SubControlVolumeFace& scvf) const
69
    {
70
        const auto& scv = fvGeometry.scv(scvf.insideScvIdx());
71
        const auto localScvIdx = scv.localDofIndex();
72
        residual[localScvIdx] += this->asImp().evalFlux(problem, element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
73
74
    }

75
    //! evaluate the flux residual for a sub control volume face
76
    NumEqVector evalFlux(const Problem& problem,
Sina Ackermann's avatar
Sina Ackermann committed
77
78
79
80
81
                         const Element& element,
                         const FVElementGeometry& fvGeometry,
                         const ElementVolumeVariables& elemVolVars,
                         const ElementFluxVariablesCache& elemFluxVarsCache,
                         const SubControlVolumeFace& scvf) const
82
    {
83
        NumEqVector flux(0.0);
84

85
        // inner faces
86
        if (!scvf.boundary())
87
        {
88
            flux += this->asImp().computeFlux(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
89
        }
90

91
92
        // boundary faces
        else
93
        {
94
            const auto& bcTypes = problem.boundaryTypes(element, scvf);
95

96
97
            // Dirichlet boundaries
            if (bcTypes.hasDirichlet() && !bcTypes.hasNeumann())
98
                flux += this->asImp().computeFlux(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
99

100
101
            // Neumann and Robin ("solution dependent Neumann") boundary conditions
            else if (bcTypes.hasNeumann() && !bcTypes.hasDirichlet())
102
            {
103
                auto neumannFluxes = problem.neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
104

105
                // multiply neumann fluxes with the area and the extrusion factor
106
                const auto& scv = fvGeometry.scv(scvf.insideScvIdx());
107
                neumannFluxes *= Extrusion::area(scvf)*elemVolVars[scv].extrusionFactor();
108

109
                flux += neumannFluxes;
110
111
            }

112
113
            else
                DUNE_THROW(Dune::NotImplemented, "Mixed boundary conditions. Use pure boundary conditions by converting Dirichlet BCs to Robin BCs");
114
115
        }

116
        return flux;
117
    }
118
119
};

120
} // end namespace Dumux
121

122
#endif