main.cc 7.38 KB
Newer Older
Timo Koch's avatar
Timo Koch committed
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       *
Timo Koch's avatar
Timo Koch committed
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
 * \ingroup CO2Tests
Timo Koch's avatar
Timo Koch committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 * \brief Test for the two-phase two-component CC model.
 */
#include <config.h>
#include <ctime>
#include <iostream>

#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/timer.hh>
#include <dune/grid/io/file/dgfparser/dgfexception.hh>
#include <dune/grid/io/file/vtk.hh>
#include <dune/istl/io.hh>

#include <dumux/common/properties.hh>
#include <dumux/common/parameters.hh>
#include <dumux/common/valgrind.hh>
#include <dumux/common/dumuxmessage.hh>

#include <dumux/linear/amgbackend.hh>
40
#include <dumux/nonlinear/newtonsolver.hh>
Timo Koch's avatar
Timo Koch committed
41
42
43
44

#include <dumux/assembly/fvassembler.hh>
#include <dumux/assembly/diffmethod.hh>

45
#include <dumux/discretization/method.hh>
Timo Koch's avatar
Timo Koch committed
46
47

#include <dumux/io/vtkoutputmodule.hh>
48
#include <dumux/io/grid/gridmanager.hh>
Timo Koch's avatar
Timo Koch committed
49
50

// the problem definitions
51
#include "problem.hh"
Timo Koch's avatar
Timo Koch committed
52
53
54
55
56
57

int main(int argc, char** argv) try
{
    using namespace Dumux;

    // define the type tag for this problem
58
    using TypeTag = Properties::TTag::TYPETAG;
Timo Koch's avatar
Timo Koch committed
59
60
61
62
63
64
65
66
67
68
69
70

    // initialize MPI, finalize is done automatically on exit
    const auto& mpiHelper = Dune::MPIHelper::instance(argc, argv);

    // print dumux start message
    if (mpiHelper.rank() == 0)
        DumuxMessage::print(/*firstCall=*/true);

    // parse command line arguments and input file
    Parameters::init(argc, argv);

    // try to create a grid (from the given grid file or the input file)
71
    GridManager<GetPropType<TypeTag, Properties::Grid>> gridManager;
72
    gridManager.init();
Timo Koch's avatar
Timo Koch committed
73
74
75
76
77
78

    ////////////////////////////////////////////////////////////
    // run instationary non-linear problem on this grid
    ////////////////////////////////////////////////////////////

    // we compute on the leaf grid view
79
    const auto& leafGridView = gridManager.grid().leafGridView();
Timo Koch's avatar
Timo Koch committed
80
81

    // create the finite volume grid geometry
82
83
    using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
    auto fvGridGeometry = std::make_shared<GridGeometry>(leafGridView);
Timo Koch's avatar
Timo Koch committed
84
85
    fvGridGeometry->update();

86
    // the spatial parameters
87
    using SpatialParams = GetPropType<TypeTag, Properties::SpatialParams>;
88
89
    auto spatialParams = std::make_shared<SpatialParams>(fvGridGeometry, gridManager.getGridData());

Timo Koch's avatar
Timo Koch committed
90
    // the problem (initial and boundary conditions)
91
    using Problem = GetPropType<TypeTag, Properties::Problem>;
92
    auto problem = std::make_shared<Problem>(fvGridGeometry, spatialParams);
Timo Koch's avatar
Timo Koch committed
93
94

    // the solution vector
95
    using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>;
Timo Koch's avatar
Timo Koch committed
96
97
98
99
100
    SolutionVector x(fvGridGeometry->numDofs());
    problem->applyInitialSolution(x);
    auto xOld = x;

    // the grid variables
101
    using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
Timo Koch's avatar
Timo Koch committed
102
    auto gridVariables = std::make_shared<GridVariables>(problem, fvGridGeometry);
103
    gridVariables->init(x);
Timo Koch's avatar
Timo Koch committed
104
105

    // get some time loop parameters
106
    using Scalar = GetPropType<TypeTag, Properties::Scalar>;
Timo Koch's avatar
Timo Koch committed
107
108
109
110
111
    const auto tEnd = getParam<Scalar>("TimeLoop.TEnd");
    const auto maxDt = getParam<Scalar>("TimeLoop.MaxTimeStepSize");
    auto dt = getParam<Scalar>("TimeLoop.DtInitial");

    // intialize the vtk output module
112
    using IOFields = GetPropType<TypeTag, Properties::IOFields>;
Timo Koch's avatar
Timo Koch committed
113
    VtkOutputModule<GridVariables, SolutionVector> vtkWriter(*gridVariables, x, problem->name());
114
    using VelocityOutput = GetPropType<TypeTag, Properties::VelocityOutput>;
Timo Koch's avatar
Timo Koch committed
115
    vtkWriter.addVelocityOutput(std::make_shared<VelocityOutput>(*gridVariables));
116
    IOFields::initOutputModule(vtkWriter); // Add model specific output fields
117
    problem->addFieldsToWriter(vtkWriter); //!< Add some more problem dependent fields
Timo Koch's avatar
Timo Koch committed
118
119
120
    vtkWriter.write(0.0);

    // instantiate time loop
121
    auto timeLoop = std::make_shared<TimeLoop<Scalar>>(0, dt, tEnd);
Timo Koch's avatar
Timo Koch committed
122
123
124
125
    timeLoop->setMaxTimeStepSize(maxDt);

    // the assembler with time loop for instationary problem
    using Assembler = FVAssembler<TypeTag, DiffMethod::numeric>;
126
    auto assembler = std::make_shared<Assembler>(problem, fvGridGeometry, gridVariables, timeLoop, xOld);
Timo Koch's avatar
Timo Koch committed
127
128
129
130
131
132

    // the linear solver
    using LinearSolver = AMGBackend<TypeTag>;
    auto linearSolver = std::make_shared<LinearSolver>(leafGridView, fvGridGeometry->dofMapper());

    // the non-linear solver
133
    using NewtonSolver = NewtonSolver<Assembler, LinearSolver>;
134
    NewtonSolver nonLinearSolver(assembler, linearSolver);
Timo Koch's avatar
Timo Koch committed
135
136
137
138

    // time loop
    timeLoop->start(); do
    {
139
140
        // solve the non-linear system with time step control
        nonLinearSolver.solve(x, *timeLoop);
Timo Koch's avatar
Timo Koch committed
141
142
143
144
145
146
147
148
149
150
151

        // make the new solution the old solution
        xOld = x;
        gridVariables->advanceTimeStep();

        // advance to the time loop to the next step
        timeLoop->advanceTimeStep();

        // report statistics of this time step
        timeLoop->reportTimeStep();

152
153
        // set new dt as suggested by the newton solver
        timeLoop->setTimeStepSize(nonLinearSolver.suggestTimeStepSize(timeLoop->timeStepSize()));
Timo Koch's avatar
Timo Koch committed
154
155
156
157
158
159
160
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

        // write vtk output
        vtkWriter.write(timeLoop->time());

    } while (!timeLoop->finished());

    timeLoop->finalize(leafGridView.comm());

    ////////////////////////////////////////////////////////////
    // finalize, print dumux message to say goodbye
    ////////////////////////////////////////////////////////////

    // print dumux end message
    if (mpiHelper.rank() == 0)
    {
        Parameters::print();
        DumuxMessage::print(/*firstCall=*/false);
    }

    return 0;
} // end main
catch (Dumux::ParameterException &e)
{
    std::cerr << std::endl << e << " ---> Abort!" << std::endl;
    return 1;
}
catch (Dune::DGFException & e)
{
    std::cerr << "DGF exception thrown (" << e <<
                 "). Most likely, the DGF file name is wrong "
                 "or the DGF file is corrupted, "
                 "e.g. missing hash at end of file or wrong number (dimensions) of entries."
                 << " ---> Abort!" << std::endl;
    return 2;
}
catch (Dune::Exception &e)
{
    std::cerr << "Dune reported error: " << e << " ---> Abort!" << std::endl;
    return 3;
}
catch (...)
{
    std::cerr << "Unknown exception thrown! ---> Abort!" << std::endl;
    return 4;
}