xref: /libCEED/tests/t206-elemrestriction.c (revision 39b2de37682296be8460181179eb4e44de5cc3de)
1 /// @file
2 /// Test creation, transpose use, and destruction of a multicomponent element restriction
3 /// \test Test creation, transpose use, and destruction of a multicomponent element restriction
4 #include <ceed.h>
5 
6 int main(int argc, char **argv) {
7   Ceed ceed;
8   CeedVector x, y;
9   CeedInt ne = 5, mult;
10   CeedInt ind[2*ne];
11   CeedScalar a[2*(ne*2)];
12   const CeedScalar *yy;
13   CeedElemRestriction r;
14 
15   CeedInit(argv[1], &ceed);
16 
17   // Setup
18   CeedVectorCreate(ceed, 2*(ne*2), &x);
19   for (CeedInt i=0; i<ne; i++)
20     for (CeedInt n=0; n<2; n++) {
21       a[i*4+n] = 10+(2*i+n+1)/2;
22       a[i*4+n+2] = 20+(2*i+n+1)/2;
23     }
24   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
25 
26   for (CeedInt i=0; i<ne; i++) {
27     ind[2*i+0] = i;
28     ind[2*i+1] = i+1;
29   }
30   CeedElemRestrictionCreate(ceed, ne, 2, ne+1, 2, CEED_MEM_HOST,
31                             CEED_USE_POINTER, ind, &r);
32   CeedVectorCreate(ceed, 2*(ne+1), &y);
33   CeedVectorSetValue(y, 0); // Allocates array
34 
35   // Restrict
36   CeedElemRestrictionApply(r, CEED_TRANSPOSE, CEED_NOTRANSPOSE, x, y,
37                            CEED_REQUEST_IMMEDIATE);
38 
39   // Check
40   CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy);
41   for (CeedInt i=0; i<ne+1; i++) {
42     mult = i>0&&i<ne ? 2 : 1;
43     if (yy[i] != (10+i)*mult)
44       // LCOV_EXCL_START
45       printf("Error in restricted array y[%d] = %f != %f\n",
46              i, (double)yy[i], (10.+i)*mult);
47     // LCOV_EXCL_STOP
48     if (yy[i+ne+1] != (20+i)*mult)
49       // LCOV_EXCL_START
50       printf("Error in restricted array y[%d] = %f != %f\n",
51              i+ne+1, (double)yy[i+ne+1], (20.+i)*mult);
52     // LCOV_EXCL_STOP
53   }
54 
55   CeedVectorRestoreArrayRead(y, &yy);
56   CeedVectorDestroy(&x);
57   CeedVectorDestroy(&y);
58   CeedElemRestrictionDestroy(&r);
59   CeedDestroy(&ceed);
60   return 0;
61 }
62