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