From 0a3a1e4acb0b8297f2856a0da584e27fcac2ad8b Mon Sep 17 00:00:00 2001
From: Kilian Weishaupt <kilian.weishaupt@iws.uni-stuttgart.de>
Date: Mon, 30 Nov 2020 20:53:29 +0100
Subject: [PATCH] [io][gridmanager_yasp] Add init function taking cells and
 dimensions

* old function forwards to new ones
* was already implemented for TensorCoordinates
---
 dumux/io/grid/gridmanager_yasp.hh | 65 ++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 27 deletions(-)

diff --git a/dumux/io/grid/gridmanager_yasp.hh b/dumux/io/grid/gridmanager_yasp.hh
index 6ecb00067e..d98c73d279 100644
--- a/dumux/io/grid/gridmanager_yasp.hh
+++ b/dumux/io/grid/gridmanager_yasp.hh
@@ -94,10 +94,13 @@ public:
             // get the overlap
             const int overlap =  getParamFromGroup<int>(modelParamGroup, "Grid.Overlap", 1);
 
-            // make the grid
-            ParentType::gridPtr() = createGrid_(modelParamGroup, upperRight, cells, periodic, overlap, Coordinates{});
-
-            postProcessing_(modelParamGroup);
+            if constexpr (std::is_same_v<Dune::EquidistantCoordinates<ct, dim>, Coordinates>)
+                init(upperRight, cells, modelParamGroup, overlap, periodic);
+            else
+            {
+                const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
+                init(lowerLeft, upperRight, cells, modelParamGroup, overlap, periodic);
+            }
         }
 
         // Didn't find a way to construct the grid
@@ -111,57 +114,67 @@ public:
         }
     }
 
-private:
     /*!
-     * \brief Create a grid with zero offset
+     * \brief Make the grid using input data not read from the input file.
+     * \note Use this function for EquidistantCoordinates where lowerLeft is always zero.
      */
-    std::unique_ptr<Grid> createGrid_(const std::string& modelParamGroup,
-                                      const GlobalPosition& upperRight,
-                                      const std::array<int, dim>& cells,
-                                      const std::bitset<dim>& periodic,
-                                      const int overlap,
-                                      Dune::EquidistantCoordinates<ct, dim>) const
+    void init(const GlobalPosition& upperRight,
+              const std::array<int, dim>& cells,
+              const std::string& modelParamGroup = "",
+              const int overlap = 1,
+              const std::bitset<dim> periodic = std::bitset<dim>{})
     {
+        static_assert(std::is_same_v<Dune::EquidistantCoordinates<ct, dim>, Coordinates>,
+                      "Use init function taking lowerLeft as argument when working with EquidistantOffsetCoordinates");
+
         if (!hasParamInGroup(modelParamGroup, "Grid.Partitioning"))
         {
             // construct using default load balancing
-            return std::make_unique<Grid>(upperRight, cells, periodic, overlap);
+            ParentType::gridPtr() = std::make_unique<Grid>(upperRight, cells, periodic, overlap);
         }
         else
         {
             // construct using user defined partitioning
             const auto partitioning = getParamFromGroup<std::array<int, dim>>(modelParamGroup, "Grid.Partitioning");
             Dune::YaspFixedSizePartitioner<dim> lb(partitioning);
-            return std::make_unique<Grid>(upperRight, cells, periodic, overlap, typename Grid::CollectiveCommunicationType(), &lb);
+            ParentType::gridPtr() = std::make_unique<Grid>(upperRight, cells, periodic, overlap, typename Grid::CollectiveCommunicationType(), &lb);
         }
+
+        postProcessing_(modelParamGroup);
     }
 
     /*!
-     * \brief Create a grid with non-zero offset
+     * \brief Make the grid using input data not read from the input file.
+     * \note Use this function for EquidistantOffsetCoordinates.
      */
-    std::unique_ptr<Grid> createGrid_(const std::string& modelParamGroup,
-                                      const GlobalPosition& upperRight,
-                                      const std::array<int, dim>& cells,
-                                      const std::bitset<dim>& periodic,
-                                      const int overlap,
-                                      Dune::EquidistantOffsetCoordinates<ct, dim>) const
+    void init(const GlobalPosition& lowerLeft,
+              const GlobalPosition& upperRight,
+              const std::array<int, dim>& cells,
+              const std::string& modelParamGroup = "",
+              const int overlap = 1,
+              const std::bitset<dim> periodic = std::bitset<dim>{})
     {
-        const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
+        static_assert(std::is_same_v<Dune::EquidistantOffsetCoordinates<ct, dim>, Coordinates>,
+                      "LowerLeft can only be specified with EquidistantOffsetCoordinates");
 
         if (!hasParamInGroup(modelParamGroup, "Grid.Partitioning"))
         {
             // construct using default load balancing
-            return std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap);
+            ParentType::gridPtr() = std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap);
         }
         else
         {
             // construct using user defined partitioning
             const auto partitioning = getParamFromGroup<std::array<int, dim>>(modelParamGroup, "Grid.Partitioning");
             Dune::YaspFixedSizePartitioner<dim> lb(partitioning);
-            return std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap, typename Grid::CollectiveCommunicationType(), &lb);
+            ParentType::gridPtr() = std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap, typename Grid::CollectiveCommunicationType(), &lb);
         }
+
+        postProcessing_(modelParamGroup);
     }
 
+private:
+
     /*!
      * \brief Postprocessing for YaspGrid
      */
@@ -252,9 +265,7 @@ public:
               const std::array<std::vector<ctype>, dim>& grading,
               const std::string& modelParamGroup = "")
     {
-
-
-        // Additional arameters (they have a default)
+        // Additional parameters (they have a default)
         const int overlap = getParamFromGroup<int>(modelParamGroup, "Grid.Overlap", 1);
         const bool verbose = getParamFromGroup<bool>(modelParamGroup, "Grid.Verbosity", false);
         // \todo TODO periodic boundaries with yasp (the periodicity concept of yasp grid is currently not supported, use dune-spgrid)
-- 
GitLab