From f2e05c23ff54d456b8ad1257561c43d46685c706 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Wed, 8 Nov 2017 16:37:20 +0100 Subject: [PATCH] [gridCreator] Use new getParamFromGroup method for Yasp with offset --- dumux/io/gridcreator.hh | 89 ++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/dumux/io/gridcreator.hh b/dumux/io/gridcreator.hh index 114930a920..82db09a1f2 100644 --- a/dumux/io/gridcreator.hh +++ b/dumux/io/gridcreator.hh @@ -550,69 +550,68 @@ public: /*! * \brief Make the grid. This is implemented by specializations of this method. */ - static void makeGrid() + static void makeGrid(const std::string& modelParamGroup = "") { - // Only construction from the input file is possible - // Look for the necessary keys to construct from the input file - try { - // The required parameters - typedef Dune::FieldVector GlobalPosition; - const GlobalPosition upperRight = GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, GlobalPosition, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), UpperRight); + // First try to create it from a DGF file in GridParameterGroup.File + if (haveParamInGroup(modelParamGroup, "Grid.File")) + { + ParentType::makeGridFromDgfFile(getParamFromGroup(modelParamGroup, "Grid.File")); + postProcessing_(modelParamGroup); + return; + } - // The optional parameters (they have a default) - GlobalPosition lowerLeft(0.0); - try { lowerLeft = GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, GlobalPosition, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), LowerLeft); } - catch (ParameterException &e) { } + // Then look for the necessary keys to construct from the input file + if (!haveParamInGroup(modelParamGroup, "Grid.UpperRight")) + DUNE_THROW(ParameterException, "Please supply the mandatory parameter " + << modelParamGroup << ".UpperRight or a grid file in " + << modelParamGroup << ".File."); - typedef std::array CellArray; - CellArray cells; - std::fill(cells.begin(), cells.end(), 1); - try { cells = GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, CellArray, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), Cells); } - catch (ParameterException &e) { } + using GlobalPosition = Dune::FieldVector; - typedef std::bitset BitSet; - BitSet periodic; - try { periodic = GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, BitSet, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), Periodic);} - catch (ParameterException &e) { } + // get the upper right corner coordinates + const auto upperRight = getParamFromGroup(modelParamGroup, "Grid.UpperRight"); - // the default is dependent on the discretization - int overlap = YaspOverlapHelper::getOverlap(); + // get the lowerLeft corner coordinates (have a default value) + const auto lowerLeft = getParamFromGroup(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0)); - bool default_lb = false; - CellArray partitioning; - try { partitioning = GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, CellArray, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), Partitioning);} - catch (ParameterException &e) { default_lb = true; } + // number of cells in each direction + std::array cells; cells.fill(1); + cells = getParamFromGroup>(modelParamGroup, "Grid.Cells", cells); - //make the grid - if (default_lb) - ParentType::gridPtr() = std::make_shared(lowerLeft, upperRight, cells, periodic, overlap); - else - { - typename Dune::YaspFixedSizePartitioner lb(partitioning); - ParentType::gridPtr() = std::make_shared(lowerLeft, upperRight, cells, periodic, overlap, typename Grid::CollectiveCommunicationType(), &lb); - } - postProcessing_(); + // periodic boundaries + const auto periodic = getParamFromGroup>(modelParamGroup, "Grid.Periodic", std::bitset()); + + // get the overlap dependent on some template parameters + const int overlap = YaspOverlapHelper::getOverlap(modelParamGroup); + + bool default_lb = !haveParamInGroup(modelParamGroup, "Grid.Partitioning"); + + // make the grid + if (default_lb) + { + // construct using default load balancing + ParentType::gridPtr() = std::make_shared(lowerLeft, upperRight, cells, periodic, overlap); } - catch (ParameterException &e) { - DUNE_THROW(ParameterException, "Please supply the mandatory parameters " - << GET_PROP_VALUE(TypeTag, GridParameterGroup) << ".UpperRight or a grid file in " - << GET_PROP_VALUE(TypeTag, GridParameterGroup) << ".File."); + else + { + // construct using user defined partitioning + const auto partitioning = getParamFromGroup>(modelParamGroup, "Grid.Partitioning"); + Dune::YaspFixedSizePartitioner lb(partitioning); + ParentType::gridPtr() = std::make_shared(lowerLeft, upperRight, cells, periodic, overlap, typename Grid::CollectiveCommunicationType(), &lb); } - catch (...) { throw; } + postProcessing_(modelParamGroup); } private: /*! * \brief Postprocessing for YaspGrid */ - static void postProcessing_() + static void postProcessing_(const std::string& modelParamGroup) { // Check if should refine the grid - bool keepPhysicalOverlap = true; - try { keepPhysicalOverlap = GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, bool, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), KeepPhysicalOverlap);} - catch (ParameterException &e) { } + const bool keepPhysicalOverlap = getParamFromGroup(modelParamGroup, "Grid.KeepPhysicalOverlap", true); ParentType::grid().refineOptions(keepPhysicalOverlap); - ParentType::maybeRefineGrid(); + ParentType::maybeRefineGrid(modelParamGroup); } }; -- GitLab