diff --git a/test/porousmediumflow/1p/compressible/instationary/CMakeLists.txt b/test/porousmediumflow/1p/compressible/instationary/CMakeLists.txt index 938bd8ba7f792e7065f3538258f8a2f49fc14fb7..9585357a31665465779b1cb9caeb17fca5c66092 100644 --- a/test/porousmediumflow/1p/compressible/instationary/CMakeLists.txt +++ b/test/porousmediumflow/1p/compressible/instationary/CMakeLists.txt @@ -30,3 +30,14 @@ dumux_add_test(NAME test_1p_compressible_instationary_box --files ${CMAKE_SOURCE_DIR}/test/references/test_1p_box-reference.vtu ${CMAKE_CURRENT_BINARY_DIR}/test_1p_compressible_instationary_box-00010.vtu --command "${CMAKE_CURRENT_BINARY_DIR}/test_1p_compressible_instationary_box params.input -Problem.Name test_1p_compressible_instationary_box") + +dumux_add_test(NAME test_1p_compressible_instationary_tpfa_experimental + LABELS porousmediumflow 1p + SOURCES main_experimental.cc + COMPILE_DEFINITIONS TYPETAG=OnePCompressibleTpfa + COMPILE_DEFINITIONS EXPERIMENTAL=1 + COMMAND ${CMAKE_SOURCE_DIR}/bin/testing/runtest.py + CMD_ARGS --script fuzzy + --files ${CMAKE_SOURCE_DIR}/test/references/test_1p_cc-reference.vtu + ${CMAKE_CURRENT_BINARY_DIR}/test_1p_compressible_instationary_tpfa_experimental-00010.vtu + --command "${CMAKE_CURRENT_BINARY_DIR}/test_1p_compressible_instationary_tpfa_experimental params.input -Problem.Name test_1p_compressible_instationary_tpfa_experimental") diff --git a/test/porousmediumflow/1p/compressible/instationary/assembler.hh b/test/porousmediumflow/1p/compressible/instationary/assembler.hh new file mode 100644 index 0000000000000000000000000000000000000000..115b25570c655bbae65f89bde25120ca7db1dc7e --- /dev/null +++ b/test/porousmediumflow/1p/compressible/instationary/assembler.hh @@ -0,0 +1,54 @@ +// -*- 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 3 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 + * \ingroup OnePTests + * \brief Dummy assembler that fulfills the new experimental assembly interface. + */ +#ifndef DUMUX_COMPRESSIBLE_ONEP_TEST_ASSEMBLER_HH +#define DUMUX_COMPRESSIBLE_ONEP_TEST_ASSEMBLER_HH + +namespace Dumux::OnePCompressibleTest { + +// Custom assembler to test assembly with grid variables, +// fulfilling the foreseen required interface +template<class Assembler> +class GridVarsAssembler : public Assembler +{ +public: + using Assembler::Assembler; + using typename Assembler::GridVariables; + using typename Assembler::ResidualType; + + using Variables = GridVariables; + + void assembleJacobianAndResidual(const GridVariables& gridVars) + { Assembler::assembleJacobianAndResidual(gridVars.dofs()); } + + void assembleResidual(const GridVariables& gridVars) + { Assembler::assembleResidual(gridVars.dofs()); } + + //! Remove residualNorm once this is fixed in the solvers !2113 + auto residualNorm(const GridVariables& gridVars) + { return Assembler::residualNorm(gridVars.dofs()); } +}; + +} // end namespace Dumux::OnePCompressibleTest + +#endif diff --git a/test/porousmediumflow/1p/compressible/instationary/gridvariables.hh b/test/porousmediumflow/1p/compressible/instationary/gridvariables.hh new file mode 100644 index 0000000000000000000000000000000000000000..c9234e9c05802d15f5e37828f6c9d6323010e6ac --- /dev/null +++ b/test/porousmediumflow/1p/compressible/instationary/gridvariables.hh @@ -0,0 +1,68 @@ +// -*- 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 3 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 + * \ingroup OnePTests + * \brief Wrapper around the current FVGridVariables to fulfill the layout + * of the new grid variables to test grid variables-based assembly. + */ +#ifndef DUMUX_COMPRESSIBLE_ONEP_TEST_GRID_VARIABLES_HH +#define DUMUX_COMPRESSIBLE_ONEP_TEST_GRID_VARIABLES_HH + +#include <dumux/discretization/gridvariables.hh> + +namespace Dumux::OnePCompressibleTest { + +template<class GG, class BaseGridVariables, class SolutionVector> +class TestGridVariables +: public BaseGridVariables +, public Dumux::Experimental::GridVariables<GG, SolutionVector> +{ + using ExperimentalBase = Dumux::Experimental::GridVariables<GG, SolutionVector>; + +public: + // export some types to avoid ambiguity + using GridGeometry = GG; + using Scalar = typename BaseGridVariables::Scalar; + + template<class Problem> + TestGridVariables(std::shared_ptr<Problem> problem, + std::shared_ptr<const GridGeometry> gridGeometry, + const SolutionVector& x) + : BaseGridVariables(problem, gridGeometry) + , ExperimentalBase(gridGeometry, x) + { + BaseGridVariables::init(x); + } + + // update to a new solution + void update(const SolutionVector& x) + { + BaseGridVariables::update(x); + ExperimentalBase::update(x); + } + + // overload some functions to avoid ambiguity + decltype(auto) gridGeometry() const + { return ExperimentalBase::gridGeometry(); } +}; + +} // end namespace Dumux::OnePCompressibleTest + +#endif diff --git a/test/porousmediumflow/1p/compressible/instationary/main_experimental.cc b/test/porousmediumflow/1p/compressible/instationary/main_experimental.cc new file mode 100644 index 0000000000000000000000000000000000000000..06f71a35b3843603232e669bc97b7fe431a77a96 --- /dev/null +++ b/test/porousmediumflow/1p/compressible/instationary/main_experimental.cc @@ -0,0 +1,173 @@ +// -*- 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 3 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 + * \ingroup OnePTests + * \brief Test for the one-phase 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/vtk.hh> +#include <dune/istl/io.hh> + +#include <dumux/discretization/method.hh> + +#include <dumux/common/properties.hh> +#include <dumux/common/parameters.hh> +#include <dumux/common/dumuxmessage.hh> + +#include <dumux/nonlinear/newtonsolver.hh> +#include <dumux/linear/seqsolverbackend.hh> + +#include <dumux/assembly/fvassembler.hh> + +#include <dumux/io/vtkoutputmodule.hh> +#include <dumux/io/grid/gridmanager.hh> + +#include "properties.hh" +#include "assembler.hh" + +int main(int argc, char** argv) +{ + using namespace Dumux; + + // define the type tag for this problem + using TypeTag = Properties::TTag::TYPETAG; + + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + + // 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); + + // initialize parameter tree + Parameters::init(argc, argv); + + ////////////////////////////////////////////////////////////////////// + // try to create a grid (from the given grid file or the input file) + ///////////////////////////////////////////////////////////////////// + + GridManager<GetPropType<TypeTag, Properties::Grid>> gridManager; + 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 + using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; + auto gridGeometry = std::make_shared<GridGeometry>(leafGridView); + gridGeometry->update(); + + // the problem (initial and boundary conditions) + using Problem = GetPropType<TypeTag, Properties::Problem>; + auto problem = std::make_shared<Problem>(gridGeometry); + + // the solution vector + using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>; + SolutionVector x(gridGeometry->numDofs()); + problem->applyInitialSolution(x); + auto xOld = x; + + // the grid variables + using GridVariables = GetPropType<TypeTag, Properties::GridVariables>; + auto gridVariables = std::make_shared<GridVariables>(problem, gridGeometry, x); + + // get some time loop parameters + using Scalar = GetPropType<TypeTag, Properties::Scalar>; + auto tEnd = getParam<Scalar>("TimeLoop.TEnd"); + auto dt = getParam<Scalar>("TimeLoop.DtInitial"); + auto maxDt = getParam<Scalar>("TimeLoop.MaxTimeStepSize"); + + // intialize the vtk output module + VtkOutputModule<GridVariables, SolutionVector> vtkWriter(*gridVariables, gridVariables->dofs(), problem->name()); + using VelocityOutput = GetPropType<TypeTag, Properties::VelocityOutput>; + vtkWriter.addVelocityOutput(std::make_shared<VelocityOutput>(*gridVariables)); + using IOFields = GetPropType<TypeTag, Properties::IOFields>; + IOFields::initOutputModule(vtkWriter); // Add model specific output fields + vtkWriter.write(0.0); + + // instantiate time loop + auto timeLoop = std::make_shared<CheckPointTimeLoop<Scalar>>(0.0, dt, tEnd); + timeLoop->setMaxTimeStepSize(maxDt); + + // the assembler with time loop for instationary problem + using BaseAssembler = FVAssembler<TypeTag, DiffMethod::numeric>; + using Assembler = Dumux::OnePCompressibleTest::GridVarsAssembler<BaseAssembler>; + auto assembler = std::make_shared<Assembler>(problem, gridGeometry, gridVariables, timeLoop, xOld); + + // the linear solver + using LinearSolver = ILU0BiCGSTABBackend; + auto linearSolver = std::make_shared<LinearSolver>(); + + // the non-linear solver + using NewtonSolver = Dumux::NewtonSolver<Assembler, LinearSolver>; + NewtonSolver nonLinearSolver(assembler, linearSolver); + + // set some check points for the time loop + timeLoop->setPeriodicCheckPoint(tEnd/10.0); + + // time loop + timeLoop->start(); do + { + // linearize & solve + nonLinearSolver.solve(*gridVariables, *timeLoop); + + // make the new solution the old solution + xOld = gridVariables->dofs(); + + // advance to the time loop to the next step + timeLoop->advanceTimeStep(); + + // write vtk output + if (timeLoop->isCheckPoint()) + vtkWriter.write(timeLoop->time()); + + // report statistics of this time step + timeLoop->reportTimeStep(); + + // set new dt as suggested by the newton solver + timeLoop->setTimeStepSize(nonLinearSolver.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) + DumuxMessage::print(/*firstCall=*/false); + + return 0; + +} diff --git a/test/porousmediumflow/1p/compressible/instationary/properties.hh b/test/porousmediumflow/1p/compressible/instationary/properties.hh index c3e71c6a9b62fa372a82a9e87548c18acf092ce9..98a21fb4c973a8f5b9e37c51a0016000acbfa0ab 100644 --- a/test/porousmediumflow/1p/compressible/instationary/properties.hh +++ b/test/porousmediumflow/1p/compressible/instationary/properties.hh @@ -27,17 +27,22 @@ #include <dune/grid/yaspgrid.hh> - #include <dumux/material/fluidsystems/1pliquid.hh> #include <dumux/discretization/cctpfa.hh> #include <dumux/discretization/ccmpfa.hh> #include <dumux/discretization/box.hh> +#include <dumux/discretization/fvgridvariables.hh> #include <dumux/porousmediumflow/1p/model.hh> #include "problem.hh" #include "spatialparams.hh" +#include "gridvariables.hh" + +#ifndef EXPERIMENTAL +#define EXPERIMENTAL 0 +#endif namespace Dumux::Properties { // create the type tag nodes @@ -76,6 +81,24 @@ public: using type = FluidSystems::OnePLiquid<Scalar, Components::TabulatedComponent<Components::H2O<Scalar>>>; }; +// for the experimental test, overwrite grid variables +// property in order to test grid variables-based assembly +#if EXPERIMENTAL +template<class TypeTag> +struct GridVariables<TypeTag, TTag::OnePCompressible> +{ +private: + using GG = GetPropType<TypeTag, Properties::GridGeometry>; + using GVV = GetPropType<TypeTag, Properties::GridVolumeVariables>; + using GFC = GetPropType<TypeTag, Properties::GridFluxVariablesCache>; + using Base = Dumux::FVGridVariables<GG, GVV, GFC>; + using X = GetPropType<TypeTag, Properties::SolutionVector>; + +public: + using type = Dumux::OnePCompressibleTest::TestGridVariables<GG, Base, X>; +}; +#endif + // Disable caching (for testing purposes) template<class TypeTag> struct EnableGridVolumeVariablesCache<TypeTag, TTag::OnePCompressible> { static constexpr bool value = false; }; @@ -83,6 +106,7 @@ template<class TypeTag> struct EnableGridFluxVariablesCache<TypeTag, TTag::OnePCompressible> { static constexpr bool value = false; }; template<class TypeTag> struct EnableGridGeometryCache<TypeTag, TTag::OnePCompressible> { static constexpr bool value = false; }; -} -#endif \ No newline at end of file +} // end namespace Dumux::Properties + +#endif