xref: /libCEED/tests/t201-elemrestriction.c (revision 59f9181e1c585e2777fc79a7abc99a62c123904e)
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 
6 int main(int argc, char **argv) {
7   Ceed ceed;
8   CeedVector x, y;
9   CeedInt ne = 3;
10   CeedScalar a[ne*2];
11   const CeedScalar *yy;
12   CeedInt strides[3] = {1, 2, 2};
13   CeedElemRestriction r;
14 
15   CeedInit(argv[1], &ceed);
16 
17   CeedVectorCreate(ceed, ne*2, &x);
18   for (CeedInt i=0; i<ne*2; i++)
19     a[i] = 10 + i;
20   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
21 
22   CeedElemRestrictionCreateStrided(ceed, ne, 2, ne*2, 1, strides, &r);
23   CeedVectorCreate(ceed, ne*2, &y);
24   CeedVectorSetValue(y, 0); // Allocates array
25   CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
26 
27   CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy);
28   for (CeedInt i=0; i<ne*2; i++)
29     if (yy[i] != 10+i)
30       // LCOV_EXCL_START
31       printf("Error in restricted array y[%d] = %f",
32              i, (double)yy[i]);
33   // LCOV_EXCL_STOP
34   CeedVectorRestoreArrayRead(y, &yy);
35 
36   CeedVectorDestroy(&x);
37   CeedVectorDestroy(&y);
38   CeedElemRestrictionDestroy(&r);
39   CeedDestroy(&ceed);
40   return 0;
41 }
42