~ubuntu-branches/ubuntu/trusty/rheolef/trusty

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
///
/// This file is part of Rheolef.
///
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
///
/// Rheolef is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// Rheolef is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Rheolef; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
///
/// =========================================================================
#include "P2_numbering.h"
namespace rheolef {
using namespace std;

/* For mopre info: Dhatt et Touzot 2eme ed p110 
 * WARNING:
 * The node numbering correspond to the basis numbering.
 * The node numbering convention is different from Dhatt et Touzot:
 * we use P. L. Georges et H. Borouchaki
 *        "Triangulation de Delaunay et maillages",
 *        Hermes, 1997
 *   - first the vertices
 *   - then the middle of the edges
 *
 * WARNING2: the transformation is still linear
 */

/*
 * global numbering statement: uses symbolic values (do not uses as variable !):
 *
 *    K_idx                 : the current element index in the mesh
 *    K.face(i)             : the i-th element face index in the mesh
 *    K.edge(i)             : the i-th element edge index in the mesh
 *    K[i]                  : the i-th element vertice index in the mesh
 *    mesh_n_geo (dim)      : total number of vertices(dim=0), edges(1), faces(2), volume(3)
 *                            in the mesh
 *    mesh_n_element (type) : total number of element of type 'p', 't', 'q', 'T', 'P', 'H'
 *                            in the mesh
 */
std::string
numbering_P2::name() const
{
  return "P2";
}
numbering_P2::size_type
numbering_P2::idof (
	const size_type*      mesh_n_geo,
	const size_type*      mesh_n_element,
	const geo_element&    K,
	size_type             loc_idof) const
{
        // all vertices-based dof are numbered first
        // then all edge-based dof
        // and then all dof based on interior nodes (e.g. quadrangles)

	// for mixed triangle-quadrangle mesh : assume triangle are numbered first
        switch (K.variant()) {
	  case reference_element::p: 
            return K.index();
	  case reference_element::e: 
            if (loc_idof < 2) {
              return K [loc_idof];
            } else {
              return mesh_n_geo[0] + K.index();
            }
	  case reference_element::t: {
            if (loc_idof < 3) {
              return K [loc_idof];
            }
            size_type nv = mesh_n_geo[0];
	    size_type loc_iedg = loc_idof - 3;
            size_type iedg = K.edge(loc_iedg);
            return nv + iedg;
          }
	  case reference_element::q: {
            if (loc_idof < 4) {
              return K [loc_idof];
            } 
            if (loc_idof < 8) {
              return mesh_n_geo[0] + K.edge(loc_idof - 4);
            }
	    size_type iqua = K.index() - mesh_n_element[reference_element::t];
            return mesh_n_geo[0] + mesh_n_geo[1] + iqua;
          }
	  case reference_element::T: 
            if (loc_idof < 4) {
              return K [loc_idof];
            } else {
              return mesh_n_geo[0] + K.edge(loc_idof - 4);
            }
	  case reference_element::P: {
            if (loc_idof < 6) { // 6 vertex dofs
              return K [loc_idof];
            }
            size_type nv = mesh_n_geo[0];
            if (loc_idof < 6+9) { // 9 edge face dofs
              return nv + K.edge(loc_idof - 6);
            } 
            // 3 quad face dofs
            size_type nedg = mesh_n_geo[1];
            size_type ntri = mesh_n_element[reference_element::t];
	    size_type iqua = K.face(loc_idof - 6 - 9) - ntri;
            return nv + nedg + iqua;
          }
	  case reference_element::H: {
            if (loc_idof < 8) { // 8 vertex dofs
              return K [loc_idof];
            } 
            size_type nv = mesh_n_geo[0];
            if (loc_idof < 8+12) { // 12 edge face dofs
              return nv + K.edge(loc_idof - 8);
            } 
            size_type nedg = mesh_n_geo[1];
            size_type ntri = mesh_n_element[reference_element::t];
            if (loc_idof < 8+12+6) { // 6 face dofs
	      size_type iqua = K.face(loc_idof - 8 - 12) - ntri;
              return nv + nedg + iqua;
            } 
            // else: 1 volume dof
	    assert_macro (loc_idof < 27, "invalid loc_idof="<<loc_idof);
	    size_type nqua = mesh_n_element[reference_element::q];
	    size_type ntet = mesh_n_element[reference_element::T];
	    size_type npri = mesh_n_element[reference_element::P];
	    size_type ihex = K.index() - ntet - npri;
            return nv + nedg + nqua + ihex;
          }
	  default:
	    error_macro ("unsupported P2 element on `" << K.name() << "'");
	    return 0;
    	}
}
void
numbering_P2::idof (
	const size_type*      mesh_n_geo,
	const size_type*      mesh_n_element,
	const geo_element&    K, 
	vector<size_type>&    idof) const
{
  for (size_type loc_idof = 0; loc_idof < K.size(); loc_idof++)
    idof[loc_idof] 
     = numbering_P2::idof (mesh_n_geo, mesh_n_element, K, loc_idof);
}
numbering_P2::size_type
numbering_P2::ndof (
              size_type  mesh_map_dimension,
        const size_type* mesh_n_geo,
        const size_type* mesh_n_element) const
{
    switch (mesh_map_dimension) {
      case 0:
	return mesh_n_geo[0];
      case 1:
	return mesh_n_geo[0] + mesh_n_geo[1];
      case 2:
        // number of vertices + nb of edges in the mesh
	// + number of quadrangle (extra interior node)
	return mesh_n_geo[0]
	  + mesh_n_geo[1]
	  + mesh_n_element[reference_element::q];
      case 3: {
        // number of vertices + nb of edges in the mesh
	// + number of quadrangle (extra interior node)
	// + number of hexaedra   (extra interior node)
	return mesh_n_geo[0]
	  + mesh_n_geo[1]
	  + mesh_n_element[reference_element::q]
	  + mesh_n_element[reference_element::H];
      }
      default:
	fatal_macro ("unsupported P2 approximation in `" << mesh_map_dimension << "'");
	return 0;
    }
}
bool
numbering_P2::is_continuous () const
{
  	return true;
}

} // namespace rheolef