xref: /libCEED/tests/t201-elemrestriction.c (revision 3f21f6b10abeb5d85d3454ea5cd38498737dc88a)
1 /// @file
2 /// Test creation, use, and destruction of a strided element restriction
3 /// \test Test creation, use, and destruction of a strided element restriction
4 #include <ceed.h>
5 #include <ceed/backend.h>
6 
7 int main(int argc, char **argv) {
8   Ceed ceed;
9   CeedVector x, y;
10   CeedInt num_elem = 3;
11   CeedScalar a[num_elem*2];
12   const CeedScalar *yy;
13   CeedInt strides[3] = {1, 2, 2};
14   CeedInt layout[3];
15   CeedElemRestriction r;
16 
17   CeedInit(argv[1], &ceed);
18 
19   CeedVectorCreate(ceed, num_elem*2, &x);
20   for (CeedInt i=0; i<num_elem*2; i++)
21     a[i] = 10 + i;
22   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
23 
24   CeedElemRestrictionCreateStrided(ceed, num_elem, 2, 1, num_elem*2, strides, &r);
25   CeedVectorCreate(ceed, num_elem*2, &y);
26   CeedVectorSetValue(y, 0); // Allocates array
27   CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
28 
29   CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy);
30   CeedElemRestrictionGetELayout(r, &layout);
31   for (CeedInt i=0; i<2; i++)            // Node
32     for (CeedInt j=0; j<1; j++)          // Component
33       for (CeedInt k=0; k<num_elem; k++) // Element
34         if (yy[i*layout[0] + j*layout[1] + k*layout[2]] !=
35             a[i*strides[0] + j*strides[1] + k*strides[2]])
36           // LCOV_EXCL_START
37           printf("Error in restricted array y[%d][%d][%d] = %f",
38                  i, j, k, (CeedScalar)yy[i*strides[0] + j*strides[1] + j*strides[2]]);
39   // LCOV_EXCL_STOP
40   CeedVectorRestoreArrayRead(y, &yy);
41 
42   CeedVectorDestroy(&x);
43   CeedVectorDestroy(&y);
44   CeedElemRestrictionDestroy(&r);
45   CeedDestroy(&ceed);
46   return 0;
47 }
48