~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/kernel/elements/ffc_03.h

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// This code conforms with the UFC specification version 1.0
2
 
// and was automatically generated by FFC version 0.4.3.
3
 
 
4
 
#ifndef __FFC_03_H
5
 
#define __FFC_03_H
6
 
 
7
 
#include <cmath>
8
 
#include <stdexcept>
9
 
#include <ufc.h>
10
 
 
11
 
/// This class defines the interface for a finite element.
12
 
 
13
 
class ffc_03_finite_element_0: public ufc::finite_element
14
 
{
15
 
public:
16
 
 
17
 
  /// Constructor
18
 
  ffc_03_finite_element_0() : ufc::finite_element()
19
 
  {
20
 
    // Do nothing
21
 
  }
22
 
 
23
 
  /// Destructor
24
 
  virtual ~ffc_03_finite_element_0()
25
 
  {
26
 
    // Do nothing
27
 
  }
28
 
 
29
 
  /// Return a string identifying the finite element
30
 
  virtual const char* signature() const
31
 
  {
32
 
    return "Lagrange finite element of degree 1 on a tetrahedron";
33
 
  }
34
 
 
35
 
  /// Return the cell shape
36
 
  virtual ufc::shape cell_shape() const
37
 
  {
38
 
    return ufc::tetrahedron;
39
 
  }
40
 
 
41
 
  /// Return the dimension of the finite element function space
42
 
  virtual unsigned int space_dimension() const
43
 
  {
44
 
    return 4;
45
 
  }
46
 
 
47
 
  /// Return the rank of the value space
48
 
  virtual unsigned int value_rank() const
49
 
  {
50
 
    return 0;
51
 
  }
52
 
 
53
 
  /// Return the dimension of the value space for axis i
54
 
  virtual unsigned int value_dimension(unsigned int i) const
55
 
  {
56
 
    return 1;
57
 
  }
58
 
 
59
 
  /// Evaluate basis function i at given point in cell
60
 
  virtual void evaluate_basis(unsigned int i,
61
 
                              double* values,
62
 
                              const double* coordinates,
63
 
                              const ufc::cell& c) const
64
 
  {
65
 
    // Extract vertex coordinates
66
 
    const double * const * element_coordinates = c.coordinates;
67
 
    
68
 
    // Compute Jacobian of affine map from reference cell
69
 
    const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
70
 
    const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
71
 
    const double J_02 = element_coordinates[3][0] - element_coordinates[0][0];
72
 
    const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
73
 
    const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
74
 
    const double J_12 = element_coordinates[3][1] - element_coordinates[0][1];
75
 
    const double J_20 = element_coordinates[1][2] - element_coordinates[0][2];
76
 
    const double J_21 = element_coordinates[2][2] - element_coordinates[0][2];
77
 
    const double J_22 = element_coordinates[3][2] - element_coordinates[0][2];
78
 
      
79
 
    // Compute sub determinants
80
 
    const double d00 = J_11*J_22 - J_12*J_21;
81
 
    const double d01 = J_12*J_20 - J_10*J_22;
82
 
    const double d02 = J_10*J_21 - J_11*J_20;
83
 
    
84
 
    const double d10 = J_02*J_21 - J_01*J_22;
85
 
    const double d11 = J_00*J_22 - J_02*J_20;
86
 
    const double d12 = J_01*J_20 - J_00*J_21;
87
 
    
88
 
    const double d20 = J_01*J_12 - J_02*J_11;
89
 
    const double d21 = J_02*J_10 - J_00*J_12;
90
 
    const double d22 = J_00*J_11 - J_01*J_10;
91
 
      
92
 
    // Compute determinant of Jacobian
93
 
    double detJ = J_00*d00 + J_10*d10 + J_20*d20;
94
 
    
95
 
    // Compute inverse of Jacobian
96
 
    
97
 
    // Compute constants
98
 
    const double C0 = d00*(element_coordinates[0][0] - element_coordinates[2][0] - element_coordinates[3][0]) \
99
 
                    + d10*(element_coordinates[0][1] - element_coordinates[2][1] - element_coordinates[3][1]) \
100
 
                    + d20*(element_coordinates[0][2] - element_coordinates[2][2] - element_coordinates[3][2]);
101
 
    
102
 
    const double C1 = d01*(element_coordinates[0][0] - element_coordinates[1][0] - element_coordinates[3][0]) \
103
 
                    + d11*(element_coordinates[0][1] - element_coordinates[1][1] - element_coordinates[3][1]) \
104
 
                    + d21*(element_coordinates[0][2] - element_coordinates[1][2] - element_coordinates[3][2]);
105
 
    
106
 
    const double C2 = d02*(element_coordinates[0][0] - element_coordinates[1][0] - element_coordinates[2][0]) \
107
 
                    + d12*(element_coordinates[0][1] - element_coordinates[1][1] - element_coordinates[2][1]) \
108
 
                    + d22*(element_coordinates[0][2] - element_coordinates[1][2] - element_coordinates[2][2]);
109
 
    
110
 
    // Get coordinates and map to the UFC reference element
111
 
    double x = (C0 + d00*coordinates[0] + d10*coordinates[1] + d20*coordinates[2]) / detJ;
112
 
    double y = (C1 + d01*coordinates[0] + d11*coordinates[1] + d21*coordinates[2]) / detJ;
113
 
    double z = (C2 + d02*coordinates[0] + d12*coordinates[1] + d22*coordinates[2]) / detJ;
114
 
    
115
 
    // Map coordinates to the reference cube
116
 
    if (std::abs(y + z - 1.0) < 1e-14)
117
 
      x = 1.0;
118
 
    else
119
 
      x = -2.0 * x/(y + z - 1.0) - 1.0;
120
 
    if (std::abs(z - 1.0) < 1e-14)
121
 
      y = -1.0;
122
 
    else
123
 
      y = 2.0 * y/(1.0 - z) - 1.0;
124
 
    z = 2.0 * z - 1.0;
125
 
    
126
 
    // Reset values
127
 
    *values = 0;
128
 
    
129
 
    // Map degree of freedom to element degree of freedom
130
 
    const unsigned int dof = i;
131
 
    
132
 
    // Generate scalings
133
 
    const double scalings_y_0 = 1;
134
 
    const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
135
 
    const double scalings_z_0 = 1;
136
 
    const double scalings_z_1 = scalings_z_0*(0.5 - 0.5*z);
137
 
    
138
 
    // Compute psitilde_a
139
 
    const double psitilde_a_0 = 1;
140
 
    const double psitilde_a_1 = x;
141
 
    
142
 
    // Compute psitilde_bs
143
 
    const double psitilde_bs_0_0 = 1;
144
 
    const double psitilde_bs_0_1 = 1.5*y + 0.5;
145
 
    const double psitilde_bs_1_0 = 1;
146
 
    
147
 
    // Compute psitilde_cs
148
 
    const double psitilde_cs_00_0 = 1;
149
 
    const double psitilde_cs_00_1 = 2*z + 1;
150
 
    const double psitilde_cs_01_0 = 1;
151
 
    const double psitilde_cs_10_0 = 1;
152
 
    
153
 
    // Compute basisvalues
154
 
    const double basisvalue0 = 0.866025403784439*psitilde_a_0*scalings_y_0*psitilde_bs_0_0*scalings_z_0*psitilde_cs_00_0;
155
 
    const double basisvalue1 = 2.73861278752583*psitilde_a_1*scalings_y_1*psitilde_bs_1_0*scalings_z_1*psitilde_cs_10_0;
156
 
    const double basisvalue2 = 1.58113883008419*psitilde_a_0*scalings_y_0*psitilde_bs_0_1*scalings_z_1*psitilde_cs_01_0;
157
 
    const double basisvalue3 = 1.11803398874989*psitilde_a_0*scalings_y_0*psitilde_bs_0_0*scalings_z_0*psitilde_cs_00_1;
158
 
    
159
 
    // Table(s) of coefficients
160
 
    const static double coefficients0[4][4] = \
161
 
    {{0.288675134594813, -0.182574185835055, -0.105409255338946, -0.074535599249993},
162
 
    {0.288675134594813, 0.182574185835055, -0.105409255338946, -0.074535599249993},
163
 
    {0.288675134594813, 0, 0.210818510677892, -0.074535599249993},
164
 
    {0.288675134594813, 0, 0, 0.223606797749979}};
165
 
    
166
 
    // Extract relevant coefficients
167
 
    const double coeff0_0 = coefficients0[dof][0];
168
 
    const double coeff0_1 = coefficients0[dof][1];
169
 
    const double coeff0_2 = coefficients0[dof][2];
170
 
    const double coeff0_3 = coefficients0[dof][3];
171
 
    
172
 
    // Compute value(s)
173
 
    *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2 + coeff0_3*basisvalue3;
174
 
  }
175
 
 
176
 
  /// Evaluate all basis functions at given point in cell
177
 
  virtual void evaluate_basis_all(double* values,
178
 
                                  const double* coordinates,
179
 
                                  const ufc::cell& c) const
180
 
  {
181
 
    throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
182
 
  }
183
 
 
184
 
  /// Evaluate order n derivatives of basis function i at given point in cell
185
 
  virtual void evaluate_basis_derivatives(unsigned int i,
186
 
                                          unsigned int n,
187
 
                                          double* values,
188
 
                                          const double* coordinates,
189
 
                                          const ufc::cell& c) const
190
 
  {
191
 
    // Extract vertex coordinates
192
 
    const double * const * element_coordinates = c.coordinates;
193
 
    
194
 
    // Compute Jacobian of affine map from reference cell
195
 
    const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
196
 
    const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
197
 
    const double J_02 = element_coordinates[3][0] - element_coordinates[0][0];
198
 
    const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
199
 
    const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
200
 
    const double J_12 = element_coordinates[3][1] - element_coordinates[0][1];
201
 
    const double J_20 = element_coordinates[1][2] - element_coordinates[0][2];
202
 
    const double J_21 = element_coordinates[2][2] - element_coordinates[0][2];
203
 
    const double J_22 = element_coordinates[3][2] - element_coordinates[0][2];
204
 
      
205
 
    // Compute sub determinants
206
 
    const double d00 = J_11*J_22 - J_12*J_21;
207
 
    const double d01 = J_12*J_20 - J_10*J_22;
208
 
    const double d02 = J_10*J_21 - J_11*J_20;
209
 
    
210
 
    const double d10 = J_02*J_21 - J_01*J_22;
211
 
    const double d11 = J_00*J_22 - J_02*J_20;
212
 
    const double d12 = J_01*J_20 - J_00*J_21;
213
 
    
214
 
    const double d20 = J_01*J_12 - J_02*J_11;
215
 
    const double d21 = J_02*J_10 - J_00*J_12;
216
 
    const double d22 = J_00*J_11 - J_01*J_10;
217
 
      
218
 
    // Compute determinant of Jacobian
219
 
    double detJ = J_00*d00 + J_10*d10 + J_20*d20;
220
 
    
221
 
    // Compute inverse of Jacobian
222
 
    
223
 
    // Compute constants
224
 
    const double C0 = d00*(element_coordinates[0][0] - element_coordinates[2][0] - element_coordinates[3][0]) \
225
 
                    + d10*(element_coordinates[0][1] - element_coordinates[2][1] - element_coordinates[3][1]) \
226
 
                    + d20*(element_coordinates[0][2] - element_coordinates[2][2] - element_coordinates[3][2]);
227
 
    
228
 
    const double C1 = d01*(element_coordinates[0][0] - element_coordinates[1][0] - element_coordinates[3][0]) \
229
 
                    + d11*(element_coordinates[0][1] - element_coordinates[1][1] - element_coordinates[3][1]) \
230
 
                    + d21*(element_coordinates[0][2] - element_coordinates[1][2] - element_coordinates[3][2]);
231
 
    
232
 
    const double C2 = d02*(element_coordinates[0][0] - element_coordinates[1][0] - element_coordinates[2][0]) \
233
 
                    + d12*(element_coordinates[0][1] - element_coordinates[1][1] - element_coordinates[2][1]) \
234
 
                    + d22*(element_coordinates[0][2] - element_coordinates[1][2] - element_coordinates[2][2]);
235
 
    
236
 
    // Get coordinates and map to the UFC reference element
237
 
    double x = (C0 + d00*coordinates[0] + d10*coordinates[1] + d20*coordinates[2]) / detJ;
238
 
    double y = (C1 + d01*coordinates[0] + d11*coordinates[1] + d21*coordinates[2]) / detJ;
239
 
    double z = (C2 + d02*coordinates[0] + d12*coordinates[1] + d22*coordinates[2]) / detJ;
240
 
    
241
 
    // Map coordinates to the reference cube
242
 
    if (std::abs(y + z - 1.0) < 1e-14)
243
 
      x = 1.0;
244
 
    else
245
 
      x = -2.0 * x/(y + z - 1.0) - 1.0;
246
 
    if (std::abs(z - 1.0) < 1e-14)
247
 
      y = -1.0;
248
 
    else
249
 
      y = 2.0 * y/(1.0 - z) - 1.0;
250
 
    z = 2.0 * z - 1.0;
251
 
    
252
 
    // Compute number of derivatives
253
 
    unsigned int num_derivatives = 1;
254
 
    
255
 
    for (unsigned int j = 0; j < n; j++)
256
 
      num_derivatives *= 3;
257
 
    
258
 
    
259
 
    // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
260
 
    unsigned int **combinations = new unsigned int *[num_derivatives];
261
 
        
262
 
    for (unsigned int j = 0; j < num_derivatives; j++)
263
 
    {
264
 
      combinations[j] = new unsigned int [n];
265
 
      for (unsigned int k = 0; k < n; k++)
266
 
        combinations[j][k] = 0;
267
 
    }
268
 
        
269
 
    // Generate combinations of derivatives
270
 
    for (unsigned int row = 1; row < num_derivatives; row++)
271
 
    {
272
 
      for (unsigned int num = 0; num < row; num++)
273
 
      {
274
 
        for (unsigned int col = n-1; col+1 > 0; col--)
275
 
        {
276
 
          if (combinations[row][col] + 1 > 2)
277
 
            combinations[row][col] = 0;
278
 
          else
279
 
          {
280
 
            combinations[row][col] += 1;
281
 
            break;
282
 
          }
283
 
        }
284
 
      }
285
 
    }
286
 
    
287
 
    // Compute inverse of Jacobian
288
 
    const double Jinv[3][3] ={{d00 / detJ, d10 / detJ, d20 / detJ}, {d01 / detJ, d11 / detJ, d21 / detJ}, {d02 / detJ, d12 / detJ, d22 / detJ}};
289
 
    
290
 
    // Declare transformation matrix
291
 
    // Declare pointer to two dimensional array and initialise
292
 
    double **transform = new double *[num_derivatives];
293
 
        
294
 
    for (unsigned int j = 0; j < num_derivatives; j++)
295
 
    {
296
 
      transform[j] = new double [num_derivatives];
297
 
      for (unsigned int k = 0; k < num_derivatives; k++)
298
 
        transform[j][k] = 1;
299
 
    }
300
 
    
301
 
    // Construct transformation matrix
302
 
    for (unsigned int row = 0; row < num_derivatives; row++)
303
 
    {
304
 
      for (unsigned int col = 0; col < num_derivatives; col++)
305
 
      {
306
 
        for (unsigned int k = 0; k < n; k++)
307
 
          transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
308
 
      }
309
 
    }
310
 
    
311
 
    // Reset values
312
 
    for (unsigned int j = 0; j < 1*num_derivatives; j++)
313
 
      values[j] = 0;
314
 
    
315
 
    // Map degree of freedom to element degree of freedom
316
 
    const unsigned int dof = i;
317
 
    
318
 
    // Generate scalings
319
 
    const double scalings_y_0 = 1;
320
 
    const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
321
 
    const double scalings_z_0 = 1;
322
 
    const double scalings_z_1 = scalings_z_0*(0.5 - 0.5*z);
323
 
    
324
 
    // Compute psitilde_a
325
 
    const double psitilde_a_0 = 1;
326
 
    const double psitilde_a_1 = x;
327
 
    
328
 
    // Compute psitilde_bs
329
 
    const double psitilde_bs_0_0 = 1;
330
 
    const double psitilde_bs_0_1 = 1.5*y + 0.5;
331
 
    const double psitilde_bs_1_0 = 1;
332
 
    
333
 
    // Compute psitilde_cs
334
 
    const double psitilde_cs_00_0 = 1;
335
 
    const double psitilde_cs_00_1 = 2*z + 1;
336
 
    const double psitilde_cs_01_0 = 1;
337
 
    const double psitilde_cs_10_0 = 1;
338
 
    
339
 
    // Compute basisvalues
340
 
    const double basisvalue0 = 0.866025403784439*psitilde_a_0*scalings_y_0*psitilde_bs_0_0*scalings_z_0*psitilde_cs_00_0;
341
 
    const double basisvalue1 = 2.73861278752583*psitilde_a_1*scalings_y_1*psitilde_bs_1_0*scalings_z_1*psitilde_cs_10_0;
342
 
    const double basisvalue2 = 1.58113883008419*psitilde_a_0*scalings_y_0*psitilde_bs_0_1*scalings_z_1*psitilde_cs_01_0;
343
 
    const double basisvalue3 = 1.11803398874989*psitilde_a_0*scalings_y_0*psitilde_bs_0_0*scalings_z_0*psitilde_cs_00_1;
344
 
    
345
 
    // Table(s) of coefficients
346
 
    const static double coefficients0[4][4] = \
347
 
    {{0.288675134594813, -0.182574185835055, -0.105409255338946, -0.074535599249993},
348
 
    {0.288675134594813, 0.182574185835055, -0.105409255338946, -0.074535599249993},
349
 
    {0.288675134594813, 0, 0.210818510677892, -0.074535599249993},
350
 
    {0.288675134594813, 0, 0, 0.223606797749979}};
351
 
    
352
 
    // Interesting (new) part
353
 
    // Tables of derivatives of the polynomial base (transpose)
354
 
    const static double dmats0[4][4] = \
355
 
    {{0, 0, 0, 0},
356
 
    {6.32455532033676, 0, 0, 0},
357
 
    {0, 0, 0, 0},
358
 
    {0, 0, 0, 0}};
359
 
    
360
 
    const static double dmats1[4][4] = \
361
 
    {{0, 0, 0, 0},
362
 
    {3.16227766016838, 0, 0, 0},
363
 
    {5.47722557505166, 0, 0, 0},
364
 
    {0, 0, 0, 0}};
365
 
    
366
 
    const static double dmats2[4][4] = \
367
 
    {{0, 0, 0, 0},
368
 
    {3.16227766016838, 0, 0, 0},
369
 
    {1.82574185835055, 0, 0, 0},
370
 
    {5.16397779494322, 0, 0, 0}};
371
 
    
372
 
    // Compute reference derivatives
373
 
    // Declare pointer to array of derivatives on FIAT element
374
 
    double *derivatives = new double [num_derivatives];
375
 
    
376
 
    // Declare coefficients
377
 
    double coeff0_0 = 0;
378
 
    double coeff0_1 = 0;
379
 
    double coeff0_2 = 0;
380
 
    double coeff0_3 = 0;
381
 
    
382
 
    // Declare new coefficients
383
 
    double new_coeff0_0 = 0;
384
 
    double new_coeff0_1 = 0;
385
 
    double new_coeff0_2 = 0;
386
 
    double new_coeff0_3 = 0;
387
 
    
388
 
    // Loop possible derivatives
389
 
    for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
390
 
    {
391
 
      // Get values from coefficients array
392
 
      new_coeff0_0 = coefficients0[dof][0];
393
 
      new_coeff0_1 = coefficients0[dof][1];
394
 
      new_coeff0_2 = coefficients0[dof][2];
395
 
      new_coeff0_3 = coefficients0[dof][3];
396
 
    
397
 
      // Loop derivative order
398
 
      for (unsigned int j = 0; j < n; j++)
399
 
      {
400
 
        // Update old coefficients
401
 
        coeff0_0 = new_coeff0_0;
402
 
        coeff0_1 = new_coeff0_1;
403
 
        coeff0_2 = new_coeff0_2;
404
 
        coeff0_3 = new_coeff0_3;
405
 
    
406
 
        if(combinations[deriv_num][j] == 0)
407
 
        {
408
 
          new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0] + coeff0_3*dmats0[3][0];
409
 
          new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1] + coeff0_3*dmats0[3][1];
410
 
          new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2] + coeff0_3*dmats0[3][2];
411
 
          new_coeff0_3 = coeff0_0*dmats0[0][3] + coeff0_1*dmats0[1][3] + coeff0_2*dmats0[2][3] + coeff0_3*dmats0[3][3];
412
 
        }
413
 
        if(combinations[deriv_num][j] == 1)
414
 
        {
415
 
          new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0] + coeff0_3*dmats1[3][0];
416
 
          new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1] + coeff0_3*dmats1[3][1];
417
 
          new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2] + coeff0_3*dmats1[3][2];
418
 
          new_coeff0_3 = coeff0_0*dmats1[0][3] + coeff0_1*dmats1[1][3] + coeff0_2*dmats1[2][3] + coeff0_3*dmats1[3][3];
419
 
        }
420
 
        if(combinations[deriv_num][j] == 2)
421
 
        {
422
 
          new_coeff0_0 = coeff0_0*dmats2[0][0] + coeff0_1*dmats2[1][0] + coeff0_2*dmats2[2][0] + coeff0_3*dmats2[3][0];
423
 
          new_coeff0_1 = coeff0_0*dmats2[0][1] + coeff0_1*dmats2[1][1] + coeff0_2*dmats2[2][1] + coeff0_3*dmats2[3][1];
424
 
          new_coeff0_2 = coeff0_0*dmats2[0][2] + coeff0_1*dmats2[1][2] + coeff0_2*dmats2[2][2] + coeff0_3*dmats2[3][2];
425
 
          new_coeff0_3 = coeff0_0*dmats2[0][3] + coeff0_1*dmats2[1][3] + coeff0_2*dmats2[2][3] + coeff0_3*dmats2[3][3];
426
 
        }
427
 
    
428
 
      }
429
 
      // Compute derivatives on reference element as dot product of coefficients and basisvalues
430
 
      derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2 + new_coeff0_3*basisvalue3;
431
 
    }
432
 
    
433
 
    // Transform derivatives back to physical element
434
 
    for (unsigned int row = 0; row < num_derivatives; row++)
435
 
    {
436
 
      for (unsigned int col = 0; col < num_derivatives; col++)
437
 
      {
438
 
        values[row] += transform[row][col]*derivatives[col];
439
 
      }
440
 
    }
441
 
    // Delete pointer to array of derivatives on FIAT element
442
 
    delete [] derivatives;
443
 
    
444
 
    // Delete pointer to array of combinations of derivatives and transform
445
 
    for (unsigned int row = 0; row < num_derivatives; row++)
446
 
    {
447
 
      delete [] combinations[row];
448
 
      delete [] transform[row];
449
 
    }
450
 
    
451
 
    delete [] combinations;
452
 
    delete [] transform;
453
 
  }
454
 
 
455
 
  /// Evaluate order n derivatives of all basis functions at given point in cell
456
 
  virtual void evaluate_basis_derivatives_all(unsigned int n,
457
 
                                              double* values,
458
 
                                              const double* coordinates,
459
 
                                              const ufc::cell& c) const
460
 
  {
461
 
    throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
462
 
  }
463
 
 
464
 
  /// Evaluate linear functional for dof i on the function f
465
 
  virtual double evaluate_dof(unsigned int i,
466
 
                              const ufc::function& f,
467
 
                              const ufc::cell& c) const
468
 
  {
469
 
    // The reference points, direction and weights:
470
 
    const static double X[4][1][3] = {{{0, 0, 0}}, {{1, 0, 0}}, {{0, 1, 0}}, {{0, 0, 1}}};
471
 
    const static double W[4][1] = {{1}, {1}, {1}, {1}};
472
 
    const static double D[4][1][1] = {{{1}}, {{1}}, {{1}}, {{1}}};
473
 
    
474
 
    const double * const * x = c.coordinates;
475
 
    double result = 0.0;
476
 
    // Iterate over the points:
477
 
    // Evaluate basis functions for affine mapping
478
 
    const double w0 = 1.0 - X[i][0][0] - X[i][0][1] - X[i][0][2];
479
 
    const double w1 = X[i][0][0];
480
 
    const double w2 = X[i][0][1];
481
 
    const double w3 = X[i][0][2];
482
 
    
483
 
    // Compute affine mapping y = F(X)
484
 
    double y[3];
485
 
    y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0] + w3*x[3][0];
486
 
    y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1] + w3*x[3][1];
487
 
    y[2] = w0*x[0][2] + w1*x[1][2] + w2*x[2][2] + w3*x[3][2];
488
 
    
489
 
    // Evaluate function at physical points
490
 
    double values[1];
491
 
    f.evaluate(values, y, c);
492
 
    
493
 
    // Map function values using appropriate mapping
494
 
    // Affine map: Do nothing
495
 
    
496
 
    // Note that we do not map the weights (yet).
497
 
    
498
 
    // Take directional components
499
 
    for(int k = 0; k < 1; k++)
500
 
      result += values[k]*D[i][0][k];
501
 
    // Multiply by weights 
502
 
    result *= W[i][0];
503
 
    
504
 
    return result;
505
 
  }
506
 
 
507
 
  /// Evaluate linear functionals for all dofs on the function f
508
 
  virtual void evaluate_dofs(double* values,
509
 
                             const ufc::function& f,
510
 
                             const ufc::cell& c) const
511
 
  {
512
 
    throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
513
 
  }
514
 
 
515
 
  /// Interpolate vertex values from dof values
516
 
  virtual void interpolate_vertex_values(double* vertex_values,
517
 
                                         const double* dof_values,
518
 
                                         const ufc::cell& c) const
519
 
  {
520
 
    // Evaluate at vertices and use affine mapping
521
 
    vertex_values[0] = dof_values[0];
522
 
    vertex_values[1] = dof_values[1];
523
 
    vertex_values[2] = dof_values[2];
524
 
    vertex_values[3] = dof_values[3];
525
 
  }
526
 
 
527
 
  /// Return the number of sub elements (for a mixed element)
528
 
  virtual unsigned int num_sub_elements() const
529
 
  {
530
 
    return 1;
531
 
  }
532
 
 
533
 
  /// Create a new finite element for sub element i (for a mixed element)
534
 
  virtual ufc::finite_element* create_sub_element(unsigned int i) const
535
 
  {
536
 
    return new ffc_03_finite_element_0();
537
 
  }
538
 
 
539
 
};
540
 
 
541
 
/// This class defines the interface for a local-to-global mapping of
542
 
/// degrees of freedom (dofs).
543
 
 
544
 
class ffc_03_dof_map_0: public ufc::dof_map
545
 
{
546
 
private:
547
 
 
548
 
  unsigned int __global_dimension;
549
 
 
550
 
public:
551
 
 
552
 
  /// Constructor
553
 
  ffc_03_dof_map_0() : ufc::dof_map()
554
 
  {
555
 
    __global_dimension = 0;
556
 
  }
557
 
 
558
 
  /// Destructor
559
 
  virtual ~ffc_03_dof_map_0()
560
 
  {
561
 
    // Do nothing
562
 
  }
563
 
 
564
 
  /// Return a string identifying the dof map
565
 
  virtual const char* signature() const
566
 
  {
567
 
    return "FFC dof map for Lagrange finite element of degree 1 on a tetrahedron";
568
 
  }
569
 
 
570
 
  /// Return true iff mesh entities of topological dimension d are needed
571
 
  virtual bool needs_mesh_entities(unsigned int d) const
572
 
  {
573
 
    switch ( d )
574
 
    {
575
 
    case 0:
576
 
      return true;
577
 
      break;
578
 
    case 1:
579
 
      return false;
580
 
      break;
581
 
    case 2:
582
 
      return false;
583
 
      break;
584
 
    case 3:
585
 
      return false;
586
 
      break;
587
 
    }
588
 
    return false;
589
 
  }
590
 
 
591
 
  /// Initialize dof map for mesh (return true iff init_cell() is needed)
592
 
  virtual bool init_mesh(const ufc::mesh& m)
593
 
  {
594
 
    __global_dimension = m.num_entities[0];
595
 
    return false;
596
 
  }
597
 
 
598
 
  /// Initialize dof map for given cell
599
 
  virtual void init_cell(const ufc::mesh& m,
600
 
                         const ufc::cell& c)
601
 
  {
602
 
    // Do nothing
603
 
  }
604
 
 
605
 
  /// Finish initialization of dof map for cells
606
 
  virtual void init_cell_finalize()
607
 
  {
608
 
    // Do nothing
609
 
  }
610
 
 
611
 
  /// Return the dimension of the global finite element function space
612
 
  virtual unsigned int global_dimension() const
613
 
  {
614
 
    return __global_dimension;
615
 
  }
616
 
 
617
 
  /// Return the dimension of the local finite element function space
618
 
  virtual unsigned int local_dimension() const
619
 
  {
620
 
    return 4;
621
 
  }
622
 
 
623
 
  // Return the geometric dimension of the coordinates this dof map provides
624
 
  virtual unsigned int geometric_dimension() const
625
 
  {
626
 
    throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
627
 
  }
628
 
 
629
 
  /// Return the number of dofs on each cell facet
630
 
  virtual unsigned int num_facet_dofs() const
631
 
  {
632
 
    return 3;
633
 
  }
634
 
 
635
 
  /// Return the number of dofs associated with each cell entity of dimension d
636
 
  virtual unsigned int num_entity_dofs(unsigned int d) const
637
 
  {
638
 
    throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
639
 
  }
640
 
 
641
 
  /// Tabulate the local-to-global mapping of dofs on a cell
642
 
  virtual void tabulate_dofs(unsigned int* dofs,
643
 
                             const ufc::mesh& m,
644
 
                             const ufc::cell& c) const
645
 
  {
646
 
    dofs[0] = c.entity_indices[0][0];
647
 
    dofs[1] = c.entity_indices[0][1];
648
 
    dofs[2] = c.entity_indices[0][2];
649
 
    dofs[3] = c.entity_indices[0][3];
650
 
  }
651
 
 
652
 
  /// Tabulate the local-to-local mapping from facet dofs to cell dofs
653
 
  virtual void tabulate_facet_dofs(unsigned int* dofs,
654
 
                                   unsigned int facet) const
655
 
  {
656
 
    switch ( facet )
657
 
    {
658
 
    case 0:
659
 
      dofs[0] = 1;
660
 
      dofs[1] = 2;
661
 
      dofs[2] = 3;
662
 
      break;
663
 
    case 1:
664
 
      dofs[0] = 0;
665
 
      dofs[1] = 2;
666
 
      dofs[2] = 3;
667
 
      break;
668
 
    case 2:
669
 
      dofs[0] = 0;
670
 
      dofs[1] = 1;
671
 
      dofs[2] = 3;
672
 
      break;
673
 
    case 3:
674
 
      dofs[0] = 0;
675
 
      dofs[1] = 1;
676
 
      dofs[2] = 2;
677
 
      break;
678
 
    }
679
 
  }
680
 
 
681
 
  /// Tabulate the local-to-local mapping of dofs on entity (d, i)
682
 
  virtual void tabulate_entity_dofs(unsigned int* dofs,
683
 
                                    unsigned int d, unsigned int i) const
684
 
  {
685
 
    throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
686
 
  }
687
 
 
688
 
  /// Tabulate the coordinates of all dofs on a cell
689
 
  virtual void tabulate_coordinates(double** coordinates,
690
 
                                    const ufc::cell& c) const
691
 
  {
692
 
    const double * const * x = c.coordinates;
693
 
    coordinates[0][0] = x[0][0];
694
 
    coordinates[0][1] = x[0][1];
695
 
    coordinates[0][2] = x[0][2];
696
 
    coordinates[1][0] = x[1][0];
697
 
    coordinates[1][1] = x[1][1];
698
 
    coordinates[1][2] = x[1][2];
699
 
    coordinates[2][0] = x[2][0];
700
 
    coordinates[2][1] = x[2][1];
701
 
    coordinates[2][2] = x[2][2];
702
 
    coordinates[3][0] = x[3][0];
703
 
    coordinates[3][1] = x[3][1];
704
 
    coordinates[3][2] = x[3][2];
705
 
  }
706
 
 
707
 
  /// Return the number of sub dof maps (for a mixed element)
708
 
  virtual unsigned int num_sub_dof_maps() const
709
 
  {
710
 
    return 1;
711
 
  }
712
 
 
713
 
  /// Create a new dof_map for sub dof map i (for a mixed element)
714
 
  virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
715
 
  {
716
 
    return new ffc_03_dof_map_0();
717
 
  }
718
 
 
719
 
};
720
 
 
721
 
#endif