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