xref: /libCEED/tests/t203-elemrestriction.c (revision 39b2de37682296be8460181179eb4e44de5cc3de)
1 /// @file
2 /// Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector
3 /// \test Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector
4 #include <ceed.h>
5 
6 int main(int argc, char **argv) {
7   Ceed ceed;
8   CeedVector x, y;
9   CeedInt ne = 8;
10   CeedInt blksize = 5;
11   CeedInt ncomp = 3;
12   CeedInt ind[2*ne];
13   CeedScalar a[ncomp*(ne+1)];
14   CeedElemRestriction r;
15 
16   CeedInit(argv[1], &ceed);
17 
18   CeedVectorCreate(ceed, (ne+1)*ncomp, &x);
19   for (CeedInt i=0; i<(ne+1); i++) {
20     a[i+0*(ne+1)] = 10 + i;
21     a[i+1*(ne+1)] = 20 + i;
22     a[i+2*(ne+1)] = 30 + i;
23   }
24   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
25   CeedVectorView(x, "%12.8f", stdout);
26   for (CeedInt i=0; i<ne; i++) {
27     ind[2*i+0] = i;
28     ind[2*i+1] = i+1;
29   }
30   CeedElemRestrictionCreateBlocked(ceed, ne, 2, blksize, ne+1, ncomp,
31                                    CEED_MEM_HOST, CEED_USE_POINTER, ind, &r);
32   CeedVectorCreate(ceed, 2*blksize*2*ncomp, &y);
33   CeedVectorSetValue(y, 0); // Allocates array
34 
35   // NoTranspose
36   CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, CEED_NOTRANSPOSE, x, y,
37                            CEED_REQUEST_IMMEDIATE);
38   CeedVectorView(y, "%12.8f", stdout);
39 
40   // Transpose
41   CeedVectorGetArray(x, CEED_MEM_HOST, (CeedScalar **)&a);
42   for (CeedInt i=0; i<(ne+1)*ncomp; i++)
43     a[i] = 0;
44   CeedVectorRestoreArray(x, (CeedScalar **)&a);
45   CeedElemRestrictionApply(r, CEED_TRANSPOSE, CEED_NOTRANSPOSE, y, x,
46                            CEED_REQUEST_IMMEDIATE);
47   CeedVectorView(x, "%12.8f", stdout);
48 
49   CeedVectorDestroy(&x);
50   CeedVectorDestroy(&y);
51   CeedElemRestrictionDestroy(&r);
52   CeedDestroy(&ceed);
53   return 0;
54 }
55