dune-grid 2.11
Loading...
Searching...
No Matches
agrid.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_ALBERTAGRID_IMP_HH
6#define DUNE_ALBERTAGRID_IMP_HH
7
12
13#if HAVE_ALBERTA || DOXYGEN
14
15#include <cassert>
16#include <cstddef>
17
18#include <algorithm>
19#include <iostream>
20#include <fstream>
21#include <memory>
22#include <vector>
23
24// Dune includes
25#include <dune/common/fvector.hh>
26#include <dune/common/fmatrix.hh>
27#include <dune/common/stdstreams.hh>
28#include <dune/common/parallel/communication.hh>
29
34
35//- Local includes
36// some cpp defines and include of alberta.h
37#include "albertaheader.hh"
38
42
50
51#include "indexsets.hh"
52#include "geometry.hh"
53#include "entity.hh"
54#include "hierarchiciterator.hh"
55#include "treeiterator.hh"
56#include "leveliterator.hh"
57#include "leafiterator.hh"
58
59namespace Dune
60{
61
62 // External Forward Declarations
63 // -----------------------------
64
65 template< class Grid >
66 struct DGFGridFactory;
67
68
69
70 // AlbertaGrid
71 // -----------
72
105 template< int dim, int dimworld = Alberta::dimWorld >
108 < dim, dimworld, Alberta::Real, AlbertaGridFamily< dim, dimworld > >
109 {
110 typedef AlbertaGrid< dim, dimworld > This;
113 Base;
114
115 template< int, int, class > friend class AlbertaGridEntity;
116 template< class > friend class AlbertaLevelGridView;
117 template< class > friend class AlbertaLeafGridView;
118 template< int, class, bool > friend class AlbertaGridTreeIterator;
119 template< class > friend class AlbertaGridHierarchicIterator;
120
121 friend class GridFactory< This >;
122 friend struct DGFGridFactory< This >;
123
124 friend class AlbertaGridIntersectionBase< const This >;
125 friend class AlbertaGridLeafIntersection< const This >;
126
127 friend class AlbertaMarkerVector< dim, dimworld >;
128#if (__GNUC__ < 4) && !(defined __ICC)
129 // add additional friend decls for gcc 3.4
130 friend struct AlbertaMarkerVector< dim, dimworld >::MarkSubEntities<true>;
131 friend struct AlbertaMarkerVector< dim, dimworld >::MarkSubEntities<false>;
132#endif
133 friend class AlbertaGridIndexSet< dim, dimworld >;
134 friend class AlbertaGridHierarchicIndexSet< dim, dimworld >;
135
136 template< class, class >
138
139 public:
141 typedef AlbertaGridFamily< dim, dimworld > GridFamily;
142
143 typedef typename GridFamily::ctype ctype;
144
147
148 // the Traits
149 typedef typename AlbertaGridFamily< dim, dimworld >::Traits Traits;
150
155
158
163
166
167 private:
169 typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
170
172 typedef AlbertaGridIdSet<dim,dimworld> IdSetImp;
173
175 struct AdaptationState
176 {
177 enum Phase { ComputationPhase, PreAdaptationPhase, PostAdaptationPhase };
178
179 private:
180 Phase phase_;
181 int coarsenMarked_;
182 int refineMarked_;
183
184 public:
185 AdaptationState ()
186 : phase_( ComputationPhase ),
187 coarsenMarked_( 0 ),
188 refineMarked_( 0 )
189 {}
190
191 void mark ( int count )
192 {
193 if( count < 0 )
194 ++coarsenMarked_;
195 if( count > 0 )
196 refineMarked_ += (2 << count);
197 }
198
199 void unmark ( int count )
200 {
201 if( count < 0 )
202 --coarsenMarked_;
203 if( count > 0 )
204 refineMarked_ -= (2 << count);
205 }
206
207 bool coarsen () const
208 {
209 return (coarsenMarked_ > 0);
210 }
211
212 int refineMarked () const
213 {
214 return refineMarked_;
215 }
216
217 void preAdapt ()
218 {
219 if( phase_ != ComputationPhase )
220 error( "preAdapt may only be called in computation phase." );
221 phase_ = PreAdaptationPhase;
222 }
223
224 void adapt ()
225 {
226 if( phase_ != PreAdaptationPhase )
227 error( "adapt may only be called in preadapdation phase." );
228 phase_ = PostAdaptationPhase;
229 }
230
231 void postAdapt ()
232 {
233 if( phase_ != PostAdaptationPhase )
234 error( "postAdapt may only be called in postadaptation phase." );
235 phase_ = ComputationPhase;
236
237 coarsenMarked_ = 0;
238 refineMarked_ = 0;
239 }
240
241 private:
242 void error ( const std::string &message )
243 {
244 DUNE_THROW( InvalidStateException, message );
245 }
246 };
247
248 template< class DataHandler >
249 struct AdaptationCallback;
250
251 // max number of allowed levels is 64
252 static const int MAXL = 64;
253
254 typedef Alberta::ElementInfo< dimension > ElementInfo;
255 typedef Alberta::MeshPointer< dimension > MeshPointer;
257 typedef AlbertaGridLevelProvider< dimension > LevelProvider;
258
259 public:
260 AlbertaGrid ( const This & ) = delete;
261 This &operator= ( const This & ) = delete;
262
265
272 const std::shared_ptr< DuneBoundaryProjection< dimensionworld > > &projection
273 = std::shared_ptr< DuneBoundaryProjection< dimensionworld > >() );
274
275 template< class Proj, class Impl >
277 const Alberta::ProjectionFactoryInterface< Proj, Impl > &projectionFactory );
278
283 AlbertaGrid ( const std::string &macroGridFileName );
284
287
290 int maxLevel () const;
291
293 template<int cd, PartitionIteratorType pitype>
294 typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
295 lbegin (int level) const;
296
298 template<int cd, PartitionIteratorType pitype>
299 typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
300 lend (int level) const;
301
303 template< int codim >
304 typename Traits::template Codim< codim >::LevelIterator
305 lbegin ( int level ) const;
306
308 template< int codim >
309 typename Traits::template Codim< codim >::LevelIterator
310 lend ( int level ) const;
311
313 template< int codim, PartitionIteratorType pitype >
314 typename Traits
315 ::template Codim< codim >::template Partition< pitype >::LeafIterator
316 leafbegin () const;
317
319 template< int codim, PartitionIteratorType pitype >
320 typename Traits
321 ::template Codim< codim >::template Partition< pitype >::LeafIterator
322 leafend () const;
323
325 template< int codim >
326 typename Traits::template Codim< codim >::LeafIterator
327 leafbegin () const;
328