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