xref: /libCEED/tests/t203-elemrestriction.c (revision dfdf5a531ad639a005f6e2fb19c1b902a7a82be2)
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   CeedVectorCreate(ceed, (ne+1)*ncomp, &x);
18   for (CeedInt i=0; i<(ne+1); i++) {
19     a[i+0*(ne+1)] = 10 + i;
20     a[i+1*(ne+1)] = 20 + i;
21     a[i+2*(ne+1)] = 30 + i;
22   }
23   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
24   CeedVectorView(x, "%12.8f", stdout);
25   for (CeedInt i=0; i<ne; i++) {
26     ind[2*i+0] = i;
27     ind[2*i+1] = i+1;
28   }
29   CeedElemRestrictionCreateBlocked(ceed, ne, 2, blksize, ne+1, ncomp, CEED_MEM_HOST,
30                                    CEED_USE_POINTER, ind, &r);
31   CeedVectorCreate(ceed, 2*blksize*2*ncomp, &y);
32   CeedVectorSetArray(y, CEED_MEM_HOST, CEED_COPY_VALUES, NULL); // Allocates array
33 
34   // NoTranspose
35   CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, CEED_NOTRANSPOSE, x, y,
36                            CEED_REQUEST_IMMEDIATE);
37   CeedVectorView(y, "%12.8f", stdout);
38 
39   // Transpose
40   CeedVectorGetArray(x, CEED_MEM_HOST, (CeedScalar **)&a);
41   for (CeedInt i=0; i<(ne+1)*ncomp; i++) a[i] = 0;
42   CeedVectorRestoreArray(x, (CeedScalar **)&a);
43   CeedElemRestrictionApply(r, CEED_TRANSPOSE, CEED_NOTRANSPOSE, y, x,
44                            CEED_REQUEST_IMMEDIATE);
45   CeedVectorView(x, "%12.8f", stdout);
46 
47   CeedVectorDestroy(&x);
48   CeedVectorDestroy(&y);
49   CeedElemRestrictionDestroy(&r);
50   CeedDestroy(&ceed);
51   return 0;
52 }
53