From 128c1cd5174e8e1d279745691abe368c8fd40cf7 Mon Sep 17 00:00:00 2001
From: "Dennis.Glaeser" <dennis.glaeser@iws.uni-stuttgart.de>
Date: Mon, 20 May 2019 16:36:38 +0200
Subject: [PATCH] [discretization] add fem grid geometry

---
 dumux/discretization/CMakeLists.txt           |   1 +
 dumux/discretization/checkoverlapsize.hh      |  10 ++
 dumux/discretization/fem/CMakeLists.txt       |   4 +
 dumux/discretization/fem/feelementgeometry.hh |  78 ++++++++++++
 dumux/discretization/fem/fegridgeometry.hh    | 116 ++++++++++++++++++
 5 files changed, 209 insertions(+)
 create mode 100644 dumux/discretization/fem/CMakeLists.txt
 create mode 100644 dumux/discretization/fem/feelementgeometry.hh
 create mode 100644 dumux/discretization/fem/fegridgeometry.hh

diff --git a/dumux/discretization/CMakeLists.txt b/dumux/discretization/CMakeLists.txt
index 9798db6b0b..d67d77fbf4 100644
--- a/dumux/discretization/CMakeLists.txt
+++ b/dumux/discretization/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_subdirectory(box)
 add_subdirectory(cellcentered)
+add_subdirectory(fem)
 add_subdirectory(staggered)
 
 install(FILES
diff --git a/dumux/discretization/checkoverlapsize.hh b/dumux/discretization/checkoverlapsize.hh
index 4fc0c44ce9..9fb0d3d350 100644
--- a/dumux/discretization/checkoverlapsize.hh
+++ b/dumux/discretization/checkoverlapsize.hh
@@ -52,6 +52,16 @@ struct CheckOverlapSize<DiscretizationMethod::box>
     { return gridView.comm().size() <= 1 || gridView.overlapSize(0) == 0; }
 };
 
+//! specialization for the finite element method which requires an overlap size of 0
+//! \note Overloads for bases that require overlap regions can be defined in the future
+template<>
+struct CheckOverlapSize<DiscretizationMethod::fem>
+{
+    template<class FEBasis>
+    static bool isValid(const FEBasis& feBasis) noexcept
+    { return feBasis.gridView().comm().size() <= 1 || feBasis.gridView().overlapSize(0) == 0; }
+};
+
 } // end namespace Dumux
 
 #endif
diff --git a/dumux/discretization/fem/CMakeLists.txt b/dumux/discretization/fem/CMakeLists.txt
new file mode 100644
index 0000000000..6017400011
--- /dev/null
+++ b/dumux/discretization/fem/CMakeLists.txt
@@ -0,0 +1,4 @@
+install(FILES
+feelementgeometry.hh
+fegridgeometry.hh
+DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/discretization/fem)
diff --git a/dumux/discretization/fem/feelementgeometry.hh b/dumux/discretization/fem/feelementgeometry.hh
new file mode 100644
index 0000000000..2c32adab74
--- /dev/null
+++ b/dumux/discretization/fem/feelementgeometry.hh
@@ -0,0 +1,78 @@
+// -*- 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 FEMDiscretization
+ * \brief Grid geometry local view, which is a wrapper around a
+ *        finite element basis local view.
+ */
+#ifndef DUMUX_DISCRETIZATION_FE_ELEMENT_GEOMETRY_HH
+#define DUMUX_DISCRETIZATION_FE_ELEMENT_GEOMETRY_HH
+
+namespace Dumux {
+
+/*!
+ * \ingroup FEMDiscretization
+ * \brief Grid geometry local view, which is a wrapper around a
+ *        finite element basis local view.
+ * \tparam The grid geometry type
+ * \tparam The FEBasis local view
+ */
+template<class GridGeometry>
+class FEElementGeometry
+{
+    using GridView = typename GridGeometry::GridView;
+    using Element = typename GridView::template Codim<0>::Entity;
+
+    using FEBasis = typename GridGeometry::FEBasis;
+    using FEBasisLocalView = typename FEBasis::LocalView;
+
+public:
+    //! constructor taking grid geometry
+    FEElementGeometry(const GridGeometry& gg)
+    : gridGeometry_(gg)
+    , feBasisLocalView_(gg.feBasis().localView())
+    {}
+
+    //! Prepare element-local data
+    void bind(const Element& element)
+    {
+        feBasisLocalView_.bind(element);
+    }
+
+    //! Prepare element-local data
+    void bindElement(const Element& element)
+    { bind(element); }
+
+    //! Return the finite element basis local view
+    const FEBasisLocalView& feBasisLocalView() const
+    { return feBasisLocalView_; }
+
+    //! Return reference to the grid geometry
+    const GridGeometry& gridGeometry() const
+    { return gridGeometry_; }
+
+private:
+    const GridGeometry& gridGeometry_;
+    FEBasisLocalView feBasisLocalView_;
+};
+
+} // end namespace Dumux
+
+#endif
diff --git a/dumux/discretization/fem/fegridgeometry.hh b/dumux/discretization/fem/fegridgeometry.hh
new file mode 100644
index 0000000000..dfeea026cc
--- /dev/null
+++ b/dumux/discretization/fem/fegridgeometry.hh
@@ -0,0 +1,116 @@
+// -*- 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 FEMDiscretization
+ * \brief The grid geometry class for models using finite element schemes.
+ *        This is basically a wrapper around a function space basis.
+ */
+#ifndef DUMUX_DISCRETIZATION_FE_GRID_GEOMETRY_HH
+#define DUMUX_DISCRETIZATION_FE_GRID_GEOMETRY_HH
+
+#include <dumux/common/indextraits.hh>
+#include <dumux/common/defaultmappertraits.hh>
+
+#include <dumux/discretization/method.hh>
+#include <dumux/discretization/basegridgeometry.hh>
+#include <dumux/discretization/checkoverlapsize.hh>
+#include <dumux/discretization/fem/feelementgeometry.hh>
+
+namespace Dumux {
+
+/*!
+ * \ingroup FEMDiscretization
+ * \brief Default Traits class for the fem grid geometry.
+ * \tparam The finite element function space basis
+ * \tparam MapperTraits Traits class containing data types for mappers
+ */
+template<class FEBasis, class MapperTraits = DefaultMapperTraits<typename FEBasis::GridView>>
+struct DefaultFEGridGeometryTraits : public MapperTraits
+{
+    template<class GridGeometry>
+    using LocalView = FEElementGeometry<GridGeometry>;
+};
+
+/*!
+ * \ingroup FEMDiscretization
+ * \brief The grid geometry class for models using finite element schemes.
+ *        This is basically a wrapper around a function space basis.
+ * \tparam FEB The finite element function space basis
+ * \tparam MapperTraits Traits class containing data types for mappers
+ */
+template<class FEB, class Traits = DefaultFEGridGeometryTraits<FEB>>
+class FEGridGeometry
+: public BaseGridGeometry< typename FEB::GridView, Traits >
+{
+    using ThisType = FEGridGeometry<FEB, Traits>;
+    using ParentType = BaseGridGeometry<typename FEB::GridView, Traits>;
+
+    using GridIndexType = typename IndexTraits<typename FEB::GridView>::GridIndex;
+    using LocalIndexType = typename IndexTraits<typename FEB::GridView>::LocalIndex;
+
+public:
+    //! export discretization method
+    static constexpr DiscretizationMethod discMethod = DiscretizationMethod::fem;
+
+    //! export the grid view type
+    using GridView = typename FEB::GridView;
+    //! export the type of finite element basis
+    using FEBasis = FEB;
+    //! export local view
+    using LocalView = typename Traits::template LocalView<ThisType>;
+
+    //! Constructor
+    FEGridGeometry(std::shared_ptr<FEBasis> feBasis)
+    : ParentType(feBasis->gridView())
+    , feBasis_(feBasis)
+    {
+        // Check if the overlap size is what we expect
+        if (!CheckOverlapSize<DiscretizationMethod::fem>::isValid(*feBasis))
+            DUNE_THROW(Dune::InvalidStateException, "The finite element discretization method only works with zero overlap for parallel computations. "
+                                                     << " Set the parameter \"Grid.Overlap\" in the input file.");
+    }
+
+    //! The total number of degrees of freedom
+    auto numDofs() const
+    { return feBasis_->size(); }
+
+    //! The total number of degrees of freedom
+    const FEBasis& feBasis() const
+    { return *feBasis_; }
+
+    //! If a vertex / d.o.f. is on a periodic boundary
+    bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
+    { DUNE_THROW(Dune::NotImplemented, "Periodic BC support for FEM schemes"); }
+
+    //! The index of the vertex / d.o.f. on the other side of the periodic boundary
+    GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
+    { DUNE_THROW(Dune::NotImplemented, "Periodic BC support for FEM schemes"); }
+
+    //! Returns the map between dofs across periodic boundaries
+    const std::unordered_map<GridIndexType, GridIndexType>& periodicVertexMap() const
+    { DUNE_THROW(Dune::NotImplemented, "Periodic BC support for FEM schemes"); }
+
+private:
+    std::shared_ptr<FEBasis> feBasis_;
+};
+
+} // end namespace Dumux
+
+#endif
-- 
GitLab