12#ifndef DUMUX_IO_GRID_MANAGER_YASP_HH 
   13#define DUMUX_IO_GRID_MANAGER_YASP_HH 
   15#include <dune/common/math.hh> 
   17#include <dune/grid/yaspgrid.hh> 
   18#include <dune/grid/io/file/dgfparser/dgfyasp.hh> 
   20#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH 
   47template<
class Coordinates, 
int dim>
 
   52    using GlobalPosition = Dune::FieldVector<ct, dim>;
 
   60    void init(
const std::string& modelParamGroup = 
"")
 
   66            postProcessing_(modelParamGroup);
 
   77            std::array<int, dim> cells; cells.fill(1);
 
   82            const std::bitset<dim> periodic;
 
   87            if constexpr (std::is_same_v<Dune::EquidistantCoordinates<ct, dim>, Coordinates>)
 
   88                init(upperRight, cells, modelParamGroup, overlap, periodic);
 
   92                init(lowerLeft, upperRight, cells, modelParamGroup, overlap, periodic);
 
   99            const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + 
".";
 
  101                                           << prefix + 
"Grid.UpperRight" 
  102                                           << 
", or a grid file in " << prefix + 
"Grid.File");
 
 
  111    void init(
const GlobalPosition& upperRight,
 
  112              const std::array<int, dim>& cells,
 
  113              const std::string& modelParamGroup = 
"",
 
  114              const int overlap = 1,
 
  115              const std::bitset<dim> periodic = std::bitset<dim>{})
 
  117        static_assert(std::is_same_v<Dune::EquidistantCoordinates<ct, dim>, Coordinates>,
 
  118                      "Use init function taking lowerLeft as argument when working with EquidistantOffsetCoordinates");
 
  123            ParentType::gridPtr() = std::make_unique<Grid>(upperRight, cells, periodic, overlap);
 
  129            Dune::Yasp::FixedSizePartitioning<dim> lb(partitioning);
 
  130            ParentType::gridPtr() = std::make_unique<Grid>(upperRight, cells, periodic, overlap, 
typename Grid::Communication(), &lb);
 
  133        postProcessing_(modelParamGroup);
 
 
  140    void init(
const GlobalPosition& lowerLeft,
 
  141              const GlobalPosition& upperRight,
 
  142              const std::array<int, dim>& cells,
 
  143              const std::string& modelParamGroup = 
"",
 
  144              const int overlap = 1,
 
  145              const std::bitset<dim> periodic = std::bitset<dim>{})
 
  147        static_assert(std::is_same_v<Dune::EquidistantOffsetCoordinates<ct, dim>, Coordinates>,
 
  148                      "LowerLeft can only be specified with EquidistantOffsetCoordinates");
 
  153            ParentType::gridPtr() = std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap);
 
  159            Dune::Yasp::FixedSizePartitioning<dim> lb(partitioning);
 
  160            ParentType::gridPtr() = std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap, 
typename Grid::Communication(), &lb);
 
  163        postProcessing_(modelParamGroup);
 
 
  171    void postProcessing_(
const std::string& modelParamGroup)
 
  175        ParentType::grid().refineOptions(keepPhysicalOverlap);
 
  176        ParentType::maybeRefineGrid(modelParamGroup);
 
  177        ParentType::loadBalance();
 
 
  210template<
class ctype, 
int dim>
 
  212: 
public GridManagerBase<Dune::YaspGrid<dim, Dune::TensorProductCoordinates<ctype, dim> > >
 
  221    void init(
const std::string& modelParamGroup = 
"")
 
  226        std::array<std::vector<ctype>, dim> positions;
 
  227        for (
int i = 0; i < dim; ++i)
 
  228            positions[i] = 
getParamFromGroup<std::vector<ctype>>(modelParamGroup, 
"Grid.Positions" + std::to_string(i));
 
  231        std::array<std::vector<int>, dim> cells;
 
  232        for (
int i = 0; i < dim; ++i)
 
  234            cells[i].resize(positions[i].size()-1, 1.0);
 
  239        std::array<std::vector<ctype>, dim> grading;
 
  240        for (
int i = 0; i < dim; ++i)
 
  242            grading[i].resize(positions[i].size()-1, 1.0);
 
  247        init(positions, cells, grading, modelParamGroup);
 
 
  253    void init(
const std::array<std::vector<ctype>, dim>& positions,
 
  254              const std::array<std::vector<int>, dim>& cells,
 
  255              const std::array<std::vector<ctype>, dim>& grading,
 
  256              const std::string& modelParamGroup = 
"")
 
  263        const std::bitset<dim> periodic;
 
  266        for (
unsigned int dimIdx = 0; dimIdx < dim; ++dimIdx)
 
  268            if (cells[dimIdx].size() + 1 != positions[dimIdx].size())
 
  270                DUNE_THROW(Dune::RangeError, 
"Make sure to specify correct \"Cells\" and \"Positions\" arrays");
 
  272            if (grading[dimIdx].size() + 1 != positions[dimIdx].size())
 
  274                DUNE_THROW(Dune::RangeError, 
"Make sure to specify correct \"Grading\" and \"Positions\" arrays");
 
  276            ctype temp = std::numeric_limits<ctype>::lowest();
 
  277            for (
unsigned int posIdx = 0; posIdx < positions[dimIdx].size(); ++posIdx)
 
  279                if (temp > positions[dimIdx][posIdx])
 
  281                    DUNE_THROW(Dune::RangeError, 
"Make sure to specify a monotone increasing \"Positions\" array");
 
  283                temp = positions[dimIdx][posIdx];
 
  287        const auto globalPositions = computeGlobalPositions_(positions, cells, grading, verbose);
 
  299            Dune::Yasp::FixedSizePartitioning<dim> lb(partitioning);
 
  300            ParentType::gridPtr() = std::make_shared<Grid>(globalPositions, periodic, overlap, 
typename Grid::Communication(), &lb);
 
  303        postProcessing_(modelParamGroup);
 
 
  310    void postProcessing_(
const std::string& modelParamGroup)
 
  314        ParentType::grid().refineOptions(keepPhysicalOverlap);
 
  315        ParentType::maybeRefineGrid(modelParamGroup);
 
  316        ParentType::loadBalance();
 
  320    std::array<std::vector<ctype>, dim>
 
  321    computeGlobalPositions_(
const std::array<std::vector<ctype>, dim>& positions,
 
  322                            const std::array<std::vector<int>, dim>& cells,
 
  323                            const std::array<std::vector<ctype>, dim>& grading,
 
  324                            bool verbose = 
false)
 
  326        std::array<std::vector<ctype>, dim> globalPositions;
 
  329        for (
int dimIdx = 0; dimIdx < dim; dimIdx++)
 
  331            for (
int zoneIdx = 0; zoneIdx < cells[dimIdx].size(); ++zoneIdx)
 
  333                ctype lower = positions[dimIdx][zoneIdx];
 
  334                ctype upper = positions[dimIdx][zoneIdx+1];
 
  335                int numCells = cells[dimIdx][zoneIdx];
 
  336                ctype gradingFactor = grading[dimIdx][zoneIdx];
 
  337                ctype length = upper - lower;
 
  339                bool increasingCellSize = 
false;
 
  343                    std::cout << 
"dim " << dimIdx
 
  344                              << 
" lower "  << lower
 
  345                              << 
" upper "  << upper
 
  346                              << 
" numCells "  << numCells
 
  347                              << 
" grading "  << gradingFactor;
 
  350                if (gradingFactor > 1.0)
 
  352                    increasingCellSize = 
true;
 
  357                if (gradingFactor < 0.0)
 
  360                    gradingFactor = abs(gradingFactor);
 
  361                    if (gradingFactor < 1.0)
 
  363                        increasingCellSize = 
true;
 
  368                if (gradingFactor > 1.0 - 1e-7 && gradingFactor < 1.0 + 1e-7)
 
  370                    height = 1.0 / numCells;
 
  373                        std::cout << 
" -> h "  << height * length << std::endl;
 
  379                    height = (1.0 - gradingFactor) / (1.0 - power(gradingFactor, numCells));
 
  383                        std::cout << 
" -> grading_eff "  << gradingFactor
 
  384                                  << 
" h_min "  << height * power(gradingFactor, 0) * length
 
  385                                  << 
" h_max "  << height * power(gradingFactor, numCells-1) * length
 
  390                std::vector<ctype> localPositions;
 
  391                localPositions.push_back(0);
 
  392                for (
int i = 0; i < numCells-1; i++)
 
  395                    if (!(gradingFactor < 1.0 + 1e-7 && gradingFactor > 1.0 - 1e-7))
 
  397                        if (increasingCellSize)
 
  399                            hI *= power(gradingFactor, i);
 
  403                            hI *= power(gradingFactor, numCells-i-1);
 
  406                    localPositions.push_back(localPositions[i] + hI);
 
  409                for (
int i = 0; i < localPositions.size(); i++)
 
  411                    localPositions[i] *= length;
 
  412                    localPositions[i] += lower;
 
  415                for (
unsigned int i = 0; i < localPositions.size(); ++i)
 
  417                    globalPositions[dimIdx].push_back(localPositions[i]);
 
  420            globalPositions[dimIdx].push_back(positions[dimIdx].back());
 
  423        return globalPositions;
 
 
  431template<
class Coordinates, 
int dim>
 
typename Dune::YaspGrid< dim, Coordinates > Grid
Definition gridmanager_yasp.hh:54
void init(const std::string &modelParamGroup="")
Make the grid. This is implemented by specializations of this method.
Definition gridmanager_yasp.hh:60
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 >{})
Make the grid using input data not read from the input file.
Definition gridmanager_yasp.hh:111
GridManagerBase< Grid > ParentType
Definition gridmanager_yasp.hh:55
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 >{})
Make the grid using input data not read from the input file.
Definition gridmanager_yasp.hh:140
GridManagerBase< Grid > ParentType
Definition gridmanager_yasp.hh:216
typename Dune::YaspGrid< dim, Dune::TensorProductCoordinates< ctype, dim > > Grid
Definition gridmanager_yasp.hh:215
void init(const std::array< std::vector< ctype >, dim > &positions, const std::array< std::vector< int >, dim > &cells, const std::array< std::vector< ctype >, dim > &grading, const std::string &modelParamGroup="")
Make the grid using input data not read from the input file.
Definition gridmanager_yasp.hh:253
void init(const std::string &modelParamGroup="")
Make the grid. This is implemented by specializations of this method.
Definition gridmanager_yasp.hh:221
The grid manager base interface (public) and methods common to most grid manager specializations (pro...
Definition gridmanager_base.hh:55
void makeGridFromDgfFile(const std::string &fileName)
Definition gridmanager_base.hh:257
std::shared_ptr< Grid > & gridPtr()
Definition gridmanager_base.hh:155
void init(const std::string &modelParamGroup="")
Definition gridmanager_base.hh:63
The grid manager (this is the class used by the user) for all supported grid managers that constructs...
Definition gridmanager_base.hh:336
Exception thrown if a run-time parameter is not specified correctly.
Definition exceptions.hh:48
Definition consistentlyorientedgrid.hh:20
dune-grid capabilities compatibility layer
Provides a grid manager for all supported grid managers with input file interfaces....
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:149
bool hasParamInGroup(const std::string ¶mGroup, const std::string ¶m)
Check whether a key exists in the parameter tree with a model group prefix.
Definition parameters.hh:165
Definition gridcapabilities.hh:57
Definition common/pdesolver.hh:24
static bool eval(const GV &gv)
Definition gridmanager_yasp.hh:435
Definition gridcapabilities.hh:67