This file is indexed.

/usr/include/dune/grid/test/checkadaptation.cc 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
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_CHECK_ADAPTATION_CC
#define DUNE_CHECK_ADAPTATION_CC

#include <dune/common/typetraits.hh>
#include <dune/common/exceptions.hh>
#include <dune/grid/common/capabilities.hh>

/** \file
    \brief A test for the Adaptation interface
 */

template <class GridType>
void markForAdaptation(GridType& grid, const int marker )
{
  using namespace Dune;

  // Loop over all levels except the lowest one
  for (int level = 0; level <= grid.maxLevel(); ++level)
  {
    typedef typename GridType::template Codim<0>::LevelIterator ElementIterator;
    typedef typename ElementIterator :: Entity EntityType ;

    const ElementIterator eEndIt = grid.template lend<0>( level );
    for (ElementIterator it = grid.template lbegin<0>( level );
         it != eEndIt; ++it )
    {
      const EntityType& entity = *it ;

      // marking should only be possible on leaf entities
      const bool marked = grid.mark(marker, entity );

      if( marker < 0 && entity.level() == 0 )
      {
        if( marked )
        {
          DUNE_THROW(InvalidStateException,"Macro entity was marked for coarsening");
        }
      }
      else
      {
        if( ! entity.isLeaf() && marked == true )
        {
          DUNE_THROW(InvalidStateException,"Non-leaf entity was marked");
        }

        if( entity.isLeaf() && marked == false )
        {
          DUNE_THROW(InvalidStateException,"Leaf entity could not be marked");
        }
      }
    }
  }
}

template <class EntityType>
void checkHierarchy(const EntityType& entity)
{
  using namespace Dune;

  if( ! entity.isLeaf() )
  {
    // only leaf entities can vanish
    if( entity.mightVanish() )
    {
      DUNE_THROW(InvalidStateException,"Non-leaf entity marked might vanish");
    }

    const int level = entity.level() + 1 ;

    typedef typename EntityType :: HierarchicIterator HierarchicIterator;
    const HierarchicIterator end = entity.hend( level );
    for(HierarchicIterator it = entity.hbegin( level ); it != end; ++it)
    {
      checkHierarchy( *it );
    }
  }
  else
  {
    if( entity.level() == 0 )
    {
      if( entity.mightVanish() )
        DUNE_THROW(InvalidStateException,"entity.mightVanish() returns true for macro element");
    }
    else
    {
      // on level 0 this should be false
      if( ! entity.mightVanish() )
      {
        DUNE_THROW(InvalidStateException,"entity.mightVanish() returns wrong result");
      }
    }
  }
}

template <class GridType>
void checkAdaptRefinement(GridType& grid, const bool greenClosure = false )
{
  using namespace Dune;

  // skip empty grids
  if( grid.template lbegin<0>( 0 ) == grid.template lend<0>( 0 ) ) return ;

  // some things are different for bisection grids
  const bool bisectionGrid =
    Capabilities::isLevelwiseConforming<GridType> :: v  == false &&
    Capabilities::isLeafwiseConforming<GridType>  :: v  == true ;

  for(int i=0; i<2; ++i)
  {
    const int oldMaxLevel = grid.maxLevel();

    // mark all leaf entities for refinement
    markForAdaptation( grid , 1 );

    bool markedCoarsen = grid.preAdapt();
    if( markedCoarsen != greenClosure )
    {
      DUNE_THROW(InvalidStateException,"grid.preAdapt() does not return correct information");
    }

    bool refined = grid.adapt() ;
    if( ! refined )
    {
      DUNE_THROW(InvalidStateException,"grid.adapt() returns wrong information");
    }

    /// check new max level
    if( grid.maxLevel () <= oldMaxLevel )
    {
      DUNE_THROW(InvalidStateException,"grid.maxLevel() wrong after refinement " << oldMaxLevel << " " << grid.maxLevel() );
    }

    // Loop over all levels except the lowest one
    for (int level = 0 ; level <= grid.maxLevel(); ++level )
    {
      typedef typename GridType::template Codim<0>::LevelIterator ElementIterator;
      typedef typename ElementIterator :: Entity EntityType ;
      ElementIterator eEndIt = grid.template lend<0>( level );

      for (ElementIterator it = grid.template lbegin<0>( level );
           it != eEndIt; ++ it)
      {
        const EntityType& entity = *it ;

        // this check fails on biscetion grids
        if( ! bisectionGrid )
        {
          if( entity.isLeaf () != entity.isNew () )
          {
            DUNE_THROW(InvalidStateException,"isNew information on entity gives wrong result");
          }
        }
        else  // at least all leafs have to be new
        {
          if( entity.isLeaf () && ! entity.isNew () )
          {
            DUNE_THROW(InvalidStateException,"isNew information on entity gives wrong result");
          }
        }
      }
    }

    grid.postAdapt();

    // Loop over all levels except the lowest one
    for (int level = 0 ; level <= grid.maxLevel(); ++level )
    {
      typedef typename GridType::template Codim<0>::LevelIterator ElementIterator;
      ElementIterator eEndIt = grid.template lend<0>( level );

      for (ElementIterator it = grid.template lbegin<0>( level );
           it != eEndIt; ++ it)
      {
        if( it->isNew () )
        {
          DUNE_THROW(InvalidStateException,"After postAdapt() was called no entity is new, i.e., isNew() == false");
        }
      }
    }
  }
}

template <class GridType>
void checkAdaptation(GridType& grid, const bool greenClosure = false )
{
  using namespace Dune;

  // skip empty grids
  if( grid.template lbegin<0>( 0 ) == grid.template lend<0>( 0 ) ) return ;

  // save start level
  const int startLevel = grid.maxLevel();
  // save start grid size
  const int startSize  = grid.size( 0 );

  // some things are different for bisection grids
  const bool bisectionGrid =
    Capabilities::isLevelwiseConforming<GridType> :: v  == false &&
    Capabilities::isLeafwiseConforming<GridType>  :: v  == true ;

  /*
     run the refinement check
   */
  checkAdaptRefinement(grid, greenClosure);

  /*
     run coarsening check
   */
  int counter = 0;
  const int counterEstimate = (grid.maxLevel() - startLevel) * 10;
  // now the same with coarsening
  while ( grid.maxLevel() > startLevel )
  {
    const int oldMaxLevel = grid.maxLevel();

    // mark all leaf entities for coarsening
    markForAdaptation( grid , -1 );

    bool markedCoarsen = grid.preAdapt();
    if( markedCoarsen == false )
    {
      DUNE_THROW(InvalidStateException,"grid.preAdapt() does not return correct information");
    }

    // check mightVanish
    typedef typename GridType::template Codim<0>::LevelIterator ElementIterator;
    ElementIterator eEndIt = grid.template lend<0>( 0 );

    for (ElementIterator it = grid.template lbegin<0>( 0 );
         it != eEndIt; ++ it)
    {
      checkHierarchy( *it );
    }

    // only marked for coarsening ==> refined = false
    bool refined = grid.adapt() ;
    if( refined )
    {
      DUNE_THROW(InvalidStateException,"grid.adapt() returns wrong information");
    }

    /// check new max level
    if( grid.maxLevel () >= oldMaxLevel )
    {
      if( ! bisectionGrid )
        DUNE_THROW(InvalidStateException,"grid.maxLevel() wrong after coarsening " << oldMaxLevel << " " << grid.maxLevel() );
    }

    // Loop over all levels except the lowest one
    for (int level = 0 ; level <= grid.maxLevel(); ++level )
    {
      typedef typename GridType::template Codim<0>::LevelIterator ElementIterator;
      ElementIterator eEndIt = grid.template lend<0>( level );

      for (ElementIterator it = grid.template lbegin<0>( level );
           it != eEndIt; ++ it)
      {
        if( it->isNew () )
        {
          DUNE_THROW(InvalidStateException,"After postAdapt() was called no entity is new, i.e., isNew() == false");
        }
      }
    }

    grid.postAdapt();

    // Loop over all levels except the lowest one
    for (int level = 0 ; level <= grid.maxLevel(); ++level )
    {
      typedef typename GridType::template Codim<0>::LevelIterator ElementIterator;
      ElementIterator eEndIt = grid.template lend<0>( level );

      for (ElementIterator it = grid.template lbegin<0>( level );
           it != eEndIt; ++ it)
      {
        if( it->isNew () )
        {
          DUNE_THROW(InvalidStateException,"After postAdapt() was called no entity is new, i.e., isNew() == false");
        }
        if( it->mightVanish() )
        {
          DUNE_THROW(InvalidStateException,"After postAdapt() was called no entity might vanish, i.e., mightVanish() == false");
        }
      }
    }

    ++counter;
    if( counter > counterEstimate )
      DUNE_THROW(InvalidStateException,"Coarsening does not get back to startLevel");
  }

  const int newSize = grid.size( 0 );
  if( startSize != newSize )
  {
    dwarn << "After coarsening a different number of elements is obtained! old = "
          << startSize << "  new = " << newSize << std::endl;
  }

  if( startLevel != grid.maxLevel() )
  {
    dwarn << "After coarsening a different maxLevel is obtained! old = "
          << startLevel << "  new = " << grid.maxLevel() << std::endl;
  }
}

#endif