From dd01d7633ff072cb08135fc9e0c7e54222d7b1cb Mon Sep 17 00:00:00 2001 From: Andreas Lauser <and@poware.org> Date: Tue, 28 Jun 2011 13:38:00 +0000 Subject: [PATCH] start: enable startFromInputFile if DUNE >= 2.1 is used for dune 2.0 and below there is parameter tree is not yet available, so it stays unavailable... git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@6090 2fb0f335-1f38-0410-981e-8018bf24f1b0 --- dumux/common/start.hh | 177 +++++++++++++++++++++--------------------- 1 file changed, 89 insertions(+), 88 deletions(-) diff --git a/dumux/common/start.hh b/dumux/common/start.hh index 4fafe7862e..09d29d5c4c 100644 --- a/dumux/common/start.hh +++ b/dumux/common/start.hh @@ -229,6 +229,12 @@ int startWithGrid(const typename GET_PROP_TYPE(TypeTag, PTAG(Grid)) &grid, return 3; }; +/////// +// commented out, because it does not work with dune 2.0 +/////// +#if DUNE_VERSION_NEWER_REV(GRID, 2, 0, 99) +// requires DUNE 2.1 and above + /*! * \brief Provides a default main function for simulations requiring * only a single DGF file as their grid specification. @@ -238,97 +244,92 @@ int startWithGrid(const typename GET_PROP_TYPE(TypeTag, PTAG(Grid)) &grid, * \param argc The 'argc' argument of the main function * \param argv The 'argv' argument of the main function */ +template <class ProblemTypeTag> +int startFromInputFile(int argc, char **argv) +{ +#ifdef NDEBUG + try { +#endif -/////// -// commented out, because it does not work with dune 2.0 -/////// + typedef typename GET_PROP_TYPE(ProblemTypeTag, PTAG(Grid)) Grid; + typedef typename GET_PROP_TYPE(ProblemTypeTag, PTAG(Problem)) Problem; + typedef typename GET_PROP_TYPE(ProblemTypeTag, PTAG(TimeManager)) TimeManager; + typedef Dune::GridPtr<Grid> GridPointer; + + // initialize MPI, finalize is done automatically on exit + static Dune::MPIHelper& mpiHelper = Dune::MPIHelper::instance(argc, argv); + + // parse the command line arguments for the program + if (argc < 2) + printUsageInputFile(argv[0]); + + // deal with the restart stuff + int argIdx = 1; + bool restart = false; + double restartTime = 0; + if (std::string("--restart") == argv[argIdx]) { + restart = true; + ++argIdx; + + std::istringstream(argv[argIdx++]) >> restartTime; + } + + if (argc - argIdx != 1) { + printUsageInputFile(argv[0]); + } + + std::string inputFileName; + std::istringstream(argv[argIdx++]) >> inputFileName; + + //////////////////////////////////////////////////////////// + // Load the input parameters + //////////////////////////////////////////////////////////// + Dune::ParameterTree inputParameters; + Dune::ParameterTreeParser::readINITree(inputFileName, inputParameters); + + + double tEnd, dt; + tEnd = inputParameters.get<double>("SimulationControl.tEnd"); + dt = inputParameters.get<double>("SimulationControl.tIni"); + + const std::string dgfFileName = + inputParameters.template get<std::string>("SimulationControl.gridName", "test_inputfile"); + + // create grid + // -> load the grid from file + GridPointer gridPtr(dgfFileName); + if (mpiHelper.size() > 1) { + if (!Dune::Capabilities::isParallel<Grid>::v) { + std::cerr << "DUMUX WARNING: THE PROGRAM IS STARTED USING MPI, BUT THE GRID IMPLEMENTATION\n" + << " YOU HAVE CHOSEN IS NOT PARALLEL!\n"; + } + gridPtr.loadBalance(); + } + + // instantiate and run the concrete problem + TimeManager timeManager; + Problem problem(timeManager, + gridPtr->leafView(), + inputParameters); + timeManager.init(problem, 0, dt, tEnd, !restart); + if (restart) + problem.restart(restartTime); + timeManager.run(); + return 0; -//template <class ProblemTypeTag> -//int startFromInputFile(int argc, char **argv) -//{ -//#ifdef NDEBUG -// try { -//#endif -// -// typedef typename GET_PROP_TYPE(ProblemTypeTag, PTAG(Grid)) Grid; -// typedef typename GET_PROP_TYPE(ProblemTypeTag, PTAG(Problem)) Problem; -// typedef typename GET_PROP_TYPE(ProblemTypeTag, PTAG(TimeManager)) TimeManager; -// typedef Dune::GridPtr<Grid> GridPointer; -// -// // initialize MPI, finalize is done automatically on exit -// static Dune::MPIHelper& mpiHelper = Dune::MPIHelper::instance(argc, argv); -// -// // parse the command line arguments for the program -// if (argc < 2) -// printUsageInputFile(argv[0]); -// -// // deal with the restart stuff -// int argIdx = 1; -// bool restart = false; -// double restartTime = 0; -// if (std::string("--restart") == argv[argIdx]) { -// restart = true; -// ++argIdx; -// -// std::istringstream(argv[argIdx++]) >> restartTime; -// } -// -// if (argc - argIdx != 1) { -// printUsageInputFile(argv[0]); -// } -// -// std::string inputFileName; -// std::istringstream(argv[argIdx++]) >> inputFileName; -// -// //////////////////////////////////////////////////////////// -// // Load the input parameters -// //////////////////////////////////////////////////////////// -// Dune::ParameterTree inputParameters; -// Dune::ParameterTreeParser::readINITree(inputFileName, inputParameters); -// -// -// double tEnd, dt; -// tEnd = inputParameters.get<double>("SimulationControl.tEnd"); -// dt = inputParameters.get<double>("SimulationControl.tIni"); -// -// const std::string dgfFileName = -// inputParameters.template get<std::string>("SimulationControl.gridName", "test_inputfile"); -// -// // create grid -// // -> load the grid from file -// GridPointer gridPtr(dgfFileName); -// if (mpiHelper.size() > 1) { -// if (!Dune::Capabilities::isParallel<Grid>::v) { -// std::cerr << "DUMUX WARNING: THE PROGRAM IS STARTED USING MPI, BUT THE GRID IMPLEMENTATION\n" -// << " YOU HAVE CHOSEN IS NOT PARALLEL!\n"; -// } -// gridPtr.loadBalance(); -// } -// -// // instantiate and run the concrete problem -// TimeManager timeManager; -// Problem problem(timeManager, -// gridPtr->leafView(), -// inputParameters); -// timeManager.init(problem, 0, dt, tEnd, !restart); -// if (restart) -// problem.restart(restartTime); -// timeManager.run(); -// return 0; -// -//#ifdef NDEBUG -// } -// catch (Dune::Exception &e) { -// std::cerr << "Dune reported error: " << e << std::endl; -// } -// catch (...) { -// std::cerr << "Unknown exception thrown!\n"; -// } -//#endif -// -// return 3; -//} +#ifdef NDEBUG + } + catch (Dune::Exception &e) { + std::cerr << "Dune reported error: " << e << std::endl; + } + catch (...) { + std::cerr << "Unknown exception thrown!\n"; + } +#endif + return 3; +} +#endif // DUNE_VERSION_NEWER_REV(GRID, 2, 0, 99) } -- GitLab