13#ifndef DUMUX_IO_GRID_MANAGER_ALU_HH
14#define DUMUX_IO_GRID_MANAGER_ALU_HH
18#include <dune/alugrid/grid.hh>
19#include <dune/alugrid/dgf.hh>
22#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
52template<
int dim,
int dimworld, Dune::ALUGr
idElementType elType, Dune::ALUGr
idRefinementType refinementType>
54:
public GridManagerBase<Dune::ALUGrid<dim, dimworld, elType, refinementType>>
57 using Grid = Dune::ALUGrid<dim, dimworld, elType, refinementType>;
63 void init(
const std::string& modelParamGroup =
"",
bool adaptiveRestart =
false)
67 if (adaptiveRestart ||
hasParam(
"Restart") ||
hasParam(
"TimeManager.Restart"))
74 std::cerr <<
"Warning: You are using a deprecated restart mechanism. The usage will change in the future.\n";
77 const int rank = Dune::MPIHelper::getCommunication().rank();
79 std::ostringstream oss;
80 oss << name <<
"_time=" << restartTime <<
"_rank=" << rank <<
".grs";
81 std::cout <<
"Restoring an ALUGrid from " << oss.str() << std::endl;
82 ParentType::gridPtr() = std::shared_ptr<Grid>(Dune::BackupRestoreFacility<Grid>::restore(oss.str()));
99 if (elType == Dune::cube)
101 else if (elType == Dune::simplex)
104 DUNE_THROW(Dune::IOError,
"ALUGrid only supports Dune::cube or Dune::simplex as cell type!");
113 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup +
".";
115 << prefix +
"Grid.UpperRight"
116 <<
", or a grid file in " << prefix +
"Grid.File");
125 const std::string& modelParamGroup)
129 if (extension !=
"dgf" && extension !=
"msh" && extension !=
"vtu" && extension !=
"vti")
130 DUNE_THROW(Dune::IOError,
"Grid type " << Dune::className<Grid>() <<
" doesn't support grid files with extension: *."<< extension);
133 if (extension ==
"dgf")
141 else if (extension ==
"msh")
151 std::vector<int> boundaryMarkersInsertionIndex, boundaryMarkers, faceMarkers, elementMarkers;
152 auto gridFactory = std::make_unique<Dune::GridFactory<Grid>>();
153 Dune::GmshReader<Grid>::read(*gridFactory, fileName, boundaryMarkersInsertionIndex, elementMarkers, verbose, boundarySegments);
162 for (
const auto& intersection : intersections(
ParentType::gridPtr()->leafGridView(), element))
164 if (intersection.boundary() && gridFactory->wasInserted(intersection))
166 auto marker = boundaryMarkersInsertionIndex[gridFactory->insertionIndex(intersection)];
167 boundaryMarkers[intersection.boundarySegmentIndex()] = marker;
168 faceMarkers[indexSet.index(element.template subEntity<1>(intersection.indexInInside()))] = marker;
174 std::move(elementMarkers), std::move(boundaryMarkers), std::move(faceMarkers));
178 auto gridFactory = std::make_unique<Dune::GridFactory<Grid>>();
179 Dune::GmshReader<Grid>::read(*gridFactory, fileName, verbose, boundarySegments);
186 else if (extension ==
"vtu" || extension ==
"vti")
190 auto gridFactory = std::make_unique<Dune::GridFactory<Grid>>();
201 template <
int dimension,
int dimensionworld, std::enable_if_t<dimension != dimensionworld,
int> = 0>
203 const std::string& modelParamGroup)
205 DUNE_THROW(Dune::IOError,
"ALUGrid currently only supports the creation of structured grids with dimension == dimensionworld. Consider reading in a grid file instead.");
211 template <
int dimension,
int dimensionworld, std::enable_if_t<dimension == dimensionworld,
int> = 0>
213 const std::string& modelParamGroup)
216 if (elType == Dune::cube)
218 else if (elType == Dune::simplex)
221 DUNE_THROW(Dune::IOError,
"ALUGrid only supports Dune::cube or Dune::simplex as cell type!");
230template<
int dim,
int dimworld, Dune::ALUGr
idElementType elType, Dune::ALUGr
idRefinementType refinementType>
236 template<
class Intersection>
240 flag_ = i.impl().boundaryId();
247 operator bool()
const {
return flag_ != invalidFlag_; }
250 static constexpr value_type invalidFlag_ = -1;
254namespace Grid::Capabilities {
258template<
int dim,
int dimworld, Dune::ALUGr
idElementType elType, Dune::ALUGr
idRefinementType refinementType>
Boundary flag to store e.g. in sub control volume faces.
int value_type
Definition gridmanager_alu.hh:243
BoundaryFlag(const Intersection &i)
Definition gridmanager_alu.hh:237
value_type get() const
Definition gridmanager_alu.hh:245
BoundaryFlag()
Definition gridmanager_alu.hh:234
std::size_t value_type
Definition boundaryflag.hh:28
void init(const std::string &modelParamGroup="", bool adaptiveRestart=false)
Make the grid. This is implemented by specializations of this method.
Definition gridmanager_alu.hh:63
GridManagerBase< Grid > ParentType
Definition gridmanager_alu.hh:58
void makeStructuredGrid(typename ParentType::CellType cellType, const std::string &modelParamGroup)
Makes a structured cube grid using the structured grid factory.
Definition gridmanager_alu.hh:202
Dune::ALUGrid< dim, dimworld, elType, refinementType > Grid
Definition gridmanager_alu.hh:57
void makeGridFromFile(const std::string &fileName, const std::string &modelParamGroup)
Makes a grid from a file. We currently support *.dgf (Dune Grid Format) and *.msh (Gmsh mesh format).
Definition gridmanager_alu.hh:124
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
bool enableVtkData_
Definition gridmanager_base.hh:335
void makeGridFromFile(const std::string &fileName, const std::string &modelParamGroup)
Definition gridmanager_base.hh:205
void makeStructuredGrid(CellType cellType, const std::string &modelParamGroup)
Definition gridmanager_base.hh:286
Dune::GridPtr< Grid > & dgfGridPtr()
Definition gridmanager_base.hh:174
std::shared_ptr< GridData > gridData_
Definition gridmanager_base.hh:340
bool enableGmshDomainMarkers_
Definition gridmanager_base.hh:330
void loadBalance()
Definition gridmanager_base.hh:98
CellType
Definition gridmanager_base.hh:280
@ Simplex
Definition gridmanager_base.hh:280
@ Cube
Definition gridmanager_base.hh:280
std::shared_ptr< Grid > & gridPtr()
Definition gridmanager_base.hh:163
bool enableDgfGridPointer_
Definition gridmanager_base.hh:325
std::string getFileExtension(const std::string &fileName) const
Definition gridmanager_base.hh:185
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
A vtk file reader using tinyxml2 as xml backend.
Definition vtkreader.hh:360
std::unordered_map< std::string, std::vector< double > > Data
the cell / point data type for point data read from a grid file
Definition vtkreader.hh:368
std::unique_ptr< Grid > readGrid(bool verbose=false) const
Read a grid from a vtk/vtu/vtp file, ignoring cell and point data.
Definition vtkreader.hh:441
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
bool hasParam(const std::string ¶m)
Check whether a key exists in the parameter tree.
Definition parameters.hh:157
Definition common/pdesolver.hh:24
static bool eval(const GV &)
Definition gridmanager_alu.hh:262
Definition gridcapabilities.hh:27