multidomainconvergencewriter.hh 5.72 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// -*- 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
20
21
 * \file
 * \brief Reference implementation of a newton convergence writer for coupled problems.
22
*/
23
24
#ifndef DUMUX_MULTIDOMAIN_CONVERGENCEWRITER_HH
#define DUMUX_MULTIDOMAIN_CONVERGENCEWRITER_HH
25
26
27
28
29

#include <dune/pdelab/backend/istlsolverbackend.hh>
#include <dumux/io/vtkmultiwriter.hh>
#include <dune/grid/multidomaingrid.hh>

30
31
#include "splitandmerge.hh"
#include "multidomainnewtoncontroller.hh"
32
33
34
35

namespace Dumux
{
/*!
Thomas Fetzer's avatar
Thomas Fetzer committed
36
 * \ingroup MultidomainModel
37
38
39
40
 * \brief Writes the intermediate solutions during
 *        the Newton scheme
 */
template <class TypeTag>
41
struct MultiDomainConvergenceWriter
42
43
44
45
46
47
{
    typedef typename GET_PROP_TYPE(TypeTag, NewtonController) NewtonController;

    typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
    typedef typename GET_PROP_TYPE(TypeTag, SolutionVector) SolutionVector;

48
49
    typedef typename GET_PROP_TYPE(TypeTag, SubDomain1TypeTag) SubDomain1TypeTag;
    typedef typename GET_PROP_TYPE(TypeTag, SubDomain2TypeTag) SubDomain2TypeTag;
50

51
52
    typedef typename GET_PROP_TYPE(SubDomain1TypeTag, GridView) GridView1;
    typedef typename GET_PROP_TYPE(SubDomain2TypeTag, GridView) GridView2;
53

54
55
    typedef typename GET_PROP_TYPE(SubDomain1TypeTag, SolutionVector) SolutionVector1;
    typedef typename GET_PROP_TYPE(SubDomain2TypeTag, SolutionVector) SolutionVector2;
56
57
58
59

    typedef Dumux::VtkMultiWriter<GridView1> VtkMultiWriter1;
    typedef Dumux::VtkMultiWriter<GridView2> VtkMultiWriter2;

60
61
62
    /*!
    * \brief The constructor
    * \param ctl The newton controller
63
    */
64
    MultiDomainConvergenceWriter(NewtonController &ctl)
65
66
67
68
69
70
71
72
        : ctl_(ctl)
    {
        timeStepIndex_ = 0;
        iteration_ = 0;
        vtkMultiWriter1_ = 0;
        vtkMultiWriter2_ = 0;
    }

73
    //! \brief Destructor
74
    ~MultiDomainConvergenceWriter()
75
76
77
78
79
    {
        delete vtkMultiWriter1_;
        delete vtkMultiWriter2_;
    };

80
81
82
    /*!
     * \brief Start and advance in time
     */
83
84
85
86
87
    void beginTimestep()
    {
        ++timeStepIndex_;
        iteration_ = 0;
        if (!vtkMultiWriter1_)
88
            vtkMultiWriter1_ = new VtkMultiWriter1(problem_().sdProblem1().gridView(), "convergence1");
89
90

        if (!vtkMultiWriter2_)
91
            vtkMultiWriter2_ = new VtkMultiWriter2(problem_().sdProblem2().gridView(), "convergence2");
92
    }
93
94
95
96
97
98
99

    /*!
     * \brief Start and advance one iteration
     *
     * \param gridView1 The grid view of sub problem 1
     * \param gridView2 The grid view of sub problem 2
     */
100
101
102
103
104
105
    void beginIteration(const GridView1 &gridView1,
                        const GridView2 &gridView2)
    {
        ++ iteration_;
        vtkMultiWriter1_->beginWrite(timeStepIndex_ + iteration_ / 100.0);
        vtkMultiWriter2_->beginWrite(timeStepIndex_ + iteration_ / 100.0);
106
    }
107

108
109
110
111
112
113
114
115
    /*!
     * \brief Start and advance one iteration
     *
     * \param uLastIter The solution of the last iteration
     * \param deltaU The delta as calculated from solving the linear
     *               system of equations. This parameter also stores
     *               the updated solution.
     */
116
117
118
    void writeFields(const SolutionVector &uLastIter,
                     const SolutionVector &deltaU)
    {
119
120
121
122
            SolutionVector1 uLastIter1(ctl_.method().model().sdModel1().curSol());
            SolutionVector2 uLastIter2(ctl_.method().model().sdModel2().curSol());
            SolutionVector1 deltaU1(uLastIter1);
            SolutionVector2 deltaU2(uLastIter2);
123

124
125
            SplitAndMerge<TypeTag>::splitSolVector(uLastIter, uLastIter1, uLastIter2);
            SplitAndMerge<TypeTag>::splitSolVector(deltaU, deltaU1, deltaU2);
126
127

            std::cout << "\n writing convergence file of current Newton iteration \n";
128
129
            ctl_.method().model().sdModel1().addConvergenceVtkFields(*vtkMultiWriter1_, uLastIter1, deltaU1);
            ctl_.method().model().sdModel2().addConvergenceVtkFields(*vtkMultiWriter2_, uLastIter2, deltaU2);
130
    }
131

132
    //! \brief End of iteration
133
134
135
136
    void endIteration()
    {
        vtkMultiWriter1_->endWrite();
        vtkMultiWriter2_->endWrite();
137
    }
138

139
    //! \brief End of time step
140
141
142
143
    void endTimestep()
    {
        ++timeStepIndex_;
        iteration_ = 0;
144
    }
145
146
147
148
149
150
151
152
153
154
155
156
157
158

private:
    const Problem &problem_() const
    { return ctl_.method().problem(); }

    int timeStepIndex_;
    int iteration_;
    VtkMultiWriter1 *vtkMultiWriter1_;
    VtkMultiWriter2 *vtkMultiWriter2_;
    NewtonController &ctl_;
};

} // namespace Dumux

159
#endif // DUMUX_MULTIDOMAIN_CONVERGENCEWRITER_HH