Debian Codegraph @

test/uflacs/crosslanguage/cppsupport/mock_cells.h

raw
1 // This is utility code for UFLACS unit tests.
2 // This code is released into the public domain.
3 //
4 // The FEniCS Project (http://www.fenicsproject.org/) 2006-2012.
5
6 #ifndef __MOCK_CELLS_H
7 #define __MOCK_CELLS_H
8
9 #include <ufc.h>
10
11 //namespace uflacs
12 //{
13 struct mock_cell
14 {
15 // These coordinates are all that generated code should care
16 // about, the rest is to support the tests
17 double coordinate_dofs[8*3]; // Worst case hexahedron: 8 vertices in 3d
18
19 // Dimensions needed for generic cell transformations
20 size_t geometric_dimension;
21 size_t topological_dimension;
22 size_t num_vertices;
23
24 // Constructor just clears everything to zero
25 mock_cell()
26 {
27 init_dimensions(0,0,0);
28 }
29
30 // Utility initialization function
31 void init_dimensions(size_t geometric_dimension,
32 size_t topological_dimension, size_t num_vertices)
33 {
34 this->geometric_dimension = geometric_dimension;
35 this->topological_dimension = topological_dimension;
36 this->num_vertices = num_vertices;
37 int n = int(sizeof(coordinate_dofs) / sizeof(coordinate_dofs[0]));
38 for (int i=0; i<n; ++i)
39 {
40 coordinate_dofs[i] = 0.0;
41 }
42 }
43
44 void fill_reference_interval(size_t geometric_dimension)
45 {
46 init_dimensions(geometric_dimension, 1, 2);
47
48 // Fill in coordinate_dofs for reference cell
49 coordinate_dofs[0*geometric_dimension + 0] = 0.0;
50 coordinate_dofs[1*geometric_dimension + 0] = 1.0;
51 }
52
53 void fill_reference_triangle(size_t geometric_dimension)
54 {
55 init_dimensions(geometric_dimension, 2, 3);
56
57 // Fill in coordinate_dofs for reference cell
58 coordinate_dofs[0*geometric_dimension + 0] = 0.0;
59 coordinate_dofs[0*geometric_dimension + 1] = 0.0;
60
61 coordinate_dofs[1*geometric_dimension + 0] = 1.0;
62 coordinate_dofs[1*geometric_dimension + 1] = 0.0;
63
64 coordinate_dofs[2*geometric_dimension + 0] = 0.0;
65 coordinate_dofs[2*geometric_dimension + 1] = 1.0;
66 }
67
68 void fill_reference_tetrahedron(size_t geometric_dimension)
69 {
70 init_dimensions(geometric_dimension, 3, 4);
71
72 // Fill in coordinate_dofs for reference cell
73 coordinate_dofs[0*geometric_dimension + 0] = 0.0;
74 coordinate_dofs[0*geometric_dimension + 1] = 0.0;
75 coordinate_dofs[0*geometric_dimension + 2] = 0.0;
76
77 coordinate_dofs[1*geometric_dimension + 0] = 1.0;
78 coordinate_dofs[1*geometric_dimension + 1] = 0.0;
79 coordinate_dofs[1*geometric_dimension + 2] = 0.0;
80
81 coordinate_dofs[2*geometric_dimension + 0] = 0.0;
82 coordinate_dofs[2*geometric_dimension + 1] = 1.0;
83 coordinate_dofs[2*geometric_dimension + 2] = 0.0;
84
85 coordinate_dofs[3*geometric_dimension + 0] = 0.0;
86 coordinate_dofs[3*geometric_dimension + 1] = 0.0;
87 coordinate_dofs[3*geometric_dimension + 2] = 1.0;
88 }
89
90 void fill_reference_quadrilateral(size_t geometric_dimension)
91 {
92 init_dimensions(geometric_dimension, 2, 4);
93
94 // Fill in coordinate_dofs for reference cell
95 coordinate_dofs[0*geometric_dimension + 0] = 0.0;
96 coordinate_dofs[0*geometric_dimension + 1] = 0.0;
97
98 coordinate_dofs[1*geometric_dimension + 0] = 1.0;
99 coordinate_dofs[1*geometric_dimension + 1] = 0.0;
100
101 coordinate_dofs[2*geometric_dimension + 0] = 1.0;
102 coordinate_dofs[2*geometric_dimension + 1] = 1.0;
103
104 coordinate_dofs[3*geometric_dimension + 0] = 0.0;
105 coordinate_dofs[3*geometric_dimension + 1] = 1.0;
106 }
107
108 void fill_reference_hexahedron(size_t geometric_dimension)
109 {
110 init_dimensions(geometric_dimension, 3, 8);
111
112 // Fill in coordinate_dofs for reference cell
113 coordinate_dofs[0*geometric_dimension + 0] = 0.0;
114 coordinate_dofs[0*geometric_dimension + 1] = 0.0;
115 coordinate_dofs[0*geometric_dimension + 2] = 0.0;
116
117 coordinate_dofs[1*geometric_dimension + 0] = 1.0;
118 coordinate_dofs[1*geometric_dimension + 1] = 0.0;
119 coordinate_dofs[1*geometric_dimension + 2] = 0.0;
120
121 coordinate_dofs[2*geometric_dimension + 0] = 1.0;
122 coordinate_dofs[2*geometric_dimension + 1] = 1.0;
123 coordinate_dofs[2*geometric_dimension + 2] = 0.0;
124
125 coordinate_dofs[3*geometric_dimension + 0] = 0.0;
126 coordinate_dofs[3*geometric_dimension + 1] = 1.0;
127 coordinate_dofs[3*geometric_dimension + 2] = 0.0;
128
129 coordinate_dofs[4*geometric_dimension + 0] = 0.0;
130 coordinate_dofs[4*geometric_dimension + 1] = 0.0;
131 coordinate_dofs[4*geometric_dimension + 2] = 1.0;
132
133 coordinate_dofs[5*geometric_dimension + 0] = 1.0;
134 coordinate_dofs[5*geometric_dimension + 1] = 0.0;
135 coordinate_dofs[5*geometric_dimension + 2] = 1.0;
136
137 coordinate_dofs[6*geometric_dimension + 0] = 1.0;
138 coordinate_dofs[6*geometric_dimension + 1] = 1.0;
139 coordinate_dofs[6*geometric_dimension + 2] = 1.0;
140
141 coordinate_dofs[7*geometric_dimension + 0] = 0.0;
142 coordinate_dofs[7*geometric_dimension + 1] = 1.0;
143 coordinate_dofs[7*geometric_dimension + 2] = 1.0;
144 }
145
146 // Scale cell coordinates
147 void scale(double factor)
148 {
149 for (size_t i=0; i<num_vertices; ++i)
150 {
151 for (size_t j=0; j<geometric_dimension; ++j)
152 coordinate_dofs[i*geometric_dimension + j] *= factor;
153 }
154 }
155
156 // Scale cell coordinates differently in each geometric
157 // dimension
158 void scale(const double * factors)
159 {
160 for (size_t i=0; i<num_vertices; ++i)
161 {
162 for (size_t j=0; j<geometric_dimension; ++j)
163 coordinate_dofs[i*geometric_dimension + j] *= factors[j];
164
165 }
166 }
167
168 // Translate cell coordinates
169 void translate(double x)
170 {
171 assert(geometric_dimension == 1);
172 double t[3] = { x, 0.0, 0.0 };
173 translate(t);
174 }
175
176 void translate(double x, double y)
177 {
178 assert(geometric_dimension == 2);
179 double t[3] = { x, y, 0.0 };
180 translate(t);
181 }
182
183 void translate(double x, double y, double z)
184 {
185 assert(geometric_dimension == 3);
186 double t[3] = { x, y, z };
187 translate(t);
188 }
189
190 void translate(const double * x)
191 {
192 for (size_t i=0; i<num_vertices; ++i)
193 {
194 for (size_t j=0; j<geometric_dimension; ++j)
195 coordinate_dofs[i*geometric_dimension + j] += x[j];
196 }
197 }
198
199 // Apply affine mapping to cell coordinates
200 void affine_map(const double * A, const double * x0)
201 {
202 for (size_t i=0; i<num_vertices; ++i)
203 {
204 double result[3];
205 for (size_t j=0; j<geometric_dimension; ++j)
206 {
207 result[j] = x0[j];
208 for (size_t k=0; k<geometric_dimension; ++k)
209 {
210 result[j] += A[geometric_dimension*j + k] * coordinate_dofs[i*geometric_dimension + k];
211 }
212 }
213 for (size_t j=0; j<geometric_dimension; ++j)
214 coordinate_dofs[i*geometric_dimension + j] = result[j];
215 }
216 }
217 };
218
219 //}
220
221 #endif