1 #ifndef DUNE_FEM_MISC_BOUNDARYIDPROVIDER_HH
2 #define DUNE_FEM_MISC_BOUNDARYIDPROVIDER_HH
3 
4 #if HAVE_DUNE_SPGRID
5 #include <dune/grid/spgrid/declaration.hh>
6 #endif // #if HAVE_DUNE_SPGRID
7 
8 #if HAVE_OPM_GRID
9 #include <opm/grid/polyhedralgrid/declaration.hh>
10 #endif // #if HAVE_OPM_GRID
11 
12 #if HAVE_DUNE_POLYGONGRID
13 #include <dune/polygongrid/declaration.hh>
14 #endif // #if HAVE_DUNE_POLYGONGRID
15 
16 #include <dune/fem/misc/griddeclaration.hh>
17 
18 namespace Dune
19 {
20 
21   // External Forward Declarations
22   // -----------------------------
23 
24   template< class Grid >
25   struct HostGridAccess;
26 
27 
28 
29   namespace Fem
30   {
31 
32     // Internal Forward Declarations
33     // -----------------------------
34 
35     template< class Grid >
36     struct BoundaryIdProvider;
37 
38 
39 
40     // BoundaryIdProvider for AlbertaGrid
41     // ----------------------------------
42 
43 #if HAVE_ALBERTA
44     template< int dim, int dimW >
45     struct BoundaryIdProvider< AlbertaGrid< dim, dimW > >
46     {
47       typedef AlbertaGrid< dim, dimW > GridType;
48 
49       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider50       static int boundaryId ( const Intersection &intersection )
51       {
52         return intersection.impl().boundaryId();
53       }
54     };
55 #endif // #if HAVE_ALBERTA
56 
57 
58 
59     // BoundaryIdProvider for ALUGrid
60     // ------------------------------
61 
62 #if HAVE_DUNE_ALUGRID
63     template< int dim, int dimw, ALUGridElementType elType, ALUGridRefinementType refineType, class Comm >
64     struct BoundaryIdProvider< ALUGrid< dim, dimw, elType, refineType, Comm > >
65     {
66       typedef ALUGrid< dim, dimw, elType, refineType, Comm > GridType;
67 
68       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider69       static int boundaryId ( const Intersection &intersection )
70       {
71         return intersection.impl().boundaryId();
72       }
73     };
74 #endif // #if HAVE_DUNE_ALUGRID
75 
76 
77 
78     // BoundaryIdProvider for CacheItGrid
79     // ----------------------------------
80 
81 #if HAVE_DUNE_METAGRID
82     template< class HostGrid >
83     struct BoundaryIdProvider< CacheItGrid< HostGrid > >
84     {
85       typedef CacheItGrid< HostGrid > GridType;
86 
87       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider88       static int boundaryId ( const Intersection &intersection )
89       {
90         return BoundaryIdProvider< HostGrid >
91           ::boundaryId ( HostGridAccess< GridType >::hostIntersection( intersection ) );
92       }
93     };
94 #endif // #if HAVE_DUNE_METAGRID
95 
96 
97 
98     // BoundaryIdProvider for CartesianGrid
99     // ------------------------------------
100 
101 #if HAVE_DUNE_METAGRID
102     template< class HostGrid >
103     struct BoundaryIdProvider< CartesianGrid< HostGrid > >
104     {
105       typedef CartesianGrid< HostGrid > GridType;
106 
107       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider108       static int boundaryId ( const Intersection &intersection )
109       {
110         return BoundaryIdProvider< HostGrid >
111           ::boundaryId ( HostGridAccess< GridType >::hostIntersection( intersection ) );
112       }
113     };
114 #endif // #if HAVE_DUNE_METAGRID
115 
116 
117 
118     // BoundaryIdProvider for FilteredGrid
119     // -----------------------------------
120 
121 #if HAVE_DUNE_METAGRID
122     template< class HostGrid >
123     struct BoundaryIdProvider< FilteredGrid< HostGrid > >
124     {
125       typedef FilteredGrid< HostGrid > GridType;
126 
127       // todo: FilteredGrid is a filtering grid and, hence, needs a specialized
128       //       version of boundaryId.
129       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider130       static int boundaryId ( const Intersection &intersection )
131       {
132         if( !HostGridAccess< GridType >::hostIntersection( intersection ).boundary() )
133           DUNE_THROW( NotImplemented, "BoundaryIdProvider for artificial boundaries of FilteredGrid not implemented." );
134         return BoundaryIdProvider< HostGrid >
135           ::boundaryId ( HostGridAccess< GridType >::hostIntersection( intersection ) );
136       }
137     };
138 #endif // #if HAVE_DUNE_METAGRID
139 
140 
141 
142     // BoundaryIdProvider for GeometryGrid
143     // -----------------------------------
144 
145     template< class HostGrid, class CoordFunction, class Allocator >
146     struct BoundaryIdProvider< GeometryGrid< HostGrid, CoordFunction, Allocator > >
147     {
148       typedef GeometryGrid< HostGrid, CoordFunction, Allocator > GridType;
149 
150       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider151       static int boundaryId ( const Intersection &intersection )
152       {
153         return BoundaryIdProvider< HostGrid >
154           ::boundaryId ( HostGridAccess< GridType >::hostIntersection( intersection ) );
155       }
156     };
157 
158 
159 
160     // BoundaryIdProvider for IdGrid
161     // -----------------------------
162 
163 #if HAVE_DUNE_METAGRID
164     template< class HostGrid >
165     struct BoundaryIdProvider< IdGrid< HostGrid > >
166     {
167       typedef IdGrid< HostGrid > GridType;
168 
169       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider170       static int boundaryId ( const Intersection &intersection )
171       {
172         return BoundaryIdProvider< HostGrid >
173           ::boundaryId ( HostGridAccess< GridType >::hostIntersection( intersection ) );
174       }
175     };
176 #endif // #if HAVE_DUNE_METAGRID
177 
178 
179 
180     // BoundaryIdProvider for OneDGrid
181     // -------------------------------
182 
183     template<>
184     struct BoundaryIdProvider< OneDGrid >
185     {
186       typedef OneDGrid GridType;
187 
188       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider189       static int boundaryId ( const Intersection &intersection )
190       {
191         return intersection.boundarySegmentIndex();
192       }
193     };
194 
195 
196 
197     // BoundaryIdProvider for ParallelGrid
198     // -----------------------------------
199 
200 #if HAVE_DUNE_METAGRID
201     template< class HostGrid >
202     struct BoundaryIdProvider< ParallelGrid< HostGrid > >
203     {
204       typedef ParallelGrid< HostGrid > GridType;
205 
206       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider207       static int boundaryId ( const Intersection &intersection )
208       {
209         return BoundaryIdProvider< HostGrid >
210           ::boundaryId ( HostGridAccess< GridType >::hostIntersection( intersection ) );
211       }
212     };
213 #endif // #if HAVE_DUNE_METAGRID
214 
215 
216 
217     // BoundaryIdProvider for SphereGrid
218     // ---------------------------------
219 
220 #if HAVE_DUNE_METAGRID
221     template< class HostGrid, class MapToSphere >
222     struct BoundaryIdProvider< SphereGrid< HostGrid, MapToSphere > >
223     {
224       typedef SphereGrid< HostGrid, MapToSphere > GridType;
225 
226       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider227       static int boundaryId ( const Intersection &intersection )
228       {
229         return BoundaryIdProvider< HostGrid >
230           ::boundaryId ( HostGridAccess< GridType >::hostIntersection( intersection ) );
231       }
232     };
233 #endif // #if HAVE_DUNE_METAGRID
234 
235 
236 
237     // BoundaryIdProvider for SPGrid
238     // -----------------------------
239 
240 #if HAVE_DUNE_SPGRID
241     template< class ct, int dim, template< int > class Strategy, class Comm >
242     struct BoundaryIdProvider< SPGrid< ct, dim, Strategy, Comm > >
243     {
244       typedef SPGrid< ct, dim, Strategy, Comm > GridType;
245 
246       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider247       static int boundaryId ( const Intersection &intersection )
248       {
249         return (intersection.boundary() ? (intersection.indexInInside()+1) : 0);
250       }
251     };
252 #endif // #if HAVE_DUNE_SPGRID
253 
254 
255     // BoundaryIdProvider for PolygonGrid
256     // ----------------------------------
257 
258 #if HAVE_DUNE_POLYGONGRID
259     template< class ct >
260     struct BoundaryIdProvider< PolygonGrid< ct > >
261     {
262       typedef PolygonGrid< ct > GridType;
263 
264       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider265       static int boundaryId ( const Intersection &intersection )
266       {
267         return (intersection.boundary() ? (intersection.impl().boundaryId()) : 0);
268       }
269     };
270 #endif // #if HAVE_OPM_GRID
271 
272     // BoundaryIdProvider for PolyhedralGrid
273     // -------------------------------------
274 
275 #if HAVE_OPM_GRID
276     template< int dim, int dimworld, class ct >
277     struct BoundaryIdProvider< PolyhedralGrid< dim, dimworld, ct > >
278     {
279       typedef PolyhedralGrid< dim, dimworld, ct > GridType;
280 
281       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider282       static int boundaryId ( const Intersection &intersection )
283       {
284         return (intersection.boundary() ? (intersection.impl().boundaryId()) : 0);
285       }
286     };
287 #endif // #if HAVE_OPM_GRID
288 
289 
290     // BoundaryIdProvider for UGGrid
291     // -----------------------------
292 
293     template< int dim >
294     struct BoundaryIdProvider< UGGrid< dim > >
295     {
296       typedef UGGrid< dim > GridType;
297 
298       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider299       static int boundaryId ( const Intersection &intersection )
300       {
301         return intersection.boundarySegmentIndex();
302       }
303     };
304 
305 
306 
307     // BoundaryIdProvider for YaspGrid
308     // -------------------------------
309 
310     template< int dim, class CoordCont >
311     struct BoundaryIdProvider< YaspGrid< dim, CoordCont > >
312     {
313       typedef YaspGrid< dim, CoordCont > GridType;
314 
315       template< class Intersection >
boundaryIdDune::Fem::BoundaryIdProvider316       static int boundaryId ( const Intersection &intersection )
317       {
318         return (intersection.boundary() ? (intersection.indexInInside()+1) : 0);
319       }
320     };
321 
322   } // namespace Fem
323 
324 } // namespace Dune
325 
326 #endif // #ifndef DUNE_FEM_MISC_BOUNDARYIDPROVIDER_HH
327