File: cppcode.py

package info (click to toggle)
ffc 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 50,704 kB
  • sloc: cpp: 572,515; python: 15,790; makefile: 134; sh: 67
file content (175 lines) | stat: -rw-r--r-- 5,087 bytes parent folder | download
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
"This module provides simple C++ code for verification of UFC code."

# Copyright (C) 2010 Kristian B. Oelgaard
#
# This file is part of FFC.
#
# FFC is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FFC 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
#
# First added:  2010-01-18
# Last changed: 2010-01-18

#evaluate_basis_code = """\
##include <iostream>
##include <ufc.h>
##include "test.h"

#int main()
#{
#  // Create element
#  %(element)s element;

#  // Size of dof_values
#  // FIXME: This will not work for TensorElements
#  int N = element.value_dimension(0);

#  // Create values
#  double* dof_values = new double[N];
#  for (unsigned int i = 0; i < N; i++)
#    dof_values[i] = 0.0;

#  // Create cell and fill with some arbitrary data
#  double cell_coordinates[8][3] = {{0.90, 0.34, 0.45},
#                                   {0.56, 0.76, 0.83},
#                                   {0.98, 0.78, 0.19},
#                                   {0.12, 0.56, 0.66},
#                                   {0.96, 0.78, 0.63},
#                                   {0.11, 0.35, 0.49},
#                                   {0.51, 0.88, 0.65},
#                                   {0.98, 0.45, 0.01}};
#  ufc::cell cell;
#  cell.coordinates = new double * [8];
#  for (int i = 0; i < 8; i++)
#  {
#    cell.coordinates[i] = new double[3];
#    for (int j = 0; j < 3; j++)
#      cell.coordinates[i][j] = cell_coordinates[i][j];
#  }

#  // Random coordinates where we want to evaluate the basis functions
#  double coordinates[3] = {0.32, 0.51, 0.05};

#  // Loop element space dimension and call evaluate_basis.
#  for (unsigned int i = 0; i < element.space_dimension(); i++)
#  {
#    element.evaluate_basis(i, dof_values, coordinates, cell);
#    // Print values
#    for (unsigned int j = 0; j < N; j++)
#      std::cout << dof_values[j] << " ";
#  }
#  std::cout << std::endl;
#  return 0;
#}
#"""

evaluate_basis_code_fiat = """\
#include <iostream>
#include <ufc.h>
#include <cstdlib>
#include "test.h"

int main(int argc, char* argv[])
{
  // Create element
  %(element)s element;


  // Get derivative order
  unsigned int n = std::atoi(argv[1]);

  // Value dimension
  // FIXME: This will not work for TensorElements
  int N = element.value_dimension(0);

  // Compute number of derivatives.
  unsigned int  num_derivatives = 1;
  for (unsigned int r = 0; r < n; r++)
  {
    num_derivatives *= %(dim)d;
  }

  // Create values
  unsigned int num_dof_vals = N*num_derivatives;
  double* dof_values = new double[num_dof_vals];
  for (unsigned int i = 0; i < num_dof_vals; i++)
    dof_values[i] = 0.0;

  %(cell_ref_coords)s
  ufc::cell cell;
  cell.coordinates = new double * [%(num_coords)d];
  for (int i = 0; i < %(num_coords)d; i++)
  {
    cell.coordinates[i] = new double[%(dim)d];
    for (int j = 0; j < %(dim)d; j++)
      cell.coordinates[i][j] = cell_ref_coords[i][j];
  }

  // Random points where we want to evaluate the basis functions
  // coordinates of dofs and three arbitrary points on the reference cell.
  double points[%(num_points)d][%(dim)d] = %(points)s

  // Init array of coordinates
  double coordinates[3] = {0,0,0};

  std::cout.precision(8);
  std::cout.setf(std::ios::fixed);

  // If we're testing evaluate_basis, loop all points.
  if (n == 0)
  {
    for (unsigned int p = 0; p < %(num_points)d; p++)
    {
      for (unsigned int d = 0; d < %(dim)d; d++)
      {
        coordinates[d] = points[p][d];
      }
      // Loop element space dimension and call evaluate_basis.
      for (unsigned int i = 0; i < element.space_dimension(); i++)
      {
        element.evaluate_basis(i, dof_values, coordinates, cell);

        // Print values
        for (unsigned int j = 0; j < num_dof_vals; j++)
          std::cout << dof_values[j] << " ";
      }
      std::cout << std::endl;
    }
  }
  else
  {
    // Else loop the arbitrary 3 points, otherwise the number of tests explode
    // with the element.space_dimension()^2.
    for (unsigned int p = element.space_dimension(); p < %(num_points)d; p++)
    {
      for (unsigned int d = 0; d < %(dim)d; d++)
      {
        coordinates[d] = points[p][d];
      }
      // Loop element space dimension and call evaluate_basis.
      for (unsigned int i = 0; i < element.space_dimension(); i++)
      {
        element.evaluate_basis_derivatives(i, n, dof_values, coordinates, cell);

        // Print values
        for (unsigned int j = 0; j < num_dof_vals; j++)
          std::cout << dof_values[j] << " ";
      }
      std::cout << std::endl;
    }
  }

  return 0;
}
"""