xref: /libCEED/tests/t220-elemrestriction.c (revision f190906abec33cf8d9eb9776bd62dd828c8ae3fd)
1 /// @file
2 /// Test creation, use, and destruction of an element restriction oriented
3 /// \test Test creation, use, and destruction of an element restriction oriented
4 #include <ceed.h>
5 
6 int main(int argc, char **argv) {
7   Ceed ceed;
8   CeedVector x, y;
9   CeedInt num_elem = 6, P = 2, dim = 1;
10   CeedInt ind[P*num_elem];
11   bool orient[P*num_elem];
12   CeedScalar a[num_elem+1];
13   const CeedScalar *yy;
14   CeedElemRestriction r;
15 
16   CeedInit(argv[1], &ceed);
17 
18   CeedVectorCreate(ceed, num_elem+1, &x);
19   for (CeedInt i=0; i<num_elem+1; i++)
20     a[i] = 10 + i;
21   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
22 
23   for (CeedInt i=0; i<num_elem; i++) {
24     ind[2*i+0] = i;
25     ind[2*i+1] = i+1;
26     // flip the dofs on element 1,3,...
27     orient[2*i+0] = (i%(2))*-1 < 0;
28     orient[2*i+1] = (i%(2))*-1 < 0;
29   }
30   CeedElemRestrictionCreateOriented(ceed, num_elem, P, dim, 1,
31                                     num_elem+1, CEED_MEM_HOST,
32                                     CEED_USE_POINTER, ind, orient, &r);
33   CeedVectorCreate(ceed, num_elem*2, &y);
34   CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
35 
36   CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy);
37   for (CeedInt i=0; i<num_elem; i++) {
38     for (CeedInt j=0; j<P; j++) {
39       CeedInt k = j + P*i;
40       if (10+(k+1)/2 != yy[k] * CeedIntPow(-1, i%2))
41         // LCOV_EXCL_START
42         printf("Error in restricted array y[%d] = %f",
43                k, (CeedScalar)yy[k]);
44       // LCOV_EXCL_STOP
45     }
46   }
47   CeedVectorRestoreArrayRead(y, &yy);
48 
49   CeedVectorDestroy(&x);
50   CeedVectorDestroy(&y);
51   CeedElemRestrictionDestroy(&r);
52   CeedDestroy(&ceed);
53   return 0;
54 }
55