version 3.11-dev
Loading...
Searching...
No Matches
gridmanager_mmesh.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_IO_GRID_MANAGER_MMESH_HH
14#define DUMUX_IO_GRID_MANAGER_MMESH_HH
15
16#if HAVE_DUNE_MMESH
17#include <dune/mmesh/mmesh.hh>
18#endif
19
20#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
22#endif
23
24namespace Dumux {
25
26#if HAVE_DUNE_MMESH
27
47template<int dim>
48class GridManager<Dune::MovingMesh<dim>>
49: public GridManagerBase<Dune::MovingMesh<dim>>
50{
51public:
52 using Grid = Dune::MovingMesh<dim>;
54
58 void init(const std::string& modelParamGroup = "")
59 {
60 // First, try to create it from file
61 if (hasParamInGroup(modelParamGroup, "Grid.File"))
62 {
63 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
64 ParentType::maybeRefineGrid(modelParamGroup);
66 return;
67 }
68
69 // Then look for the necessary keys to construct a structured grid from the input file
70 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
71 {
72 using GlobalPosition = Dune::FieldVector<typename Grid::ctype, dim>;
73 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
74 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
75
76 using CellArray = std::array<unsigned int, dim>;
77 CellArray numCells; numCells.fill(1);
78 numCells = getParamFromGroup<CellArray>(modelParamGroup, "Grid.Cells", numCells);
79
80 // Insert uniformly spaced vertices
81 std::array<unsigned int, dim> numVertices = numCells;
82 for (int i = 0; i < dim; ++i)
83 numVertices[i]++;
84
85 Dune::MMeshImplicitGridFactory<Grid> factory;
86
87 // Insert equally spaced vertices
88 Dune::FactoryUtilities::MultiIndex<dim> index(numVertices);
89 for (int i = 0; i < index.cycle(); ++i, ++index)
90 {
91 GlobalPosition pos(0);
92 for (int j=0; j<dim; j++)
93 pos[j] = lowerLeft[j] + index[j] * (upperRight[j]-lowerLeft[j])/(numVertices[j]-1);
94
95 factory.insertVertex(pos);
96 }
97
98 this->gridPtr() = std::unique_ptr<Grid>(factory.createGrid());
99 ParentType::maybeRefineGrid(modelParamGroup);
101 }
102
103 // Didn't find a way to construct the grid
104 else
105 {
106 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
107 DUNE_THROW(ParameterException, "Please supply one of the parameters "
108 << prefix + "Grid.UpperRight"
109 << ", or a grid file in " << prefix + "Grid.File");
110
111 }
112 }
113};
114
115#endif // HAVE_DUNE_MMESH
116
117} // end namespace Dumux
118
119#endif
void init(const std::string &modelParamGroup="")
Make the grid. This is implemented by specializations of this method.
Definition gridmanager_mmesh.hh:58
GridManagerBase< Grid > ParentType
Definition gridmanager_mmesh.hh:53
Dune::MovingMesh< dim > Grid
Definition gridmanager_mmesh.hh:52
The grid manager base interface (public) and methods common to most grid manager specializations (pro...
Definition gridmanager_base.hh:56
void maybeRefineGrid(const std::string &modelParamGroup)
Definition gridmanager_base.hh:315
void makeGridFromFile(const std::string &fileName, const std::string &modelParamGroup)
Definition gridmanager_base.hh:205
void loadBalance()
Definition gridmanager_base.hh:98
std::shared_ptr< Grid > & gridPtr()
Definition gridmanager_base.hh:163
The grid manager (this is the class used by the user) for all supported grid managers that constructs...
Definition gridmanager_base.hh:344
Exception thrown if a run-time parameter is not specified correctly.
Definition exceptions.hh:48
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 &paramGroup, const std::string &param)
Check whether a key exists in the parameter tree with a model group prefix.
Definition parameters.hh:165
Definition adapt.hh:17
Definition common/pdesolver.hh:24