xref: /libCEED/tests/t200-elemrestriction.c (revision 4092d0ee9dee1dc94927b92ec4a4f5b5b7bb02dc)
1 /// @file
2 /// Test creation, use, and destruction of an element restriction
3 /// \test Test creation, use, and destruction of an 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   CeedInt ind[2*ne];
11   CeedScalar a[ne+1];
12   const CeedScalar *yy;
13   CeedElemRestriction r;
14   CeedInterlaceMode imode = CEED_NONINTERLACED;
15 
16   CeedInit(argv[1], &ceed);
17 
18   CeedVectorCreate(ceed, ne+1, &x);
19   for (CeedInt i=0; i<ne+1; i++)
20     a[i] = 10 + i;
21   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
22 
23   for (CeedInt i=0; i<ne; i++) {
24     ind[2*i+0] = i;
25     ind[2*i+1] = i+1;
26   }
27   CeedElemRestrictionCreate(ceed, imode, ne, 2, ne+1, 1, CEED_MEM_HOST,
28                             CEED_USE_POINTER, ind, &r);
29   CeedVectorCreate(ceed, ne*2, &y);
30   CeedVectorSetValue(y, 0); // Allocates array
31   CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
32 
33   CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy);
34   for (CeedInt i=0; i<ne*2; i++)
35     if (10+(i+1)/2 != yy[i])
36       // LCOV_EXCL_START
37       printf("Error in restricted array y[%d] = %f",
38              i, (double)yy[i]);
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