dune-grid  2.9.0
level.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 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_ALBERTA_LEVEL_HH
6 #define DUNE_ALBERTA_LEVEL_HH
7 
8 #include <cassert>
9 #include <cstdlib>
10 
14 
15 #if HAVE_ALBERTA
16 
17 namespace Dune
18 {
19 
20  // AlbertaGridLevelProvider
21  // ------------------------
22 
23  template< int dim >
25  {
27 
28  typedef unsigned char Level;
29 
32 
34 
35  static const Level isNewFlag = (1 << 7);
36  static const Level levelMask = (1 << 7) - 1;
37 
38  class SetLocal;
39  class CalcMaxLevel;
40 
41  template< Level flags >
42  struct ClearFlags;
43 
44  struct Interpolation;
45 
46  public:
50 
51  Level operator() ( const Alberta::Element *element ) const
52  {
53  const Level *array = (Level *)level_;
54  return array[ dofAccess_( element, 0 ) ] & levelMask;
55  }
56 
57  Level operator() ( const ElementInfo &elementInfo ) const
58  {
59  return (*this)( elementInfo.el() );
60  }
61 
62  bool isNew ( const Alberta::Element *element ) const
63  {
64  const Level *array = (Level *)level_;
65  return ((array[ dofAccess_( element, 0 ) ] & isNewFlag) != 0);
66  }
67 
68  bool isNew ( const ElementInfo &elementInfo ) const
69  {
70  return isNew( elementInfo.el() );
71  }
72 
73  Level maxLevel () const
74  {
75  CalcMaxLevel calcFromCache;
76  level_.forEach( calcFromCache );
77 #ifndef NDEBUG
78  CalcMaxLevel calcFromGrid;
79  mesh().leafTraverse( calcFromGrid, FillFlags::nothing );
80  assert( calcFromCache.maxLevel() == calcFromGrid.maxLevel() );
81 #endif
82  return calcFromCache.maxLevel();;
83  }
84 
85  MeshPointer mesh () const
86  {
87  return MeshPointer( level_.dofSpace()->mesh );
88  }
89 
90  void markAllOld ()
91  {
92  ClearFlags< isNewFlag > clearIsNew;
93  level_.forEach( clearIsNew );
94  }
95 
96  void create ( const DofNumbering &dofNumbering )
97  {
98  const Alberta::DofSpace *const dofSpace = dofNumbering.dofSpace( 0 );
99  dofAccess_ = DofAccess( dofSpace );
100 
101  level_.create( dofSpace, "Element level" );
102  assert( level_ );
103  level_.template setupInterpolation< Interpolation >();
104 
105  SetLocal setLocal( level_ );
107  }
108 
109  void release ()
110  {
111  level_.release();
112  dofAccess_ = DofAccess();
113  }
114 
115  private:
116  DofVectorPointer level_;
117  DofAccess dofAccess_;
118  };
119 
120 
121 
122  // AlbertaGridLevelProvider::SetLocal
123  // ----------------------------------
124 
125  template< int dim >
127  {
128  DofVectorPointer level_;
129  DofAccess dofAccess_;
130 
131  public:
132  explicit SetLocal ( const DofVectorPointer &level )
133  : level_( level ),
134  dofAccess_( level.dofSpace() )
135  {}
136 
137  void operator() ( const Alberta::ElementInfo< dim > &elementInfo ) const
138  {
139  Level *const array = (Level *)level_;
140  array[ dofAccess_( elementInfo, 0 ) ] = elementInfo.level();
141  }
142  };
143 
144 
145 
146  // AlbertaGridLevelProvider::CalcMaxLevel
147  // --------------------------------------
148 
149  template< int dim >
151  {
152  Level maxLevel_;
153 
154  public:
156  : maxLevel_( 0 )
157  {}
158 
159  void operator() ( const Level &dof )
160  {
161  maxLevel_ = std::max( maxLevel_, Level( dof & levelMask ) );
162  }
163 
164  void operator() ( const Alberta::ElementInfo< dim > &elementInfo )
165  {
166  maxLevel_ = std::max( maxLevel_, Level( elementInfo.level() ) );
167  }
168 
169  Level maxLevel () const
170  {
171  return maxLevel_;
172  }
173  };
174 
175 
176 
177  // AlbertaGridLevelProvider::ClearFlags
178  // ------------------------------------
179 
180  template< int dim >
181  template< typename AlbertaGridLevelProvider< dim >::Level flags >
182  struct AlbertaGridLevelProvider< dim >::ClearFlags
183  {
184  void operator() ( Level &dof ) const
185  {
186  dof &= ~flags;
187  }
188  };
189 
190 
191 
192  // AlbertaGridLevelProvider::Interpolation
193  // ---------------------------------------
194 
195  template< int dim >
197  {
198  static const int dimension = dim;
199 
201 
202  static void interpolateVector ( const DofVectorPointer &dofVector,
203  const Patch &patch )
204  {
205  const DofAccess dofAccess( dofVector.dofSpace() );
206  Level *array = (Level *)dofVector;
207 
208  for( int i = 0; i < patch.count(); ++i )
209  {
210  const Alberta::Element *const father = patch[ i ];
211  assert( (array[ dofAccess( father, 0 ) ] & levelMask) < levelMask );
212  const Level childLevel = (array[ dofAccess( father, 0 ) ] + 1) | isNewFlag;
213  for( int i = 0; i < 2; ++i )
214  {
215  const Alberta::Element *child = father->child[ i ];
216  array[ dofAccess( child, 0 ) ] = childLevel;
217  }
218  }
219  }
220  };
221 
222 }
223 
224 #endif // #if HAVE_ALBERTA
225 
226 #endif
provides a wrapper for ALBERTA's mesh structure
Include standard header files.
Definition: agrid.hh:60
ALBERTA EL Element
Definition: misc.hh:54
ALBERTA FE_SPACE DofSpace
Definition: misc.hh:65
int max(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:337
Definition: meshpointer.hh:40
void leafTraverse(Functor &functor, typename FillFlags::Flags fillFlags=FillFlags::standard) const
Definition: meshpointer.hh:385
void hierarchicTraverse(Functor &functor, typename FillFlags::Flags fillFlags=FillFlags::standard) const
Definition: meshpointer.hh:370
Definition: dofadmin.hh:93
const DofSpace * dofSpace(int codim) const
Definition: dofadmin.hh:145
void create(const DofSpace *dofSpace, const std::string &name="")
Definition: dofvector.hh:236
void release()
Definition: dofvector.hh:254
const DofSpace * dofSpace() const
Definition: dofvector.hh:223
void forEach(Functor &functor) const
Definition: dofvector.hh:264
Definition: elementinfo.hh:43
int level() const
Definition: elementinfo.hh:533
Element * el() const
Definition: elementinfo.hh:737
Definition: level.hh:25
bool isNew(const Alberta::Element *element) const
Definition: level.hh:62
bool isNew(const ElementInfo &elementInfo) const
Definition: level.hh:68
Alberta::MeshPointer< dim > MeshPointer
Definition: level.hh:48
MeshPointer mesh() const
Definition: level.hh:85
void create(const DofNumbering &dofNumbering)
Definition: level.hh:96
Level maxLevel() const
Definition: level.hh:73
Alberta::HierarchyDofNumbering< dim > DofNumbering
Definition: level.hh:49
void release()
Definition: level.hh:109
Level operator()(const Alberta::Element *element) const
Definition: level.hh:51
void markAllOld()
Definition: level.hh:90
Alberta::ElementInfo< dim > ElementInfo
Definition: level.hh:44
SetLocal(const DofVectorPointer &level)
Definition: level.hh:132
Level maxLevel() const
Definition: level.hh:169
Alberta::Patch< dimension > Patch
Definition: level.hh:200
static void interpolateVector(const DofVectorPointer &dofVector, const Patch &patch)
Definition: level.hh:202
Definition: misc.hh:231
static const Flags nothing
Definition: misc.hh:234
Definition: refinement.hh:40
int count() const
Definition: refinement.hh:67