This file is indexed.

/usr/include/dune/grid/albertagrid/misc.hh is in libdune-grid-dev 2.2.1-2.

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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
#ifndef DUNE_ALBERTA_MISC_HH
#define DUNE_ALBERTA_MISC_HH

#include <cassert>

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

#include <dune/grid/albertagrid/albertaheader.hh>

#if HAVE_ALBERTA

// should the coordinates be cached in a vector (required for ALBERTA 2.0)?
#ifndef DUNE_ALBERTA_CACHE_COORDINATES
#define DUNE_ALBERTA_CACHE_COORDINATES 1
#endif

// set to 1 to use generic geometries in AlbertaGrid
#ifndef DUNE_ALBERTA_USE_GENERICGEOMETRY
#define DUNE_ALBERTA_USE_GENERICGEOMETRY 0
#endif

namespace Dune
{

  // Exceptions
  // ----------

  class AlbertaError
  : public Exception
  {};

  class AlbertaIOError
  : public IOError
  {};



  namespace Alberta
  {

    // Import Types
    // ------------

    static const int dimWorld = DIM_OF_WORLD;

    typedef ALBERTA REAL Real;
    typedef ALBERTA REAL_B LocalVector; // in barycentric coordinates
    typedef ALBERTA REAL_D GlobalVector;
    typedef ALBERTA REAL_DD GlobalMatrix;

#if DUNE_ALBERTA_VERSION >= 0x300
    typedef ALBERTA AFF_TRAFO AffineTransformation;
#else
    struct AffineTransformation
    {
      GlobalMatrix M;
      GlobalVector t;
    };
#endif

    typedef ALBERTA MESH Mesh;
    typedef ALBERTA EL Element;

    static const int meshRefined = MESH_REFINED;
    static const int meshCoarsened = MESH_COARSENED;

    static const int InteriorBoundary = INTERIOR;
    static const int DirichletBoundary = DIRICHLET;
#if DUNE_ALBERTA_VERSION >= 0x300
    typedef ALBERTA BNDRY_TYPE BoundaryId;
#else
    typedef S_CHAR BoundaryId;
#endif

    typedef U_CHAR ElementType;

    typedef ALBERTA FE_SPACE DofSpace;



    // Memory Manipulation Functions
    // -----------------------------

    template< class Data >
    inline Data *memAlloc ( size_t size )
    {
      return MEM_ALLOC( size, Data );
    }

    template< class Data >
    inline Data *memCAlloc ( size_t size )
    {
      return MEM_CALLOC( size, Data );
    }

    template< class Data >
    inline Data *memReAlloc ( Data *ptr, size_t oldSize, size_t newSize )
    {
      return MEM_REALLOC( ptr, oldSize, newSize, Data );
    }

    template< class Data >
    inline void memFree ( Data *ptr, size_t size )
    {
      return MEM_FREE( ptr, size, Data );
    }



    // GlobalSpace
    // -----------

    class GlobalSpace
    {
      typedef GlobalSpace This;

    public:
      typedef GlobalMatrix Matrix;
      typedef GlobalVector Vector;

    private:
      Matrix identityMatrix_;
      Vector nullVector_;

      GlobalSpace ()
      {
        for( int i = 0; i < dimWorld; ++i )
        {
          for( int j = 0; j < dimWorld; ++j )
            identityMatrix_[ i ][ j ] = Real( 0 );
          identityMatrix_[ i ][ i ] = Real( 1 );
          nullVector_[ i ] = Real( 0 );
        }
      }

      static This &instance ()
      {
        static This theInstance;
        return theInstance;
      }

    public:
      static const Matrix &identityMatrix ()
      {
        return instance().identityMatrix_;
      }

      static const Vector &nullVector ()
      {
        return instance().nullVector_;
      }
    };



    // NumSubEntities
    // --------------

    template< int dim, int codim >
    struct NumSubEntities;

    template< int dim >
    struct NumSubEntities< dim, 0 >
    {
      static const int value = 1;
    };

    template< int dim >
    struct NumSubEntities< dim, dim >
    {
      static const int value = dim+1;
    };

    template<>
    struct NumSubEntities< 0, 0 >
    {
      static const int value = 1;
    };

    template<>
    struct NumSubEntities< 2, 1 >
    {
      static const int value = 3;
    };

    template<>
    struct NumSubEntities< 3, 1 >
    {
      static const int value = 4;
    };

    template<>
    struct NumSubEntities< 3, 2 >
    {
      static const int value = 6;
    };



    // CodimType
    // ---------

    template< int dim, int codim >
    struct CodimType;

    template< int dim >
    struct CodimType< dim, 0 >
    {
      static const int value = CENTER;
    };

    template< int dim >
    struct CodimType< dim, dim >
    {
      static const int value = VERTEX;
    };

    template<>
    struct CodimType< 2, 1 >
    {
      static const int value = EDGE;
    };

    template<>
    struct CodimType< 3, 1 >
    {
      static const int value = FACE;
    };

    template<>
    struct CodimType< 3, 2 >
    {
      static const int value = EDGE;
    };



    // FillFlags
    // ---------

    template< int dim >
    struct FillFlags
    {
      typedef ALBERTA FLAGS Flags;

      static const Flags nothing = FILL_NOTHING;

      static const Flags coords = FILL_COORDS;

      static const Flags neighbor = FILL_NEIGH;

      static const Flags orientation = (dim == 3 ? FILL_ORIENTATION : FILL_NOTHING);

      static const Flags projection = FILL_PROJECTION;

#if DUNE_ALBERTA_VERSION >= 0x300
      static const Flags elementType = FILL_NOTHING;
#else
      static const Flags elementType = (dim == 3 ? FILL_EL_TYPE : FILL_NOTHING);
#endif

#if DUNE_ALBERTA_VERSION >= 0x300
      static const Flags boundaryId = FILL_MACRO_WALLS;
#else
      static const Flags boundaryId = FILL_BOUND;
#endif

#if DUNE_ALBERTA_VERSION >= 0x300
      static const Flags nonPeriodic = FILL_NON_PERIODIC;
#else
      static const Flags nonPeriodic = FILL_NOTHING;
#endif

      static const Flags all = coords | neighbor | boundaryId | nonPeriodic
                               | orientation | projection | elementType;

#if DUNE_ALBERTA_VERSION >= 0x300
      static const Flags standardWithCoords = all & ~nonPeriodic & ~projection;
#else
      static const Flags standardWithCoords = all;
#endif

#if DUNE_ALBERTA_CACHE_COORDINATES
      static const Flags standard = standardWithCoords & ~coords;
#else
      static const Flags standard = standardWithCoords;
#endif
    };



    // RefinementEdge
    // --------------

    template< int dim >
    struct RefinementEdge
    {
      static const int value = 0;
    };

    template<>
    struct RefinementEdge< 2 >
    {
      static const int value = 2;
    };



    // Dune2AlbertaNumbering
    // ---------------------

    template< int dim, int codim >
    struct Dune2AlbertaNumbering
    {
      static int apply ( const int i )
      {
        assert( (i >= 0) && (i < NumSubEntities< dim, codim >::value) );
        return i;
      }
    };

    template<>
    struct Dune2AlbertaNumbering< 3, 2 >
    {
      static const int numSubEntities = NumSubEntities< 3, 2 >::value;

      static int apply ( const int i )
      {
        assert( (i >= 0) && (i < numSubEntities) );
        static int dune2alberta[ numSubEntities ] = { 0, 3, 1, 2, 4, 5 };
        return dune2alberta[ i ];
      }
    };



    // Generic2AlbertaNumbering
    // ------------------------

    template< int dim, int codim >
    struct Generic2AlbertaNumbering
    {
      static int apply ( const int i )
      {
        assert( (i >= 0) && (i < NumSubEntities< dim, codim >::value) );
        return i;
      }
    };

    template< int dim >
    struct Generic2AlbertaNumbering< dim, 1 >
    {
      static int apply ( const int i )
      {
        assert( (i >= 0) && (i < NumSubEntities< dim, 1 >::value) );
        return dim - i;
      }
    };

    template<>
    struct Generic2AlbertaNumbering< 1, 1 >
    {
      static int apply ( const int i )
      {
        assert( (i >= 0) && (i < NumSubEntities< 1, 1 >::value) );
        return i;
      }
    };

    template<>
    struct Generic2AlbertaNumbering< 3, 2 >
    {
      static const int numSubEntities = NumSubEntities< 3, 2 >::value;

      static int apply ( const int i )
      {
        assert( (i >= 0) && (i < numSubEntities) );
        static int generic2alberta[ numSubEntities ] = { 0, 1, 3, 2, 4, 5 };
        return generic2alberta[ i ];
      }
    };



    // NumberingMap
    // ------------

    template< int dim, template< int, int > class Numbering = Generic2AlbertaNumbering >
    class NumberingMap
    {
      typedef NumberingMap< dim, Numbering > This;

      template< int codim >
      struct Initialize;

      int *dune2alberta_[ dim+1 ];
      int *alberta2dune_[ dim+1 ];
      int numSubEntities_[ dim+1 ];

      NumberingMap ( const This & );
      This &operator= ( const This & );

    public:
      NumberingMap ()
      {
        ForLoop< Initialize, 0, dim >::apply( *this );
      }

      ~NumberingMap ()
      {
        for( int codim = 0; codim <= dim; ++codim )
        {
          delete[]( dune2alberta_[ codim ] );
          delete[]( alberta2dune_[ codim ] );
        }
      }

      int dune2alberta ( int codim, int i ) const
      {
        assert( (codim >= 0) && (codim <= dim) );
        assert( (i >= 0) && (i < numSubEntities( codim )) );
        return dune2alberta_[ codim ][ i ];
      }

      int alberta2dune ( int codim, int i ) const
      {
        assert( (codim >= 0) && (codim <= dim) );
        assert( (i >= 0) && (i < numSubEntities( codim )) );
        return alberta2dune_[ codim ][ i ];
      }

      int numSubEntities ( int codim ) const
      {
        assert( (codim >= 0) && (codim <= dim) );
        return numSubEntities_[ codim ];
      }
    };



    // NumberingMap::Initialize
    // ------------------------

    template< int dim, template< int, int > class Numbering >
    template< int codim >
    struct NumberingMap< dim, Numbering >::Initialize
    {
      static const int numSubEntities = NumSubEntities< dim, codim >::value;

      static void apply ( NumberingMap< dim, Numbering > &map )
      {
        map.numSubEntities_[ codim ] = numSubEntities;
        map.dune2alberta_[ codim ] = new int[ numSubEntities ];
        map.alberta2dune_[ codim ] = new int[ numSubEntities ];

        for( int i = 0; i < numSubEntities; ++i )
        {
          const int j = Numbering< dim, codim >::apply( i );
          map.dune2alberta_[ codim ][ i ] = j;
          map.alberta2dune_[ codim ][ j ] = i;
        }
      }
    };



    // MapVertices
    // -----------

    template< int dim, int codim >
    struct MapVertices;

    template< int dim >
    struct MapVertices< dim, 0 >
    {
      static int apply ( int subEntity, int vertex )
      {
        assert( subEntity == 0 );
        assert( (vertex >= 0) && (vertex <= NumSubEntities< dim, dim >::value) );
        return vertex;
      }
    };

    template<>
    struct MapVertices< 2, 1 >
    {
      static int apply ( int subEntity, int vertex )
      {
        assert( (subEntity >= 0) && (subEntity < 3) );
        assert( (vertex >= 0) && (vertex < 2) );
        //static const int map[ 3 ][ 2 ] = { {1,2}, {2,0}, {0,1} };
        static const int map[ 3 ][ 2 ] = { {1,2}, {0,2}, {0,1} };
        return map[ subEntity ][ vertex ];
      }
    };

    template<>
    struct MapVertices< 3, 1 >
    {
      static int apply ( int subEntity, int vertex )
      {
        assert( (subEntity >= 0) && (subEntity < 4) );
        assert( (vertex >= 0) && (vertex < 3) );
        //static const int map[ 4 ][ 3 ] = { {1,2,3}, {0,3,2}, {0,1,3}, {0,2,1} };
        static const int map[ 4 ][ 3 ] = { {1,2,3}, {0,2,3}, {0,1,3}, {0,1,2} };
        return map[ subEntity ][ vertex ];
      }
    };

    template<>
    struct MapVertices< 3, 2 >
    {
      static int apply ( int subEntity, int vertex )
      {
        assert( (subEntity >= 0) && (subEntity < 6) );
        assert( (vertex >= 0) && (vertex < 2) );
        static const int map[ 6 ][ 2 ] = { {0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3} };
        return map[ subEntity ][ vertex ];
      }
    };

    template< int dim >
    struct MapVertices< dim, dim >
    {
      static int apply ( int subEntity, int vertex )
      {
        assert( (subEntity >= 0) && (subEntity < NumSubEntities< dim, 1 >::value) );
        assert( vertex == 0 );
        return subEntity;
      }
    };



    // Twist
    // -----

    // ******************************************************************
    // Meaning of the twist (same as in ALU)
    // -------------------------------------
    //
    // Consider a fixed ordering of the vertices v_1, ... v_n of a face
    // (here, we assume their indices to be increasing). Denote by k the
    // local number of a vertex v within the element and by t the twist.
    // Then, v = v_j, where j is computed by the following formula:
    //
    //        / (2n + 1 - k + t) % n, if t < 0
    //   j = <
    //        \ (k + t) % n,          if t >= 0
    //
    //  Note: We use the order of the 0-th vertex dof to assign the twist.
    //        This is ok for two reasons:
    //        - ALBERTA preserves the relative order of the dofs during
    //          dof compression.
    //        - ALBERTA enforces the first vertex dof admin to be periodic.
    // ******************************************************************

    template< int dim, int subdim >
    struct Twist
    {
      static const int numSubEntities = NumSubEntities< dim, dim-subdim >::value;

      static const int minTwist = 0;
      static const int maxTwist = 0;

      static int twist ( const Element *element, int subEntity )
      {
        assert( (subEntity >= 0) && (subEntity < numSubEntities) );
        return 0;
      }
    };

    template< int dim >
    struct Twist< dim, 1 >
    {
      static const int numSubEntities = NumSubEntities< dim, dim-1 >::value;

      static const int minTwist = 0;
      static const int maxTwist = 1;

      static int twist ( const Element *element, int subEntity )
      {
        assert( (subEntity >= 0) && (subEntity < numSubEntities) );
        const int numVertices = NumSubEntities< 1, 1 >::value;
        int dof[ numVertices ];
        for( int i = 0; i < numVertices; ++i )
        {
          const int j = MapVertices< dim, dim-1 >::apply( subEntity, i );
          dof[ i ] = element->dof[ j ][ 0 ];
        }
        return (dof[ 0 ] < dof[ 1 ] ? 0 : 1);
      }
    };


    template<>
    struct Twist< 1, 1 >
    {
      static const int minTwist = 0;
      static const int maxTwist = 0;

      static int twist ( const Element *element, int subEntity )
      {
        assert( subEntity == 0 );
        return 0;
      }
    };


    template< int dim >
    struct Twist< dim, 2 >
    {
      static const int numSubEntities = NumSubEntities< dim, dim-2 >::value;

      static const int minTwist = -3;
      static const int maxTwist = 2;

      static int twist ( const Element *element, int subEntity )
      {
        assert( (subEntity >= 0) && (subEntity < numSubEntities) );
        const int numVertices = NumSubEntities< 2, 2 >::value;
        int dof[ numVertices ];
        for( int i = 0; i < numVertices; ++i )
        {
          const int j = MapVertices< dim, dim-2 >::apply( subEntity, i );
          dof[ i ] = element->dof[ j ][ 0 ];
        }

        const int twist[ 8 ] = { -2, 1, 666, -1, 2, 666, -3, 0 };
        const int k = int( dof[ 0 ] < dof[ 1 ] )
                      | (int( dof[ 0 ] < dof[ 2 ] ) << 1)
                      | (int( dof[ 1 ] < dof[ 2 ] ) << 2);
        assert( twist[ k ] != 666 );
        return twist[ k ];
      }
    };


    template<>
    struct Twist< 2, 2 >
    {
      static const int minTwist = 0;
      static const int maxTwist = 0;

      static int twist ( const Element *element, int subEntity )
      {
        assert( subEntity == 0 );
        return 0;
      }
    };



    template< int dim >
    inline int applyTwist ( int twist, int i )
    {
      const int numCorners = NumSubEntities< dim, dim >::value;
      return (twist < 0 ? (2*numCorners + 1 - i + twist) : i + twist) % numCorners;
    }

    template< int dim >
    inline int applyInverseTwist ( int twist, int i )
    {
      const int numCorners = NumSubEntities< dim, dim >::value;
      return (twist < 0 ? (2*numCorners + 1 - i + twist) : numCorners + i - twist) % numCorners;
    }

  }

}

#endif // #if HAVE_ALBERTA

#endif // #ifndef DUNE_ALBERTA_MISC_HH