convmixproblem.hh 9.34 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// -*- 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/>.   *
 *****************************************************************************/
Kai Wendel's avatar
Kai Wendel committed
19
20
21
22
23
24
25
26
/**
 * \file
 * \brief Definition of a problem, for the 1pnc problem:
 * Component transport of nitrogen dissolved in the water phase.
 */
#ifndef DUMUX_CONVMIXING_PROBLEM_HH
#define DUMUX_CONVMIXING_PROBLEM_HH

27
28
#include <dumux/common/properties.hh>
#include <dumux/common/parameters.hh>
29
#include <dumux/common/boundarytypes.hh>
30
#include <dumux/common/numeqvector.hh>
Kai Wendel's avatar
Kai Wendel committed
31
#include <dumux/porousmediumflow/problem.hh>
Melanie Darcis's avatar
Melanie Darcis committed
32

33
#include <dumux/material/fluidsystems/brineco2.hh>
34
35
#include <lecture/common/co2tablesbenchmark3.hh>

Kai Wendel's avatar
Kai Wendel committed
36
37
38
39
40
41
42
43
namespace Dumux {

/*!
 * \brief Definition of a problem, for the 1pnc problem:
 *
 * This problem uses the \ref OnePNCModel model.
 *
 */
44
template <class TypeTag>
Kai Wendel's avatar
Kai Wendel committed
45
class ConvmixProblem : public PorousMediumFlowProblem<TypeTag>
Melanie Darcis's avatar
Melanie Darcis committed
46
{
Kai Wendel's avatar
Kai Wendel committed
47
48
    using ParentType = PorousMediumFlowProblem<TypeTag>;

49
50
    using Scalar = GetPropType<TypeTag, Properties::Scalar>;
    using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
51
    using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
52
    using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
53
    using BoundaryTypes = Dumux::BoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>;
54
    using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
55
56
    using FVGridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
    using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
57
    using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
58
59
60
    using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
    using ElementFluxVariablesCache = typename GridVariables::GridFluxVariablesCache::LocalView;
    using ElementVolumeVariables = typename GridVariables::GridVolumeVariables::LocalView;
Kai Wendel's avatar
Kai Wendel committed
61
62
63
    using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
    using Element = typename GridView::template Codim<0>::Entity;

Yue Wang's avatar
Yue Wang committed
64
65
    using CO2 = Components::CO2<Scalar, GeneratedCO2Tables::CO2Tables>;
    using Brine_CO2 = BinaryCoeff::Brine_CO2<Scalar, GeneratedCO2Tables::CO2Tables>;
Melanie Darcis's avatar
Melanie Darcis committed
66
67

    // copy some indices for convenience
Kai Wendel's avatar
Kai Wendel committed
68
69
    enum
    {
Melanie Darcis's avatar
Melanie Darcis committed
70
        // indices of the primary variables
Kai Wendel's avatar
Kai Wendel committed
71
        pressureIdx = Indices::pressureIdx,
Melanie Darcis's avatar
Melanie Darcis committed
72

Kai Wendel's avatar
Kai Wendel committed
73
74
75
        // component indices
        BrineIdx = FluidSystem::MultiPhaseFluidSystem::comp0Idx,
        CO2Idx = FluidSystem::MultiPhaseFluidSystem::CO2Idx,
Melanie Darcis's avatar
Melanie Darcis committed
76

Kai Wendel's avatar
Kai Wendel committed
77
78
79
80
        // equation indices
        conti0EqIdx = Indices::conti0EqIdx,
        contiCO2EqIdx = conti0EqIdx + CO2Idx
    };
Melanie Darcis's avatar
Melanie Darcis committed
81

Kai Wendel's avatar
Kai Wendel committed
82
    //! property that defines whether mole or mass fractions are used
83
    static constexpr bool useMoles = getPropValue<TypeTag, Properties::UseMoles>();
84
    static const bool isBox = GetPropType<TypeTag, Properties::GridGeometry>::discMethod == DiscretizationMethod::box;
Melanie Darcis's avatar
Melanie Darcis committed
85

Kai Wendel's avatar
Kai Wendel committed
86
87
    static const int dimWorld = GridView::dimensionworld;
    using GlobalPosition = typename SubControlVolumeFace::GlobalPosition;
Melanie Darcis's avatar
Melanie Darcis committed
88
89

public:
Kai Wendel's avatar
Kai Wendel committed
90
91
    ConvmixProblem(std::shared_ptr<const FVGridGeometry> fvGridGeometry)
    : ParentType(fvGridGeometry)
Melanie Darcis's avatar
Melanie Darcis committed
92
    {
Kai Wendel's avatar
Kai Wendel committed
93
        name_ = getParam<std::string>("Problem.Name");
Melanie Darcis's avatar
Melanie Darcis committed
94

Kai Wendel's avatar
Kai Wendel committed
95
        //initialize fluid system
Melanie Darcis's avatar
Melanie Darcis committed
96
        FluidSystem::init();
Kai Wendel's avatar
Kai Wendel committed
97
98
99
100
101
102

        // stating in the console whether mole or mass fractions are used
        if(useMoles)
            std::cout<<"problem uses mole fractions"<<std::endl;
        else
            std::cout<<"problem uses mass fractions"<<std::endl;
Melanie Darcis's avatar
Melanie Darcis committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    }

    /*!
     * \name Problem parameters
     */
    // \{


    // \}

    /*!
     * \name Boundary conditions
     */
    // \{

    /*!
     * \brief Specifies which kind of boundary condition should be
     *        used for which equation on a given boundary segment.
Kai Wendel's avatar
Kai Wendel committed
121
122
     *
     * \param globalPos The position for which the bc type should be evaluated
Melanie Darcis's avatar
Melanie Darcis committed
123
     */
Kai Wendel's avatar
Kai Wendel committed
124
    BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
Melanie Darcis's avatar
Melanie Darcis committed
125
    {
Kai Wendel's avatar
Kai Wendel committed
126
        BoundaryTypes values;
Melanie Darcis's avatar
Melanie Darcis committed
127
128
129

        values.setAllNeumann();

130
        if(globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_)
Kai Wendel's avatar
Kai Wendel committed
131
            values.setDirichlet(CO2Idx, contiCO2EqIdx);
Melanie Darcis's avatar
Melanie Darcis committed
132
        if(globalPos[1] < eps_)
Kai Wendel's avatar
Kai Wendel committed
133
134
135
            values.setAllDirichlet();

        return values;
Melanie Darcis's avatar
Melanie Darcis committed
136
137
138
139
140
141
    }

    /*!
     * \brief Evaluate the boundary conditions for a dirichlet
     *        boundary segment.
     *
Kai Wendel's avatar
Kai Wendel committed
142
     * \param globalPos The position for which the bc type should be evaluated
Melanie Darcis's avatar
Melanie Darcis committed
143
     */
Kai Wendel's avatar
Kai Wendel committed
144
    PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
Melanie Darcis's avatar
Melanie Darcis committed
145
    {
Kai Wendel's avatar
Kai Wendel committed
146
        PrimaryVariables values = initial_(globalPos);
Melanie Darcis's avatar
Melanie Darcis committed
147

Kai Wendel's avatar
Kai Wendel committed
148
        return values;
Melanie Darcis's avatar
Melanie Darcis committed
149
150
151
152
153
154
    }

    /*!
     * \brief Evaluate the boundary conditions for a neumann
     *        boundary segment.
     *
Kai Wendel's avatar
Kai Wendel committed
155
156
157
158
159
160
161
162
163
     * This is the method for the case where the Neumann condition is
     * potentially solution dependent and requires some quantities that
     * are specific to the fully-implicit method.
     *
     * \param values The neumann values for the conservation equations in units of
     *                 \f$ [ \textnormal{unit of conserved quantity} / (m^2 \cdot s )] \f$
     * \param element The finite element
     * \param fvGeometry The finite-volume geometry
     * \param elemVolVars All volume variables for the element
164
     * \param elemFluxVarsCache Flux variables caches for all faces in stencil
Kai Wendel's avatar
Kai Wendel committed
165
166
167
168
169
     * \param scvf The sub control volume face
     *
     * For this method, the \a values parameter stores the flux
     * in normal direction of each phase. Negative values mean influx.
     * E.g. for the mass balance that would the mass flux in \f$ [ kg / (m^2 \cdot s)] \f$.
Melanie Darcis's avatar
Melanie Darcis committed
170
     */
Kai Wendel's avatar
Kai Wendel committed
171
    NumEqVector neumann(const Element& element,
172
173
174
175
                        const FVElementGeometry& fvGeometry,
                        const ElementVolumeVariables& elemVolVars,
                        const ElementFluxVariablesCache& elemFluxVarsCache,
                        const SubControlVolumeFace& scvf) const
Melanie Darcis's avatar
Melanie Darcis committed
176
    {
Kai Wendel's avatar
Kai Wendel committed
177
178
179
180
        NumEqVector flux(0.0);

        // no-flow everywhere
        return flux;
Melanie Darcis's avatar
Melanie Darcis committed
181
182
183
184
185
186
187
188
189
190
191
192
193
    }

    // \}

    /*!
     * \name Volume terms
     */
    // \{

    /*!
     * \brief Evaluate the source term for all phases within a given
     *        sub-control-volume.
     *
Kai Wendel's avatar
Kai Wendel committed
194
     * For this method, the \a priVars parameter stores the rate mass
Melanie Darcis's avatar
Melanie Darcis committed
195
196
197
     * of a component is generated or annihilate per volume
     * unit. Positive values mean that mass is created, negative ones
     * mean that it vanishes.
Kai Wendel's avatar
Kai Wendel committed
198
199
     *
     * The units must be according to either using mole or mass fractions. (mole/(m^3*s) or kg/(m^3*s))
Melanie Darcis's avatar
Melanie Darcis committed
200
     */
Kai Wendel's avatar
Kai Wendel committed
201
202
    NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
    { return NumEqVector(0.0); }
Melanie Darcis's avatar
Melanie Darcis committed
203
204
205
206

    /*!
     * \brief Evaluate the initial value for a control volume.
     *
Kai Wendel's avatar
Kai Wendel committed
207
208
     * \param globalPos The position for which the initial condition should be evaluated
     *
Melanie Darcis's avatar
Melanie Darcis committed
209
210
211
     * For this method, the \a values parameter stores primary
     * variables.
     */
Kai Wendel's avatar
Kai Wendel committed
212
213
    PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
    { return initial_(globalPos); }
Melanie Darcis's avatar
Melanie Darcis committed
214
215
216
217

    // \}

private:
Kai Wendel's avatar
Kai Wendel committed
218
219
    // the internal method for the initial condition
    PrimaryVariables initial_(const GlobalPosition &globalPos) const
Melanie Darcis's avatar
Melanie Darcis committed
220
    {
Kai Wendel's avatar
Kai Wendel committed
221
        PrimaryVariables priVars;
Melanie Darcis's avatar
Melanie Darcis committed
222

223
        const Scalar temp = this->spatialParams().temperatureAtPos(globalPos);
224
        const Scalar salinity = getParam<Scalar>("Brine.Salinity");
225

226
        priVars[pressureIdx] = 1.013e5 + (this->spatialParams().depthBorAtPos(globalPos) - globalPos[1]) * 1100 * 9.81;  // hydrostatic pressure distribution
Kai Wendel's avatar
Kai Wendel committed
227
        priVars[CO2Idx] = 0.;  // initial condition for the CO2 massfraction
Melanie Darcis's avatar
Melanie Darcis committed
228
229
230

        Scalar moleFracCO2, xgH2O;
        Brine_CO2::calculateMoleFractions(temp,
Kai Wendel's avatar
Kai Wendel committed
231
                                          priVars[pressureIdx],
232
                                          salinity,
Melanie Darcis's avatar
Melanie Darcis committed
233
234
235
236
                                          /*knownPhaseIdx=*/-1,
                                          moleFracCO2,
                                          xgH2O);

237
        if(globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_)
Melanie Darcis's avatar
Melanie Darcis committed
238
        {
239
            priVars[CO2Idx] = moleFracCO2;   // massfraction at top boundary [-]
Melanie Darcis's avatar
Melanie Darcis committed
240
        }
Kai Wendel's avatar
Kai Wendel committed
241
242

        return priVars;
Melanie Darcis's avatar
Melanie Darcis committed
243
    }
Kai Wendel's avatar
Kai Wendel committed
244
245
246
247
248
        static constexpr Scalar eps_ = 1e-6;
        std::string name_ ;
    };

} //end namespace Dumux
Melanie Darcis's avatar
Melanie Darcis committed
249
250

#endif