mpncvtkwriter.hh 5.33 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/>.   *
 *****************************************************************************/
Thomas Fetzer's avatar
Thomas Fetzer committed
19
20
21
22
23
/*!
 * \file
 * \brief Writes the VTK output files for a solution of the Mp-Nc model.
 */

24
25
26
27
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef DUMUX_MPNC_VTK_WRITER_HH
#define DUMUX_MPNC_VTK_WRITER_HH

#include "mpncproperties.hh"

#include <dumux/io/vtkmultiwriter.hh>

namespace Dumux
{
/*!
 * \ingroup MPNCModel
 * \brief Writes the VTK output files for a
 * solution of the Mp-Nc model.
 */
template<class TypeTag>
class MPNCVtkWriter
{
    typedef typename GET_PROP_TYPE(TypeTag, MPNCVtkCommonModule) MPNCVtkCommonModule;
    typedef typename GET_PROP_TYPE(TypeTag, MPNCVtkMassModule) MPNCVtkMassModule;
    typedef typename GET_PROP_TYPE(TypeTag, MPNCVtkEnergyModule) MPNCVtkEnergyModule;
    typedef typename GET_PROP_TYPE(TypeTag, MPNCVtkCustomModule) MPNCVtkCustomModule;
    typedef typename GET_PROP_TYPE(TypeTag, ElementVolumeVariables) ElementVolumeVariables;
    typedef typename GET_PROP_TYPE(TypeTag, FVElementGeometry) FVElementGeometry;
    typedef typename GET_PROP_TYPE(TypeTag, ElementBoundaryTypes) ElementBoundaryTypes;
    typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
    typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
    typedef typename GridView::template Codim<0>::Entity Element;
    typedef typename GridView::template Codim<0>::Iterator ElementIterator;

public:
    MPNCVtkWriter(const Problem &problem)
        : problem_(problem)
        , commonWriter_(problem)
        , massWriter_(problem)
        , energyWriter_(problem)
        , customWriter_(problem)
    {
    }

    /*!
     * \brief Add  the current solution to the VtkMultiWriter.
     */
    template <class MultiWriter>
    void addCurrentSolution(MultiWriter &writer)
    {
        // tell sub-writers to allocate their buffers
        commonWriter_.allocBuffers(writer);
        massWriter_.allocBuffers(writer);
        energyWriter_.allocBuffers(writer);
        customWriter_.allocBuffers(writer);

        // iterate over grid
        FVElementGeometry fvGeometry;
        ElementVolumeVariables elemVolVars;
        ElementBoundaryTypes elemBcTypes;

        ElementIterator elemIt = problem_.gridView().template begin<0>();
        ElementIterator elemEndIt = problem_.gridView().template end<0>();
        for (; elemIt != elemEndIt; ++elemIt)
        {
            fvGeometry.update(problem_.gridView(), *elemIt);
            elemBcTypes.update(problem_, *elemIt);
            this->problem_.model().setHints(*elemIt, elemVolVars);
            elemVolVars.update(problem_,
                               *elemIt,
                               fvGeometry,
                               false);
            this->problem_.model().updateCurHints(*elemIt, elemVolVars);

            // tell the sub-writers to do what ever they need to with
            // their internal buffers when a given element is seen.
            commonWriter_.processElement(*elemIt,
                                         fvGeometry,
                                         elemVolVars,
                                         elemBcTypes);
            massWriter_.processElement(*elemIt,
                                       fvGeometry,
                                       elemVolVars,
                                       elemBcTypes);
            energyWriter_.processElement(*elemIt,
                                         fvGeometry,
                                         elemVolVars,
                                         elemBcTypes);
            customWriter_.processElement(*elemIt,
                                         fvGeometry,
                                         elemVolVars,
                                         elemBcTypes);
        }

        // write everything to the output file
        commonWriter_.commitBuffers(writer);
        massWriter_.commitBuffers(writer);
        energyWriter_.commitBuffers(writer);
        customWriter_.commitBuffers(writer);
    }

private:
    const Problem &problem_;

    MPNCVtkCommonModule commonWriter_;
    MPNCVtkMassModule massWriter_;
    MPNCVtkEnergyModule energyWriter_;
    MPNCVtkCustomModule customWriter_;
};

}

#endif