1 /// @file
2 /// Test creation, use, and destruction of a blocked element restriction
3 /// \test Test creation, use, and destruction of a blocked element restriction
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 blk_size = 5;
14 CeedInt ind[elem_size * num_elem];
15 CeedScalar x_array[num_elem + 1];
16 CeedInt e_layout[3];
17 CeedElemRestriction elem_restriction;
18
19 CeedInit(argv[1], &ceed);
20
21 CeedVectorCreate(ceed, num_elem + 1, &x);
22 for (CeedInt i = 0; i < num_elem + 1; i++) x_array[i] = 10 + i;
23 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array);
24 CeedVectorCreate(ceed, blk_size * elem_size, &y);
25
26 for (CeedInt i = 0; i < num_elem; i++) {
27 ind[2 * i + 0] = i;
28 ind[2 * i + 1] = i + 1;
29 }
30 CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, 1, 1, num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction);
31
32 // No Transpose
33 CeedElemRestrictionApplyBlock(elem_restriction, 1, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
34 {
35 const CeedScalar *y_array;
36
37 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array);
38 CeedElemRestrictionGetELayout(elem_restriction, e_layout);
39 for (CeedInt i = 0; i < elem_size; i++) { // Node
40 for (CeedInt j = 0; j < 1; j++) { // Component
41 for (CeedInt k = blk_size; k < num_elem; k++) { // Element
42 CeedInt block = k / blk_size;
43 CeedInt elem = k % blk_size;
44 CeedInt index = (i * blk_size + elem) * e_layout[0] + j * e_layout[1] * blk_size + block * e_layout[2] * blk_size - blk_size * elem_size;
45 if (y_array[index] != x_array[ind[k * elem_size + i]]) {
46 // LCOV_EXCL_START
47 printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, (double)y_array[index]);
48 // LCOV_EXCL_STOP
49 }
50 }
51 }
52 }
53 CeedVectorRestoreArrayRead(y, &y_array);
54 }
55
56 // Transpose
57 CeedVectorSetValue(x, 0);
58 CeedElemRestrictionApplyBlock(elem_restriction, 1, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE);
59 {
60 const CeedScalar *x_array;
61
62 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &x_array);
63 for (CeedInt i = blk_size; i < num_elem + 1; i++) {
64 if (x_array[i] != (10 + i) * (i > blk_size && i < num_elem ? 2.0 : 1.0)) {
65 // LCOV_EXCL_START
66 printf("Error in restricted array x[%" CeedInt_FMT "] = %f\n", i, (double)x_array[i]);
67 // LCOV_EXCL_STOP
68 }
69 }
70 CeedVectorRestoreArrayRead(x, &x_array);
71 }
72
73 CeedVectorDestroy(&x);
74 CeedVectorDestroy(&y);
75 CeedElemRestrictionDestroy(&elem_restriction);
76 CeedDestroy(&ceed);
77 return 0;
78 }
79