3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
start.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * 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 *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_COMMON_START_HH
25#define DUMUX_COMMON_START_HH
26
27#include <ctime>
28#include <iostream>
29
30#include <dune/common/parallel/mpihelper.hh>
31#include <dune/grid/io/file/dgfparser/dgfexception.hh>
32
37
38#warning "start.hh is deprecated. Use new style main files see e.g. /test/porousmediumflow/1p."
39
40namespace Dumux {
41
54template <class TypeTag>
55int start_(int argc,
56 char **argv,
57 void (*usage)(const char *, const std::string &))
58{
59 // some aliases for better readability
63
64 // initialize MPI, finalize is done automatically on exit
65 const auto& mpiHelper = Dune::MPIHelper::instance(argc, argv);
66
67 // print dumux start message
68 if (mpiHelper.rank() == 0)
69 DumuxMessage::print(/*firstCall=*/true);
70
72 // parse the command line arguments and input file
74
75 auto defaultParams = [] (Dune::ParameterTree& p) {GetProp<TypeTag, Properties::ModelDefaultParameters>::defaultParams(p);};
76 Parameters::init(argc, argv, defaultParams, usage);
77
79 // try to create a grid (from the given grid file or the input file)
81
83 gridManager.init();
84
86 // run the simulation
88
89 // read the initial time step and the end time (mandatory parameters)
90 auto tEnd = getParam<Scalar>("TimeManager.TEnd");
91 auto dt = getParam<Scalar>("TimeManager.DtInitial");
92
93 // check if we are about to restart a previously interrupted simulation
94 bool restart = false;
95 Scalar restartTime = 0;
96 if (hasParam("Restart") || hasParam("TimeManager.Restart"))
97 {
98 restart = true;
99 restartTime = getParam<Scalar>("TimeManager.Restart");
100 }
101
102 // instantiate and run the problem
103 TimeManager timeManager;
104 Problem problem(timeManager, gridManager.grid());
105 timeManager.init(problem, restartTime, dt, tEnd, restart);
106 timeManager.run();
107
108 // print dumux end message and maybe the parameters for debugging
109 if (mpiHelper.rank() == 0)
110 DumuxMessage::print(/*firstCall=*/false);
111
112 return 0;
113}
114
126template <class TypeTag>
127int start(int argc,
128 char **argv,
129 void (*usage)(const char *, const std::string &))
130{
131 try {
132 return start_<TypeTag>(argc, argv, usage);
133 }
134 catch (ParameterException &e) {
135 std::cerr << std::endl << e << ". Abort!" << std::endl;
136 return 1;
137 }
138 catch (Dune::DGFException & e) {
139 std::cerr << "DGF exception thrown (" << e <<
140 "). Most likely, the DGF file name is wrong "
141 "or the DGF file is corrupted, "
142 "e.g. missing hash at end of file or wrong number (dimensions) of entries."
143 << std::endl;
144 return 2;
145 }
146 catch (Dune::Exception &e) {
147 std::cerr << "Dune reported error: " << e << std::endl;
148 return 3;
149 }
150 catch (...) {
151 std::cerr << "Unknown exception thrown!\n";
152 return 4;
153 }
154}
155
156} // end namespace Dumux
157
158#endif
Provides the class creating the famous DuMux start and end messages.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
int start(int argc, char **argv, void(*usage)(const char *, const std::string &))
Provides a main function with error handling.
Definition: start.hh:127
bool hasParam(const std::string &param)
Check whether a key exists in the parameter tree.
Definition: parameters.hh:383
int start_(int argc, char **argv, void(*usage)(const char *, const std::string &))
Provides a main function which reads in parameters from the command line and a parameter file.
Definition: start.hh:55
Definition: adapt.hh:29
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type GetProp
get the type of a property (equivalent to old macro GET_PROP(...))
Definition: propertysystem.hh:140
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
static void print(bool firstCall=false)
Selects random messages to write out at the start and end of a simulation run.
Definition: dumuxmessage.hh:48
Exception thrown if a run-time parameter is not specified correctly.
Definition: exceptions.hh:60
static void init(int argc, char **argv, const Usage &usage)
Initialize the parameter tree singletons.
Definition: parameters.hh:57
Manages the handling of time dependent problems.
Definition: timemanager.hh:62
void run()
Runs the simulation using a given problem class.
Definition: timemanager.hh:376
void init(Problem &problem, Scalar tStart, Scalar dtInitial, Scalar tEnd, bool restart=false)
Initialize the model and problem and write the initial condition to disk.
Definition: timemanager.hh:100
The grid manager (this is the class used by the user) for all supported grid managers that constructs...
Definition: gridmanager_base.hh:320
Grid & grid()
Returns a reference to the grid.
Definition: gridmanager_base.hh:92
void init(const std::string &modelParamGroup="")
Make the grid. Implement this method in the specialization of this class for a grid type.
Definition: gridmanager_base.hh:81
Declares all properties used in Dumux.
Convience header that includes all grid manager specializations.