diff --git a/.patches/exercise-grids/exercise-grids.patch b/.patches/exercise-grids/exercise-grids.patch index f9d358fb35f0491bfadbe7c3b34e8d21afc80dd0..465789bd2c21f2b3e2ef6d1e3e03775c06164732 100644 --- a/.patches/exercise-grids/exercise-grids.patch +++ b/.patches/exercise-grids/exercise-grids.patch @@ -1,6 +1,6 @@ diff -ruN exercises/exercise-grids/CMakeLists.txt exercises/solution/exercise-grids/CMakeLists.txt ---- exercises/exercise-grids/CMakeLists.txt 2024-05-21 14:15:07.149554794 +0200 -+++ exercises/solution/exercise-grids/CMakeLists.txt 2024-05-21 14:15:07.213555107 +0200 +--- exercises/exercise-grids/CMakeLists.txt 2023-03-31 13:48:56.162686698 +0200 ++++ exercises/solution/exercise-grids/CMakeLists.txt 2023-03-31 13:48:56.182686617 +0200 @@ -1,5 +1,5 @@ # the grid exercise simulation program -dumux_add_test(NAME exercise_grids @@ -9,7 +9,7 @@ diff -ruN exercises/exercise-grids/CMakeLists.txt exercises/solution/exercise-gr # add a symlink for each input file diff -ruN exercises/exercise-grids/grids/grid_structured.dgf exercises/solution/exercise-grids/grids/grid_structured.dgf ---- exercises/exercise-grids/grids/grid_structured.dgf 2024-05-21 14:15:07.149554794 +0200 +--- exercises/exercise-grids/grids/grid_structured.dgf 2023-03-31 13:48:56.162686698 +0200 +++ exercises/solution/exercise-grids/grids/grid_structured.dgf 1970-01-01 01:00:00.000000000 +0100 @@ -1,6 +0,0 @@ -DGF @@ -19,7 +19,7 @@ diff -ruN exercises/exercise-grids/grids/grid_structured.dgf exercises/solution/ -30 20 % cells in x and y direction -# diff -ruN exercises/exercise-grids/grids/grid_structured.geo exercises/solution/exercise-grids/grids/grid_structured.geo ---- exercises/exercise-grids/grids/grid_structured.geo 2024-05-21 14:15:07.149554794 +0200 +--- exercises/exercise-grids/grids/grid_structured.geo 2023-03-31 13:48:56.162686698 +0200 +++ exercises/solution/exercise-grids/grids/grid_structured.geo 1970-01-01 01:00:00.000000000 +0100 @@ -1,30 +0,0 @@ -X = 60; @@ -53,8 +53,8 @@ diff -ruN exercises/exercise-grids/grids/grid_structured.geo exercises/solution/ -Transfinite Volume "*"; - diff -ruN exercises/exercise-grids/main.cc exercises/solution/exercise-grids/main.cc ---- exercises/exercise-grids/main.cc 2024-05-21 14:15:07.149554794 +0200 -+++ exercises/solution/exercise-grids/main.cc 2024-05-21 14:15:07.213555107 +0200 +--- exercises/exercise-grids/main.cc 2023-03-31 13:48:56.162686698 +0200 ++++ exercises/solution/exercise-grids/main.cc 2023-03-31 13:48:56.182686617 +0200 @@ -18,7 +18,7 @@ *****************************************************************************/ /*! @@ -65,8 +65,8 @@ diff -ruN exercises/exercise-grids/main.cc exercises/solution/exercise-grids/mai #include <config.h> diff -ruN exercises/exercise-grids/params.input exercises/solution/exercise-grids/params.input ---- exercises/exercise-grids/params.input 2024-05-29 14:31:49.246625171 +0200 -+++ exercises/solution/exercise-grids/params.input 2024-05-21 14:15:07.213555107 +0200 +--- exercises/exercise-grids/params.input 2023-03-31 13:48:56.162686698 +0200 ++++ exercises/solution/exercise-grids/params.input 2023-03-31 13:48:56.182686617 +0200 @@ -3,13 +3,34 @@ TEnd = 3.154e9 # in seconds, i.e ten years @@ -111,21 +111,9 @@ diff -ruN exercises/exercise-grids/params.input exercises/solution/exercise-grid -Aquifer.Snr = 0.0 \ No newline at end of file +Aquifer.Snr = 0.0 -diff -ruN exercises/exercise-grids/problem.hh exercises/solution/exercise-grids/problem.hh ---- exercises/exercise-grids/problem.hh 2024-05-21 14:15:07.149554794 +0200 -+++ exercises/solution/exercise-grids/problem.hh 2024-05-21 14:15:07.213555107 +0200 -@@ -134,7 +134,7 @@ - } - - /*! -- * \brief Evaluate the boundary conditions for a neumann -+ * \brief Evaluate the boundary conditions for a Neumann - * boundary segment. - * - * \param globalPos The position of the integration point of the boundary segment. diff -ruN exercises/exercise-grids/properties.hh exercises/solution/exercise-grids/properties.hh ---- exercises/exercise-grids/properties.hh 2024-05-29 14:31:49.246625171 +0200 -+++ exercises/solution/exercise-grids/properties.hh 2024-05-21 14:15:07.213555107 +0200 +--- exercises/exercise-grids/properties.hh 2023-03-31 13:48:56.162686698 +0200 ++++ exercises/solution/exercise-grids/properties.hh 2023-03-31 13:48:56.182686617 +0200 @@ -17,9 +17,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * *****************************************************************************/ @@ -177,9 +165,9 @@ diff -ruN exercises/exercise-grids/properties.hh exercises/solution/exercise-gri // Set the problem property template<class TypeTag> diff -ruN exercises/exercise-grids/README.md exercises/solution/exercise-grids/README.md ---- exercises/exercise-grids/README.md 2024-05-21 14:15:07.149554794 +0200 +--- exercises/exercise-grids/README.md 2024-07-16 16:06:28.053964733 +0200 +++ exercises/solution/exercise-grids/README.md 1970-01-01 01:00:00.000000000 +0100 -@@ -1,169 +0,0 @@ +@@ -1,159 +0,0 @@ -# Exercise Grids (DuMuX course) -<br> - @@ -208,9 +196,7 @@ diff -ruN exercises/exercise-grids/README.md exercises/solution/exercise-grids/R - -As you may have noticed, the resolution of our grid isn't quite optimal. A finer grid could help to show a more realistic picture of the physics. - --<br><br> --### Task 1: Applying a Global Refinement --<hr> +-## Task 1: Applying a Global Refinement - -A simple strategy for addressing this resolution issue would be a global refinement. -In the `[Grid]` section of your input file, you can add a parameter `Refinement`. @@ -220,9 +206,7 @@ diff -ruN exercises/exercise-grids/README.md exercises/solution/exercise-grids/R - -The simulation should take much more time. Luckily there are other ways to resolve your grid that will not be as computationally expensive. - --<br><br> --### Task 2: Changing the Grid Type --<hr> +-## Task 2: Changing the Grid Type - -Up until now, we have used a basic uniform structured grid. This grid is provided in the Dune environment and is called the YASP grid (Yet Another Structured Parallel Grid). - @@ -231,10 +215,10 @@ diff -ruN exercises/exercise-grids/README.md exercises/solution/exercise-grids/R -```c++ -// Set the grid type -template<class TypeTag> --struct Grid<TypeTag, TTag::Injection2pTypeTag> { using type = Dune::YaspGrid<2>; }; +-struct Grid<TypeTag, TTag::Injection2p> { using type = Dune::YaspGrid<2>; }; -``` - --This sets the Grid, which belongs to the `Injection2pTypeTag` type tag, and calls the manager with a basic `YaspGrid` in the second dimension. +-This sets the Grid, which belongs to the `Injection2p` type tag, and calls the manager with a basic `YaspGrid` in the second dimension. - -If we look in the grid manager header file, `dumux/dumux/io/grid/gridmanager_yasp.hh`, -we will see that there are a few grid development options. Until now, we have used the most basic definition. @@ -266,9 +250,7 @@ diff -ruN exercises/exercise-grids/README.md exercises/solution/exercise-grids/R - -* > __Task 2__: Following the format shown above, change the grid type specified in `properties.hh`. Make the required changes to the input file and run the simulation. - --<br><br> --### Task 3: Grid Zoning and Grading --<hr> +-## Task 3: Grid Zoning and Grading - -The `Positions0` and `Positions1` parameters will segment the grid into zones split at the values provided. In this case, the X-direction -will be made of one zone between 0 and 60, and the Y-direction will be split into one zone between 0 and 40. @@ -317,9 +299,7 @@ diff -ruN exercises/exercise-grids/README.md exercises/solution/exercise-grids/R -Grading1 = 1.0 -1.3 1.3 1.0 -``` - --<br><br> --### Task 4: Reading in a Structured Grid (*.dgf or *.msh grid files) --<hr> +-## Task 4: Reading in a Structured Grid (*.dgf or *.msh grid files) - -DuMu$^\mathsf{X}$ can also read in grids from external files. There are two supported file types: `.dgf` grids, and `.msh` grids. -* __`.dgf`__ grids (DUNE Grid Format grids) are developed within the dune environment and are often used in dumux tests. @@ -334,15 +314,13 @@ diff -ruN exercises/exercise-grids/README.md exercises/solution/exercise-grids/R -``` -Our `dim` and `dimworld` will both be 2, we can use `Dune::cube` as our `elType` (element type), and for the `refinementType` we can use `Dune::nonconforming`. - --There are two external structured grid files located in the `grid/` folder (`grid_structured.msh` and `grid_structured.dgf`). A path to one of these grids should be included in the input file. +-There are two external structured grid files located in the `grid/` folder (`grid_structured.msh` and `grid_structured.dgf`). A path to one of these grids should be included in the input file by adding the parameter `File` in the `[Grid]` section. - - -* > __Task 4__: Edit the grid properties to set up an ALUGrid made of cubes. Call one of the structured meshes via the input file. - - --<br><br> --### Task 5: Reading in a Unstructured Grid (*.dgf or *.msh grid files) --<hr> +-## Task 5: Reading in a Unstructured Grid (*.dgf or *.msh grid files) - -An example of an unstructured grid is located in the `grid/` folder (`grid_unstructured.msh`) - diff --git a/exercises/exercise-grids/README.md b/exercises/exercise-grids/README.md index 6a995b742c209b97dd485eae2d4cf39f198744c1..1879326dc6cf169b756c852af71ae45f48076df9 100644 --- a/exercises/exercise-grids/README.md +++ b/exercises/exercise-grids/README.md @@ -26,9 +26,7 @@ The upper right point of our domain is defined using the first parameter, and al As you may have noticed, the resolution of our grid isn't quite optimal. A finer grid could help to show a more realistic picture of the physics. -<br><br> -### Task 1: Applying a Global Refinement -<hr> +## Task 1: Applying a Global Refinement A simple strategy for addressing this resolution issue would be a global refinement. In the `[Grid]` section of your input file, you can add a parameter `Refinement`. @@ -38,9 +36,7 @@ This will apply a global refinement to the grid you provided. A refinement of va The simulation should take much more time. Luckily there are other ways to resolve your grid that will not be as computationally expensive. -<br><br> -### Task 2: Changing the Grid Type -<hr> +## Task 2: Changing the Grid Type Up until now, we have used a basic uniform structured grid. This grid is provided in the Dune environment and is called the YASP grid (Yet Another Structured Parallel Grid). @@ -49,10 +45,10 @@ In the properties file (`properties.hh`), the grid properties are defined using ```c++ // Set the grid type template<class TypeTag> -struct Grid<TypeTag, TTag::Injection2pTypeTag> { using type = Dune::YaspGrid<2>; }; +struct Grid<TypeTag, TTag::Injection2p> { using type = Dune::YaspGrid<2>; }; ``` -This sets the Grid, which belongs to the `Injection2pTypeTag` type tag, and calls the manager with a basic `YaspGrid` in the second dimension. +This sets the Grid, which belongs to the `Injection2p` type tag, and calls the manager with a basic `YaspGrid` in the second dimension. If we look in the grid manager header file, `dumux/dumux/io/grid/gridmanager_yasp.hh`, we will see that there are a few grid development options. Until now, we have used the most basic definition. @@ -84,9 +80,7 @@ Grading1 = 1.0 * > __Task 2__: Following the format shown above, change the grid type specified in `properties.hh`. Make the required changes to the input file and run the simulation. -<br><br> -### Task 3: Grid Zoning and Grading -<hr> +## Task 3: Grid Zoning and Grading The `Positions0` and `Positions1` parameters will segment the grid into zones split at the values provided. In this case, the X-direction will be made of one zone between 0 and 60, and the Y-direction will be split into one zone between 0 and 40. @@ -135,9 +129,7 @@ Grading0 = 1.0 -1.3 Grading1 = 1.0 -1.3 1.3 1.0 ``` -<br><br> -### Task 4: Reading in a Structured Grid (*.dgf or *.msh grid files) -<hr> +## Task 4: Reading in a Structured Grid (*.dgf or *.msh grid files) DuMu$^\mathsf{X}$ can also read in grids from external files. There are two supported file types: `.dgf` grids, and `.msh` grids. * __`.dgf`__ grids (DUNE Grid Format grids) are developed within the dune environment and are often used in dumux tests. @@ -152,15 +144,13 @@ GridManager<Dune::ALUGrid<dim, dimworld, elType, refinementType>> ``` Our `dim` and `dimworld` will both be 2, we can use `Dune::cube` as our `elType` (element type), and for the `refinementType` we can use `Dune::nonconforming`. -There are two external structured grid files located in the `grid/` folder (`grid_structured.msh` and `grid_structured.dgf`). A path to one of these grids should be included in the input file. +There are two external structured grid files located in the `grid/` folder (`grid_structured.msh` and `grid_structured.dgf`). A path to one of these grids should be included in the input file by adding the parameter `File` in the `[Grid]` section. * > __Task 4__: Edit the grid properties to set up an ALUGrid made of cubes. Call one of the structured meshes via the input file. -<br><br> -### Task 5: Reading in a Unstructured Grid (*.dgf or *.msh grid files) -<hr> +## Task 5: Reading in a Unstructured Grid (*.dgf or *.msh grid files) An example of an unstructured grid is located in the `grid/` folder (`grid_unstructured.msh`) diff --git a/exercises/exercise-grids/problem.hh b/exercises/exercise-grids/problem.hh index ad45de3f8498d1383539195482f2f61b357fdd1c..1e6817d2ceda8813cb5637b21d3252350f438083 100644 --- a/exercises/exercise-grids/problem.hh +++ b/exercises/exercise-grids/problem.hh @@ -25,10 +25,10 @@ #ifndef DUMUX_EXGRIDS_INJECTION_PROBLEM_2P_HH #define DUMUX_EXGRIDS_INJECTION_PROBLEM_2P_HH -#include <dumux/porousmediumflow/problem.hh> #include <dumux/common/properties.hh> #include <dumux/common/boundarytypes.hh> #include <dumux/common/numeqvector.hh> +#include <dumux/porousmediumflow/problem.hh> namespace Dumux { @@ -134,7 +134,7 @@ public: } /*! - * \brief Evaluate the boundary conditions for a neumann + * \brief Evaluate the boundary conditions for a Neumann * boundary segment. * * \param globalPos The position of the integration point of the boundary segment. @@ -147,12 +147,11 @@ public: // if we are inside the injection zone set inflow Neumann boundary conditions // using < boundary + eps_ or > boundary - eps_ is safer for floating point comparisons // than using <= or >= as it is robust with regard to imprecision introduced by rounding errors. - if (time_ < injectionDuration_ - && globalPos[1] < 15 + eps_ && globalPos[1] > 7 - eps_ && globalPos[0] > 0.9*this->gridGeometry().bBoxMax()[0]) + if (injectionActive() && onInjectionBoundary(globalPos)) { // inject nitrogen. negative values mean injection // units kg/(s*m^2) - values[Indices::conti0EqIdx + FluidSystem::N2Idx]= -1e-4/FluidSystem::molarMass(FluidSystem::N2Idx); + values[Indices::conti0EqIdx + FluidSystem::N2Idx]= -1e-4; values[Indices::conti0EqIdx + FluidSystem::H2OIdx] = 0.0; } @@ -188,6 +187,18 @@ public: void setTime(Scalar time) { time_ = time; } + //! Return true if the injection is currently active + bool injectionActive() const + { return time_ < injectionDuration_; } + + //! Return true if the given position is in the injection boundary region + bool onInjectionBoundary(const GlobalPosition& globalPos) const + { + return globalPos[1] < 15. + eps_ + && globalPos[1] > 7. - eps_ + && globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; + } + private: static constexpr Scalar eps_ = 1e-6; std::string name_; //! Problem name diff --git a/exercises/solution/exercise-grids/problem.hh b/exercises/solution/exercise-grids/problem.hh index 2eb4594e53d5af7285ffa0798daa8da4dcb9a789..1e6817d2ceda8813cb5637b21d3252350f438083 100644 --- a/exercises/solution/exercise-grids/problem.hh +++ b/exercises/solution/exercise-grids/problem.hh @@ -25,10 +25,10 @@ #ifndef DUMUX_EXGRIDS_INJECTION_PROBLEM_2P_HH #define DUMUX_EXGRIDS_INJECTION_PROBLEM_2P_HH -#include <dumux/porousmediumflow/problem.hh> #include <dumux/common/properties.hh> #include <dumux/common/boundarytypes.hh> #include <dumux/common/numeqvector.hh> +#include <dumux/porousmediumflow/problem.hh> namespace Dumux { @@ -147,12 +147,11 @@ public: // if we are inside the injection zone set inflow Neumann boundary conditions // using < boundary + eps_ or > boundary - eps_ is safer for floating point comparisons // than using <= or >= as it is robust with regard to imprecision introduced by rounding errors. - if (time_ < injectionDuration_ - && globalPos[1] < 15 + eps_ && globalPos[1] > 7 - eps_ && globalPos[0] > 0.9*this->gridGeometry().bBoxMax()[0]) + if (injectionActive() && onInjectionBoundary(globalPos)) { // inject nitrogen. negative values mean injection // units kg/(s*m^2) - values[Indices::conti0EqIdx + FluidSystem::N2Idx]= -1e-4/FluidSystem::molarMass(FluidSystem::N2Idx); + values[Indices::conti0EqIdx + FluidSystem::N2Idx]= -1e-4; values[Indices::conti0EqIdx + FluidSystem::H2OIdx] = 0.0; } @@ -188,6 +187,18 @@ public: void setTime(Scalar time) { time_ = time; } + //! Return true if the injection is currently active + bool injectionActive() const + { return time_ < injectionDuration_; } + + //! Return true if the given position is in the injection boundary region + bool onInjectionBoundary(const GlobalPosition& globalPos) const + { + return globalPos[1] < 15. + eps_ + && globalPos[1] > 7. - eps_ + && globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; + } + private: static constexpr Scalar eps_ = 1e-6; std::string name_; //! Problem name diff --git a/slides/grid.md b/slides/grid.md index d6635a5b3c12ea1a5dcdb8799af60ea02c341b34..156990b2fcf5e5cc996a373d1372bd1d9b3063d9 100644 --- a/slides/grid.md +++ b/slides/grid.md @@ -23,6 +23,8 @@ Implementations of the Dune grid interface * **SubGrid** (meta-grid, turn subdomain into grid) * **GeometryGrid** (meta-grid, grid by coordinate transformation) +[Overview of grid features](https://www.dune-project.org/doc/grids/) + ## Create grid * Set grid types via properties specialization: