~ubuntu-branches/ubuntu/raring/ffc/raring

« back to all changes in this revision

Viewing changes to test/evaluate_basis/cppcode.py

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2010-02-03 20:22:35 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100203202235-fe8d0kajuvgy2sqn
Tags: 0.9.0-1
* New upstream release.
* debian/control: Bump Standards-Version (no changes needed).
* Update debian/copyright and debian/copyright_hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"This module provides simple C++ code for verification of UFC code."
 
2
 
 
3
__author__ = "Kristian B. Oelgaard (k.b.oelgaard@gmail.com)"
 
4
__date__ = "2010-01-18"
 
5
__copyright__ = "Copyright (C) 2010 Kristian B. Oelgaard"
 
6
__license__  = "GNU GPL version 3 or any later version"
 
7
 
 
8
# Common code for all integral types
 
9
evaluate_basis_code = """\
 
10
#include <iostream>
 
11
#include <ufc.h>
 
12
#include "test.h"
 
13
 
 
14
int main()
 
15
{
 
16
  // Create element
 
17
  %(element)s element;
 
18
 
 
19
  // Size of dof_values
 
20
  // FIXME: This will not work for TensorElements
 
21
  int N = element.value_dimension(0);
 
22
 
 
23
  // Create values
 
24
  double* dof_values = new double[N];
 
25
  for (int i = 0; i < N; i++)
 
26
    dof_values[i] = 0.0;
 
27
 
 
28
  // Create cell and fill with some arbitrary data
 
29
  double cell_coordinates[8][3] = {{0.90, 0.34, 0.45},
 
30
                                   {0.56, 0.76, 0.83},
 
31
                                   {0.98, 0.78, 0.19},
 
32
                                   {0.12, 0.56, 0.66},
 
33
                                   {0.96, 0.78, 0.63},
 
34
                                   {0.11, 0.35, 0.49},
 
35
                                   {0.51, 0.88, 0.65},
 
36
                                   {0.98, 0.45, 0.01}};
 
37
  ufc::cell cell;
 
38
  cell.coordinates = new double * [8];
 
39
  for (int i = 0; i < 8; i++)
 
40
  {
 
41
    cell.coordinates[i] = new double[3];
 
42
    for (int j = 0; j < 3; j++)
 
43
      cell.coordinates[i][j] = cell_coordinates[i][j];
 
44
  }
 
45
 
 
46
  // Random coordinates where we want to evaluate the basis functions
 
47
  double coordinates[3] = {0.32, 0.51, 0.05};
 
48
 
 
49
  // Loop element space dimension and call evaluate_basis.
 
50
  for (unsigned int i = 0; i < element.space_dimension(); i++)
 
51
  {
 
52
    element.evaluate_basis(i, dof_values, coordinates, cell);
 
53
    // Print values
 
54
    for (int j = 0; j < N; j++)
 
55
      std::cout << dof_values[j] << " ";
 
56
  }
 
57
  std::cout << std::endl;
 
58
  return 0;
 
59
}
 
60
"""
 
61