Debian Codegraph @

test/regression/ufctest.h

raw
1 // Copyright (C) 2010-2015 Anders Logg
2 //
3 // This file is part of FFC.
4 //
5 // FFC is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // FFC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with FFC. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Functions for calling generated UFC functions with "random" (but
19 // fixed) data and print the output to screen. Useful for running
20 // regression tests.
21
22 #include <sstream>
23 #include <string>
24 #include <iostream>
25 #include <iomanip>
26 #include <cmath>
27 #include <ctime>
28 #include <memory>
29 #include <ufc.h>
30
31 #include "printer.h"
32
33 // How many derivatives to test
34 const std::size_t max_derivative = 2;
35
36 // Parameters for adaptive timing
37 const std::size_t initial_num_reps = 10;
38 const double minimum_timing = 1.0;
39
40 // Function for timing
41 double time()
42 {
43 clock_t __toc_time = std::clock();
44 return ((double) (__toc_time)) / CLOCKS_PER_SEC;
45 }
46
47 // Function for creating "random" vertex coordinates
48 std::vector<double> test_coordinate_dofs(std::size_t gdim, std::size_t gdeg)
49 {
50 // Generate some "random" coordinates
51 std::vector<double> coordinate_dofs;
52 if (gdim == 1)
53 {
54 coordinate_dofs.resize(2);
55 coordinate_dofs[0] = 0.903;
56 coordinate_dofs[1] = 0.561;
57 // Huh? Only 2 vertices for interval, is this for tdim=1,gdim=2?
58 // coordinate_dofs[2] = 0.987;
59 // coordinate_dofs[3] = 0.123;
60 if (gdeg > 1)
61 {
62 assert(gdeg == 2);
63 coordinate_dofs.resize(3);
64 coordinate_dofs[2] = 0.750;
65 }
66 }
67 else if (gdim == 2)
68 {
69 coordinate_dofs.resize(6);
70 coordinate_dofs[0] = 0.903;
71 coordinate_dofs[1] = 0.341;
72 coordinate_dofs[2] = 0.561;
73 coordinate_dofs[3] = 0.767;
74 coordinate_dofs[4] = 0.987;
75 coordinate_dofs[5] = 0.783;
76 // Huh? Only 4 vertices for triangle, is this for quads?
77 // coordinate_dofs[6] = 0.123;
78 // coordinate_dofs[7] = 0.561;
79 if (gdeg > 1)
80 {
81 assert(gdeg == 2);
82 coordinate_dofs.resize(12);
83 coordinate_dofs[6] = 0.750;
84 coordinate_dofs[7] = 0.901;
85 coordinate_dofs[8] = 0.999;
86 coordinate_dofs[9] = 0.500;
87 coordinate_dofs[10] = 0.659;
88 coordinate_dofs[11] = 0.555;
89 }
90 }
91 else if (gdim == 3)
92 {
93 coordinate_dofs.resize(12);
94 coordinate_dofs[0] = 0.903;
95 coordinate_dofs[1] = 0.341;
96 coordinate_dofs[2] = 0.457;
97 coordinate_dofs[3] = 0.561;
98 coordinate_dofs[4] = 0.767;
99 coordinate_dofs[5] = 0.833;
100 coordinate_dofs[6] = 0.987;
101 coordinate_dofs[7] = 0.783;
102 coordinate_dofs[8] = 0.191;
103 coordinate_dofs[9] = 0.123;
104 coordinate_dofs[10] = 0.561;
105 coordinate_dofs[11] = 0.667;
106 if (gdeg > 1)
107 {
108 assert(gdeg == 2);
109 coordinate_dofs.resize(30);
110 // FIXME: Add some quadratic tetrahedron
111 assert(false);
112 }
113 }
114 return coordinate_dofs;
115 }
116
117 // Function for creating "random" vertex coordinates
118 std::pair<std::vector<double>, std::vector<double>> test_coordinate_dof_pair(int gdim, int gdeg, int facet0, int facet1)
119 {
120 // For affine simplices only so far...
121 assert(gdeg == 1);
122
123 // Return pair of cell coordinates there facet0 of cell 0 cooresponds to facet1 of cell 1
124 int num_vertices = gdim+1;
125 std::vector<double> c0 = test_coordinate_dofs(gdim, gdeg);
126 std::vector<double> c1(c0.size());
127 std::vector<double> m(gdim);
128
129 for (int i=0; i<gdim; ++i)
130 m[i] = 0.0;
131
132 int k = 0;
133 int j0 = 0;
134 int j1 = 0;
135 while (k < num_vertices-1)
136 {
137 // Skip the vertex that has vertex index == facet index, this is _not_ part of the facet.
138 if (j0 == facet0)
139 ++j0;
140 if (j1 == facet1)
141 ++j1;
142
143 // Copy vertex and accumulate midpoint
144 for (int i=0; i<gdim; ++i)
145 m[i] += (c1[gdim*j1 + i] = c0[gdim*j0 + i]);
146
147 // Skip to next vertex
148 ++j0;
149 ++j1;
150 ++k;
151 }
152 // Scale midpoint
153 for (int i=0; i<gdim; ++i)
154 m[i] /= (num_vertices-1.0);
155
156 // Place last vertex (not on facet) on the opposite side of facet
157 j0 = facet0; // Simplex specific rule
158 j1 = facet1;
159 for (int i=0; i<gdim; ++i)
160 c1[gdim*j1 + i] = 2.0*m[i] - c0[gdim*j0 + i];
161
162 return {c0, c1};
163 }
164
165 // Class for creating "random" ufc::cell objects
166 class test_cell : public ufc::cell
167 {
168 public:
169
170 test_cell(ufc::shape cell_shape, int gdim=0, int offset=0)
171 {
172 // Store cell shape
173 this->cell_shape = cell_shape;
174
175 // Store dimensions
176 switch (cell_shape)
177 {
178 case ufc::shape::interval:
179 topological_dimension = 1;
180 if (gdim == 0)
181 geometric_dimension = 1;
182 else
183 geometric_dimension = gdim;
184 break;
185 case ufc::shape::triangle:
186 topological_dimension = 2;
187 if (gdim == 0)
188 geometric_dimension = 2;
189 else
190 geometric_dimension = gdim;
191 break;
192 case ufc::shape::tetrahedron:
193 topological_dimension = 3;
194 if (gdim == 0)
195 geometric_dimension = 3;
196 else
197 geometric_dimension = gdim;
198 break;
199 default:
200 throw std::runtime_error("Unhandled cell shape.");
201 }
202
203 // Set orientation (random, but must be set)
204 this->orientation = 1;
205
206 // Generate some "random" entity indices
207 entity_indices.resize(topological_dimension+1);
208 for (std::size_t i = 0; i <= topological_dimension; i++)
209 {
210 entity_indices[i].resize(12); // hack: sufficient for any cell entities list, 12 edges of hex
211 for (std::size_t j = 0; j < entity_indices[i].size(); j++)
212 entity_indices[i][j] = i*j + offset;
213 }
214 }
215
216 ~test_cell() {}
217
218 };
219
220
221 // Class for creating a "random" ufc::function object
222 class test_function : public ufc::function
223 {
224 public:
225
226 test_function(std::size_t value_size) : value_size(value_size) {}
227
228 void evaluate(double* values, const double* coordinates,
229 const ufc::cell& c) const
230 {
231 for (std::size_t i = 0; i < value_size; i++)
232 {
233 values[i] = 1.0;
234 for (std::size_t j = 0; j < c.geometric_dimension; j++)
235 values[i] *= static_cast<double>(i + 1)*coordinates[j];
236 }
237 }
238
239 private:
240
241 std::size_t value_size;
242
243 };
244
245 std::string format_name(std::string name, int i=-1, int j=-1)
246 {
247 std::stringstream s;
248 s << name;
249 if (i >= 0)
250 s << "_" << i;
251 if (j >= 0)
252 s << "_" << j;
253 return s.str();
254 }
255
256 // Function for testing ufc::element objects
257 void test_finite_element(ufc::finite_element& element, int id, Printer& printer)
258 {
259 printer.begin("finite_element", id);
260
261 // Prepare arguments
262 test_cell c(element.cell_shape(), element.geometric_dimension());
263 // NOTE: Assuming geometry degree 1
264 const std::vector<double> coordinate_dofs
265 = test_coordinate_dofs(element.geometric_dimension(), 1);
266 std::size_t value_size = 1;
267 for (std::size_t i = 0; i < element.value_rank(); i++)
268 value_size *= element.value_dimension(i);
269 std::size_t derivative_size = 1;
270 for (std::size_t i = 0; i < max_derivative; i++)
271 derivative_size *= c.geometric_dimension;
272 std::vector<double>
273 values(element.space_dimension()*value_size*derivative_size, 0.0);
274
275 std::vector<double> dof_values(element.space_dimension(), 0.0);
276 std::vector<double> vertex_values((c.topological_dimension + 1)*value_size,
277 0.0);
278
279 std::vector<double> coordinates(c.geometric_dimension);
280 for (std::size_t i = 0; i < c.geometric_dimension; i++)
281 coordinates[i] = 0.1*static_cast<double>(i);
282 test_function f(value_size);
283
284 // signature
285 //printer.print_scalar("signature", element.signature());
286
287 // cell_shape
288 printer.print_scalar("cell_shape", static_cast<int>(element.cell_shape()));
289
290 // space_dimension
291 printer.print_scalar("space_dimension", element.space_dimension());
292
293 // value_rank
294 printer.print_scalar("value_rank", element.value_rank());
295
296 // value_dimension
297 for (std::size_t i = 0; i < element.value_rank(); i++)
298 printer.print_scalar("value_dimension", element.value_dimension(i), i);
299
300 // evaluate_basis
301 for (std::size_t i = 0; i < element.space_dimension(); i++)
302 {
303 element.evaluate_basis(i, values.data(), coordinates.data(),
304 coordinate_dofs.data(), 1);
305 printer.print_array("evaluate_basis:", value_size, values.data(), i);
306 }
307
308 // evaluate_basis all
309 element.evaluate_basis_all(values.data(), coordinates.data(),
310 coordinate_dofs.data(), 1);
311 printer.print_vector("evaluate_basis_all", values);
312
313 // evaluate_basis_derivatives
314 for (std::size_t i = 0; i < element.space_dimension(); i++)
315 {
316 for (std::size_t n = 0; n <= max_derivative; n++)
317 {
318 std::size_t num_derivatives = 1;
319 for (std::size_t j = 0; j < n; j++)
320 num_derivatives *= c.geometric_dimension;
321 element.evaluate_basis_derivatives(i,
322 n,
323 values.data(),
324 coordinates.data(),
325 coordinate_dofs.data(),
326 1);
327 printer.print_array("evaluate_basis_derivatives",
328 value_size*num_derivatives, values.data(), i, n);
329 }
330 }
331
332 // evaluate_basis_derivatives_all
333 for (std::size_t n = 0; n <= max_derivative; n++)
334 {
335 std::size_t num_derivatives = 1;
336 for (std::size_t j = 0; j < n; j++)
337 num_derivatives *= c.geometric_dimension;
338 element.evaluate_basis_derivatives_all(n,
339 values.data(),
340 coordinates.data(),
341 coordinate_dofs.data(),
342 1);
343 printer.print_array("evaluate_basis_derivatives_all",
344 element.space_dimension()*value_size*num_derivatives,
345 values.data(), n);
346 }
347
348 // evaluate_dof
349 for (std::size_t i = 0; i < element.space_dimension(); i++)
350 {
351 dof_values[i] = element.evaluate_dof(i, f,
352 coordinate_dofs.data(),
353 1, c);
354 printer.print_scalar("evaluate_dof", dof_values[i], i);
355 }
356
357 // evaluate_dofs
358 element.evaluate_dofs(values.data(), f, coordinate_dofs.data(), 1, c);
359 printer.print_array("evaluate_dofs", element.space_dimension(),
360 values.data());
361
362 // interpolate_vertex_values
363 element.interpolate_vertex_values(vertex_values.data(),
364 dof_values.data(),
365 coordinate_dofs.data(),
366 1);
367 printer.print_vector("interpolate_vertex_values", vertex_values);
368
369 // tabulate_coordinates
370 std::vector<double>
371 dof_coordinates(element.geometric_dimension()*element.space_dimension());
372 element.tabulate_dof_coordinates(dof_coordinates.data(),
373 coordinate_dofs.data());
374 printer.print_vector("tabulate_dof_coordinates", dof_coordinates);
375
376 // num_sub_dof_elements
377 printer.print_scalar("num_sub_elements", element.num_sub_elements());
378
379 // create_sub_element
380 for (std::size_t i = 0; i < element.num_sub_elements(); i++)
381 {
382 std::unique_ptr<ufc::finite_element>
383 sub_element(element.create_sub_element(i));
384 test_finite_element(*sub_element, i, printer);
385 }
386
387 printer.end();
388 }
389
390 // Function for testing ufc::element objects
391 void test_dofmap(ufc::dofmap& dofmap, ufc::shape cell_shape, int id,
392 Printer& printer)
393 {
394 printer.begin("dofmap", id);
395
396 // Prepare arguments
397 std::vector<std::size_t> num_entities(4);
398 num_entities[0] = 10001;
399 num_entities[1] = 10002;
400 num_entities[2] = 10003;
401 num_entities[3] = 10004;
402
403 //test_cell c(cell_shape, dofmap.geometric_dimension());
404 test_cell c(cell_shape, dofmap.topological_dimension());
405 std::size_t n = dofmap.num_element_dofs();
406 std::vector<std::size_t> dofs(n, 0);
407
408 std::size_t num_facets = c.topological_dimension + 1;
409 std::vector<double> coordinates(n*c.geometric_dimension);
410
411 // needs_mesh_entities
412 for (std::size_t d = 0; d <= c.topological_dimension; d++)
413 {
414 printer.print_scalar("needs_mesh_entities", dofmap.needs_mesh_entities(d),
415 d);
416 }
417
418 // global_dimension
419 printer.print_scalar("global_dimension",
420 dofmap.global_dimension(num_entities));
421
422 // num_element_dofs
423 printer.print_scalar("num_element_dofs", dofmap.num_element_dofs());
424
425 // num_facet_dofs
426 printer.print_scalar("num_facet_dofs", dofmap.num_facet_dofs());
427
428 // num_entity_dofs
429 for (std::size_t d = 0; d <= c.topological_dimension; d++)
430 printer.print_scalar("num_entity_dofs", dofmap.num_entity_dofs(d), d);
431
432 // tabulate_dofs
433 dofmap.tabulate_dofs(dofs.data(), num_entities, c.entity_indices);
434 printer.print_array("tabulate_dofs", dofmap.num_element_dofs(), dofs.data());
435
436 // tabulate_facet_dofs
437 for (std::size_t facet = 0; facet < num_facets; facet++)
438 {
439 dofmap.tabulate_facet_dofs(dofs.data(), facet);
440 printer.print_array("tabulate_facet_dofs", dofmap.num_facet_dofs(),
441 dofs.data(), facet);
442 }
443
444 // tabulate_entity_dofs
445 for (std::size_t d = 0; d <= c.topological_dimension; d++)
446 {
447 std::size_t num_entities[4][4] = {{0, 0, 0, 0}, // dummy entities in 0D
448 {2, 1, 0, 0}, // interval
449 {3, 3, 1, 0}, // triangle
450 {4, 6, 4, 1}}; // tetrahedron
451 for (std::size_t i = 0; i < num_entities[c.topological_dimension][d]; i++)
452 {
453 dofmap.tabulate_entity_dofs(dofs.data(), d, i);
454 printer.print_array("tabulate_entity_dofs", dofmap.num_entity_dofs(d),
455 dofs.data(), d, i);
456 }
457 }
458
459 // num_sub_dofmaps
460 printer.print_scalar("num_sub_dofmaps", dofmap.num_sub_dofmaps());
461
462 // create_sub_dofmap
463 for (std::size_t i = 0; i < dofmap.num_sub_dofmaps(); i++)
464 {
465 std::unique_ptr<ufc::dofmap> sub_dofmap(dofmap.create_sub_dofmap(i));
466 test_dofmap(*sub_dofmap, cell_shape, i, printer);
467 }
468
469 printer.end();
470 }
471
472 // Function for testing ufc::cell_integral objects
473 void test_cell_integral(ufc::cell_integral& integral,
474 ufc::shape cell_shape,
475 std::size_t gdim,
476 std::size_t gdeg,
477 std::size_t tensor_size,
478 double** w,
479 bool bench,
480 int id,
481 Printer & printer)
482 {
483 printer.begin("cell_integral", id);
484
485 // Prepare arguments
486 test_cell c(cell_shape, gdim);
487 const std::vector<double> coordinate_dofs = test_coordinate_dofs(gdim, gdeg);
488 std::vector<double> A(tensor_size, 0.0);
489
490 // Call tabulate_tensor
491 integral.tabulate_tensor(A.data(), w, coordinate_dofs.data(), c.orientation);
492 printer.print_vector("tabulate_tensor", A);
493
494 // Benchmark tabulate tensor
495 if (bench)
496 {
497 printer.begin("timing");
498 for (std::size_t num_reps = initial_num_reps;; num_reps *= 2)
499 {
500 double t0 = time();
501 for (std::size_t i = 0; i < num_reps; i++)
502 {
503 integral.tabulate_tensor(A.data(), w, coordinate_dofs.data(),
504 c.orientation);
505 }
506 double dt = time() - t0;
507 if (dt > minimum_timing)
508 {
509 dt /= static_cast<double>(num_reps);
510 printer.print_scalar("cell_integral_timing_iterations", num_reps);
511 printer.print_scalar("cell_integral_time", dt);
512 break;
513 }
514 }
515 printer.end();
516 }
517
518 printer.end();
519 }
520
521 // Function for testing ufc::exterior_facet_integral objects
522 void test_exterior_facet_integral(ufc::exterior_facet_integral& integral,
523 ufc::shape cell_shape,
524 std::size_t gdim,
525 std::size_t gdeg,
526 std::size_t tensor_size,
527 double** w,
528 bool bench,
529 int id,
530 Printer & printer)
531 {
532 printer.begin("exterior_facet_integral", id);
533
534 // Prepare arguments
535 test_cell c(cell_shape, gdim);
536 const std::vector<double> coordinate_dofs = test_coordinate_dofs(gdim, gdeg);
537 std::size_t num_facets = c.topological_dimension + 1;
538 std::vector<double> A(tensor_size);
539
540 // Call tabulate_tensor for each facet
541 for (std::size_t facet = 0; facet < num_facets; facet++)
542 {
543 for(std::size_t i = 0; i < tensor_size; i++)
544 A[i] = 0.0;
545
546 integral.tabulate_tensor(A.data(), w, coordinate_dofs.data(), facet,
547 c.orientation);
548 printer.print_array("tabulate_tensor", tensor_size, A.data(), facet);
549 }
550
551 // Benchmark tabulate tensor
552 if (bench)
553 {
554 printer.begin("timing");
555 for (std::size_t num_reps = initial_num_reps;; num_reps *= 2)
556 {
557 double t0 = time();
558 for (std::size_t i = 0; i < num_reps; i++)
559 {
560 integral.tabulate_tensor(A.data(), w, coordinate_dofs.data(), 0,
561 c.orientation);
562 }
563 double dt = time() - t0;
564 if (dt > minimum_timing)
565 {
566 dt /= static_cast<double>(num_reps);
567 printer.print_scalar("exterior_facet_integral_timing_iterations",
568 num_reps);
569 printer.print_scalar("exterior_facet_integral_time", dt);
570 break;
571 }
572 }
573 printer.end();
574 }
575
576 printer.end();
577 }
578
579 // Function for testing ufc::interior_facet_integral objects
580 void test_interior_facet_integral(ufc::interior_facet_integral& integral,
581 ufc::shape cell_shape,
582 std::size_t gdim,
583 std::size_t gdeg,
584 std::size_t macro_tensor_size,
585 double** w,
586 bool bench,
587 int id,
588 Printer & printer)
589 {
590 printer.begin("interior_facet_integral", id);
591
592 // Prepare arguments
593 test_cell c0(cell_shape, gdim);
594 //test_cell c1(cell_shape, gdim);
595 std::size_t num_facets = c0.topological_dimension + 1;
596 std::vector<double> A(macro_tensor_size);
597
598 // Call tabulate_tensor for each facet-facet combination
599 for (std::size_t facet0 = 0; facet0 < num_facets; facet0++)
600 {
601 for (std::size_t facet1 = 0; facet1 < num_facets; facet1++)
602 {
603 const std::pair<std::vector<double>, std::vector<double>> coordinate_dofs
604 = test_coordinate_dof_pair(gdim, gdeg, facet0, facet1);
605
606 for(std::size_t i = 0; i < macro_tensor_size; i++)
607 A[i] = 0.0;
608
609 integral.tabulate_tensor(A.data(),
610 w,
611 coordinate_dofs.first.data(),
612 coordinate_dofs.second.data(),
613 facet0, facet1,
614 1, 1);
615 printer.print_array("tabulate_tensor", macro_tensor_size, A.data(),
616 facet0, facet1);
617 }
618 }
619
620 // Benchmark tabulate tensor
621 if (bench)
622 {
623 const std::pair<std::vector<double>, std::vector<double>> coordinate_dofs
624 = test_coordinate_dof_pair(gdim, gdeg, 0, 0);
625
626 printer.begin("timing");
627 for (std::size_t num_reps = initial_num_reps;; num_reps *= 2)
628 {
629 double t0 = time();
630 for (std::size_t i = 0; i < num_reps; i++)
631 {
632 integral.tabulate_tensor(A.data(), w,
633 coordinate_dofs.first.data(),
634 coordinate_dofs.second.data(),
635 0, 0,
636 1, 1);
637 }
638
639 double dt = time() - t0;
640 if (dt > minimum_timing)
641 {
642 dt /= static_cast<double>(num_reps);
643 printer.print_scalar("interior_facet_integral_timing_iterations",
644 num_reps);
645 printer.print_scalar("interior_facet_integral_time", dt);
646 break;
647 }
648 }
649 printer.end();
650 }
651
652 printer.end();
653 }
654
655 // Function for testing ufc::vertex_integral objects
656 void test_vertex_integral(ufc::vertex_integral& integral,
657 ufc::shape cell_shape,
658 std::size_t gdim,
659 std::size_t gdeg,
660 std::size_t tensor_size,
661 double** w,
662 bool bench,
663 int id,
664 Printer & printer)
665 {
666 printer.begin("vertex_integral", id);
667
668 // Prepare arguments
669 test_cell c(cell_shape, gdim);
670 const std::vector<double> coordinate_dofs = test_coordinate_dofs(gdim, gdeg);
671 std::size_t num_vertices = c.topological_dimension + 1;
672 std::vector<double> A(tensor_size);
673
674 // Call tabulate_tensor for each vertex
675 for (std::size_t vertex = 0; vertex < num_vertices; vertex++)
676 {
677 for(std::size_t i = 0; i < tensor_size; i++)
678 A[i] = 0.0;
679
680 integral.tabulate_tensor(A.data(), w, coordinate_dofs.data(), vertex,
681 c.orientation);
682 printer.print_array("tabulate_tensor", tensor_size, A.data(), vertex);
683 }
684
685 // Benchmark tabulate tensor
686 if (bench)
687 {
688 printer.begin("timing");
689 for (std::size_t num_reps = initial_num_reps;; num_reps *= 2)
690 {
691 double t0 = time();
692 for (std::size_t i = 0; i < num_reps; i++)
693 {
694 integral.tabulate_tensor(A.data(), w, coordinate_dofs.data(), 0,
695 c.orientation);
696 }
697 double dt = time() - t0;
698 if (dt > minimum_timing)
699 {
700 dt /= static_cast<double>(num_reps);
701 printer.print_scalar("vertex_integral_timing_iterations", num_reps);
702 printer.print_scalar("vertex_integral_time", dt);
703 break;
704 }
705 }
706 printer.end();
707 }
708
709 printer.end();
710 }
711
712 // Function for testing ufc::form objects
713 void test_form(ufc::form& form, bool bench, int id, Printer & printer)
714 {
715 printer.begin("form", id);
716
717 // Compute size of tensors
718 int tensor_size = 1;
719 int macro_tensor_size = 1;
720 for (std::size_t i = 0; i < form.rank(); i++)
721 {
722 std::unique_ptr<ufc::finite_element> element(form.create_finite_element(i));
723 tensor_size *= element->space_dimension();
724
725 // *2 for interior facet integrals
726 macro_tensor_size *= 2*element->space_dimension();
727 }
728
729 // Prepare dummy coefficients
730 double** w = 0;
731 if (form.num_coefficients() > 0)
732 {
733 w = new double * [form.num_coefficients()];
734 for (std::size_t i = 0; i < form.num_coefficients(); i++)
735 {
736 std::unique_ptr<ufc::finite_element>
737 element(form.create_finite_element(form.rank() + i));
738
739 // *2 for interior facet integrals
740 const std::size_t macro_dim = 2*element->space_dimension();
741
742 w[i] = new double[macro_dim];
743 for (std::size_t j = 0; j < macro_dim; j++)
744 w[i][j] = 0.1*static_cast<double>((i + 1)*(j + 1));
745 }
746 }
747
748 // Get cell shape
749 std::unique_ptr<ufc::finite_element> element(form.create_coordinate_finite_element());
750 ufc::shape cell_shape = element->cell_shape();
751 std::size_t gdim = element->geometric_dimension();
752 std::size_t gdeg = element->degree();
753 assert(element->value_rank() == 1);
754 assert(element->value_dimension(0) == gdim);
755 assert(element->family() == std::string("Lagrange"));
756 element.reset();
757
758 // signature
759 //printer.print_scalar("signature", form.signature());
760
761 // rank
762 printer.print_scalar("rank", form.rank());
763
764 // num_coefficients
765 printer.print_scalar("num_coefficients", form.num_coefficients());
766
767 // has_cell_integrals
768 printer.print_scalar("has_cell_integrals", form.has_cell_integrals());
769
770 // has_exterior_facet_integrals
771 printer.print_scalar("has_exterior_facet_integrals",
772 form.has_exterior_facet_integrals());
773
774 // has_interior_facet_integrals
775 printer.print_scalar("has_interior_facet_integrals",
776 form.has_interior_facet_integrals());
777
778 // has_vertex_integrals
779 printer.print_scalar("has_vertex_integrals", form.has_vertex_integrals());
780
781 // max_cell_subdomain_id
782 printer.print_scalar("max_cell_subdomain_id", form.max_cell_subdomain_id());
783
784 // max_exterior_facet_subdomain_id
785 printer.print_scalar("max_exterior_facet_subdomain_id",
786 form.max_exterior_facet_subdomain_id());
787
788 // max_interior_facet_subdomain_id
789 printer.print_scalar("max_interior_facet_subdomain_id",
790 form.max_interior_facet_subdomain_id());
791
792 // max_vertex_subdomain_id
793 printer.print_scalar("max_vertex_subdomain_id",
794 form.max_vertex_subdomain_id());
795
796 // create_finite_element
797 for (std::size_t i = 0; i < form.rank() + form.num_coefficients(); i++)
798 {
799 std::unique_ptr<ufc::finite_element> element(form.create_finite_element(i));
800 test_finite_element(*element, i, printer);
801 }
802
803 // create_dofmap
804 for (std::size_t i = 0; i < form.rank() + form.num_coefficients(); i++)
805 {
806 std::unique_ptr<ufc::dofmap> dofmap(form.create_dofmap(i));
807 test_dofmap(*dofmap, cell_shape, i, printer);
808 }
809
810 // create_cell_integral
811 {
812 std::unique_ptr<ufc::cell_integral>
813 integral(form.create_default_cell_integral());
814 printer.print_scalar("default_cell_integral", (bool)integral);
815 if (integral)
816 {
817 test_cell_integral(*integral, cell_shape, gdim, gdeg,
818 tensor_size, w, bench, -1, printer);
819 }
820 }
821 for (std::size_t i = 0; i < form.max_cell_subdomain_id(); i++)
822 {
823 std::unique_ptr<ufc::cell_integral> integral(form.create_cell_integral(i));
824 if (integral)
825 {
826 test_cell_integral(*integral, cell_shape, gdim, gdeg,
827 tensor_size, w, bench, i, printer);
828 }
829 }
830
831 // create_exterior_facet_integral
832 {
833 std::unique_ptr<ufc::exterior_facet_integral>
834 integral(form.create_default_exterior_facet_integral());
835 printer.print_scalar("default_exterior_facet_integral", (bool)integral);
836 if (integral)
837 {
838 test_exterior_facet_integral(*integral, cell_shape, gdim, gdeg,
839 tensor_size, w, bench, -1, printer);
840 }
841 }
842
843 for (std::size_t i = 0; i < form.max_exterior_facet_subdomain_id(); i++)
844 {
845 std::unique_ptr<ufc::exterior_facet_integral>
846 integral(form.create_exterior_facet_integral(i));
847 if (integral)
848 {
849 test_exterior_facet_integral(*integral, cell_shape, gdim, gdeg,
850 tensor_size, w, bench, i, printer);
851 }
852 }
853
854 // create_interior_facet_integral
855 {
856 std::unique_ptr<ufc::interior_facet_integral>
857 integral(form.create_default_interior_facet_integral());
858 printer.print_scalar("default_interior_facet_integral", (bool)integral);
859 if (integral)
860 {
861 test_interior_facet_integral(*integral, cell_shape, gdim, gdeg,
862 macro_tensor_size, w, bench, -1, printer);
863 }
864 }
865 for (std::size_t i = 0; i < form.max_interior_facet_subdomain_id(); i++)
866 {
867 std::unique_ptr<ufc::interior_facet_integral>
868 integral(form.create_interior_facet_integral(i));
869 if (integral)
870 {
871 test_interior_facet_integral(*integral, cell_shape, gdim, gdeg,
872 macro_tensor_size, w, bench, i, printer);
873 }
874 }
875
876 // create_vertex_integral
877 {
878 std::unique_ptr<ufc::vertex_integral>
879 integral(form.create_default_vertex_integral());
880 printer.print_scalar("default_vertex_integral", (bool)integral);
881 if (integral)
882 {
883 test_vertex_integral(*integral, cell_shape, gdim, gdeg,
884 tensor_size, w, bench, -1, printer);
885 }
886 }
887 for (std::size_t i = 0; i < form.max_vertex_subdomain_id(); i++)
888 {
889 std::unique_ptr<ufc::vertex_integral>
890 integral(form.create_vertex_integral(i));
891 if (integral)
892 {
893 test_vertex_integral(*integral, cell_shape, gdim, gdeg,
894 tensor_size, w, bench, i, printer);
895 }
896 }
897
898 // Cleanup
899 for (std::size_t i = 0; i < form.num_coefficients(); i++)
900 delete [] w[i];
901 delete [] w;
902
903 printer.end();
904 }