Loading [MathJax]/extensions/tex2jax.js

DUNE MultiDomainGrid (2.8)

mdgridtraits.hh
1#ifndef DUNE_MULTIDOMAINGRID_MDGRIDTRAITS_HH
2#define DUNE_MULTIDOMAINGRID_MDGRIDTRAITS_HH
3
4#include <vector>
5#include <type_traits>
6
7#include <dune/grid/multidomaingrid/subdomainset.hh>
8#include <dune/grid/multidomaingrid/arraybasedset.hh>
9#include <dune/grid/multidomaingrid/singlevalueset.hh>
10
11namespace Dune {
12
13namespace mdgrid {
14
15template<int dim, int codim>
16struct AllCodims {
17 static const bool supported = true;
18};
19
20template<int dim, int codim>
21struct CellAndVertexCodims {
22 static const bool supported = (codim == 0 || codim == dim);
23};
24
25template<int dim, std::size_t subDomainsPerCell, std::size_t subDomainCount, template<int dim_, int codim> class supportedCodims = AllCodims>
26struct ArrayBasedTraits {
27
28 typedef int SubDomainIndex;
29 static const SubDomainIndex empty = -1;
30 static const int dimension = dim;
31
32 static const std::size_t maxSubDomainsPerCell = subDomainsPerCell;
33
34 static constexpr bool maxSubDomainIndexIsStatic()
35 {
36 return true;
37 }
38
39 static constexpr SubDomainIndex maxSubDomainIndex()
40 {
41 return subDomainCount;
42 }
43
44 struct EmptyCodimBase {
45 typedef int SizeContainer;
46 typedef int MultiIndexContainer;
47 typedef int SubDomainSet;
48 };
49
50 template<int codim>
51 struct CodimBase {
52 static const std::size_t maxSubDomainsPerEntity = (2<<(codim)) * maxSubDomainsPerCell;
53 typedef Dune::mdgrid::ArrayBasedSet<SubDomainIndex,maxSubDomainsPerEntity> SubDomainSet;
54 typedef std::array<int,maxSubDomainsPerEntity> MultiIndexContainer; // TODO: really int??
55 typedef std::array<int,subDomainCount> SizeContainer; // TODO: really int??
56 };
57
58 template<int codim>
59 struct Codim : public std::conditional_t<supportedCodims<dim,codim>::supported,CodimBase<codim>,EmptyCodimBase> {
60 static const bool supported = supportedCodims<dim,codim>::supported;
61 };
62
63 template<int codim, typename SizeContainer>
64 void setupSizeContainer(SizeContainer&) const
65 {}
66
67};
68
69
70template<int dim, std::size_t subDomainsPerCell, template<int dim_, int codim> class supportedCodims = AllCodims>
71struct DynamicSubDomainCountTraits {
72
73 typedef int SubDomainIndex;
74 static const SubDomainIndex empty = -1;
75 static const int dimension = dim;
76
77 static constexpr bool maxSubDomainIndexIsStatic()
78 {
79 return false;
80 }
81
82 static const std::size_t maxSubDomainsPerCell = subDomainsPerCell;
83
84 SubDomainIndex maxSubDomainIndex() const
85 {
86 return _subDomainCount;
87 }
88
89 struct EmptyCodimBase {
90 typedef int SizeContainer;
91 typedef int MultiIndexContainer;
92 typedef int SubDomainSet;
93
94 template<typename SC>
95 static void setupSizeContainer(const SC&, std::size_t)
96 {}
97
98 };
99
100 template<int codim>
101 struct CodimBase {
102 static const std::size_t maxSubDomainsPerEntity = (2<<(codim)) * maxSubDomainsPerCell;
103 typedef Dune::mdgrid::ArrayBasedSet<SubDomainIndex,maxSubDomainsPerEntity> SubDomainSet;
104 typedef std::array<int,maxSubDomainsPerEntity> MultiIndexContainer; // TODO: really int??
105 typedef std::vector<int> SizeContainer; // TODO: really int??
106
107 static void setupSizeContainer(SizeContainer& container, std::size_t subDomainCount)
108 {
109 container.resize(subDomainCount);
110 }
111
112 };
113
114 template<int codim>
115 struct Codim : public std::conditional_t<supportedCodims<dim,codim>::supported,CodimBase<codim>,EmptyCodimBase> {
116 static const bool supported = supportedCodims<dim,codim>::supported;
117 };
118
119 DynamicSubDomainCountTraits(std::size_t subDomainCount)
120 : _subDomainCount(subDomainCount)
121 {}
122
123 template<int codim, typename SizeContainer>
124 void setupSizeContainer(SizeContainer& container) const
125 {
126 Codim<codim>::setupSizeContainer(container,_subDomainCount);
127 }
128
129private:
130
131 const std::size_t _subDomainCount;
132
133};
134
135
136template<int dim, std::size_t maxSubDomains, template<int dim_, int codim> class supportedCodims = AllCodims >
137struct FewSubDomainsTraits {
138
139 typedef unsigned int SubDomainIndex;
140 static const SubDomainIndex empty = ~SubDomainIndex(0); // this is not used, but has to be present to make the compiler happy
141 static const int dimension = dim;
142
143 static const std::size_t maxSubDomainsPerCell = maxSubDomains;
144
145 static constexpr bool maxSubDomainIndexIsStatic()
146 {
147 return true;
148 }
149
150 static constexpr SubDomainIndex maxSubDomainIndex()
151 {
152 return maxSubDomains - 1;
153 }
154
155 struct EmptyCodimBase {
156 typedef int SizeContainer;
157 typedef int MultiIndexContainer;
158 typedef int SubDomainSet;
159 };
160
161 template<int codim>
162 struct CodimBase {
163 static const std::size_t maxSubDomainsPerEntity = maxSubDomains;
164 typedef Dune::mdgrid::IntegralTypeSubDomainSet<SubDomainIndex,maxSubDomainsPerEntity> SubDomainSet;
165 typedef std::array<int,maxSubDomainsPerEntity> MultiIndexContainer;
166 typedef std::array<int,maxSubDomains> SizeContainer;
167 };
168
169 template<int codim>
170 struct Codim : public std::conditional_t<supportedCodims<dim,codim>::supported,CodimBase<codim>,EmptyCodimBase> {
171 static const bool supported = supportedCodims<dim,codim>::supported;
172 };
173
174 template<int codim>
175 void setupSizeContainer(typename Codim<codim>::SizeContainer&) const
176 {}
177
178};
179
180} // namespace mdrid
181
182} // namespace Dune
183
184#endif // DUNE_MULTIDOMAINGRID_MDGRIDTRAITS_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 3, 22:46, 2025)