DUNE MultiDomainGrid (2.10)

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 inline static const SubDomainIndex empty = -1;
75 inline static const int dimension = dim;
76
77 inline static const std::size_t maxSubDomainsPerCell = subDomainsPerCell;
78
79 static constexpr bool maxSubDomainIndexIsStatic()
80 {
81 return false;
82 }
83
84
85 SubDomainIndex maxSubDomainIndex() const
86 {
87 return _subDomainCount;
88 }
89
90 struct EmptyCodimBase {
91 typedef int SizeContainer;
92 typedef int MultiIndexContainer;
93 typedef int SubDomainSet;
94
95 template<typename SC>
96 static void setupSizeContainer(const SC&, std::size_t)
97 {}
98
99 };
100
101 template<int codim>
102 struct CodimBase {
103 static const std::size_t maxSubDomainsPerEntity = (2<<(codim)) * maxSubDomainsPerCell;
104 typedef Dune::mdgrid::ArrayBasedSet<SubDomainIndex,maxSubDomainsPerEntity> SubDomainSet;
105 typedef std::array<int,maxSubDomainsPerEntity> MultiIndexContainer; // TODO: really int??
106 typedef std::vector<int> SizeContainer; // TODO: really int??
107
108 static void setupSizeContainer(SizeContainer& container, std::size_t subDomainCount)
109 {
110 container.resize(subDomainCount);
111 }
112
113 };
114
115 template<int codim>
116 struct Codim : public std::conditional_t<supportedCodims<dim,codim>::supported,CodimBase<codim>,EmptyCodimBase> {
117 static const bool supported = supportedCodims<dim,codim>::supported;
118 };
119
120 DynamicSubDomainCountTraits(std::size_t subDomainCount)
121 : _subDomainCount(subDomainCount)
122 {}
123
124 template<int codim, typename SizeContainer>
125 void setupSizeContainer(SizeContainer& container) const
126 {
127 Codim<codim>::setupSizeContainer(container,_subDomainCount);
128 }
129
130private:
131
132 const std::size_t _subDomainCount;
133
134};
135
136
137template<int dim, std::size_t maxSubDomains, template<int dim_, int codim> class supportedCodims = AllCodims >
138struct FewSubDomainsTraits {
139
140 typedef unsigned int SubDomainIndex;
141 inline static const SubDomainIndex empty = ~SubDomainIndex(0); // this is not used, but has to be present to make the compiler happy
142 inline static const int dimension = dim;
143
144 inline static const std::size_t maxSubDomainsPerCell = maxSubDomains;
145
146 static constexpr bool maxSubDomainIndexIsStatic()
147 {
148 return true;
149 }
150
151 static constexpr SubDomainIndex maxSubDomainIndex()
152 {
153 return maxSubDomains - 1;
154 }
155
156 struct EmptyCodimBase {
157 typedef int SizeContainer;
158 typedef int MultiIndexContainer;
159 typedef int SubDomainSet;
160 };
161
162 template<int codim>
163 struct CodimBase {
164 inline static const std::size_t maxSubDomainsPerEntity = maxSubDomains;
165 typedef Dune::mdgrid::IntegralTypeSubDomainSet<SubDomainIndex,maxSubDomainsPerEntity> SubDomainSet;
166 typedef std::array<int,maxSubDomainsPerEntity> MultiIndexContainer;
167 typedef std::array<int,maxSubDomains> SizeContainer;
168 };
169
170 template<int codim>
171 struct Codim : public std::conditional_t<supportedCodims<dim,codim>::supported,CodimBase<codim>,EmptyCodimBase> {
172 inline static const bool supported = supportedCodims<dim,codim>::supported;
173 };
174
175 template<int codim>
176 void setupSizeContainer(typename Codim<codim>::SizeContainer&) const
177 {}
178
179};
180
181} // namespace mdrid
182
183} // namespace Dune
184
185#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)