From 88703a1a18fc8fa84f2c6ccabce9a9e22b97fe72 Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Thu, 12 Jul 2018 19:06:31 +0200 Subject: [PATCH] [io][gridmanager] Add support for dune-spgrid --- dumux/io/grid/gridmanager.hh | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/dumux/io/grid/gridmanager.hh b/dumux/io/grid/gridmanager.hh index feeb4a5906..6a291594f7 100644 --- a/dumux/io/grid/gridmanager.hh +++ b/dumux/io/grid/gridmanager.hh @@ -67,6 +67,12 @@ #include <dune/foamgrid/dgffoam.hh> #endif +// SPGrid specific includes +#if HAVE_DUNE_SPGRID +#include <dune/grid/spgrid.hh> +#include <dune/grid/spgrid/dgfparser.hh> +#endif + #include <dumux/common/parameters.hh> #include <dumux/discretization/methods.hh> @@ -1281,6 +1287,69 @@ public: #endif // HAVE_DUNE_FOAMGRID +#if HAVE_DUNE_SPGRID + +/*! + * \brief Provides a grid manager for SPGrid + * + * The following keys are recognized: + * - File : A DGF or gmsh file to load from, type detection by file extension + * + */ +template<class ct, int dim, template< int > class Ref, class Comm> +class GridManager<Dune::SPGrid<ct, dim, Ref, Comm>> +: public GridManagerBase<Dune::SPGrid<ct, dim, Ref, Comm>> +{ +public: + using Grid = Dune::SPGrid<ct, dim, Ref, Comm>; + using ParentType = GridManagerBase<Grid>; + + /*! + * \brief Make the grid. This is implemented by specializations of this method. + */ + void init(const std::string& paramGroup = "") + { + // try to create it from file + if (hasParamInGroup(paramGroup, "Grid.File")) + { + ParentType::makeGridFromDgfFile(getParamFromGroup<std::string>(paramGroup, "Grid.File")); + ParentType::maybeRefineGrid(paramGroup); + ParentType::loadBalance(); + return; + } + // Didn't find a way to construct the grid + else if (hasParamInGroup(paramGroup, "Grid.UpperRight")) + { + using GlobalPosition = Dune::FieldVector<ct, dim>; + const auto lowerLeft = getParamFromGroup<GlobalPosition>(paramGroup, "Grid.LowerLeft", GlobalPosition(0.0)); + const auto upperRight = getParamFromGroup<GlobalPosition>(paramGroup, "Grid.UpperRight"); + + using IntArray = std::array<int, dim>; + IntArray cells; cells.fill(1); + cells = getParamFromGroup<IntArray>(paramGroup, "Grid.Cells", cells); + + const auto periodic = getParamFromGroup<std::bitset<dim>>(paramGroup, "Grid.Periodic", std::bitset<dim>{}); + const auto overlap = getParamFromGroup<int>(paramGroup, "Grid.Overlap", 1); + IntArray spOverlap; spOverlap.fill(overlap); + + using Domain = typename Grid::Domain; + std::vector< typename Domain::Cube > cubes; + cubes.push_back( typename Domain::Cube( lowerLeft, upperRight ) ); + Domain domain( cubes, typename Domain::Topology( static_cast<unsigned int>(periodic.to_ulong()) ) ); + ParentType::gridPtr() = std::make_shared<Grid>( domain, cells, spOverlap ); + ParentType::maybeRefineGrid(paramGroup); + ParentType::loadBalance(); + } + else + { + const auto prefix = paramGroup == "" ? paramGroup : paramGroup + "."; + DUNE_THROW(ParameterException, "Please supply a grid file in " << prefix << "Grid.File or " << prefix << "Grid.UpperRight/Cells."); + } + } +}; + +#endif // HAVE_DUNE_SPGRID + } // end namespace Dumux #endif -- GitLab