~njansson/dolfin/hpc

« back to all changes in this revision

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