porousmediumsubproblem.hh 17.3 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
27
28
// -*- 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 A simple Darcy test problem (cell-centered finite volume method).
 */
#ifndef DUMUX_DARCY_SUBPROBLEM_HH
#define DUMUX_DARCY_SUBPROBLEM_HH

#include <dune/grid/yaspgrid.hh>

29
#include <dumux/discretization/cctpfa.hh>
30
#include <dumux/io/gnuplotinterface.hh>
31
#include <dumux/material/fluidsystems/1padapter.hh>
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <dumux/material/fluidsystems/h2oair.hh>
#include <dumux/material/fluidmatrixinteractions/diffusivityconstanttortuosity.hh>

#include <dumux/porousmediumflow/problem.hh>

#if EXNUMBER >= 1
#include <dumux/porousmediumflow/2pnc/model.hh>
#include "../2pspatialparams.hh"
#else
#include <dumux/porousmediumflow/1pnc/model.hh>
#include "../1pspatialparams.hh"
#endif

namespace Dumux
{
template <class TypeTag>
48
class PorousMediumSubProblem;
49
50
51

namespace Properties
{
52
53
// Create new type tags
namespace TTag {
54
#if EXNUMBER >= 1
55
struct DarcyOnePNC { using InheritsFrom = std::tuple<TwoPNC, CCTpfaModel>; };
56
#else
57
struct DarcyOnePNC { using InheritsFrom = std::tuple<OnePNC, CCTpfaModel>; };
58
#endif
59
} // end namespace TTag
60
61

// Set the problem property
62
template<class TypeTag>
63
struct Problem<TypeTag, TTag::DarcyOnePNC> { using type = Dumux::PorousMediumSubProblem<TypeTag>; };
64
65

// The fluid system
66
template<class TypeTag>
67
struct FluidSystem<TypeTag, TTag::DarcyOnePNC>
68
{
69
    using H2OAir = FluidSystems::H2OAir<GetPropType<TypeTag, Properties::Scalar>>;
70
#if EXNUMBER == 0
71
72
73
    using type = FluidSystems::OnePAdapter<H2OAir, H2OAir::gasPhaseIdx>;
#else
    using type = H2OAir;
74
#endif
75
};
76
77

// Use moles
78
template<class TypeTag>
79
struct UseMoles<TypeTag, TTag::DarcyOnePNC> { static constexpr bool value = true; };
80
81

// Do not replace one equation with a total mass balance
82
template<class TypeTag>
83
struct ReplaceCompEqIdx<TypeTag, TTag::DarcyOnePNC> { static constexpr int value = 3; };
84
85

//! Use a model with constant tortuosity for the effective diffusivity
86
87
88
template<class TypeTag>
struct EffectiveDiffusivityModel<TypeTag, TTag::DarcyOnePNC>
{ using type = DiffusivityConstantTortuosity<GetPropType<TypeTag, Properties::Scalar>>; };
89
// Set the grid type
90
template<class TypeTag>
91
struct Grid<TypeTag, TTag::DarcyOnePNC> { using type = Dune::YaspGrid<2>; };
92
93
94

#if EXNUMBER >= 1
//! Set the default formulation to pw-Sn: This can be over written in the problem.
95
template<class TypeTag>
96
struct Formulation<TypeTag, TTag::DarcyOnePNC>
97
98
99
100
101
{ static constexpr auto value = TwoPFormulation::p1s0; };
#endif

// Set the spatial paramaters type
#if EXNUMBER >= 1
102
template<class TypeTag>
103
struct SpatialParams<TypeTag, TTag::DarcyOnePNC> {
104
    using type = TwoPSpatialParams<GetPropType<TypeTag, GridGeometry>, GetPropType<TypeTag, Scalar>>;
105
};
106
#else
107
template<class TypeTag>
108
struct SpatialParams<TypeTag, TTag::DarcyOnePNC> {
109
    using type = OnePSpatialParams<GetPropType<TypeTag, GridGeometry>, GetPropType<TypeTag, Scalar>>;
110
};
111
#endif
112
113

} // end namespace Properties
114
115

template <class TypeTag>
116
class PorousMediumSubProblem : public PorousMediumFlowProblem<TypeTag>
117
118
{
    using ParentType = PorousMediumFlowProblem<TypeTag>;
119
120
121
122
123
124
    using GridView = GetPropType<TypeTag, Properties::GridView>;
    using Scalar = GetPropType<TypeTag, Properties::Scalar>;
    using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
    using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
    using NumEqVector = GetPropType<TypeTag, Properties::NumEqVector>;
    using BoundaryTypes = GetPropType<TypeTag, Properties::BoundaryTypes>;
125
    using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
126
127
    using SubControlVolume = typename FVElementGeometry::SubControlVolume;
    using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
128
    using FVGridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
129
130
    using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
    using ElementFluxVariablesCache = typename GridVariables::GridFluxVariablesCache::LocalView;
131
132

    // copy some indices for convenience
133
    using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    enum {
        // grid and world dimension
        dim = GridView::dimension,
        dimworld = GridView::dimensionworld,

        // primary variable indices
        conti0EqIdx = Indices::conti0EqIdx,
        pressureIdx = Indices::pressureIdx,
#if EXNUMBER >= 3
        saturationIdx = Indices::switchIdx,
        transportCompIdx = Indices::switchIdx
#elif EXNUMBER >= 1
        transportCompIdx = Indices::switchIdx
#else
148
149
        phaseIdx = 0,
        transportCompIdx = 1
150
151
152
153
154
155
#endif
    };

    using Element = typename GridView::template Codim<0>::Entity;
    using GlobalPosition = Dune::FieldVector<Scalar, dimworld>;

156
    using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>;
157
158
159
    using TimeLoopPtr = std::shared_ptr<TimeLoop<Scalar>>;

public:
160
    PorousMediumSubProblem(std::shared_ptr<const FVGridGeometry> fvGridGeometry,
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
                   std::shared_ptr<CouplingManager> couplingManager)
    : ParentType(fvGridGeometry, "Darcy"), eps_(1e-7), couplingManager_(couplingManager)
    {
#if EXNUMBER >= 3
        saturation_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.Saturation");
#else
        moleFraction_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.MoleFraction");
#endif

        // initialize output file
        plotFluxes_ = getParamFromGroup<bool>(this->paramGroup(), "Problem.PlotFluxes", false);
        plotStorage_ = getParamFromGroup<bool>(this->paramGroup(), "Problem.PlotStorage", false);
        storageFileName_ = "storage_" + getParam<std::string>("Problem.Name") + "_" + this->name() + ".csv";
        storageFile_.open(storageFileName_);
        storageFile_ << "#Time[s]" << ";"
                     << "WaterMass[kg]" << ";"
                     << "WaterMassLoss[kg]" << ";"
                     << "EvaporationRate[mm/d]"
                     << std::endl;
    }

    /*!
     * \name Simulation steering
     */
    // \{

    /*!
     * \brief Initialize the problem.
     */
    template<class SolutionVector, class GridVariables>
    void init(const SolutionVector& curSol,
              const GridVariables& gridVariables)
    {
#if EXNUMBER >= 2
        initialWaterContent_ = evaluateWaterMassStorageTerm(curSol, gridVariables);
        lastWaterMass_ = initialWaterContent_;
#endif
    }

    template<class SolutionVector, class GridVariables>
    void postTimeStep(const SolutionVector& curSol,
                      const GridVariables& gridVariables)

    {
        evaluateWaterMassStorageTerm(curSol, gridVariables);
        evaluateInterfaceFluxes(curSol, gridVariables);

        gnuplotStorage_.resetPlot();
        gnuplotStorage_.setDatafileSeparator(';');
        gnuplotStorage_.setXlabel("time [d]");
        gnuplotStorage_.setXRange(0.0, getParam<Scalar>("TimeLoop.TEnd"));
        gnuplotStorage_.setYlabel("evaporation rate [mm/d]");
        gnuplotStorage_.setOption("set yrange [0.0:]");
        gnuplotStorage_.setOption("set y2label 'cumulative mass loss'");
        gnuplotStorage_.setOption("set y2range [0.0:0.5]");
        gnuplotStorage_.setOption("set y2range [0.0:0.5]");
        gnuplotStorage_.addFileToPlot(storageFileName_, "using 1:4 with lines title 'evaporation rate'");
        gnuplotStorage_.addFileToPlot(storageFileName_, "using 1:3 axes x1y2 with lines title 'cumulative mass loss'");
        if (plotStorage_)
            gnuplotStorage_.plot("temp");
    }

    template<class SolutionVector, class GridVariables>
    Scalar evaluateWaterMassStorageTerm(const SolutionVector& curSol,
                                        const GridVariables& gridVariables)

    {
        // compute the mass in the entire domain
        Scalar waterMass = 0.0;

231
        for (const auto& element : elements(this->gridGeometry().gridView()))
232
        {
233
            auto fvGeometry = localView(this->gridGeometry());
234
235
236
237
238
239
240
241
242
243
244
            fvGeometry.bindElement(element);

            auto elemVolVars = localView(gridVariables.curGridVolVars());
            elemVolVars.bindElement(element, fvGeometry, curSol);

            for (auto&& scv : scvs(fvGeometry))
            {
                for(int phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
                {
                    // insert calculation of the water mass here
#if EXNUMBER >= 2
Timo Koch's avatar
Timo Koch committed
245
                    const auto& volVars = elemVolVars[scv];
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
                    waterMass += volVars.massFraction(phaseIdx, FluidSystem::H2OIdx) * volVars.density(phaseIdx)
                                 * volVars.saturation(phaseIdx) * volVars.porosity()
                                 * scv.volume() * volVars.extrusionFactor();
#else
                    waterMass += 0.0;
#endif
                }
            }
        }
#if EXNUMBER >= 2
        std::cout << "Mass of water is: " << waterMass << std::endl;
#endif

        Scalar cumMassLoss = initialWaterContent_ - waterMass;
        Scalar evaporationRate = (lastWaterMass_ - waterMass) * 86400
261
                                 / (this->gridGeometry().bBoxMax()[0] - this->gridGeometry().bBoxMin()[0])
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
                                 / timeLoop_->timeStepSize();
        lastWaterMass_ = waterMass;

        storageFile_ << timeLoop_->time() << ";"
                     << waterMass << ";"
                     << cumMassLoss << ";"
                     << evaporationRate
                     << std::endl;

        return waterMass;
    }

    template<class SolutionVector, class GridVariables>
    void evaluateInterfaceFluxes(const SolutionVector& curSol,
                                 const GridVariables& gridVariables)

    {
        std::vector<Scalar> x;
        std::vector<Scalar> y;

282
        for (const auto& element : elements(this->gridGeometry().gridView()))
283
        {
284
            auto fvGeometry = localView(this->gridGeometry());
285
286
287
288
289
290
291
292
293
294
295
            fvGeometry.bindElement(element);

            auto elemVolVars = localView(gridVariables.curGridVolVars());
            elemVolVars.bindElement(element, fvGeometry, curSol);

            for (auto&& scvf : scvfs(fvGeometry))
            {
                if (!couplingManager().isCoupledEntity(CouplingManager::darcyIdx, scvf))
                    continue;

#if EXNUMBER >= 2
296
                NumEqVector flux = couplingManager().couplingData().massCouplingCondition(element, fvGeometry, elemVolVars, scvf);
297
298
299
300
301
302
303
304
305
306
307
#else
                NumEqVector flux(0.0); // add "massCouplingCondition" from the couplingManager here
#endif

                x.push_back(scvf.center()[0]);
                y.push_back(flux[transportCompIdx]);
            }
        }

        gnuplotInterfaceFluxes_.resetPlot();
        gnuplotInterfaceFluxes_.setXlabel("x-position [m]");
308
        gnuplotInterfaceFluxes_.setXRange(this->gridGeometry().bBoxMin()[0], this->gridGeometry().bBoxMax()[0]);
309
310
311
312
313
314
315
316
317
318
        gnuplotInterfaceFluxes_.setYlabel("flux [kg/(m^2 s)]");
        gnuplotInterfaceFluxes_.setYRange(-5e-4, 0.0);
        gnuplotInterfaceFluxes_.setOption("set label 'time: " + std::to_string(timeLoop_->time()/86400.) + "d' at graph 0.8,0.8 ");
        std::string fluxFileName = "flux_" + std::to_string(timeLoop_->timeStepIndex()) +
                                   "_" + getParam<std::string>("Problem.Name") + "_" + this->name() + ".csv";
        gnuplotInterfaceFluxes_.addDataSetToPlot(x, y, fluxFileName, "with lines title 'water mass flux'");
        if (plotFluxes_)
            gnuplotInterfaceFluxes_.plot("flux_" + std::to_string(timeLoop_->timeStepIndex()));
    }

319
320
321
322
323
    /*!
     * \name Problem parameters
     */
    // \{

324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
    /*!
     * \brief Return the temperature within the domain in [K].
     *
     */
    Scalar temperature() const
    { return 293.15; }
    // \}

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

    /*!
      * \brief Specifies which kind of boundary condition should be
      *        used for which equation on a given boundary control volume.
      *
      * \param element The element
      * \param scvf The boundary sub control volume face
      */
    BoundaryTypes boundaryTypes(const Element& element, const SubControlVolumeFace& scvf) const
    {
        BoundaryTypes values;
        values.setAllNeumann();

        if (couplingManager().isCoupledEntity(CouplingManager::darcyIdx, scvf))
            values.setAllCouplingNeumann();

        return values;
    }

    /*!
     * \brief Evaluate the boundary conditions for a Neumann control volume.
     *
     * \param element The element for which the Neumann boundary condition is set
     * \param fvGeomentry The fvGeometry
     * \param elemVolVars The element volume variables
     * \param scvf The boundary sub control volume face
     *
     * For this method, the \a values variable stores primary variables.
     */
    template<class ElementVolumeVariables>
    NumEqVector neumann(const Element& element,
                        const FVElementGeometry& fvGeometry,
                        const ElementVolumeVariables& elemVolVars,
369
                        const ElementFluxVariablesCache& elemFluxVarsCache,
370
371
372
373
374
                        const SubControlVolumeFace& scvf) const
    {
        NumEqVector values(0.0);

        if (couplingManager().isCoupledEntity(CouplingManager::darcyIdx, scvf))
375
            values = couplingManager().couplingData().massCouplingCondition(element, fvGeometry, elemVolVars, scvf);
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395

        return values;
    }

    // \}

    /*!
     * \name Volume terms
     */
    // \{
    /*!
     * \brief Evaluate the source term for all phases within a given
     *        sub-control-volume.
     *
     * \param element The element for which the source term is set
     * \param fvGeomentry The fvGeometry
     * \param elemVolVars The element volume variables
     * \param scv The subcontrolvolume
     */
    template<class ElementVolumeVariables>
396
    NumEqVector source(const Element& element,
397
398
                       const FVElementGeometry& fvGeometry,
                       const ElementVolumeVariables& elemVolVars,
399
                       const SubControlVolume& scv) const
400
401
402
403
404
405
406
407
408
409
410
411
    { return NumEqVector(0.0); }

    // \}

    /*!
     * \brief Evaluate the initial value for a control volume.
     *
     * \param element The element
     *
     * For this method, the \a priVars parameter stores primary
     * variables.
     */
412
    PrimaryVariables initialAtPos(const GlobalPosition& globalPos) const
413
    {
414
415
        static const Scalar stokesPressure = getParamFromGroup<Scalar>("Stokes", "Problem.Pressure");

416
417
418
419
420
421
422
423
424
425
        PrimaryVariables values(0.0);
#if EXNUMBER >= 3
        values.setState(3/*bothPhases*/);
        values[saturationIdx] = saturation_;
#elif EXNUMBER >= 1
        values.setState(2/*secondPhaseOnly*/);
        values[transportCompIdx] = moleFraction_;
#else
        values[transportCompIdx] = moleFraction_;
#endif
426
        values[pressureIdx] = stokesPressure;
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
        return values;
    }

    // \}

    //! Set the coupling manager
    void setCouplingManager(std::shared_ptr<CouplingManager> cm)
    { couplingManager_ = cm; }

    //! Get the coupling manager
    const CouplingManager& couplingManager() const
    { return *couplingManager_; }

    void setTimeLoop(TimeLoopPtr timeLoop)
    { timeLoop_ = timeLoop; }

private:
    bool onLeftBoundary_(const GlobalPosition &globalPos) const
445
    { return globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_; }
446
447

    bool onRightBoundary_(const GlobalPosition &globalPos) const
448
    { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; }
449
450

    bool onLowerBoundary_(const GlobalPosition &globalPos) const
451
    { return globalPos[1] < this->gridGeometry().bBoxMin()[1] + eps_; }
452
453

    bool onUpperBoundary_(const GlobalPosition &globalPos) const
454
    { return globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_; }
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475

    Scalar eps_;
#if EXNUMBER >= 3
    Scalar saturation_;
#else
    Scalar moleFraction_;
#endif

    Scalar initialWaterContent_ = 0.0;
    Scalar lastWaterMass_ = 0.0;

    TimeLoopPtr timeLoop_;
    std::shared_ptr<CouplingManager> couplingManager_;

    std::string storageFileName_;
    std::ofstream storageFile_;
    bool plotFluxes_;
    bool plotStorage_;
    Dumux::GnuplotInterface<Scalar> gnuplotInterfaceFluxes_;
    Dumux::GnuplotInterface<Scalar> gnuplotStorage_;
};
476
} //end namespace Dumux
477
478

#endif //DUMUX_DARCY_SUBPROBLEM_HH