xref: /libCEED/tests/t200-elemrestriction.c (revision 4fee36f0a30516a0b5ad51bf7eb3b32d83efd623)
1 /// @file
2 /// Test creation, use, and destruction of an element restriction
3 /// \test Test creation, use, and destruction of an 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 = 3;
10   CeedInt             ind[2 * num_elem];
11   CeedElemRestriction elem_restriction;
12 
13   CeedInit(argv[1], &ceed);
14 
15   CeedVectorCreate(ceed, num_elem + 1, &x);
16   {
17     CeedScalar array[num_elem + 1];
18 
19     for (CeedInt i = 0; i < num_elem + 1; i++) array[i] = 10 + i;
20     CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array);
21   }
22   CeedVectorCreate(ceed, num_elem * 2, &y);
23 
24   for (CeedInt i = 0; i < num_elem; i++) {
25     ind[2 * i + 0] = i;
26     ind[2 * i + 1] = i + 1;
27   }
28   CeedElemRestrictionCreate(ceed, num_elem, 2, 1, 1, num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction);
29   CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
30   {
31     const CeedScalar *read_array;
32 
33     CeedVectorGetArrayRead(y, CEED_MEM_HOST, &read_array);
34     for (CeedInt i = 0; i < num_elem * 2; i++) {
35       if (10 + (i + 1) / 2 != read_array[i]) printf("Error in restricted array y[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)read_array[i]);
36     }
37     CeedVectorRestoreArrayRead(y, &read_array);
38   }
39 
40   CeedVectorDestroy(&x);
41   CeedVectorDestroy(&y);
42   CeedElemRestrictionDestroy(&elem_restriction);
43   CeedDestroy(&ceed);
44   return 0;
45 }
46