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