1 /// @file
2 /// Test creation, use, and destruction of a blocked element restriction with multiple components in the l-vector
3 /// \test Test creation, use, and destruction of a blocked element restriction with multiple components in the l-vector
4 #include <ceed.h>
5 #include <ceed/backend.h>
6 #include <stdio.h>
7
main(int argc,char ** argv)8 int main(int argc, char **argv) {
9 Ceed ceed;
10 CeedVector x, y;
11 CeedInt num_elem = 8;
12 CeedInt elem_size = 2;
13 CeedInt num_blk = 2;
14 CeedInt blk_size = 5;
15 CeedInt num_comp = 3;
16 CeedInt ind[elem_size * num_elem];
17 CeedScalar x_array[num_comp * (num_elem + 1)];
18 CeedInt e_layout[3];
19 CeedElemRestriction elem_restriction;
20
21 CeedInit(argv[1], &ceed);
22
23 CeedVectorCreate(ceed, num_comp * (num_elem + 1), &x);
24 for (CeedInt i = 0; i < num_elem + 1; i++) {
25 x_array[i + 0 * (num_elem + 1)] = 10 + i;
26 x_array[i + 1 * (num_elem + 1)] = 20 + i;
27 x_array[i + 2 * (num_elem + 1)] = 30 + i;
28 }
29 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array);
30 CeedVectorCreate(ceed, num_comp * num_blk * blk_size * elem_size, &y);
31
32 for (CeedInt i = 0; i < num_elem; i++) {
33 ind[2 * i + 0] = i;
34 ind[2 * i + 1] = i + 1;
35 }
36 CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, num_comp, num_elem + 1, num_comp * (num_elem + 1), CEED_MEM_HOST,
37 CEED_USE_POINTER, ind, &elem_restriction);
38
39 // NoTranspose
40 CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
41 {
42 const CeedScalar *y_array;
43
44 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array);
45 CeedElemRestrictionGetELayout(elem_restriction, e_layout);
46 for (CeedInt i = 0; i < elem_size; i++) { // Node
47 for (CeedInt j = 0; j < num_comp; j++) { // Component
48 for (CeedInt k = 0; k < num_elem; k++) { // Element
49 CeedInt block = k / blk_size;
50 CeedInt elem = k % blk_size;
51 CeedInt index = (i * blk_size + elem) * e_layout[0] + j * e_layout[1] * blk_size + block * e_layout[2] * blk_size;
52 if (y_array[index] != x_array[ind[k * elem_size + i] + j * (num_elem + 1)]) {
53 // LCOV_EXCL_START
54 printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, (double)y_array[index]);
55 // LCOV_EXCL_STOP
56 }
57 }
58 }
59 }
60 CeedVectorRestoreArrayRead(y, &y_array);
61 }
62
63 // Transpose
64 CeedVectorSetValue(x, 0);
65 CeedElemRestrictionApply(elem_restriction, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE);
66 {
67 const CeedScalar *x_array;
68
69 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &x_array);
70 for (CeedInt i = 0; i < num_elem + 1; i++) {
71 for (CeedInt j = 0; j < num_comp; j++) {
72 if (x_array[i + j * (num_elem + 1)] != ((j + 1) * 10 + i) * (i > 0 && i < num_elem ? 2.0 : 1.0)) {
73 // LCOV_EXCL_START
74 printf("Error in restricted array x[%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", j, i, (double)x_array[i + j * (num_elem + 1)]);
75 // LCOV_EXCL_STOP
76 }
77 }
78 }
79 CeedVectorRestoreArrayRead(x, &x_array);
80 }
81
82 CeedVectorDestroy(&x);
83 CeedVectorDestroy(&y);
84 CeedElemRestrictionDestroy(&elem_restriction);
85 CeedDestroy(&ceed);
86 return 0;
87 }
88