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