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