diff --git a/exercises/exercise-properties/README.md b/exercises/exercise-properties/README.md index b676f489e1be8c491f08f250214f1006e0aeace4..6e59b2aaf0386e475fb3546f1dfb26f028c0e035 100644 --- a/exercises/exercise-properties/README.md +++ b/exercises/exercise-properties/README.md @@ -18,6 +18,7 @@ _Exercise Properties_ deals with a two-phase immiscible incompressible problem ( Locate all the files you will need for this exercise * The __main file__: `main.cc` * The __problem file__: `problem.hh` +* The __properties file__: `properties.hh` * The __spatial parameters file__: `spatialparams.hh` * The __input file__: `params.input` * One header file containing: @@ -54,7 +55,7 @@ Note: Because the input file has the same name as the executable, DuMu<sup>x</su Types that are properties can be changed on the problem level by using the property system. In the following task, we implement our own 2p local residual, i.e. the class that computes the element residual in every Newton iteration. The file `mylocalresidual.hh` contains a copy of the original local residual class used for all immiscible models renamed to `template<class TypeTag> class MyLocalResidual`. -* Make DuMu<sup>x</sup> use this new local residual by including the header `mylocalresidual.hh` and setting the corresponding property in the `Property` namespace in the file `problem.hh` +* Make DuMu<sup>x</sup> use this new local residual by including the header `mylocalresidual.hh` and setting the corresponding property in the `Property` namespace in the file `properties.hh` ```c++ diff --git a/exercises/exercise-properties/main.cc b/exercises/exercise-properties/main.cc index 91a44609c3fff557b62c0d4700bb0a602814e8ac..fd52d8d8f85c911b00f25000ce86348586de08f9 100644 --- a/exercises/exercise-properties/main.cc +++ b/exercises/exercise-properties/main.cc @@ -32,8 +32,6 @@ #include <dune/grid/io/file/vtk.hh> #include <dune/istl/io.hh> -#include "problem.hh" - #include <dumux/common/properties.hh> #include <dumux/common/parameters.hh> #include <dumux/common/valgrind.hh> @@ -52,6 +50,8 @@ #include <dumux/io/vtkoutputmodule.hh> #include <dumux/io/grid/gridmanager.hh> +#include "properties.hh" + /*! * \brief Provides an interface for customizing error messages associated with * reading in parameters. diff --git a/exercises/exercise-properties/problem.hh b/exercises/exercise-properties/problem.hh index cb48815924d3c6cbd3f2ca6ea2d507c50df7cbbd..668e76aa3e8e5e5cbd9603be77c16a220e5a083b 100644 --- a/exercises/exercise-properties/problem.hh +++ b/exercises/exercise-properties/problem.hh @@ -18,75 +18,15 @@ *****************************************************************************/ /*! * \ingroup TwoPTests - * \brief The properties for the incompressible 2p test + * \brief The incompressible 2p test problem for exercise-properties */ #ifndef DUMUX_INCOMPRESSIBLE_TWOP_TEST_PROBLEM_HH #define DUMUX_INCOMPRESSIBLE_TWOP_TEST_PROBLEM_HH -#include <dune/grid/yaspgrid.hh> - -#include <dumux/discretization/box.hh> -#include <dumux/discretization/cctpfa.hh> -#include <dumux/discretization/ccmpfa.hh> - -#include <dumux/material/components/trichloroethene.hh> -#include <dumux/material/components/simpleh2o.hh> -#include <dumux/material/fluidsystems/1pliquid.hh> -#include <dumux/material/fluidsystems/2pimmiscible.hh> - #include <dumux/porousmediumflow/problem.hh> -#include <dumux/porousmediumflow/2p/model.hh> -#include <dumux/porousmediumflow/2p/incompressiblelocalresidual.hh> - -#include "spatialparams.hh" - -// TODO: dumux-course-task 3 -// Include the local residual header +#include <dumux/common/properties.hh> namespace Dumux { -// forward declarations -template<class TypeTag> class TwoPTestProblem; - -namespace Properties { -// Create new type tags -namespace TTag { -struct TwoPIncompressible { using InheritsFrom = std::tuple<TwoP>; }; -struct TwoPIncompressibleTpfa { using InheritsFrom = std::tuple<TwoPIncompressible, CCTpfaModel>; }; -} // end namespace TTag - -// Set the grid type -template<class TypeTag> -struct Grid<TypeTag, TTag::TwoPIncompressible> { using type = Dune::YaspGrid<2>; }; - -// Set the problem type -template<class TypeTag> -struct Problem<TypeTag, TTag::TwoPIncompressible> { using type = TwoPTestProblem<TypeTag>; }; - -// TODO: dumux-course-task 3 -// Use MyLocalResidual as LocalResidual - - -// Set the fluid system -template<class TypeTag> -struct FluidSystem<TypeTag, TTag::TwoPIncompressible> -{ - using Scalar = GetPropType<TypeTag, Properties::Scalar>; - using WettingPhase = FluidSystems::OnePLiquid<Scalar, Components::SimpleH2O<Scalar> >; - using NonwettingPhase = FluidSystems::OnePLiquid<Scalar, Components::Trichloroethene<Scalar> >; - using type = FluidSystems::TwoPImmiscible<Scalar, WettingPhase, NonwettingPhase>; -}; - -// Set the spatial parameters -template<class TypeTag> -struct SpatialParams<TypeTag, TTag::TwoPIncompressible> -{ -private: - using FVGridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; - using Scalar = GetPropType<TypeTag, Properties::Scalar>; -public: - using type = TwoPTestSpatialParams<FVGridGeometry, Scalar>; -}; -} // end namespace Properties /*! * \ingroup TwoPTests diff --git a/exercises/exercise-properties/properties.hh b/exercises/exercise-properties/properties.hh new file mode 100644 index 0000000000000000000000000000000000000000..d8beb946a296ca88bd7b1b69fb9b877cd09f6fd7 --- /dev/null +++ b/exercises/exercise-properties/properties.hh @@ -0,0 +1,89 @@ +// -*- 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/>. * + *****************************************************************************/ +/*! + * \ingroup TwoPTests + * \brief The properties file for exercise-properties + */ +#ifndef DUMUX_EX_PROPERTIES_HH +#define DUMUX_EX_PROPERTIES_HH + +#include <dune/grid/yaspgrid.hh> + +#include <dumux/discretization/box.hh> +#include <dumux/discretization/cctpfa.hh> +#include <dumux/discretization/ccmpfa.hh> + +#include <dumux/material/components/trichloroethene.hh> +#include <dumux/material/components/simpleh2o.hh> +#include <dumux/material/fluidsystems/1pliquid.hh> +#include <dumux/material/fluidsystems/2pimmiscible.hh> + +#include <dumux/porousmediumflow/2p/model.hh> +#include <dumux/porousmediumflow/2p/incompressiblelocalresidual.hh> + +#include "spatialparams.hh" +#include "problem.hh" + +// TODO: dumux-course-task 3 +// Include the local residual header + +namespace Dumux::Properties { + +// Create new type tags +namespace TTag { +struct TwoPIncompressible { using InheritsFrom = std::tuple<TwoP>; }; +struct TwoPIncompressibleTpfa { using InheritsFrom = std::tuple<TwoPIncompressible, CCTpfaModel>; }; +} // end namespace TTag + +// Set the grid type +template<class TypeTag> +struct Grid<TypeTag, TTag::TwoPIncompressible> { using type = Dune::YaspGrid<2>; }; + +// Set the problem type +template<class TypeTag> +struct Problem<TypeTag, TTag::TwoPIncompressible> { using type = TwoPTestProblem<TypeTag>; }; + +// TODO: dumux-course-task 3 +// Use MyLocalResidual as LocalResidual + + +// Set the fluid system +template<class TypeTag> +struct FluidSystem<TypeTag, TTag::TwoPIncompressible> +{ + using Scalar = GetPropType<TypeTag, Properties::Scalar>; + using WettingPhase = FluidSystems::OnePLiquid<Scalar, Components::SimpleH2O<Scalar> >; + using NonwettingPhase = FluidSystems::OnePLiquid<Scalar, Components::Trichloroethene<Scalar> >; + using type = FluidSystems::TwoPImmiscible<Scalar, WettingPhase, NonwettingPhase>; +}; + +// Set the spatial parameters +template<class TypeTag> +struct SpatialParams<TypeTag, TTag::TwoPIncompressible> +{ +private: + using FVGridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; + using Scalar = GetPropType<TypeTag, Properties::Scalar>; +public: + using type = TwoPTestSpatialParams<FVGridGeometry, Scalar>; +}; + +} // end namespace Dumux::Properties + +#endif diff --git a/exercises/solution/exercise-properties/main.cc b/exercises/solution/exercise-properties/main.cc index 4510c44784e401b915919a35a36a41fc3b9819f3..203add5c994bb55659a2490bc5bec86903ce4f6e 100644 --- a/exercises/solution/exercise-properties/main.cc +++ b/exercises/solution/exercise-properties/main.cc @@ -32,8 +32,6 @@ #include <dune/grid/io/file/vtk.hh> #include <dune/istl/io.hh> -#include "problem.hh" - #include <dumux/common/properties.hh> #include <dumux/common/parameters.hh> #include <dumux/common/valgrind.hh> @@ -53,6 +51,8 @@ #include <dumux/io/grid/gridmanager.hh> #include <dumux/io/loadsolution.hh> +#include "properties.hh" + /*! * \brief Provides an interface for customizing error messages associated with * reading in parameters. diff --git a/exercises/solution/exercise-properties/problem.hh b/exercises/solution/exercise-properties/problem.hh index 4c81bc860ab875cbad9bd473a33ead28a5d0f119..f218701a74272c6e51cbf6dd6cca45f1313787f5 100644 --- a/exercises/solution/exercise-properties/problem.hh +++ b/exercises/solution/exercise-properties/problem.hh @@ -18,72 +18,15 @@ *****************************************************************************/ /*! * \ingroup TwoPTests - * \brief The properties for the incompressible 2p test + * \brief The incompressible 2p test problem for exercise-properties */ #ifndef DUMUX_INCOMPRESSIBLE_TWOP_TEST_PROBLEM_HH #define DUMUX_INCOMPRESSIBLE_TWOP_TEST_PROBLEM_HH -#include <dune/grid/yaspgrid.hh> - -#include <dumux/discretization/box.hh> -#include <dumux/discretization/cctpfa.hh> -#include <dumux/discretization/ccmpfa.hh> - -#include <dumux/material/components/trichloroethene.hh> -#include <dumux/material/components/simpleh2o.hh> -#include <dumux/material/fluidsystems/1pliquid.hh> -#include <dumux/material/fluidsystems/2pimmiscible.hh> - #include <dumux/porousmediumflow/problem.hh> -#include <dumux/porousmediumflow/2p/model.hh> -#include <dumux/porousmediumflow/2p/incompressiblelocalresidual.hh> - -#include "spatialparams.hh" -#include "mylocalresidual.hh" +#include <dumux/common/properties.hh> namespace Dumux { -// forward declarations -template<class TypeTag> class TwoPTestProblem; - -namespace Properties { -// Create new type tags -namespace TTag { -struct TwoPIncompressible { using InheritsFrom = std::tuple<TwoP>; }; -struct TwoPIncompressibleTpfa { using InheritsFrom = std::tuple<TwoPIncompressible, CCTpfaModel>; }; -} // end namespace TTag - -// Set the grid type -template<class TypeTag> -struct Grid<TypeTag, TTag::TwoPIncompressible> { using type = Dune::YaspGrid<2>; }; - -// Set the problem type -template<class TypeTag> -struct Problem<TypeTag, TTag::TwoPIncompressible> { using type = TwoPTestProblem<TypeTag>; }; - -template<class TypeTag> -struct LocalResidual<TypeTag, TTag::TwoPIncompressible> { using type = MyLocalResidual<TypeTag>; }; - -// Set the fluid system -template<class TypeTag> -struct FluidSystem<TypeTag, TTag::TwoPIncompressible> -{ - using Scalar = GetPropType<TypeTag, Properties::Scalar>; - using WettingPhase = FluidSystems::OnePLiquid<Scalar, Components::SimpleH2O<Scalar> >; - using NonwettingPhase = FluidSystems::OnePLiquid<Scalar, Components::Trichloroethene<Scalar> >; - using type = FluidSystems::TwoPImmiscible<Scalar, WettingPhase, NonwettingPhase>; -}; - -// Set the spatial parameters -template<class TypeTag> -struct SpatialParams<TypeTag, TTag::TwoPIncompressible> -{ -private: - using FVGridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; - using Scalar = GetPropType<TypeTag, Properties::Scalar>; -public: - using type = TwoPTestSpatialParams<FVGridGeometry, Scalar>; -}; -} // end namespace Properties /*! * \ingroup TwoPTests diff --git a/exercises/solution/exercise-properties/properties.hh b/exercises/solution/exercise-properties/properties.hh new file mode 100644 index 0000000000000000000000000000000000000000..eed1a9fbbef038506a50db7ead16eb03a7a6e987 --- /dev/null +++ b/exercises/solution/exercise-properties/properties.hh @@ -0,0 +1,86 @@ +// -*- 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/>. * + *****************************************************************************/ +/*! +* \ingroup TwoPTests + * \brief The properties file for exercise-properties + */ +#ifndef DUMUX_EX_PROPERTIES_HH +#define DUMUX_EX_PROPERTIES_HH + +#include <dune/grid/yaspgrid.hh> + +#include <dumux/discretization/box.hh> +#include <dumux/discretization/cctpfa.hh> +#include <dumux/discretization/ccmpfa.hh> + +#include <dumux/material/components/trichloroethene.hh> +#include <dumux/material/components/simpleh2o.hh> +#include <dumux/material/fluidsystems/1pliquid.hh> +#include <dumux/material/fluidsystems/2pimmiscible.hh> + +#include <dumux/porousmediumflow/2p/model.hh> +#include <dumux/porousmediumflow/2p/incompressiblelocalresidual.hh> + +#include "spatialparams.hh" +#include "problem.hh" +#include "mylocalresidual.hh" + +namespace Dumux::Properties { + +// Create new type tags +namespace TTag { +struct TwoPIncompressible { using InheritsFrom = std::tuple<TwoP>; }; +struct TwoPIncompressibleTpfa { using InheritsFrom = std::tuple<TwoPIncompressible, CCTpfaModel>; }; +} // end namespace TTag + +// Set the grid type +template<class TypeTag> +struct Grid<TypeTag, TTag::TwoPIncompressible> { using type = Dune::YaspGrid<2>; }; + +// Set the problem type +template<class TypeTag> +struct Problem<TypeTag, TTag::TwoPIncompressible> { using type = TwoPTestProblem<TypeTag>; }; + +template<class TypeTag> +struct LocalResidual<TypeTag, TTag::TwoPIncompressible> { using type = MyLocalResidual<TypeTag>; }; + +// Set the fluid system +template<class TypeTag> +struct FluidSystem<TypeTag, TTag::TwoPIncompressible> +{ + using Scalar = GetPropType<TypeTag, Properties::Scalar>; + using WettingPhase = FluidSystems::OnePLiquid<Scalar, Components::SimpleH2O<Scalar> >; + using NonwettingPhase = FluidSystems::OnePLiquid<Scalar, Components::Trichloroethene<Scalar> >; + using type = FluidSystems::TwoPImmiscible<Scalar, WettingPhase, NonwettingPhase>; +}; + +// Set the spatial parameters +template<class TypeTag> +struct SpatialParams<TypeTag, TTag::TwoPIncompressible> +{ +private: + using FVGridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; + using Scalar = GetPropType<TypeTag, Properties::Scalar>; +public: + using type = TwoPTestSpatialParams<FVGridGeometry, Scalar>; +}; + +} // end namespace Dumux::Properties + +#endif