DUNE-FEM (unstable)

nonconformitylevel.hh
1#ifndef DUNE_FEM_NONCONFORMITYLEVEL_HH
2#define DUNE_FEM_NONCONFORMITYLEVEL_HH
3
4#include <cassert>
5#include <cstdlib>
6#include <iostream>
7
9
10namespace Dune
11{
12
13 namespace Fem
14 {
15
22 template <class GridPartType>
23 static inline void
24 makeNonConformity(GridPartType& gridPart,
25 const int levelDifference,
26 const bool verbose = false)
27 {
28 // measure time
29 Dune::Timer timer;
30
31 // type of our standard grid iterator
32 typedef typename GridPartType :: GridType GridType;
33 typedef typename GridPartType :: template Codim<0>::IteratorType IteratorType;
34 typedef typename GridPartType :: GridType :: template Codim<0>:: Entity EntityType;
35 typedef typename GridPartType :: IntersectionIteratorType IntersectionIteratorType;
36
37 // end iterator
38 const IteratorType endit = gridPart.template end<0> ();
39
40 // grid reference
41 GridType& grid = gridPart.grid();
42
43 // get number of elements
44 const int gridsize = gridPart.indexSet().size(0);
45
46 // allowed level difference
47 const int levelAllowed = levelDifference - 1;
48
49 // make non-conformity only of levelDifferenc
50 bool finished = false;
51 int count = 0;
52 while ( ! finished )
53 {
54 finished = true;
55 for(IteratorType it = gridPart.template begin<0>();
56 it != endit; ++it)
57 {
58 // get entity
59 const EntityType & en = *it;
60 // get marker
61 const int enMarker = grid.getMark(en);
62
63#ifndef NDEBUG
64 {
65 // make sure we have only one level difference
66 IntersectionIteratorType endnit = gridPart.iend(en);
67 for(IntersectionIteratorType nit = gridPart.ibegin(en);
68 nit != endnit; ++nit)
69 {
70 const typename IntersectionIteratorType::Intersection &intersec = *nit;
71 // check level difference
72 if(intersec.neighbor())
73 {
74 int diff = std::abs(intersec.outside().level() - en.level());
75 assert( diff <= levelDifference );
76 if( diff > levelDifference )
77 {
78 std::cerr << "makeNonConformity: " << diff << " level difference to large! \n";
79 abort();
80 }
81 }
82 }
83 }
84#endif
85
86 // if entity will be refined, check nothing
87 if( enMarker > 0 ) continue;
88
89 // make sure we have only one level difference
90 IntersectionIteratorType endnit = gridPart.iend(en);
91 for(IntersectionIteratorType nit = gridPart.ibegin(en);
92 nit != endnit; ++nit)
93 {
94 const typename IntersectionIteratorType::Intersection &intersec = *nit;
95 if(intersec.neighbor())
96 {
97 assert( enMarker <= 0 );
98 EntityType nb = intersec.outside();
99 const int nbMarker = grid.getMark(nb);
100 const int levelDiff = nb.level() - en.level();
101
102 // if level difference and refine on neighbor also refine here
103 if(levelDiff > levelAllowed)
104 {
105 // get new marker
106 const int newMarker = std::max(enMarker,std::max(nbMarker,0));
107 // check whether we have to iterate once more
108 finished = (enMarker == newMarker) ? finished : false;
109 // mark entity with new marker
110 grid.mark(newMarker, en);
111
112 // in case of refinement break
113 if( newMarker > 0 ) break;
114 }
115 else if( (levelDiff == 0) && (nbMarker > 0) )
116 {
117 // get new marker
118 const int newMarker = std::max(enMarker,0);
119 // check whether we have to iterate once more
120 finished = (enMarker == newMarker) ? finished : false;
121 // mark entity with new marker
122 grid.mark(newMarker, en);
123
124 // in case of refinement break
125 if( newMarker > 0 ) break;
126 }
127 }
128
129 } // end intersections
130 } // end element loop
131
132 ++count;
133 if(count > gridsize)
134 {
135 std::cerr << "makeNonConformity: Break Adaptation loop because not terminating! \n";
136 break;
137 }
138 } // end while
139
140 // output time if verbosity mode
141 if(verbose)
142 {
143 std::cout << "Making non-conformity level took ";
144 std::cout << timer.elapsed() << " seconds. \n";
145 }
146 } // makeNonConformity
147
148 } // namespace Fem
149
150} // namespace Dune
151
152#endif // #ifndef DUNE_FEM_NONCONFORMITYLEVEL_HH
A simple stop watch.
Definition: timer.hh:43
double elapsed() const noexcept
Get elapsed user-time from last reset until now/last stop in seconds.
Definition: timer.hh:77
Dune namespace.
Definition: alignedallocator.hh:13
A simple timing class.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)