File: referenceelementimplementation.cc

package info (click to toggle)
dune-geometry 2.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 2,304 kB
  • sloc: cpp: 15,221; python: 253; makefile: 3
file content (192 lines) | stat: -rw-r--r-- 6,720 bytes parent folder | download | duplicates (2)
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
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception

#include <dune/geometry/referenceelementimplementation.hh>

namespace Dune
{

  namespace Geo
  {

    namespace Impl
    {

      // size
      // ----

      unsigned int size ( unsigned int topologyId, int dim, int codim )
      {
        assert( (dim >= 0) && (topologyId < numTopologies( dim )) );
        assert( (0 <= codim) && (codim <= dim) );

        if( codim > 0 )
          {
            const unsigned int baseId = baseTopologyId( topologyId, dim );
            const unsigned int m = size( baseId, dim-1, codim-1 );

            if( isPrism( topologyId, dim ) )
              {
                const unsigned int n = (codim < dim ? size( baseId, dim-1, codim ) : 0);
                return n + 2*m;
              }
            else
              {
                assert( isPyramid( topologyId, dim ) );
                const unsigned int n = (codim < dim ? size( baseId, dim-1, codim ) : 1);
                return m+n;
              }
          }
        else
          return 1;
      }



      // subTopologyId
      // -------------

      unsigned int subTopologyId ( unsigned int topologyId, int dim, int codim, unsigned int i )
      {
        assert( i < size( topologyId, dim, codim ) );
        const int mydim = dim - codim;

        if( codim > 0 )
          {
            const unsigned int baseId = baseTopologyId( topologyId, dim );
            const unsigned int m = size( baseId, dim-1, codim-1 );

            if( isPrism( topologyId, dim ) )
              {
                const unsigned int n = (codim < dim ? size( baseId, dim-1, codim ) : 0);
                if( i < n )
                  return subTopologyId( baseId, dim-1, codim, i ) | ((unsigned int)prismConstruction << (mydim - 1));
                else
                  return subTopologyId( baseId, dim-1, codim-1, (i < n+m ? i-n : i-(n+m)) );
              }
            else
              {
                assert( isPyramid( topologyId, dim ) );
                if( i < m )
                  return subTopologyId( baseId, dim-1, codim-1, i );
                else if( codim < dim )
                  return subTopologyId( baseId, dim-1, codim, i-m ) | ((unsigned int)pyramidConstruction << (mydim - 1));
                else
                  return 0u;
              }
          }
        else
          return topologyId;
      }



      // subTopologyNumbering
      // --------------------

      void subTopologyNumbering ( unsigned int topologyId, int dim, int codim, unsigned int i, int subcodim,
                                  unsigned int *beginOut, unsigned int *endOut )
      {
        assert( (codim >= 0) && (subcodim >= 0) && (codim + subcodim <= dim) );
        assert( i < size( topologyId, dim, codim ) );
        assert( (endOut - beginOut) == size( subTopologyId( topologyId, dim, codim, i ), dim-codim, subcodim ) );

        if( codim == 0 )
          {
            for( unsigned int j = 0; (beginOut + j) != endOut; ++j )
              *(beginOut + j) = j;
          }
        else if( subcodim == 0 )
          {
            assert( endOut == beginOut + 1 );
            *beginOut = i;
          }
        else
          {
            const unsigned int baseId = baseTopologyId( topologyId, dim );

            const unsigned int m = size( baseId, dim-1, codim-1 );

            const unsigned int mb = size( baseId, dim-1, codim+subcodim-1 );
            const unsigned int nb = (codim + subcodim < dim ? size( baseId, dim-1, codim+subcodim ) : 0);

            if( isPrism( topologyId, dim ) )
              {
                const unsigned int n = size( baseId, dim-1, codim );
                if( i < n )
                  {
                    const unsigned int subId = subTopologyId( baseId, dim-1, codim, i );

                    unsigned int *beginBase = beginOut;
                    if( codim + subcodim < dim )
                      {
                        beginBase = beginOut + size( subId, dim-codim-1, subcodim );
                        subTopologyNumbering( baseId, dim-1, codim, i, subcodim, beginOut, beginBase );
                      }

                    const unsigned int ms = size( subId, dim-codim-1, subcodim-1 );
                    subTopologyNumbering( baseId, dim-1, codim, i, subcodim-1, beginBase, beginBase+ms );
                    for( unsigned int j = 0; j < ms; ++j )
                      {
                        *(beginBase+j) += nb;
                        *(beginBase+j+ms) = *(beginBase+j) + mb;
                      }
                  }
                else
                  {
                    const unsigned int s = (i < n+m ? 0 : 1);
                    subTopologyNumbering( baseId, dim-1, codim-1, i-(n+s*m), subcodim, beginOut, endOut );
                    for( unsigned int *it = beginOut; it != endOut; ++it )
                      *it += nb + s*mb;
                  }
              }
            else
              {
                assert( isPyramid( topologyId, dim ) );

                if( i < m )
                  subTopologyNumbering( baseId, dim-1, codim-1, i, subcodim, beginOut, endOut );
                else
                  {
                    const unsigned int subId = subTopologyId( baseId, dim-1, codim, i-m );
                    const unsigned int ms = size( subId, dim-codim-1, subcodim-1 );

                    subTopologyNumbering( baseId, dim-1, codim, i-m, subcodim-1, beginOut, beginOut+ms );
                    if( codim+subcodim < dim )
                      {
                        subTopologyNumbering( baseId, dim-1, codim, i-m, subcodim, beginOut+ms, endOut );
                        for( unsigned int *it = beginOut + ms; it != endOut; ++it )
                          *it += mb;
                      }
                    else
                      *(beginOut + ms) = mb;
                  }
              }
          }
      }



      // ReferenceVolumeInverse
      // ----------------------

      unsigned long referenceVolumeInverse ( unsigned int topologyId, int dim )
      {
        assert( (dim >= 0) && (topologyId < numTopologies( dim )) );

        if( dim > 0 )
          {
            unsigned int baseValue = referenceVolumeInverse( baseTopologyId( topologyId, dim ), dim-1 );
            return (isPrism( topologyId, dim ) ? baseValue : baseValue * (unsigned long)dim);
          }
        else
          return 1;
      }

    } // namespace Impl

  } // namespace Geo

} // namespace Dune