17#ifndef DUMUX_FACETCOUPLING_GRID_MANAGER_HH
18#define DUMUX_FACETCOUPLING_GRID_MANAGER_HH
26#include <dune/common/exceptions.hh>
27#include <dune/common/hybridutilities.hh>
28#include <dune/grid/common/gridfactory.hh>
38namespace FCGridManagerChecks {
46 template<
bool checkDimWorld,
typename G1,
typename G2>
49 return checkDimWorld ? int(G1::dimensionworld) == int(G2::dimensionworld)
50 : int(G1::dimension) > int(G2::dimension);
55 template<
bool checkDimWorld,
typename G1,
typename... Gs>
58 using G2 =
typename std::tuple_element_t<0, std::tuple<Gs...>>;
59 static constexpr bool value = evalCondition<checkDimWorld, G1, G2>() &&
FulfillConditions<checkDimWorld, Gs...>::value;
61 template<
bool checkDimWorld,
typename G1,
typename G2>
62 struct FulfillConditions<checkDimWorld, G1, G2> {
static constexpr bool value = evalCondition<checkDimWorld, G1, G2>(); };
73template<
typename... Grids>
81 static constexpr std::size_t numGrids =
sizeof...(Grids);
83 template<std::
size_t id>
using Grid =
typename std::tuple_element_t<id, std::tuple<Grids...>>;
85 template<std::
size_t id>
using GridDataPtr = std::shared_ptr< GridData<Grid<id>> >;
87 template<std::
size_t id>
using Intersection =
typename Grid<id>::LeafGridView::Intersection;
94 template<std::
size_t id>
97 std::get<id>(gridDataPtrTuple_) = std::make_shared<GridData<id>>( std::move(gridData) );
101 template<std::
size_t id>
103 {
return std::get<id>(gridDataPtrTuple_); }
106 template<std::
size_t id>
108 {
return std::get<id>(gridDataPtrTuple_)->getElementDomainMarker(element); }
111 template<std::
size_t id>
113 {
return std::get<id>(gridDataPtrTuple_)->getBoundaryDomainMarker(is); }
116 template<std::
size_t id>
118 {
return std::get<id>(gridDataPtrTuple_)->getBoundaryDomainMarker(boundarySegmentIndex); }
121 template<std::
size_t id>
123 {
return std::get<id>(gridDataPtrTuple_)->wasInserted(intersection); }
128 GridDataPtrTuple gridDataPtrTuple_;
143template<
typename... Grids>
151 template<std::
size_t id>
using Grid =
typename std::tuple_element_t<id, std::tuple<Grids...>>;
153 template<std::
size_t id>
using GridFactory =
typename Dune::GridFactory<Grid<id>>;
158 using EmbedmentMap = std::unordered_map<GIType, std::vector<GIType>>;
162 template<std::
size_t id>
using GridView =
typename Grid<id>::LeafGridView;
165 static constexpr std::size_t
numGrids =
sizeof...(Grids);
169 static constexpr int bulkDim = Grid<bulkGridId>::dimension;
177 template<std::
size_t id>
179 {
return *std::get<id>(gridViewPtrTuple_); }
182 template<std::
size_t id,
class Entity>
184 {
return std::get<id>(gridFactoryPtrTuple_)->insertionIndex(entity); }
187 template<std::
size_t id>
188 typename std::unordered_map< GridIndexType, std::vector<GridIndexType> >::mapped_type
191 const auto& map = embeddedEntityMaps_[id];
192 auto it = map.find( std::get<id>(gridFactoryPtrTuple_)->
insertionIndex(element) );
193 if (it != map.end())
return it->second;
194 else return typename std::unordered_map< GridIndexType, std::vector<GridIndexType> >::mapped_type();
198 template<std::
size_t id>
199 typename std::unordered_map< GridIndexType, std::vector<GridIndexType> >::mapped_type
202 const auto& map = adjoinedEntityMaps_[id];
203 auto it = map.find( std::get<id>(gridFactoryPtrTuple_)->
insertionIndex(element) );
204 if (it != map.end())
return it->second;
205 else return typename std::unordered_map< GridIndexType, std::vector<GridIndexType> >::mapped_type();
209 const std::unordered_map< GridIndexType, std::vector<GridIndexType> >&
embeddedEntityMap(std::size_t
id)
const
210 { assert(
id <
numGrids);
return embeddedEntityMaps_[id]; }
213 std::unordered_map< GridIndexType, std::vector<GridIndexType> >&
embeddedEntityMap(std::size_t
id)
214 { assert(
id <
numGrids);
return embeddedEntityMaps_[id]; }
217 const std::unordered_map< GridIndexType, std::vector<GridIndexType> >&
adjoinedEntityMap(std::size_t
id)
const
218 { assert(
id <
numGrids);
return adjoinedEntityMaps_[id]; }
221 std::unordered_map< GridIndexType, std::vector<GridIndexType> >&
adjoinedEntityMap(std::size_t
id)
222 { assert(
id <
numGrids);
return adjoinedEntityMaps_[id]; }
226 { assert(
id <
numGrids);
return gridVertexIndices_[id]; }
230 {
return numVerticesInHierarchy_; }
241 template<std::
size_t id>
242 void setData( std::shared_ptr<Grid<id>> gridPtr,
243 std::shared_ptr<GridFactory<id>> gridFactoryPtr,
246 std::vector<GridIndexType>&& gridVertexIndices,
249 std::get<id>(gridViewPtrTuple_) = std::make_shared<GridView<id>>(gridPtr->leafGridView());
250 std::get<id>(gridFactoryPtrTuple_) = gridFactoryPtr;
253 gridVertexIndices_[id] = std::move(gridVertexIndices);
259 std::array<EmbedmentMap, numGrids> embeddedEntityMaps_;
260 std::array<EmbedmentMap, numGrids> adjoinedEntityMaps_;
263 std::size_t numVerticesInHierarchy_;
264 std::array<std::vector<GridIndexType>,
numGrids> gridVertexIndices_;
267 using Indices = std::make_index_sequence<numGrids>;
268 template<std::
size_t id>
using GridViewPtr = std::shared_ptr<GridView<id>>;
270 GridPtrTuple gridViewPtrTuple_;
273 template<std::
size_t id>
using GridFactoryPtr = std::shared_ptr< Dune::GridFactory<Grid<id>> >;
275 GridFactoryPtrTuple gridFactoryPtrTuple_;
287template<
typename... Grids>
298 template<std::
size_t id>
using Grid =
typename std::tuple_element_t<id, std::tuple<Grids...>>;
300 template<std::
size_t id>
using GridPtr =
typename std::shared_ptr< Grid<id> >;
303 static constexpr std::size_t
numGrids =
sizeof...(Grids);
313 template<std::
size_t id>
315 {
return *std::get<id>(gridPtrTuple_); }
320 if (!enableEntityMarkers_)
321 DUNE_THROW(Dune::IOError,
"No grid data available");
327 {
return embeddingsPtr_; }
330 void init(
const std::string& paramGroup =
"")
333 gridDataPtr_ = std::make_shared<GridData>();
334 embeddingsPtr_ = std::make_shared<Embeddings>();
337 const auto fileName = getParamFromGroup<std::string>(paramGroup,
"Grid.File");
338 const auto ext = getFileExtension(fileName);
341 const bool verbose = getParamFromGroup<bool>(paramGroup,
"Grid.Verbosity",
false);
342 const bool domainMarkers = getParamFromGroup<bool>(paramGroup,
"Grid.DomainMarkers",
false);
343 const bool boundarySegments = getParamFromGroup<bool>(paramGroup,
"Grid.BoundarySegments",
false);
348 const auto thresh = getParamFromGroup<std::size_t>(paramGroup,
"Grid.GmshPhysicalEntityThreshold", 0);
350 gmshReader.
read(fileName, (boundarySegments ? thresh : 0), verbose);
351 passDataFromReader(gmshReader, domainMarkers, boundarySegments);
354 DUNE_THROW(Dune::NotImplemented,
"Reader for grid files of type ." + ext);
357 enableEntityMarkers_ = domainMarkers || boundarySegments;
363 using namespace Dune::Hybrid;
364 forEach(integralRange(Dune::Hybrid::size(gridPtrTuple_)), [&](
const auto id)
366 std::get<id>(this->gridPtrTuple_)->loadBalance();
372 template<std::
size_t id>
374 {
return *std::get<id>(gridPtrTuple_); }
378 {
return embeddingsPtr_; }
382 static std::string getFileExtension(
const std::string& fileName)
384 const auto pos = fileName.rfind(
'.', fileName.length());
385 if (pos != std::string::npos)
386 return(fileName.substr(pos+1, fileName.length() - pos));
388 DUNE_THROW(Dune::IOError,
"Please provide an extension for your grid file ('"<< fileName <<
"')!");
392 template<
typename MeshFileReader>
393 void passDataFromReader(MeshFileReader& reader,
bool domainMarkers,
bool boundarySegments)
395 const auto& vertices = reader.gridVertices();
397 using namespace Dune::Hybrid;
398 forEach(integralRange(Dune::Hybrid::size(gridPtrTuple_)), [&](
const auto id)
400 using GridFactory = Dune::GridFactory<Grid<id>>;
401 auto factoryPtr = std::make_shared<GridFactory>();
404 for (
const auto idx : reader.vertexIndices(
id))
405 factoryPtr->insertVertex(vertices[idx]);
408 for (
const auto& e : reader.elementData(
id))
409 factoryPtr->insertElement(e.gt, e.cornerIndices);
412 if (boundarySegments)
413 for (
const auto& segment : reader.boundarySegmentData(
id))
414 factoryPtr->insertBoundarySegment(segment);
417 auto gridPtr = std::shared_ptr<Grid<id>>(factoryPtr->createGrid());
420 if (domainMarkers || boundarySegments)
422 typename GridDataWrapper::template GridData<id> gridData( gridPtr,
424 std::move(reader.elementMarkerMap(
id)),
425 std::move(reader.boundaryMarkerMap(
id)) );
426 gridDataPtr_->template setGridData<id>( std::move(gridData) );
430 embeddingsPtr_->template setData<id>( gridPtr,
432 std::move(reader.embeddedEntityMap(
id)),
433 std::move(reader.adjoinedEntityMap(
id)),
434 std::move(reader.vertexIndices(
id)),
438 std::get<id>(gridPtrTuple_) = gridPtr;
443 using Indices = std::make_index_sequence<numGrids>;
444 using GridPtrTuple =
typename makeFromIndexedType<std::tuple, GridPtr, Indices>::type;
445 GridPtrTuple gridPtrTuple_;
448 bool enableEntityMarkers_;
449 std::shared_ptr<GridData> gridDataPtr_;
452 std::shared_ptr<Embeddings> embeddingsPtr_;
Contains the embeddings between grids with codimension one among the grid hierarchy....
Definition: multidomain/facet/gridmanager.hh:145
std::unordered_map< GridIndexType, std::vector< GridIndexType > > & embeddedEntityMap(std::size_t id)
Returns non-const reference to maps of the embedded entities.
Definition: multidomain/facet/gridmanager.hh:213
std::size_t numVerticesInHierarchy() const
Returns the number of vertices contained in the entire grid hierarch.
Definition: multidomain/facet/gridmanager.hh:229
const std::vector< GridIndexType > & gridHierarchyIndices(std::size_t id) const
Returns the hierachy's insertion indices that make up the grid for the given id.
Definition: multidomain/facet/gridmanager.hh:225
static constexpr int bulkDim
state the dimension of the highest-dimensional grid
Definition: multidomain/facet/gridmanager.hh:169
GridView< bulkGridId > BulkGridView
export the bulk grid type
Definition: multidomain/facet/gridmanager.hh:172
const std::unordered_map< GridIndexType, std::vector< GridIndexType > > & adjoinedEntityMap(std::size_t id) const
Returns const reference to the maps of the adjoined entities of dimension d+1.
Definition: multidomain/facet/gridmanager.hh:217
std::unordered_map< GridIndexType, std::vector< GridIndexType > >::mapped_type adjoinedEntityIndices(const typename Grid< id >::template Codim< 0 >::Entity &element) const
Returns the insertion indices of the entities in which the element is embedded.
Definition: multidomain/facet/gridmanager.hh:200
static constexpr int bulkGridId
export the grid id of the bulk grid (descending grid dim -> always zero!)
Definition: multidomain/facet/gridmanager.hh:167
GridIndexType insertionIndex(const Entity &entity) const
return the insertion index of an entity of the i-th grid
Definition: multidomain/facet/gridmanager.hh:183
std::unordered_map< GridIndexType, std::vector< GridIndexType > >::mapped_type embeddedEntityIndices(const typename Grid< id >::template Codim< 0 >::Entity &element) const
Returns the insertion indices of the entities embedded in given element.
Definition: multidomain/facet/gridmanager.hh:189
typename Grid< id >::LeafGridView GridView
export the i-th grid view type
Definition: multidomain/facet/gridmanager.hh:162
void setData(std::shared_ptr< Grid< id > > gridPtr, std::shared_ptr< GridFactory< id > > gridFactoryPtr, EmbedmentMap &&embeddedEntityMap, EmbedmentMap &&adjoinedEntityMap, std::vector< GridIndexType > &&gridVertexIndices, std::size_t numVerticesInHierarchy)
Sets the required data for a specific grid on the hierarchy.
Definition: multidomain/facet/gridmanager.hh:242
GIType GridIndexType
export the type used for indices
Definition: multidomain/facet/gridmanager.hh:174
const std::unordered_map< GridIndexType, std::vector< GridIndexType > > & embeddedEntityMap(std::size_t id) const
Returns const reference to maps of the embedded entities.
Definition: multidomain/facet/gridmanager.hh:209
static constexpr std::size_t numGrids
export the number of created grids
Definition: multidomain/facet/gridmanager.hh:165
const GridView< id > & gridView() const
return reference to the i-th grid view
Definition: multidomain/facet/gridmanager.hh:178
std::unordered_map< GridIndexType, std::vector< GridIndexType > > & adjoinedEntityMap(std::size_t id)
Returns non-const reference to the maps of the adjoined entities of dimension d+1.
Definition: multidomain/facet/gridmanager.hh:221
Reads gmsh files where (n-1)-dimensional grids are defined on the faces or edges of n-dimensional gri...
Definition: gmshreader.hh:50
void read(const std::string &fileName, bool verbose=false)
Definition: gmshreader.hh:73
Grid data object to store element and boundary segment markers for all grids of the hierarchy.
Definition: multidomain/facet/gridmanager.hh:75
int getBoundaryDomainMarker(int boundarySegmentIndex) const
Returns the boundary marker for a given boundary segment index.
Definition: multidomain/facet/gridmanager.hh:117
std::shared_ptr< const GridData< id > > getSubDomainGridData() const
return the grid data for a specific grid
Definition: multidomain/facet/gridmanager.hh:102
GridData< Grid< id > > GridData
export the i-th grid data type
Definition: multidomain/facet/gridmanager.hh:91
bool wasInserted(const Intersection< id > &intersection) const
Returns true if an intersection was inserted during grid creation.
Definition: multidomain/facet/gridmanager.hh:122
int getElementDomainMarker(const typename Grid< id >::template Codim< 0 >::Entity &element) const
Returns domain marker of an element.
Definition: multidomain/facet/gridmanager.hh:107
void setGridData(GridData< id > &&gridData)
set the grid data object for the i-th grid
Definition: multidomain/facet/gridmanager.hh:95
int getBoundaryDomainMarker(const typename Grid< id >::LeafGridView::Intersection &is) const
Returns the boundary marker of an intersection.
Definition: multidomain/facet/gridmanager.hh:112
Creates the grids in the context of hybrid-dimensional coupled models, where the (n-1)-dimensional do...
Definition: multidomain/facet/gridmanager.hh:289
typename std::tuple_element_t< id, std::tuple< Grids... > > Grid
export the i-th grid type
Definition: multidomain/facet/gridmanager.hh:298
typename std::shared_ptr< Grid< id > > GridPtr
export the i-th grid pointer type
Definition: multidomain/facet/gridmanager.hh:300
static constexpr std::size_t numGrids
export the number of created grids
Definition: multidomain/facet/gridmanager.hh:303
std::shared_ptr< const Embeddings > getEmbeddings() const
return a pointer to the object containing embeddings
Definition: multidomain/facet/gridmanager.hh:326
Grid< id > & grid_()
return non-const reference to i-th grid
Definition: multidomain/facet/gridmanager.hh:373
void loadBalance()
Distributes the grid on all processes of a parallel computation.
Definition: multidomain/facet/gridmanager.hh:361
std::shared_ptr< Embeddings > getEmbeddings_()
return non-const pointer to the object containing embeddings
Definition: multidomain/facet/gridmanager.hh:377
static constexpr int bulkGridId
export the grid id of the bulk grid (descending grid dim -> always zero!)
Definition: multidomain/facet/gridmanager.hh:305
const Grid< id > & grid() const
returns the i-th grid
Definition: multidomain/facet/gridmanager.hh:314
std::shared_ptr< const GridData > getGridData() const
return a pointer to the grid data object
Definition: multidomain/facet/gridmanager.hh:318
void init(const std::string ¶mGroup="")
creates the grids from a file given in parameter tree
Definition: multidomain/facet/gridmanager.hh:330
Class for grid data attached to dgf or gmsh grid files.
static constexpr bool evalCondition()
Definition: multidomain/facet/gridmanager.hh:47
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
typename std::tuple_element_t< 0, std::tuple< Gs... > > G2
Definition: multidomain/facet/gridmanager.hh:58
Definition: multidomain/facet/gridmanager.hh:54
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26
Definition: utility.hh:28
Utilities for template meta programming.