exercise_properties_solution.cc 9.22 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// -*- 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
 *
22
 * \brief test for the two-phase porousmedium flow model
23
24
25
26
27
28
29
30
31
32
 */
#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>
33
34
35
#include <dune/istl/io.hh>

#include "problem.hh"
36
37
38

#include <dumux/common/properties.hh>
#include <dumux/common/parameters.hh>
39
#include <dumux/common/valgrind.hh>
40
41
42
43
#include <dumux/common/dumuxmessage.hh>
#include <dumux/common/defaultusagemessage.hh>

#include <dumux/linear/amgbackend.hh>
44
#include <dumux/nonlinear/newtonsolver.hh>
45
46
47
48

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

49
#include <dumux/discretization/method.hh>
50
51
52

#include <dumux/io/vtkoutputmodule.hh>
#include <dumux/io/grid/gridmanager.hh>
53
#include <dumux/io/loadsolution.hh>
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
/*!
 * \brief Provides an interface for customizing error messages associated with
 *        reading in parameters.
 *
 * \param progName  The name of the program, that was tried to be started.
 * \param errorMsg  The error message that was issued by the start function.
 *                  Comprises the thing that went wrong and a general help message.
 */
void usage(const char *progName, const std::string &errorMsg)
{
    if (errorMsg.size() > 0) {
        std::string errorMessageOut = "\nUsage: ";
                    errorMessageOut += progName;
                    errorMessageOut += " [options]\n";
                    errorMessageOut += errorMsg;
                    errorMessageOut += "\n\nThe list of mandatory arguments for this program is:\n"
                                        "\t-TimeManager.TEnd               End of the simulation [s] \n"
                                        "\t-TimeManager.DtInitial          Initial timestep size [s] \n"
                                        "\t-Grid.LowerLeft                 Lower left corner coordinates\n"
                                        "\t-Grid.UpperRight                Upper right corner coordinates\n"
                                        "\t-Grid.Cells                     Number of cells in respective coordinate directions\n"
                                        "\t                                definition in DGF format\n"
                                        "\t-SpatialParams.LensLowerLeft   coordinates of the lower left corner of the lens [m] \n"
                                        "\t-SpatialParams.LensUpperRight  coordinates of the upper right corner of the lens [m] \n"
                                        "\t-SpatialParams.Permeability     Permeability of the domain [m^2] \n"
                                        "\t-SpatialParams.PermeabilityLens Permeability of the lens [m^2] \n";

        std::cout << errorMessageOut
                  << "\n";
    }
}

int main(int argc, char** argv) try
88
89
90
91
{
    using namespace Dumux;

    // define the type tag for this problem
92
    using TypeTag = Properties::TTag::TwoPIncompressibleTpfa;
93
94
95
96
97
98
99
100
101

    // 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
102
    Parameters::init(argc, argv, usage);
103
104

    // try to create a grid (from the given grid file or the input file)
105
    GridManager<GetPropType<TypeTag, Properties::Grid>> gridManager;
106
107
108
109
110
111
112
113
114
115
    gridManager.init();

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

    // we compute on the leaf grid view
    const auto& leafGridView = gridManager.grid().leafGridView();

    // create the finite volume grid geometry
116
    using FVGridGeometry = GetPropType<TypeTag, Properties::FVGridGeometry>;
117
118
119
120
    auto fvGridGeometry = std::make_shared<FVGridGeometry>(leafGridView);
    fvGridGeometry->update();

    // the problem (initial and boundary conditions)
121
    using Problem = GetPropType<TypeTag, Properties::Problem>;
122
123
124
    auto problem = std::make_shared<Problem>(fvGridGeometry);

    // the solution vector
125
    using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>;
Timo Koch's avatar
Timo Koch committed
126
    SolutionVector x;
Timo Koch's avatar
Timo Koch committed
127
    problem->applyInitialSolution(x);
128
129
130
    auto xOld = x;

    // the grid variables
131
    using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
132
    auto gridVariables = std::make_shared<GridVariables>(problem, fvGridGeometry);
133
    gridVariables->init(x);
134
135

    // get some time loop parameters
136
    using Scalar = GetPropType<TypeTag, Properties::Scalar>;
137
138
139
140
141
    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
142
    using IOFields = GetPropType<TypeTag, Properties::IOFields>;
143
144
145
    VtkOutputModule<GridVariables, SolutionVector> vtkWriter(*gridVariables, x, problem->name());
    using VelocityOutput = GetPropType<TypeTag, Properties::VelocityOutput>;
    vtkWriter.addVelocityOutput(std::make_shared<VelocityOutput>(*gridVariables));
146
    IOFields::initOutputModule(vtkWriter); //!< Add model specific output fields
Timo Koch's avatar
Timo Koch committed
147
    vtkWriter.write(0.0);
148
149

    // instantiate time loop
150
    auto timeLoop = std::make_shared<TimeLoop<Scalar>>(0.0, dt, tEnd);
151
152
153
154
155
156
157
158
159
160
161
    timeLoop->setMaxTimeStepSize(maxDt);

    // the assembler with time loop for instationary problem
    using Assembler = FVAssembler<TypeTag, DiffMethod::numeric>;
    auto assembler = std::make_shared<Assembler>(problem, fvGridGeometry, gridVariables, timeLoop);

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

    // the non-linear solver
162
    using NewtonSolver = Dumux::NewtonSolver<Assembler, LinearSolver>;
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
    NewtonSolver nonLinearSolver(assembler, linearSolver);

    // time loop
    timeLoop->start(); do
    {
        // set previous solution for storage evaluations
        assembler->setPreviousSolution(xOld);

        // solve the non-linear system with time step control
        nonLinearSolver.solve(x, *timeLoop);

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

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

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

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

187
        // set new dt as suggested by the Newton solver
188
189
190
191
        timeLoop->setTimeStepSize(nonLinearSolver.suggestTimeStepSize(timeLoop->timeStepSize()));

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

192
193
194
    // output some Newton statistics
    nonLinearSolver.report();

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
231
232
233
    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;
}