/usr/include/ufc_geometry.h is in python-ffc 1.6.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 | // This file provides utility functions for computing geometric quantities.
// This code is released into the public domain.
//
// The FEniCS Project (http://www.fenicsproject.org/) 2013-2015.
#ifndef __UFC_GEOMETRY_H
#define __UFC_GEOMETRY_H
#include <cmath>
// TODO: Wrap all in namespace ufc
//namespace ufc
//{
/// A note regarding data structures. All matrices are represented as
/// row-major flattened raw C++ arrays. Benchmarks indicate that when
/// optimization (-O1 and up) is used, the following conditions hold:
///
/// 1. std::vector is just as fast as raw C++ arrays for indexing.
///
/// 2. Flattened arrays are twice as fast as nested arrays, both for
/// std:vector and raw C++ arrays.
///
/// 3. Defining an array by 'std::vector<double> x(n)', where n is a
/// literal, leads to dynamic allocation and results in significant
/// slowdowns compared to the definition 'double x[n]'.
///
/// The conclusion is that we should use flattened raw C++ arrays in
/// the interfaces for these utility functions, since some of the
/// arrays passed to these functions (in particular Jacobians) are
/// created inside the generated functions (tabulate_tensor). Note
/// that an std::vector x may also be passed as raw pointer by &x[0].
// TODO: Should signatures of compute_<foo>_<cell>_<n>d match for each foo?
// On one hand the snippets use different quantities, on the other
// some consistency is nice to simplify the code generation.
// Currently only the arguments that are actually used are included.
/// --- Some fixed numbers by name for readability in this file ---
// TODO: Use these numbers where relevant below to make this file more self documenting
// (namespaced using UFC_ in the names because they collide with variables in other libraries)
// Use this for array dimensions indexed by local vertex number
#define UFC_NUM_VERTICES_IN_INTERVAL 2
#define UFC_NUM_VERTICES_IN_TRIANGLE 3
#define UFC_NUM_VERTICES_IN_TETRAHEDRON 4
#define UFC_NUM_VERTICES_IN_QUADRILATERAL 4
#define UFC_NUM_VERTICES_IN_HEXAHEDRON 8
// Use this for array dimensions indexed by local edge number
#define UFC_NUM_EDGES_IN_INTERVAL 1
#define UFC_NUM_EDGES_IN_TRIANGLE 3
#define UFC_NUM_EDGES_IN_TETRAHEDRON 6
#define UFC_NUM_EDGES_IN_QUADRILATERAL 4
#define UFC_NUM_EDGES_IN_HEXAHEDRON 12
// Use this for array dimensions indexed by local facet number
#define UFC_NUM_FACETS_IN_INTERVAL 2
#define UFC_NUM_FACETS_IN_TRIANGLE 3
#define UFC_NUM_FACETS_IN_TETRAHEDRON 4
#define UFC_NUM_FACETS_IN_QUADRILATERAL 4
#define UFC_NUM_FACETS_IN_HEXAHEDRON 6
// Use UFC_GDIM_N to show the intention that the geometric dimension is N
#define UFC_GDIM_1 1
#define UFC_GDIM_2 2
#define UFC_GDIM_3 3
// Use UFC_TDIM_N to show the intention that the topological dimension is N
#define UFC_TDIM_1 1
#define UFC_TDIM_2 2
#define UFC_TDIM_3 3
/// --- Local reference cell coordinates by UFC conventions ---
static const double interval_vertices[UFC_NUM_VERTICES_IN_INTERVAL][UFC_TDIM_1] = {
{0.0},
{1.0}
};
static const double triangle_vertices[UFC_NUM_VERTICES_IN_TRIANGLE][UFC_TDIM_2] = {
{0.0, 0.0},
{1.0, 0.0},
{0.0, 1.0}
};
static const double tetrahedron_vertices[UFC_NUM_VERTICES_IN_TETRAHEDRON][UFC_TDIM_3] = {
{0.0, 0.0, 0.0},
{1.0, 0.0, 0.0},
{0.0, 1.0, 0.0},
{0.0, 0.0, 1.0}
};
// FIXME: Insert quad conventions here
/*
static const double quadrilateral_vertices[UFC_NUM_VERTICES_IN_QUADRILATERAL][UFC_TDIM_2] = {
{0.0, 0.0},
{0.0, 0.0},
{0.0, 0.0},
{0.0, 0.0},
};
*/
// FIXME: Insert quad conventions here
/*
static const double hexahedron_vertices[UFC_NUM_VERTICES_IN_HEXAHEDRON][UFC_TDIM_3] = {
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
};
*/
/// --- Local reference cell barycenter by UFC conventions ---
static const double interval_barycenter[UFC_TDIM_1] = {
0.5
};
static const double triangle_barycenter[UFC_TDIM_2] = {
1.0/3.0, 1.0/3.0
};
static const double tetrahedron_barycenter[UFC_TDIM_3] = {
0.25, 0.25, 0.25
};
// FIXME: Insert quad conventions here
/*
static const double quadrilateral_barycenter[UFC_TDIM_2] = {
0.5, 0.5
};
*/
// FIXME: Insert quad conventions here
/*
static const double hexahedron_barycenter[UFC_TDIM_3] = {
0.5, 0.5, 0.5
};
*/
/// --- Local reference cell facet barycenters by UFC conventions ---
static const double interval_facet_barycenter[UFC_NUM_FACETS_IN_INTERVAL][UFC_TDIM_1] = {
{0.0},
{1.0}
};
static const double triangle_facet_barycenter[UFC_NUM_FACETS_IN_TRIANGLE][UFC_TDIM_2] = {
{0.5, 0.5},
{0.0, 0.5},
{0.5, 0.0}
};
static const double tetrahedron_facet_barycenter[UFC_NUM_FACETS_IN_TETRAHEDRON][UFC_TDIM_3] = {
{0.5, 0.5, 0.5},
{0.0, 1.0/3.0, 1.0/3.0},
{1.0/3.0, 0.0, 1.0/3.0},
{1.0/3.0, 1.0/3.0, 0.0},
};
// FIXME: Insert quad conventions here
/*
static const double quadrilateral_facet_barycenter[UFC_NUM_FACETS_IN_QUADRILATERAL][UFC_TDIM_2] = {
{0.0, 0.0},
{0.0, 0.0},
{0.0, 0.0},
{0.0, 0.0},
};
*/
// FIXME: Insert quad conventions here
/*
static const double hexahedron_facet_barycenter[UFC_NUM_FACETS_IN_HEXAHEDRON][UFC_TDIM_3] = {
{0.0, 0.5, 0.5},
{0.0, 0.5, 0.5},
{0.0, 0.5, 0.5},
{0.0, 0.5, 0.5},
{0.0, 0.5, 0.5},
{0.0, 0.5, 0.5},
};
*/
/// --- Local reference cell facet orientations by UFC conventions ---
static const double interval_facet_orientations[UFC_NUM_FACETS_IN_INTERVAL] = {
-1.0,
+1.0,
};
static const double triangle_facet_orientations[UFC_NUM_FACETS_IN_TRIANGLE] = {
+1.0,
-1.0,
+1.0
};
static const double tetrahedron_facet_orientations[UFC_NUM_FACETS_IN_TETRAHEDRON] = {
+1.0,
-1.0,
+1.0,
-1.0
};
// FIXME: Insert quad conventions here
/*
static const double quadrilateral_facet_orientations[UFC_NUM_FACETS_IN_QUADRILATERAL] = {
+1.0,
+1.0,
+1.0,
+1.0,
};
*/
// FIXME: Insert quad conventions here
/*
static const double hexahedron_facet_orientations[UFC_NUM_FACETS_IN_HEXAHEDRON] = {
+1.0,
+1.0,
+1.0,
+1.0,
+1.0,
+1.0,
};
*/
/// --- Local reference cell entity relations by UFC conventions ---
static const unsigned int triangle_edge_vertices[UFC_NUM_EDGES_IN_TRIANGLE][2] = {
{1, 2},
{0, 2},
{0, 1}
};
static const unsigned int tetrahedron_edge_vertices[UFC_NUM_EDGES_IN_TETRAHEDRON][2] = {
{2, 3},
{1, 3},
{1, 2},
{0, 3},
{0, 2},
{0, 1}
};
// FIXME: Insert quad conventions here
/*
static const unsigned int quadrilateral_edge_vertices[UFC_NUM_EDGES_IN_QUADRILATERAL][2] = {
{0, 0},
{0, 0},
{0, 0},
{0, 0},
};
*/
// FIXME: Insert quad conventions here
/*
static const unsigned int hexahedron_edge_vertices[UFC_NUM_EDGES_IN_HEXAHEDRON][2] = {
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
};
*/
/// --- Local reference cell entity relations by UFC conventions ---
static const unsigned int interval_facet_vertices[UFC_NUM_FACETS_IN_INTERVAL][1] = {
{0},
{1}
};
static const unsigned int triangle_facet_vertices[UFC_NUM_FACETS_IN_TRIANGLE][UFC_NUM_VERTICES_IN_INTERVAL] = {
{1, 2},
{0, 2},
{0, 1}
};
static const unsigned int tetrahedron_facet_vertices[UFC_NUM_FACETS_IN_TETRAHEDRON][UFC_NUM_VERTICES_IN_TRIANGLE] = {
{1, 2, 3},
{0, 2, 3},
{0, 1, 3},
{0, 1, 2}
};
static const unsigned int tetrahedron_facet_edge_vertices[UFC_NUM_FACETS_IN_TETRAHEDRON][UFC_NUM_FACETS_IN_TRIANGLE][UFC_NUM_VERTICES_IN_INTERVAL] = {
{{2, 3}, {1, 3}, {1, 2}},
{{2, 3}, {0, 3}, {0, 2}},
{{1, 3}, {0, 3}, {0, 1}},
{{1, 2}, {0, 2}, {0, 1}}
};
// FIXME: Insert quad conventions here
/*
static const unsigned int quadrilateral_facet_vertices[UFC_NUM_FACETS_IN_QUADRILATERAL][UFC_NUM_VERTICES_IN_INTERVAL] = {
{0, 0},
{0, 0},
{0, 0},
{0, 0},
};
*/
// FIXME: Insert quad conventions here
/*
static const unsigned int hexahedron_facet_vertices[UFC_NUM_FACETS_IN_HEXAHEDRON][UFC_NUM_VERTICES_IN_QUADRILATERAL] = {
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
};
*/
// FIXME: Insert quad conventions here
/*
static const unsigned int hexahedron_facet_edge_vertices[UFC_NUM_FACETS_IN_HEXAHEDRON][UFC_NUM_FACETS_IN_QUADRILATERAL][UFC_NUM_VERTICES_IN_INTERVAL] = {
{{0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{0, 0}, {0, 0}, {0, 0}, {0, 0}},
{{0, 0}, {0, 0}, {0, 0}, {0, 0}},
};
*/
/// --- Reference cell edge vectors by UFC conventions (edge vertex 1 - edge vertex 0 for each edge in cell) ---
static const double triangle_reference_edge_vectors[UFC_NUM_EDGES_IN_TRIANGLE][UFC_TDIM_2] = {
{-1.0, 1.0},
{ 0.0, 1.0},
{ 1.0, 0.0},
};
static const double tetrahedron_reference_edge_vectors[UFC_NUM_EDGES_IN_TETRAHEDRON][UFC_TDIM_3] = {
{ 0.0, -1.0, 1.0},
{-1.0, 0.0, 1.0},
{-1.0, 1.0, 0.0},
{ 0.0, 0.0, 1.0},
{ 0.0, 1.0, 0.0},
{ 1.0, 0.0, 0.0},
};
// Edge vectors for each triangle facet of a tetrahedron
static const double tetrahedron_facet_reference_edge_vectors[UFC_NUM_FACETS_IN_TETRAHEDRON][UFC_NUM_EDGES_IN_TRIANGLE][UFC_TDIM_3] = {
{ // facet 0
{ 0.0, -1.0, 1.0},
{-1.0, 0.0, 1.0},
{-1.0, 1.0, 0.0},
},
{ // facet 1
{ 0.0, -1.0, 1.0},
{ 0.0, 0.0, 1.0},
{ 0.0, 1.0, 0.0},
},
{ // facet 2
{-1.0, 0.0, 1.0},
{ 0.0, 0.0, 1.0},
{ 1.0, 0.0, 0.0},
},
{ // facet 3
{-1.0, 1.0, 0.0},
{ 0.0, 1.0, 0.0},
{ 1.0, 0.0, 0.0},
},
};
// FIXME: Insert quad conventions here
/*
static const double quadrilateral_reference_edge_vectors[UFC_NUM_EDGES_IN_QUADRILATERAL][UFC_TDIM_2] = {
{ 0.0, 0.0},
{ 0.0, 0.0},
{ 0.0, 0.0},
{ 0.0, 0.0},
};
*/
// FIXME: Insert quad conventions here
/*
static const double hexahedron_reference_edge_vectors[UFC_NUM_EDGES_IN_HEXAHEDRON][UFC_TDIM_3] = {
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
};
*/
// FIXME: Insert quad conventions here
/*
// Edge vectors for each quadrilateral facet of a hexahedron
static const double hexahedron_facet_reference_edge_vectors[UFC_NUM_FACETS_IN_HEXAHEDRON][UFC_NUM_EDGES_IN_QUADRILATERAL][UFC_TDIM_3] = {
{ // facet 0
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
},
{ // facet 1
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
},
{ // facet 2
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
},
{ // facet 3
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
},
{ // facet 4
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
},
{ // facet 5
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
},
};
*/
/// --- Reference cell facet normals by UFC conventions (outwards pointing on reference cell) ---
static const double interval_reference_facet_normals[UFC_NUM_FACETS_IN_INTERVAL][UFC_TDIM_1] = {
{-1.0},
{+1.0},
};
static const double triangle_reference_facet_normals[UFC_NUM_FACETS_IN_TRIANGLE][UFC_TDIM_2] = {
{ 0.7071067811865476, 0.7071067811865476 },
{-1.0, 0.0},
{ 0.0, -1.0},
};
static const double tetrahedron_reference_facet_normals[UFC_NUM_FACETS_IN_TETRAHEDRON][UFC_TDIM_3] = {
{0.5773502691896258, 0.5773502691896258, 0.5773502691896258},
{-1.0, 0.0, 0.0},
{ 0.0, -1.0, 0.0},
{ 0.0, 0.0, -1.0},
};
// FIXME: Insert quad conventions here
/*
static const double quadrilateral_reference_facet_normals[UFC_NUM_FACETS_IN_QUADRILATERAL][UFC_TDIM_2] = {
{ 0.0, 0.0 },
{ 0.0, 0.0 },
{ 0.0, 0.0 },
{ 0.0, 0.0 },
};
*/
// FIXME: Insert quad conventions here
/*
static const double hexahedron_reference_facet_normals[UFC_NUM_FACETS_IN_HEXAHEDRON][UFC_TDIM_3] = {
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
};
*/
/// --- Jacobians of reference facet cell to reference cell coordinate mappings by UFC conventions ---
static const double triangle_reference_facet_jacobian[UFC_NUM_FACETS_IN_TRIANGLE][UFC_TDIM_2][UFC_TDIM_2-1] = {
{ {-1.0}, { 1.0} },
{ { 0.0}, { 1.0} },
{ { 1.0}, { 0.0} },
};
static const double tetrahedron_reference_facet_jacobian[UFC_NUM_FACETS_IN_TETRAHEDRON][UFC_TDIM_3][UFC_TDIM_3-1] = {
{ {-1.0, -1.0}, {1.0, 0.0}, {0.0, 1.0} },
{ { 0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0} },
{ { 1.0, 0.0}, {0.0, 0.0}, {0.0, 1.0} },
{ { 1.0, 0.0}, {0.0, 1.0}, {0.0, 0.0} },
};
// FIXME: Insert quad conventions here
/*
static const double quadrilateral_reference_facet_jacobian[UFC_NUM_FACETS_IN_QUADRILATERAL][UFC_TDIM_2][UFC_TDIM_2-1] = {
{ { 0.0}, { 0.0} },
{ { 0.0}, { 0.0} },
{ { 0.0}, { 0.0} },
{ { 0.0}, { 0.0} },
};
*/
// FIXME: Insert quad conventions here
/*
static const double hexahedron_reference_facet_jacobian[UFC_NUM_FACETS_IN_HEXAHEDRON][UFC_TDIM_3][UFC_TDIM_3-1] = {
{ { 0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
{ { 0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
{ { 0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
{ { 0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
{ { 0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
{ { 0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
};
*/
/// --- Coordinate mappings from reference facet cell to reference cell by UFC conventions ---
inline void compute_reference_facet_to_reference_cell_coordinates_interval(double Xc[UFC_TDIM_1], unsigned int facet)
{
switch (facet)
{
case 0:
Xc[0] = 0.0;
break;
case 1:
Xc[0] = 1.0;
break;
};
}
inline void compute_reference_facet_to_reference_cell_coordinates_triangle(double Xc[UFC_TDIM_2], const double Xf[UFC_TDIM_2-1], unsigned int facet)
{
switch (facet)
{
case 0:
Xc[0] = 1.0 - Xf[0];
Xc[1] = Xf[0];
break;
case 1:
Xc[0] = 0.0;
Xc[1] = Xf[0];
break;
case 2:
Xc[0] = Xf[0];
Xc[1] = 0.0;
break;
};
}
inline void compute_reference_facet_to_reference_cell_coordinates_tetrahedron(double Xc[UFC_TDIM_3], const double Xf[UFC_TDIM_3-1], unsigned int facet)
{
switch (facet)
{
case 0:
Xc[0] = 1.0 - Xf[0] - Xf[1];
Xc[1] = Xf[0];
Xc[2] = Xf[1];
break;
case 1:
Xc[0] = 0.0;
Xc[1] = Xf[0];
Xc[2] = Xf[1];
break;
case 2:
Xc[0] = Xf[0];
Xc[1] = 0.0;
Xc[2] = Xf[1];
break;
case 3:
Xc[0] = Xf[0];
Xc[1] = Xf[1];
Xc[2] = 0.0;
break;
};
}
///--- Computation of Jacobian matrices ---
/// Compute Jacobian J for interval embedded in R^1
inline void compute_jacobian_interval_1d(double J[UFC_GDIM_1*UFC_TDIM_1],
const double vertex_coordinates[2])
{
J[0] = vertex_coordinates[1] - vertex_coordinates[0];
}
/// Compute Jacobian J for interval embedded in R^2
inline void compute_jacobian_interval_2d(double J[UFC_GDIM_2*UFC_TDIM_1],
const double vertex_coordinates[4])
{
J[0] = vertex_coordinates[2] - vertex_coordinates[0];
J[1] = vertex_coordinates[3] - vertex_coordinates[1];
}
/// Compute Jacobian J for interval embedded in R^3
inline void compute_jacobian_interval_3d(double J[UFC_GDIM_3*UFC_TDIM_1],
const double vertex_coordinates[6])
{
J[0] = vertex_coordinates[3] - vertex_coordinates[0];
J[1] = vertex_coordinates[4] - vertex_coordinates[1];
J[2] = vertex_coordinates[5] - vertex_coordinates[2];
}
/// Compute Jacobian J for triangle embedded in R^2
inline void compute_jacobian_triangle_2d(double J[UFC_GDIM_2*UFC_TDIM_2],
const double vertex_coordinates[6])
{
J[0] = vertex_coordinates[2] - vertex_coordinates[0];
J[1] = vertex_coordinates[4] - vertex_coordinates[0];
J[2] = vertex_coordinates[3] - vertex_coordinates[1];
J[3] = vertex_coordinates[5] - vertex_coordinates[1];
}
/// Compute Jacobian J for triangle embedded in R^3
inline void compute_jacobian_triangle_3d(double J[UFC_GDIM_3*UFC_TDIM_2],
const double vertex_coordinates[9])
{
J[0] = vertex_coordinates[3] - vertex_coordinates[0];
J[1] = vertex_coordinates[6] - vertex_coordinates[0];
J[2] = vertex_coordinates[4] - vertex_coordinates[1];
J[3] = vertex_coordinates[7] - vertex_coordinates[1];
J[4] = vertex_coordinates[5] - vertex_coordinates[2];
J[5] = vertex_coordinates[8] - vertex_coordinates[2];
}
/// Compute Jacobian J for tetrahedron embedded in R^3
inline void compute_jacobian_tetrahedron_3d(double J[UFC_GDIM_3*UFC_TDIM_3],
const double vertex_coordinates[12])
{
J[0] = vertex_coordinates[3] - vertex_coordinates[0];
J[1] = vertex_coordinates[6] - vertex_coordinates[0];
J[2] = vertex_coordinates[9] - vertex_coordinates[0];
J[3] = vertex_coordinates[4] - vertex_coordinates[1];
J[4] = vertex_coordinates[7] - vertex_coordinates[1];
J[5] = vertex_coordinates[10] - vertex_coordinates[1];
J[6] = vertex_coordinates[5] - vertex_coordinates[2];
J[7] = vertex_coordinates[8] - vertex_coordinates[2];
J[8] = vertex_coordinates[11] - vertex_coordinates[2];
}
//--- Computation of Jacobian inverses --- // TODO: Remove this when ffc is updated to use the NEW ones below
/// Compute Jacobian inverse K for interval embedded in R^1
inline void compute_jacobian_inverse_interval_1d(double* K,
double& det,
const double* J)
{
det = J[0];
K[0] = 1.0 / det;
}
/// Compute Jacobian (pseudo)inverse K for interval embedded in R^2
inline void compute_jacobian_inverse_interval_2d(double* K,
double& det,
const double* J)
{
const double det2 = J[0]*J[0] + J[1]*J[1];
det = std::sqrt(det2);
K[0] = J[0] / det2;
K[1] = J[1] / det2;
}
/// Compute Jacobian (pseudo)inverse K for interval embedded in R^3
inline void compute_jacobian_inverse_interval_3d(double* K,
double& det,
const double* J)
{
// TODO: Move computation of det to a separate function, det is often needed when K is not
const double det2 = J[0]*J[0] + J[1]*J[1] + J[2]*J[2];
det = std::sqrt(det2);
K[0] = J[0] / det2;
K[1] = J[1] / det2;
K[2] = J[2] / det2;
}
/// Compute Jacobian inverse K for triangle embedded in R^2
inline void compute_jacobian_inverse_triangle_2d(double* K,
double& det,
const double* J)
{
det = J[0]*J[3] - J[1]*J[2];
K[0] = J[3] / det;
K[1] = -J[1] / det;
K[2] = -J[2] / det;
K[3] = J[0] / det;
}
/// Compute Jacobian (pseudo)inverse K for triangle embedded in R^3
inline void compute_jacobian_inverse_triangle_3d(double* K,
double& det,
const double* J)
{
const double d_0 = J[2]*J[5] - J[4]*J[3];
const double d_1 = J[4]*J[1] - J[0]*J[5];
const double d_2 = J[0]*J[3] - J[2]*J[1];
const double c_0 = J[0]*J[0] + J[2]*J[2] + J[4]*J[4];
const double c_1 = J[1]*J[1] + J[3]*J[3] + J[5]*J[5];
const double c_2 = J[0]*J[1] + J[2]*J[3] + J[4]*J[5];
const double den = c_0*c_1 - c_2*c_2;
const double det2 = d_0*d_0 + d_1*d_1 + d_2*d_2;
det = std::sqrt(det2);
K[0] = (J[0]*c_1 - J[1]*c_2) / den;
K[1] = (J[2]*c_1 - J[3]*c_2) / den;
K[2] = (J[4]*c_1 - J[5]*c_2) / den;
K[3] = (J[1]*c_0 - J[0]*c_2) / den;
K[4] = (J[3]*c_0 - J[2]*c_2) / den;
K[5] = (J[5]*c_0 - J[4]*c_2) / den;
}
/// Compute Jacobian inverse K for tetrahedron embedded in R^3
inline void compute_jacobian_inverse_tetrahedron_3d(double* K,
double& det,
const double* J)
{
const double d_00 = J[4]*J[8] - J[5]*J[7];
const double d_01 = J[5]*J[6] - J[3]*J[8];
const double d_02 = J[3]*J[7] - J[4]*J[6];
const double d_10 = J[2]*J[7] - J[1]*J[8];
const double d_11 = J[0]*J[8] - J[2]*J[6];
const double d_12 = J[1]*J[6] - J[0]*J[7];
const double d_20 = J[1]*J[5] - J[2]*J[4];
const double d_21 = J[2]*J[3] - J[0]*J[5];
const double d_22 = J[0]*J[4] - J[1]*J[3];
det = J[0]*d_00 + J[3]*d_10 + J[6]*d_20;
K[0] = d_00 / det;
K[1] = d_10 / det;
K[2] = d_20 / det;
K[3] = d_01 / det;
K[4] = d_11 / det;
K[5] = d_21 / det;
K[6] = d_02 / det;
K[7] = d_12 / det;
K[8] = d_22 / det;
}
//--- NEW Computation of Jacobian (sub)determinants ---
/// Compute Jacobian determinant for interval embedded in R^1
inline void compute_jacobian_determinants_interval_1d(double & det,
const double J[UFC_GDIM_1*UFC_TDIM_1])
{
det = J[0];
}
/// Compute Jacobian (pseudo)determinants for interval embedded in R^2
inline void compute_jacobian_determinants_interval_2d(double & det2,
double & det,
const double J[UFC_GDIM_2*UFC_TDIM_1])
{
det2 = J[0]*J[0] + J[1]*J[1];
det = std::sqrt(det2);
}
/// Compute Jacobian (pseudo)determinants for interval embedded in R^3
inline void compute_jacobian_determinants_interval_3d(double & det2,
double & det,
const double J[UFC_GDIM_3*UFC_TDIM_1])
{
det2 = J[0]*J[0] + J[1]*J[1] + J[2]*J[2];
det = std::sqrt(det2);
}
/// Compute Jacobian determinant for triangle embedded in R^2
inline void compute_jacobian_determinants_triangle_2d(double & det,
const double J[UFC_GDIM_2*UFC_TDIM_2])
{
det = J[0]*J[3] - J[1]*J[2];
}
/// Compute Jacobian (pseudo)determinants for triangle embedded in R^3
inline void compute_jacobian_determinants_triangle_3d(double & den,
double & det2,
double & det,
double c[3],
const double J[UFC_GDIM_3*UFC_TDIM_2])
{
const double d_0 = J[2]*J[5] - J[4]*J[3];
const double d_1 = J[4]*J[1] - J[0]*J[5];
const double d_2 = J[0]*J[3] - J[2]*J[1];
c[0] = J[0]*J[0] + J[2]*J[2] + J[4]*J[4];
c[1] = J[1]*J[1] + J[3]*J[3] + J[5]*J[5];
c[2] = J[0]*J[1] + J[2]*J[3] + J[4]*J[5];
den = c[0]*c[1] - c[2]*c[2];
det2 = d_0*d_0 + d_1*d_1 + d_2*d_2;
det = std::sqrt(det2);
}
/// Compute Jacobian determinants for tetrahedron embedded in R^3
inline void compute_jacobian_determinants_tetrahedron_3d(double & det,
double d[9],
const double J[UFC_GDIM_3*UFC_TDIM_3])
{
d[0*3 + 0] = J[4]*J[8] - J[5]*J[7];
d[0*3 + 1] = J[5]*J[6] - J[3]*J[8];
d[0*3 + 2] = J[3]*J[7] - J[4]*J[6];
d[1*3 + 0] = J[2]*J[7] - J[1]*J[8];
d[1*3 + 1] = J[0]*J[8] - J[2]*J[6];
d[1*3 + 2] = J[1]*J[6] - J[0]*J[7];
d[2*3 + 0] = J[1]*J[5] - J[2]*J[4];
d[2*3 + 1] = J[2]*J[3] - J[0]*J[5];
d[2*3 + 2] = J[0]*J[4] - J[1]*J[3];
det = J[0]*d[0*3 + 0] + J[3]*d[1*3 + 0] + J[6]*d[2*3 + 0];
}
//--- NEW Computation of Jacobian inverses ---
/// Compute Jacobian inverse K for interval embedded in R^1
inline void new_compute_jacobian_inverse_interval_1d(double K[UFC_TDIM_1*UFC_GDIM_1],
double det)
{
K[0] = 1.0 / det;
}
/// Compute Jacobian (pseudo)inverse K for interval embedded in R^2
inline void new_compute_jacobian_inverse_interval_2d(double K[UFC_TDIM_1*UFC_GDIM_2],
double det2,
const double J[UFC_GDIM_2*UFC_TDIM_1])
{
K[0] = J[0] / det2;
K[1] = J[1] / det2;
}
/// Compute Jacobian (pseudo)inverse K for interval embedded in R^3
inline void new_compute_jacobian_inverse_interval_3d(double K[UFC_TDIM_1*UFC_GDIM_3],
double det2,
const double J[UFC_GDIM_3*UFC_TDIM_1])
{
K[0] = J[0] / det2;
K[1] = J[1] / det2;
K[2] = J[2] / det2;
}
/// Compute Jacobian inverse K for triangle embedded in R^2
inline void new_compute_jacobian_inverse_triangle_2d(double K[UFC_TDIM_2*UFC_GDIM_2],
double det,
const double J[UFC_GDIM_2*UFC_TDIM_2])
{
K[0] = J[3] / det;
K[1] = -J[1] / det;
K[2] = -J[2] / det;
K[3] = J[0] / det;
}
/// Compute Jacobian (pseudo)inverse K for triangle embedded in R^3
inline void new_compute_jacobian_inverse_triangle_3d(double K[UFC_TDIM_2*UFC_GDIM_3],
double den,
const double c[3],
const double J[UFC_GDIM_3*UFC_TDIM_2])
{
K[0] = (J[0]*c[1] - J[1]*c[2]) / den;
K[1] = (J[2]*c[1] - J[3]*c[2]) / den;
K[2] = (J[4]*c[1] - J[5]*c[2]) / den;
K[3] = (J[1]*c[0] - J[0]*c[2]) / den;
K[4] = (J[3]*c[0] - J[2]*c[2]) / den;
K[5] = (J[5]*c[0] - J[4]*c[2]) / den;
}
/// Compute Jacobian inverse K for tetrahedron embedded in R^3
inline void new_compute_jacobian_inverse_tetrahedron_3d(double K[UFC_TDIM_3*UFC_GDIM_3],
double det,
const double d[9])
{
K[0] = d[0*3 + 0] / det;
K[1] = d[1*3 + 0] / det;
K[2] = d[2*3 + 0] / det;
K[3] = d[0*3 + 1] / det;
K[4] = d[1*3 + 1] / det;
K[5] = d[2*3 + 1] / det;
K[6] = d[0*3 + 2] / det;
K[7] = d[1*3 + 2] / det;
K[8] = d[2*3 + 2] / det;
}
// --- Computation of edge, face, facet scaling factors
/// Compute edge scaling factors for triangle embedded in R^2
inline void compute_edge_scaling_factors_triangle_2d(double dx[2],
const double vertex_coordinates[6],
std::size_t facet)
{
// Get vertices on edge
const unsigned int v0 = triangle_facet_vertices[facet][0];
const unsigned int v1 = triangle_facet_vertices[facet][1];
// Compute scale factor (length of edge scaled by length of reference interval)
dx[0] = vertex_coordinates[2*v1 + 0] - vertex_coordinates[2*v0 + 0];
dx[1] = vertex_coordinates[2*v1 + 1] - vertex_coordinates[2*v0 + 1];
}
/// Compute facet scaling factor for triangle embedded in R^2
inline void compute_facet_scaling_factor_triangle_2d(double & det,
const double dx[2])
{
det = std::sqrt(dx[0]*dx[0] + dx[1]*dx[1]);
}
/// Compute edge scaling factors for triangle embedded in R^3
inline void compute_edge_scaling_factors_triangle_3d(double dx[3],
const double vertex_coordinates[9],
std::size_t facet)
{
// Get vertices on edge
const unsigned int v0 = triangle_facet_vertices[facet][0];
const unsigned int v1 = triangle_facet_vertices[facet][1];
// Compute scale factor (length of edge scaled by length of reference interval)
dx[0] = vertex_coordinates[3*v1 + 0] - vertex_coordinates[3*v0 + 0];
dx[1] = vertex_coordinates[3*v1 + 1] - vertex_coordinates[3*v0 + 1];
dx[2] = vertex_coordinates[3*v1 + 2] - vertex_coordinates[3*v0 + 2];
}
/// Compute facet scaling factor for triangle embedded in R^3
inline void compute_facet_scaling_factor_triangle_3d(double & det,
const double dx[3])
{
det = std::sqrt(dx[0]*dx[0] + dx[1]*dx[1] + dx[2]*dx[2]);
}
/// Compute face scaling factors for tetrahedron embedded in R^3
inline void compute_face_scaling_factors_tetrahedron_3d(double a[3],
const double vertex_coordinates[12],
std::size_t facet)
{
// Get vertices on face
const unsigned int v0 = tetrahedron_facet_vertices[facet][0];
const unsigned int v1 = tetrahedron_facet_vertices[facet][1];
const unsigned int v2 = tetrahedron_facet_vertices[facet][2];
// Compute scale factor (area of face scaled by area of reference triangle)
a[0] = (vertex_coordinates[3*v0 + 1]*vertex_coordinates[3*v1 + 2] +
vertex_coordinates[3*v0 + 2]*vertex_coordinates[3*v2 + 1] +
vertex_coordinates[3*v1 + 1]*vertex_coordinates[3*v2 + 2]) -
(vertex_coordinates[3*v2 + 1]*vertex_coordinates[3*v1 + 2] +
vertex_coordinates[3*v2 + 2]*vertex_coordinates[3*v0 + 1] +
vertex_coordinates[3*v1 + 1]*vertex_coordinates[3*v0 + 2]);
a[1] = (vertex_coordinates[3*v0 + 2]*vertex_coordinates[3*v1 + 0] +
vertex_coordinates[3*v0 + 0]*vertex_coordinates[3*v2 + 2] +
vertex_coordinates[3*v1 + 2]*vertex_coordinates[3*v2 + 0]) -
(vertex_coordinates[3*v2 + 2]*vertex_coordinates[3*v1 + 0] +
vertex_coordinates[3*v2 + 0]*vertex_coordinates[3*v0 + 2] +
vertex_coordinates[3*v1 + 2]*vertex_coordinates[3*v0 + 0]);
a[2] = (vertex_coordinates[3*v0 + 0]*vertex_coordinates[3*v1 + 1] +
vertex_coordinates[3*v0 + 1]*vertex_coordinates[3*v2 + 0] +
vertex_coordinates[3*v1 + 0]*vertex_coordinates[3*v2 + 1]) -
(vertex_coordinates[3*v2 + 0]*vertex_coordinates[3*v1 + 1] +
vertex_coordinates[3*v2 + 1]*vertex_coordinates[3*v0 + 0] +
vertex_coordinates[3*v1 + 0]*vertex_coordinates[3*v0 + 1]);
}
/// Compute facet scaling factor for tetrahedron embedded in R^3
inline void compute_facet_scaling_factor_tetrahedron_3d(double & det,
const double a[3])
{
det = std::sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
}
///--- Compute facet normal directions ---
/// Compute facet direction for interval embedded in R^1
inline void compute_facet_normal_direction_interval_1d(bool & direction,
const double vertex_coordinates[2],
std::size_t facet)
{
direction = facet == 0
? vertex_coordinates[0] > vertex_coordinates[1]
: vertex_coordinates[1] > vertex_coordinates[0];
}
/// Compute facet direction for triangle embedded in R^2
inline void compute_facet_normal_direction_triangle_2d(bool & direction,
const double vertex_coordinates[6],
const double dx[2],
std::size_t facet)
{
const unsigned int v0 = triangle_facet_vertices[facet][0];
direction = dx[1]*(vertex_coordinates[2*facet ] - vertex_coordinates[2*v0 ])
- dx[0]*(vertex_coordinates[2*facet + 1] - vertex_coordinates[2*v0 + 1])
< 0;
}
/// Compute facet direction for tetrahedron embedded in R^3
inline void compute_facet_normal_direction_tetrahedron_3d(bool & direction,
const double vertex_coordinates[9],
const double a[3],
std::size_t facet)
{
const unsigned int v0 = tetrahedron_facet_vertices[facet][0];
direction = a[0]*(vertex_coordinates[3*facet ] - vertex_coordinates[3*v0 ])
+ a[1]*(vertex_coordinates[3*facet + 1] - vertex_coordinates[3*v0 + 1])
+ a[2]*(vertex_coordinates[3*facet + 2] - vertex_coordinates[3*v0 + 2])
< 0;
}
///--- Compute facet normal vectors ---
/// Compute facet normal for interval embedded in R^1
inline void compute_facet_normal_interval_1d(double n[UFC_GDIM_1],
bool direction)
{
// Facet normals are 1.0 or -1.0: (-1.0) <-- X------X --> (1.0)
n[0] = direction ? 1.0 : -1.0;
}
/// Compute facet normal for interval embedded in R^2
inline void compute_facet_normal_interval_2d(double n[UFC_GDIM_2],
const double vertex_coordinates[4],
std::size_t facet)
{
if (facet == 0)
{
n[0] = vertex_coordinates[0] - vertex_coordinates[2];
n[1] = vertex_coordinates[1] - vertex_coordinates[3];
}
else
{
n[0] = vertex_coordinates[2] - vertex_coordinates[0];
n[1] = vertex_coordinates[3] - vertex_coordinates[1];
}
const double n_length = std::sqrt(n[0]*n[0] + n[1]*n[1]);
n[0] /= n_length;
n[1] /= n_length;
}
/// Compute facet normal for interval embedded in R^3
inline void compute_facet_normal_interval_3d(double n[UFC_GDIM_3],
const double vertex_coordinates[6],
std::size_t facet)
{
if (facet == 0)
{
n[0] = vertex_coordinates[0] - vertex_coordinates[3];
n[1] = vertex_coordinates[1] - vertex_coordinates[4];
n[1] = vertex_coordinates[2] - vertex_coordinates[5];
}
else
{
n[0] = vertex_coordinates[3] - vertex_coordinates[0];
n[1] = vertex_coordinates[4] - vertex_coordinates[1];
n[1] = vertex_coordinates[5] - vertex_coordinates[2];
}
const double n_length = std::sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);
n[0] /= n_length;
n[1] /= n_length;
n[2] /= n_length;
}
/// Compute facet normal for triangle embedded in R^2
inline void compute_facet_normal_triangle_2d(double n[UFC_GDIM_2],
const double dx[2],
const double det,
bool direction)
{
// Compute facet normals from the facet scale factor constants
n[0] = direction ? dx[1] / det : -dx[1] / det;
n[1] = direction ? -dx[0] / det : dx[0] / det;
}
/// Compute facet normal for triangle embedded in R^3
inline void compute_facet_normal_triangle_3d(double n[UFC_GDIM_3],
const double vertex_coordinates[6],
std::size_t facet)
{
// Compute facet normal for triangles in 3D
const unsigned int vertex0 = facet;
// Get coordinates corresponding the vertex opposite this
const unsigned int vertex1 = triangle_facet_vertices[facet][0];
const unsigned int vertex2 = triangle_facet_vertices[facet][1];
// Define vectors n = (p2 - p0) and t = normalized (p2 - p1)
n[0] = vertex_coordinates[3*vertex2 + 0] - vertex_coordinates[3*vertex0 + 0];
n[1] = vertex_coordinates[3*vertex2 + 1] - vertex_coordinates[3*vertex0 + 1];
n[2] = vertex_coordinates[3*vertex2 + 2] - vertex_coordinates[3*vertex0 + 2];
double t0 = vertex_coordinates[3*vertex2 + 0] - vertex_coordinates[3*vertex1 + 0];
double t1 = vertex_coordinates[3*vertex2 + 1] - vertex_coordinates[3*vertex1 + 1];
double t2 = vertex_coordinates[3*vertex2 + 2] - vertex_coordinates[3*vertex1 + 2];
const double t_length = std::sqrt(t0*t0 + t1*t1 + t2*t2);
t0 /= t_length;
t1 /= t_length;
t2 /= t_length;
// Subtract, the projection of (p2 - p0) onto (p2 - p1), from (p2 - p0)
const double ndott = t0*n[0] + t1*n[1] + t2*n[2];
n[0] -= ndott*t0;
n[1] -= ndott*t1;
n[2] -= ndott*t2;
const double n_length = std::sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);
// Normalize
n[0] /= n_length;
n[1] /= n_length;
n[2] /= n_length;
}
/// Compute facet normal for tetrahedron embedded in R^3
inline void compute_facet_normal_tetrahedron_3d(double n[UFC_GDIM_3],
const double a[3],
const double det,
bool direction)
{
// Compute facet normals from the facet scale factor constants
n[0] = direction ? a[0] / det : -a[0] / det;
n[1] = direction ? a[1] / det : -a[1] / det;
n[2] = direction ? a[2] / det : -a[2] / det;
}
///--- Compute circumradius ---
/// Compute circumradius for interval embedded in R^1
inline void compute_circumradius_interval_1d(double & circumradius,
double volume)
{
// Compute circumradius; in 1D it is equal to half the cell length
circumradius = volume / 2.0;
}
/// Compute circumradius for interval embedded in R^2
inline void compute_circumradius_interval_2d(double & circumradius,
double volume)
{
// Compute circumradius of interval in 2D (1/2 volume)
circumradius = volume / 2.0;
}
/// Compute circumradius for interval embedded in R^3
inline void compute_circumradius_interval_3d(double & circumradius,
double volume)
{
// Compute circumradius of interval in 3D (1/2 volume)
circumradius = volume / 2.0;
}
/// Compute circumradius for triangle embedded in R^2
inline void compute_circumradius_triangle_2d(double & circumradius,
const double vertex_coordinates[6],
const double J[UFC_GDIM_2*UFC_TDIM_2],
double volume)
{
// Compute circumradius of triangle in 2D
const double v1v2 = std::sqrt( (vertex_coordinates[4] - vertex_coordinates[2])*(vertex_coordinates[4] - vertex_coordinates[2])
+ (vertex_coordinates[5] - vertex_coordinates[3])*(vertex_coordinates[5] - vertex_coordinates[3]) );
const double v0v2 = std::sqrt(J[3]*J[3] + J[1]*J[1]);
const double v0v1 = std::sqrt(J[0]*J[0] + J[2]*J[2]);
circumradius = 0.25*(v1v2*v0v2*v0v1) / volume;
}
/// Compute circumradius for triangle embedded in R^3
inline void compute_circumradius_triangle_3d(double & circumradius,
const double vertex_coordinates[9],
const double J[UFC_GDIM_3*UFC_TDIM_2],
double volume)
{
// Compute circumradius of triangle in 3D
const double v1v2 = std::sqrt( (vertex_coordinates[6] - vertex_coordinates[3])*(vertex_coordinates[6] - vertex_coordinates[3])
+ (vertex_coordinates[7] - vertex_coordinates[4])*(vertex_coordinates[7] - vertex_coordinates[4])
+ (vertex_coordinates[8] - vertex_coordinates[5])*(vertex_coordinates[8] - vertex_coordinates[5]));
const double v0v2 = std::sqrt( J[3]*J[3] + J[1]*J[1] + J[5]*J[5]);
const double v0v1 = std::sqrt( J[0]*J[0] + J[2]*J[2] + J[4]*J[4]);
circumradius = 0.25*(v1v2*v0v2*v0v1) / volume;
}
/// Compute circumradius for tetrahedron embedded in R^3
inline void compute_circumradius_tetrahedron_3d(double & circumradius,
const double vertex_coordinates[12],
const double J[UFC_GDIM_3*UFC_TDIM_3],
double volume)
{
// Compute circumradius
const double v1v2 = std::sqrt( (vertex_coordinates[6] - vertex_coordinates[3])*(vertex_coordinates[6] - vertex_coordinates[3])
+ (vertex_coordinates[7] - vertex_coordinates[4])*(vertex_coordinates[7] - vertex_coordinates[4])
+ (vertex_coordinates[8] - vertex_coordinates[5])*(vertex_coordinates[8] - vertex_coordinates[5]) );
const double v0v2 = std::sqrt(J[1]*J[1] + J[4]*J[4] + J[7]*J[7]);
const double v0v1 = std::sqrt(J[0]*J[0] + J[3]*J[3] + J[6]*J[6]);
const double v0v3 = std::sqrt(J[2]*J[2] + J[5]*J[5] + J[8]*J[8]);
const double v1v3 = std::sqrt( (vertex_coordinates[ 9] - vertex_coordinates[3])*(vertex_coordinates[ 9] - vertex_coordinates[3])
+ (vertex_coordinates[10] - vertex_coordinates[4])*(vertex_coordinates[10] - vertex_coordinates[4])
+ (vertex_coordinates[11] - vertex_coordinates[5])*(vertex_coordinates[11] - vertex_coordinates[5]) );
const double v2v3 = std::sqrt( (vertex_coordinates[ 9] - vertex_coordinates[6])*(vertex_coordinates[ 9] - vertex_coordinates[6])
+ (vertex_coordinates[10] - vertex_coordinates[7])*(vertex_coordinates[10] - vertex_coordinates[7])
+ (vertex_coordinates[11] - vertex_coordinates[8])*(vertex_coordinates[11] - vertex_coordinates[8]) );
const double la = v1v2*v0v3;
const double lb = v0v2*v1v3;
const double lc = v0v1*v2v3;
const double s = 0.5*(la+lb+lc);
const double area = std::sqrt(s*(s-la)*(s-lb)*(s-lc));
circumradius = area / (6.0*volume);
}
///--- Compute max facet edge lengths ---
/// Compute min edge length in facet of tetrahedron embedded in R^3
inline void compute_min_facet_edge_length_tetrahedron_3d(double & min_edge_length,
unsigned int facet,
const double vertex_coordinates[3*4])
{
// TODO: Extract compute_facet_edge_lengths_tetrahedron_3d(), reuse between min/max functions
double edge_lengths_sqr[3];
for (unsigned int edge = 0; edge < 3; ++edge)
{
const unsigned int vertex0 = tetrahedron_facet_edge_vertices[facet][edge][0];
const unsigned int vertex1 = tetrahedron_facet_edge_vertices[facet][edge][1];
edge_lengths_sqr[edge] = (vertex_coordinates[3*vertex1 + 0] - vertex_coordinates[3*vertex0 + 0])*(vertex_coordinates[3*vertex1 + 0] - vertex_coordinates[3*vertex0 + 0])
+ (vertex_coordinates[3*vertex1 + 1] - vertex_coordinates[3*vertex0 + 1])*(vertex_coordinates[3*vertex1 + 1] - vertex_coordinates[3*vertex0 + 1])
+ (vertex_coordinates[3*vertex1 + 2] - vertex_coordinates[3*vertex0 + 2])*(vertex_coordinates[3*vertex1 + 2] - vertex_coordinates[3*vertex0 + 2]);
}
min_edge_length = std::sqrt(std::min(std::min(edge_lengths_sqr[1], edge_lengths_sqr[1]), edge_lengths_sqr[2]));
}
///--- Compute max facet edge lengths ---
/// Compute max edge length in facet of tetrahedron embedded in R^3
inline void compute_max_facet_edge_length_tetrahedron_3d(double & max_edge_length,
unsigned int facet,
const double vertex_coordinates[12])
{
// TODO: Extract compute_facet_edge_lengths_tetrahedron_3d(), reuse between min/max functions
double edge_lengths_sqr[3];
for (unsigned int edge = 0; edge < 3; ++edge)
{
const unsigned int vertex0 = tetrahedron_facet_edge_vertices[facet][edge][0];
const unsigned int vertex1 = tetrahedron_facet_edge_vertices[facet][edge][1];
edge_lengths_sqr[edge] = (vertex_coordinates[3*vertex1 + 0] - vertex_coordinates[3*vertex0 + 0])*(vertex_coordinates[3*vertex1 + 0] - vertex_coordinates[3*vertex0 + 0])
+ (vertex_coordinates[3*vertex1 + 1] - vertex_coordinates[3*vertex0 + 1])*(vertex_coordinates[3*vertex1 + 1] - vertex_coordinates[3*vertex0 + 1])
+ (vertex_coordinates[3*vertex1 + 2] - vertex_coordinates[3*vertex0 + 2])*(vertex_coordinates[3*vertex1 + 2] - vertex_coordinates[3*vertex0 + 2]);
}
max_edge_length = std::sqrt(std::max(std::max(edge_lengths_sqr[0], edge_lengths_sqr[1]), edge_lengths_sqr[2]));
}
//} // TODO: Wrap all in namespace ufc
#endif
|