version 3.11-dev
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
periodicgridtraits.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_PERIODIC_GRID_TRAITS_HH
14#define DUMUX_IO_GRID_PERIODIC_GRID_TRAITS_HH
15
16#include <type_traits>
17#include <dune/common/exceptions.hh>
18#include <dune/common/std/type_traits.hh>
19#include <dune/grid/common/exceptions.hh>
20
21#if HAVE_DUNE_SPGRID
22#include <dune/grid/spgrid.hh>
23#endif
24
25#if HAVE_DUNE_SUBGRID
26#include <dune/subgrid/subgrid.hh>
27#endif
28
29namespace Dumux {
30
31template<typename Grid>
33{
34 struct SupportsPeriodicity : public std::false_type {};
35
36 PeriodicGridTraits(const Grid& grid) {};
37
38 bool isPeriodic (const typename Grid::LeafIntersection& intersection) const
39 {
40 return false;
41 }
42};
43
44#if HAVE_DUNE_SPGRID
45template<class ct, int dim, template< int > class Ref, class Comm>
46struct PeriodicGridTraits<Dune::SPGrid<ct, dim, Ref, Comm>>
47{
48private:
49 using Grid = Dune::SPGrid<ct, dim, Ref, Comm>;
50public:
51 struct SupportsPeriodicity : public std::true_type {};
52
53 PeriodicGridTraits(const Grid& grid) {};
54
55 bool isPeriodic (const typename Grid::LeafIntersection& intersection) const
56 {
57 return intersection.neighbor() && intersection.boundary();
58 }
59};
60#endif //HAVE_DUNE_SPGRID
61
62#if HAVE_DUNE_SUBGRID
63// SubGrid does not preserve intersection.boundary() at periodic boundaries of host grid
64template<int dim, typename HostGrid, bool MapIndexStorage>
65struct PeriodicGridTraits<Dune::SubGrid<dim, HostGrid, MapIndexStorage>>
66{
67private:
69
70 const Grid& subGrid_;
71 const PeriodicGridTraits<HostGrid> hostTraits_;
72
73public:
74 struct SupportsPeriodicity : public PeriodicGridTraits<HostGrid>::SupportsPeriodicity {};
75
76 PeriodicGridTraits(const Grid& subGrid)
77 : subGrid_(subGrid), hostTraits_(subGrid_.getHostGrid()) {};
78
79 bool isPeriodic (const typename Grid::LeafIntersection& intersection) const
80 {
81 const auto& hostElement = subGrid_.template getHostEntity<0>(intersection.inside());
82 for (const auto& hostIntersection : intersections(subGrid_.getHostGrid().leafGridView(), hostElement))
83 {
84 if (hostIntersection.indexInInside() == intersection.indexInInside())
85 {
86 const bool periodicInHostGrid = hostTraits_.isPeriodic(hostIntersection);
87 return periodicInHostGrid && subGrid_.template contains<0>(hostIntersection.outside());
88 }
89 }
90 return false;
91 }
92
93 void verifyConformingPeriodicBoundary() const
94 {
95 for (const auto& element : elements(subGrid_.leafGridView()))
96 {
97 for (const auto& intersection : intersections(subGrid_.leafGridView(), element))
98 {
99 const auto& hostElement = subGrid_.template getHostEntity<0>(intersection.inside());
100 for (const auto& hostIntersection : intersections(subGrid_.getHostGrid().leafGridView(), hostElement))
101 {
102 if (hostIntersection.indexInInside() == intersection.indexInInside())
103 {
104 const bool periodicInHostGrid = hostTraits_.isPeriodic(hostIntersection);
105 if (periodicInHostGrid && !subGrid_.template contains<0>(hostIntersection.outside()))
106 DUNE_THROW(Dune::GridError, "Periodic boundary in host grid but outside"
107 << " element not included in subgrid. If this is intentional,"
108 << " take additional care with boundary conditions and remove"
109 << " verification call.");
110 break;
111 }
112 }
113 }
114 }
115 }
116};
117#endif //HAVE_DUNE_SUBGRID
118
119template<class T>
121{
122 template<class G>
123 using SP = typename G::SupportsPeriodicity;
124public:
125 using type = typename Dune::Std::detected_or<std::false_type, SP, T>::type;
126};
127
128template<class T>
129static constexpr bool supportsPeriodicity()
130{ return typename SupportsPeriodicity<T>::type(); }
131
132} // end namespace Dumux
133
134#endif
Definition: periodicgridtraits.hh:121
typename Dune::Std::detected_or< std::false_type, SP, T >::type type
Definition: periodicgridtraits.hh:125
Definition: consistentlyorientedgrid.hh:23
Definition: adapt.hh:17
static constexpr bool supportsPeriodicity()
Definition: periodicgridtraits.hh:129
Definition: common/pdesolver.hh:24
Definition: periodicgridtraits.hh:34
Definition: periodicgridtraits.hh:33
bool isPeriodic(const typename Grid::LeafIntersection &intersection) const
Definition: periodicgridtraits.hh:38
PeriodicGridTraits(const Grid &grid)
Definition: periodicgridtraits.hh:36