diff --git a/test/freeflow/staggered/channeltestproblem.hh b/test/freeflow/staggered/channeltestproblem.hh index bdb9399edc0cfe944dc1f5843d8c69011557a3cf..75c90e1fc1da264a21ccf149d7ab8ffbeda956be 100644 --- a/test/freeflow/staggered/channeltestproblem.hh +++ b/test/freeflow/staggered/channeltestproblem.hh @@ -24,13 +24,15 @@ #ifndef DUMUX_CHANNEL_TEST_PROBLEM_HH #define DUMUX_CHANNEL_TEST_PROBLEM_HH -#include <dumux/implicit/staggered/properties.hh> -#include <dumux/freeflow/staggered/model.hh> -#include <dumux/implicit/problem.hh> +#include <dumux/freeflow/staggered/problem.hh> +#include <dumux/discretization/staggered/properties.hh> #include <dumux/material/components/simpleh2o.hh> #include <dumux/material/fluidsystems/liquidphase.hh> #include <dumux/material/components/constant.hh> +#include <dumux/discretization/staggered/properties.hh> +#include <dumux/freeflow/staggered/properties.hh> + namespace Dumux { template <class TypeTag> @@ -74,8 +76,6 @@ SET_BOOL_PROP(ChannelTestProblem, EnableFVGridGeometryCache, true); SET_BOOL_PROP(ChannelTestProblem, EnableGlobalFluxVariablesCache, true); SET_BOOL_PROP(ChannelTestProblem, EnableGlobalVolumeVariablesCache, true); -// Enable gravity -SET_BOOL_PROP(ChannelTestProblem, ProblemEnableGravity, true); #if ENABLE_NAVIERSTOKES SET_BOOL_PROP(ChannelTestProblem, EnableInertiaTerms, true); @@ -91,13 +91,14 @@ SET_BOOL_PROP(ChannelTestProblem, EnableInertiaTerms, false); template <class TypeTag> class ChannelTestProblem : public NavierStokesProblem<TypeTag> { - typedef NavierStokesProblem<TypeTag> ParentType; + using ParentType = NavierStokesProblem<TypeTag>; + + using GridView = typename GET_PROP_TYPE(TypeTag, GridView); + using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar); - typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView; - typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; // copy some indices for convenience - typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices; + using Indices = typename GET_PROP_TYPE(TypeTag, Indices); enum { // Grid and world dimension dim = GridView::dimension, @@ -118,11 +119,10 @@ class ChannelTestProblem : public NavierStokesProblem<TypeTag> }; using BoundaryTypes = typename GET_PROP_TYPE(TypeTag, BoundaryTypes); - using TimeManager = typename GET_PROP_TYPE(TypeTag, TimeManager); using Element = typename GridView::template Codim<0>::Entity; - using Intersection = typename GridView::Intersection; + using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry); using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVElementGeometry); using SubControlVolume = typename GET_PROP_TYPE(TypeTag, SubControlVolume); @@ -136,18 +136,10 @@ class ChannelTestProblem : public NavierStokesProblem<TypeTag> using SourceValues = typename GET_PROP_TYPE(TypeTag, BoundaryValues); public: - ChannelTestProblem(TimeManager &timeManager, const GridView &gridView) - : ParentType(timeManager, gridView), eps_(1e-6) + ChannelTestProblem(std::shared_ptr<const FVGridGeometry> fvGridGeometry) + : ParentType(fvGridGeometry), eps_(1e-6) { - name_ = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, - std::string, - Problem, - Name); - - inletVelocity_ = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, - Scalar, - Problem, - InletVelocity); + inletVelocity_ = getParam<Scalar>("Problem.InletVelocity"); #if NONISOTHERMAL if(inletVelocity_ > eps_) @@ -160,16 +152,6 @@ public: */ // \{ - /*! - * \brief The problem name. - * - * This is used as a prefix for files generated by the simulation. - */ - std::string name() const - { - return name_; - } - #if NONISOTHERMAL void episodeEnd() { @@ -303,17 +285,16 @@ private: bool isOutlet(const GlobalPosition& globalPos) const { - return globalPos[0] > this->bBoxMax()[0] - eps_; + return globalPos[0] > this->fvGridGeometry().bBoxMax()[0] - eps_; } bool isWall(const GlobalPosition& globalPos) const { - return globalPos[0] > eps_ || globalPos[0] < this->bBoxMax()[0] - eps_; + return globalPos[0] > eps_ || globalPos[0] < this->fvGridGeometry().bBoxMax()[0] - eps_; } Scalar eps_; Scalar inletVelocity_; - std::string name_; }; } //end namespace diff --git a/test/freeflow/staggered/test_channel.cc b/test/freeflow/staggered/test_channel.cc index 9e6fef38637fbc07d1e08565410264afab838d7a..b3200d54ee6825304e14ef017015c0fe274fab99 100644 --- a/test/freeflow/staggered/test_channel.cc +++ b/test/freeflow/staggered/test_channel.cc @@ -21,9 +21,36 @@ * * \brief Channel flow test for the staggered grid (Navier-)Stokes model */ -#include <config.h> + #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 "channeltestproblem.hh" -#include <dumux/common/start.hh> + +#include <dumux/common/propertysystem.hh> +#include <dumux/common/parameters.hh> +#include <dumux/common/valgrind.hh> +#include <dumux/common/dumuxmessage.hh> +#include <dumux/common/defaultusagemessage.hh> + +#include <dumux/linear/seqsolverbackend.hh> +#include <dumux/nonlinear/newtonmethod.hh> +#include <dumux/nonlinear/newtoncontroller.hh> + +#include <dumux/assembly/staggeredfvassembler.hh> +#include <dumux/assembly/diffmethod.hh> +#include <dumux/implicit/staggered/newtoncontroller.hh> + +#include <dumux/discretization/methods.hh> + +#include <dumux/io/vtkoutputmodule.hh> /*! * \brief Provides an interface for customizing error messages associated with @@ -57,8 +84,177 @@ void usage(const char *progName, const std::string &errorMsg) } } -int main(int argc, char** argv) +int main(int argc, char** argv) try +{ + using namespace Dumux; + + // define the type tag for this problem + using TypeTag = TTAG(ChannelTestProblem); + + // 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, usage); + + // try to create a grid (from the given grid file or the input file) + using GridCreator = typename GET_PROP_TYPE(TypeTag, GridCreator); + GridCreator::makeGrid(); + GridCreator::loadBalance(); + + //////////////////////////////////////////////////////////// + // run instationary non-linear problem on this grid + //////////////////////////////////////////////////////////// + + // we compute on the leaf grid view + const auto& leafGridView = GridCreator::grid().leafGridView(); + + // create the finite volume grid geometry + using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry); + auto fvGridGeometry = std::make_shared<FVGridGeometry>(leafGridView); + fvGridGeometry->update(); + + // the problem (initial and boundary conditions) + using Problem = typename GET_PROP_TYPE(TypeTag, Problem); + auto problem = std::make_shared<Problem>(fvGridGeometry); + + // the solution vector + using SolutionVector = typename GET_PROP_TYPE(TypeTag, SolutionVector); + using DofTypeIndices = typename GET_PROP(TypeTag, DofTypeIndices); + typename DofTypeIndices::CellCenterIdx cellCenterIdx; + typename DofTypeIndices::FaceIdx faceIdx; + const auto numDofsCellCenter = leafGridView.size(0); + const auto numDofsFace = leafGridView.size(1); + SolutionVector x; + x[cellCenterIdx].resize(numDofsCellCenter); + x[faceIdx].resize(numDofsFace); + problem->applyInitialSolution(x); + auto xOld = x; + + // the grid variables + using GridVariables = typename GET_PROP_TYPE(TypeTag, GridVariables); + auto gridVariables = std::make_shared<GridVariables>(problem, fvGridGeometry); + gridVariables->init(x, xOld); + + // get some time loop parameters + using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar); + const auto tEnd = getParam<Scalar>("TimeLoop.TEnd"); + const auto maxDivisions = getParam<int>("TimeLoop.MaxTimeStepDivisions"); + const auto maxDt = getParam<Scalar>("TimeLoop.MaxTimeStepSize"); + auto dt = getParam<Scalar>("TimeLoop.DtInitial"); + + // check if we are about to restart a previously interrupted simulation + Scalar restartTime = 0; + if (Parameters::getTree().hasKey("Restart") || Parameters::getTree().hasKey("TimeLoop.Restart")) + restartTime = getParam<Scalar>("TimeLoop.Restart"); + + // intialize the vtk output module + using VtkOutputFields = typename GET_PROP_TYPE(TypeTag, VtkOutputFields); + VtkOutputModule<TypeTag> vtkWriter(*problem, *fvGridGeometry, *gridVariables, x, problem->name()); + VtkOutputFields::init(vtkWriter); //! Add model specific output fields + vtkWriter.write(0.0); + + // instantiate time loop + auto timeLoop = std::make_shared<TimeLoop<Scalar>>(restartTime, dt, tEnd); + timeLoop->setMaxTimeStepSize(maxDt); + + // the assembler with time loop for instationary problem + using Assembler = StaggeredFVAssembler<TypeTag, DiffMethod::numeric>; + auto assembler = std::make_shared<Assembler>(problem, fvGridGeometry, gridVariables, timeLoop); + + // the linear solver + using LinearSolver = Dumux::UMFPackBackend<TypeTag>; + auto linearSolver = std::make_shared<LinearSolver>(); + + // the non-linear solver + using NewtonController = StaggeredNewtonController<TypeTag>; + using NewtonMethod = Dumux::NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>; + auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop); + NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver); + + // time loop + timeLoop->start(); do + { + // set previous solution for storage evaluations + assembler->setPreviousSolution(xOld); + + // try solving the non-linear system + for (int i = 0; i < maxDivisions; ++i) + { + // linearize & solve + auto converged = nonLinearSolver.solve(x); + + if (converged) + break; + + if (!converged && i == maxDivisions-1) + DUNE_THROW(Dune::MathError, + "Newton solver didn't converge after " + << maxDivisions + << " time-step divisions. dt=" + << timeLoop->timeStepSize() + << ".\nThe solutions of the current and the previous time steps " + << "have been saved to restart files."); + } + + // make the new solution the old solution + xOld = x; + gridVariables->advanceTimeStep(); + + // advance to the time loop to the next step + timeLoop->advanceTimeStep(); + + // write vtk output + vtkWriter.write(timeLoop->time()); + + // report statistics of this time step + timeLoop->reportTimeStep(); + + // set new dt as suggested by newton controller + timeLoop->setTimeStepSize(newtonController->suggestTimeStepSize(timeLoop->timeStepSize())); + + } 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 (...) { - typedef TTAG(ChannelTestProblem) ProblemTypeTag; - return Dumux::start<ProblemTypeTag>(argc, argv, usage); + std::cerr << "Unknown exception thrown! ---> Abort!" << std::endl; + return 4; } diff --git a/test/freeflow/staggered/test_channel_stokes.input b/test/freeflow/staggered/test_channel_stokes.input index 6dad824637992bb6c79ba9354da81bbb4a97a60e..916011989126437567270b98e9597ec0095163ad 100644 --- a/test/freeflow/staggered/test_channel_stokes.input +++ b/test/freeflow/staggered/test_channel_stokes.input @@ -1,4 +1,4 @@ -[TimeManager] +[TimeLoop] DtInitial = 1 # [s] TEnd = 2 # [s] @@ -9,7 +9,6 @@ Cells = 100 50 [Problem] Name = test_channel_stokes # name passed to the output routines InletVelocity = 1 -LiquidDensity = 1 EnableGravity = false [ Newton ] @@ -17,4 +16,5 @@ MaxSteps = 10 MaxRelativeShift = 1e-8 [Vtk] +AddVelocity = true WriteFaceData = false