xref: /libCEED/tests/t200-elemrestriction.c (revision 89c6efa49859cd40e0a2f99b4a91b922f3b4c9b2)
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 
15   CeedInit(argv[1], &ceed);
16   CeedVectorCreate(ceed, ne+1, &x);
17   for (CeedInt i=0; i<ne+1; i++) a[i] = 10 + i;
18   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
19 
20   for (CeedInt i=0; i<ne; i++) {
21     ind[2*i+0] = i;
22     ind[2*i+1] = i+1;
23   }
24   CeedElemRestrictionCreate(ceed, ne, 2, ne+1, 1, CEED_MEM_HOST, CEED_USE_POINTER,
25                             ind, &r);
26   CeedVectorCreate(ceed, ne*2, &y);
27   CeedVectorSetValue(y, 0); // Allocates array
28   CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, CEED_NOTRANSPOSE, x, y,
29                            CEED_REQUEST_IMMEDIATE);
30   CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy);
31   for (CeedInt i=0; i<ne*2; i++) {
32     if (10+(i+1)/2 != yy[i])
33       printf("Error in restricted array y[%d] = %f",
34              i, (double)yy[i]);
35   }
36   CeedVectorRestoreArrayRead(y, &yy);
37   CeedVectorDestroy(&x);
38   CeedVectorDestroy(&y);
39   CeedElemRestrictionDestroy(&r);
40   CeedDestroy(&ceed);
41   return 0;
42 }
43