This file is indexed.

/usr/include/dune/grid/common/sizecache.hh is in libdune-grid-dev 2.3.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_SIZECACHE_HH
#define DUNE_SIZECACHE_HH

#include <cassert>
#include <vector>
#include <set>

#include <dune/common/forloop.hh>
#include <dune/common/exceptions.hh>

#include <dune/geometry/type.hh>
#include <dune/geometry/referenceelements.hh>

#include <dune/grid/common/gridenums.hh>
#include <dune/grid/common/capabilities.hh>

/** @file
   @author Robert Kloefkorn
   @brief Provides size cache classes to
   implement the grids size method efficiently.
 */

namespace Dune {

  //! organizes the caching of sizes for one grid and one GeometryType
  template <class GridImp>
  class SizeCache
  {
    typedef SizeCache<GridImp> ThisType;
    //! our dimension
    enum { dim    = GridImp::dimension   };

    //! number of codims
    enum { nCodim = GridImp::dimension+1 };

    // type of grid
    typedef GridImp GridType;

    // coordinate type
    typedef typename GridType :: ctype ctype ;

    // stores all sizes of the levels
    mutable std::vector< int > levelSizes_[nCodim];

    // stores all sizes of the levels
    mutable std::vector< std::vector< int > > levelTypeSizes_[nCodim];

    // stores all sizes of leafs
    mutable int leafSizes_[nCodim];

    // stores all sizes of leafs
    mutable std::vector< int > leafTypeSizes_[nCodim];

    // the grid
    const GridType & grid_;

    // count elements of set by iterating the grid
    template < int codim, bool gridHasCodim >
    struct CountLevelEntitiesBase
    {
      template < class SzCacheType >
      static void apply(const SzCacheType & sc, int level, int cd)
      {
        if( cd == codim )
        {
          sc.template countLevelEntities<All_Partition,codim> (level);
        }
      }
    };

    template < int codim >
    struct CountLevelEntitiesBase< codim, false >
    {
      template < class SzCacheType >
      static void apply(const SzCacheType & sc, int level, int cd)
      {
        if( cd == codim )
        {
          sc.template countLevelEntitiesNoCodim<All_Partition,codim> (level);
        }
      }
    };

    template < int codim >
    struct CountLevelEntities
      : public CountLevelEntitiesBase< codim, Capabilities :: hasEntity< GridType, codim > :: v >
    {};

    // count elements of set by iterating the grid
    template < int codim, bool gridHasCodim >
    struct CountLeafEntitiesBase
    {
      template <class SzCacheType>
      static void apply(const SzCacheType & sc, int cd)
      {
        if( cd == codim )
        {
          sc.template countLeafEntities<All_Partition,codim> ();
        }
      }
    };

    // count elements of set by iterating the grid
    template < int codim >
    struct CountLeafEntitiesBase< codim, false >
    {
      template <class SzCacheType>
      static void apply(const SzCacheType & sc, int cd)
      {
        if( cd == codim )
        {
          sc.template countLeafEntitiesNoCodim<All_Partition,codim> ();
        }
      }
    };

    template < int codim >
    struct CountLeafEntities
      : public CountLeafEntitiesBase< codim, Capabilities :: hasEntity< GridType, codim > :: v >
    {};

    int gtIndex( const GeometryType& type ) const
    {
      return type.id() >> 1 ;
    }

    int sizeCodim( const int codim ) const
    {
      const int mydim = GridType :: dimension - codim;
      return ((1 << mydim) + 1) / 2;
    }

    // private copy constructor
    SizeCache (const SizeCache & );
  public:
    /** \brief constructor taking grid reference */
    SizeCache (const GridType & grid) : grid_( grid )
    {
      reset();
    }

    /** \brief reset all cached sizes */
    void reset()
    {
      for(int codim=0; codim<nCodim; ++codim)
      {
        leafSizes_[ codim ] = -1;
        leafTypeSizes_[ codim ].resize( sizeCodim( codim ), -1 );
      }

      const int numMxl = grid_.maxLevel()+1;
      for(int codim=0; codim<nCodim; ++codim)
      {
        std::vector<int> & vec = levelSizes_[codim];
        vec.resize(numMxl);
        levelTypeSizes_[codim].resize( numMxl );
        for(int level = 0; level<numMxl; ++level)
        {
          vec[level] = -1;
          levelTypeSizes_[codim][level].resize( sizeCodim( codim ), -1 );
        }
      }
    }

    //********************************************************************
    // level sizes
    //********************************************************************
    /** \copydoc Dune::Grid::size(int level,int codim) const */
    int size (int level, int codim) const
    {
      assert( codim >= 0 );
      assert( codim < nCodim );
      assert( level >= 0 );
      if( level >= (int) levelSizes_[codim].size() ) return 0;

      if( levelSizes_[codim][level] < 0)
        ForLoop< CountLevelEntities, 0, dim > :: apply( *this, level, codim );

      //  CountLevelEntities<ThisType,All_Partition,dim>::count(*this,level,codim);

      assert( levelSizes_[codim][level] >= 0 );
      return levelSizes_[codim][level];
    }

    /** \copydoc Dune::Grid::size(int level,GeometryType type) const */
    int size (int level, GeometryType type) const
    {
      const int codim = GridType ::dimension - type.dim();
      if( levelSizes_[codim][level] < 0)
        ForLoop< CountLevelEntities, 0, dim > :: apply( *this, level, codim );

      assert( levelTypeSizes_[codim][level][gtIndex( type )] >= 0 );
      return levelTypeSizes_[codim][level][gtIndex( type )];
    }

    //********************************************************************
    // leaf sizes
    //********************************************************************
    /** \copydoc Dune::Grid::size(int codim) const */
    int size (int codim) const
    {
      assert( codim >= 0 );
      assert( codim < nCodim );
      if( leafSizes_[codim] < 0 )
        ForLoop< CountLeafEntities, 0, dim > :: apply( *this, codim );

      assert( leafSizes_[codim] >= 0 );
      return leafSizes_[codim];
    };

    /** \copydoc Dune::Grid::size(GeometryType type) const */
    int size ( const GeometryType type ) const
    {
      const int codim = GridType :: dimension - type.dim();
      if( leafSizes_[codim] < 0 )
        ForLoop< CountLeafEntities, 0, dim > :: apply( *this, codim );

      assert( leafTypeSizes_[codim][ gtIndex( type )] >= 0 );
      return leafTypeSizes_[codim][ gtIndex( type )];
    }

  private:
    template <PartitionIteratorType pitype, int codim>
    void countLevelEntities(int level) const
    {
      typedef typename GridType :: LevelGridView GridView ;
      typedef typename GridView :: template Codim< codim > :: template Partition<pitype>  :: Iterator Iterator ;
      GridView gridView = grid_.levelGridView( level );
      Iterator it  = gridView.template begin<codim,pitype> ();
      Iterator end = gridView.template end<codim,pitype>   ();
      levelSizes_[codim][level] = countElements(it,end, levelTypeSizes_[codim][level]);
    }

    template <PartitionIteratorType pitype, int codim>
    void countLeafEntities() const
    {
      // count All_Partition entities
      typedef typename GridType :: LeafGridView GridView ;
      typedef typename GridView :: template Codim< codim > :: template Partition<pitype>  :: Iterator Iterator ;
      GridView gridView = grid_.leafView();
      Iterator it  = gridView.template begin<codim,pitype> ();
      Iterator end = gridView.template end<codim,pitype>   ();
      leafSizes_[codim] = countElements(it,end, leafTypeSizes_[codim] );
    }

    // counts entities with given type for given iterator
    template <class IteratorType>
    int countElements(IteratorType & it, const IteratorType & end, std::vector<int>& typeSizes) const
    {
      int overall = 0;
      const size_t types = typeSizes.size();
      for(size_t i=0; i<types; ++i) typeSizes[i] = 0;
      for( ; it != end; ++it )
      {
        const GeometryType type = it->type();
        ++typeSizes[ gtIndex( type ) ];
        ++overall;
      }

      int sumtypes = 0;
      for(size_t i=0; i<types; ++i) sumtypes += typeSizes[i];

      assert( overall == sumtypes );
      return overall;
    }

    template <PartitionIteratorType pitype, int codim>
    void countLevelEntitiesNoCodim(int level) const
    {
      typedef typename GridType :: LevelGridView GridView ;
      typedef typename GridView :: template Codim< 0 > :: template Partition<pitype>  :: Iterator Iterator ;
      GridView gridView = grid_.levelGridView( level );
      Iterator it  = gridView.template begin< 0, pitype> ();
      Iterator end = gridView.template end< 0, pitype>   ();
      levelSizes_[codim][level] = countElementsNoCodim< codim >(it,end, levelTypeSizes_[codim][level]);
    }

    template <PartitionIteratorType pitype, int codim>
    void countLeafEntitiesNoCodim() const
    {
      // count All_Partition entities
      typedef typename GridType :: LeafGridView GridView ;
      typedef typename GridView :: template Codim< 0 > :: template Partition<pitype>  :: Iterator Iterator ;
      GridView gridView = grid_.leafView();
      Iterator it  = gridView.template begin< 0, pitype > ();
      Iterator end = gridView.template end< 0, pitype >   ();
      leafSizes_[codim] = countElementsNoCodim< codim >(it,end, leafTypeSizes_[codim] );
    }

    // counts entities with given type for given iterator
    template < int codim, class IteratorType >
    int countElementsNoCodim(IteratorType & it, const IteratorType & end, std::vector<int>& typeSizes) const
    {
      typedef typename GridType :: LocalIdSet LocalIdSet ;
      typedef typename LocalIdSet :: IdType IdType ;

      typedef ReferenceElement< ctype, dim > ReferenceElementType;
      typedef ReferenceElements< ctype, dim > ReferenceElementContainerType;

      typedef std::set< IdType > CodimIdSetType ;

      typedef typename IteratorType :: Entity ElementType ;

      // get id set
      const LocalIdSet& idSet = grid_.localIdSet();

      const size_t types = typeSizes.size();
      for(size_t i=0; i<types; ++i) typeSizes[ i ] = 0;

      std::vector< CodimIdSetType > typeCount( types );

      // count all elements of codimension codim
      for( ; it != end; ++it )
      {
        // get entity
        const ElementType& element = *it ;
        // get reference element
        const ReferenceElementType& refElem =
          ReferenceElementContainerType :: general( element.type() );

        // count all sub entities of codimension codim
        const int count = element.template count< codim > ();
        for( int i=0; i< count; ++ i )
        {
          // get geometry type
          const GeometryType geomType = refElem.type( i, codim );
          // get id of sub entity
          const IdType id = idSet.subId( element, i, codim );
          // insert id into set
          typeCount[ gtIndex( geomType ) ].insert( id );
        }
      }

      // accumulate numbers
      int overall = 0;
      for(size_t i=0; i<types; ++i)
      {
        typeSizes[ i ] = typeCount[ i ].size();
        overall += typeSizes[ i ];
      }

      return overall;
    }
  };

  //! organizes the caching of sizes for one grid and one GeometryType
  template <class GridImp>
  struct SingleTypeSizeCache : public SizeCache< GridImp >
  {
    DUNE_DEPRECATED SingleTypeSizeCache( const GridImp& grid, bool isSimplex , bool isCube, bool notWorry = false ) : SizeCache< GridImp >( grid ) {}
  };

} // end namespace Dune
#endif