xref: /libCEED/tests/t233-elemrestriction.c (revision 4ed2b27715919084fc6a9c0e6a05a1e8adc518b8)
1fa42c6feSJeremy L Thompson /// @file
20b63de31SJeremy L Thompson /// Test creation, use, and destruction of an element restriction at points for single elements
30b63de31SJeremy L Thompson /// \test Test creation, use, and destruction of an element restriction at points for single elements
4fa42c6feSJeremy L Thompson #include <ceed.h>
5fa42c6feSJeremy L Thompson #include <stdio.h>
6fa42c6feSJeremy L Thompson 
7fa42c6feSJeremy L Thompson int main(int argc, char **argv) {
8fa42c6feSJeremy L Thompson   Ceed                ceed;
9fa42c6feSJeremy L Thompson   CeedInt             num_elem = 3, num_points = num_elem * 2;
10fa42c6feSJeremy L Thompson   CeedInt             ind[(num_elem + 1) + num_points];
11fa42c6feSJeremy L Thompson   CeedVector          x, y;
12fa42c6feSJeremy L Thompson   CeedElemRestriction elem_restriction;
13fa42c6feSJeremy L Thompson 
14fa42c6feSJeremy L Thompson   CeedInit(argv[1], &ceed);
15fa42c6feSJeremy L Thompson 
16fa42c6feSJeremy L Thompson   {
17fa42c6feSJeremy L Thompson     CeedInt offset      = num_elem + 1;
18fa42c6feSJeremy L Thompson     CeedInt point_index = num_elem;
19fa42c6feSJeremy L Thompson 
20fa42c6feSJeremy L Thompson     for (CeedInt i = 0; i < num_elem; i++) {
21fa42c6feSJeremy L Thompson       CeedInt num_points_in_elem = (i + 1) % num_elem + 1;
22fa42c6feSJeremy L Thompson 
23fa42c6feSJeremy L Thompson       ind[i] = offset;
24fa42c6feSJeremy L Thompson       for (CeedInt j = 0; j < num_points_in_elem; j++) {
25fa42c6feSJeremy L Thompson         ind[offset + j] = point_index;
26fa42c6feSJeremy L Thompson         point_index     = (point_index + 1) % num_points;
27fa42c6feSJeremy L Thompson       }
28fa42c6feSJeremy L Thompson       offset += num_points_in_elem;
29fa42c6feSJeremy L Thompson     }
30fa42c6feSJeremy L Thompson     ind[num_elem] = offset;
31fa42c6feSJeremy L Thompson   }
320b63de31SJeremy L Thompson   CeedElemRestrictionCreateAtPoints(ceed, num_elem, num_points, 1, num_points, CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction);
33fa42c6feSJeremy L Thompson 
34f930fbbfSJeremy L Thompson   CeedElemRestrictionCreateVector(elem_restriction, &x, NULL);
350b63de31SJeremy L Thompson   {
360b63de31SJeremy L Thompson     CeedInt    point_index = num_elem;
370b63de31SJeremy L Thompson     CeedScalar array[num_points];
380b63de31SJeremy L Thompson 
390b63de31SJeremy L Thompson     for (CeedInt i = 0; i < num_elem; i++) {
400b63de31SJeremy L Thompson       CeedInt num_points_in_elem = (i + 1) % num_elem + 1;
410b63de31SJeremy L Thompson 
420b63de31SJeremy L Thompson       for (CeedInt j = 0; j < num_points_in_elem; j++) {
430b63de31SJeremy L Thompson         array[point_index] = i;
440b63de31SJeremy L Thompson         point_index        = (point_index + 1) % num_points;
450b63de31SJeremy L Thompson       }
460b63de31SJeremy L Thompson     }
470b63de31SJeremy L Thompson     CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array);
480b63de31SJeremy L Thompson   }
490b63de31SJeremy L Thompson 
50fa42c6feSJeremy L Thompson   {
51*4ed2b277SZach Atkins     CeedInt min_points, max_points;
52fa42c6feSJeremy L Thompson 
53*4ed2b277SZach Atkins     CeedElemRestrictionGetMinPointsInElement(elem_restriction, &min_points);
54fa42c6feSJeremy L Thompson     CeedElemRestrictionGetMaxPointsInElement(elem_restriction, &max_points);
55*4ed2b277SZach Atkins     if (min_points != 1 || max_points != num_elem) {
56*4ed2b277SZach Atkins       // LCOV_EXCL_START
57*4ed2b277SZach Atkins       printf("Error in min/max points: min %" CeedInt_FMT " max %" CeedInt_FMT "\n", min_points, max_points);
58*4ed2b277SZach Atkins       // LCOV_EXCL_STOP
59*4ed2b277SZach Atkins     }
60fa42c6feSJeremy L Thompson     CeedVectorCreate(ceed, max_points, &y);
61fa42c6feSJeremy L Thompson   }
62fa42c6feSJeremy L Thompson 
63fa42c6feSJeremy L Thompson   {
64fa42c6feSJeremy L Thompson     for (CeedInt i = 0; i < num_elem; i++) {
650b63de31SJeremy L Thompson       CeedInt           num_points_in_elem = (i + 1) % num_elem + 1;
66fa42c6feSJeremy L Thompson       const CeedScalar *read_array;
67fa42c6feSJeremy L Thompson 
680b63de31SJeremy L Thompson       CeedElemRestrictionApplyAtPointsInElement(elem_restriction, i, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
690b63de31SJeremy L Thompson       CeedVectorGetArrayRead(y, CEED_MEM_HOST, &read_array);
70fa42c6feSJeremy L Thompson 
710b63de31SJeremy L Thompson       for (CeedInt j = 0; j < num_points_in_elem; j++) {
720b63de31SJeremy L Thompson         if (i != read_array[j]) {
732b62239cSJeremy L Thompson           // LCOV_EXCL_START
740b63de31SJeremy L Thompson           printf("Error in restricted element array %" CeedInt_FMT " y[%" CeedInt_FMT "] = %f\n", i, j, (CeedScalar)read_array[j]);
752b62239cSJeremy L Thompson           // LCOV_EXCL_STOP
76fa42c6feSJeremy L Thompson         }
77fa42c6feSJeremy L Thompson       }
780b63de31SJeremy L Thompson       CeedVectorRestoreArrayRead(y, &read_array);
79fa42c6feSJeremy L Thompson     }
80fa42c6feSJeremy L Thompson   }
81fa42c6feSJeremy L Thompson 
82fa42c6feSJeremy L Thompson   CeedVectorDestroy(&x);
83fa42c6feSJeremy L Thompson   CeedVectorDestroy(&y);
84fa42c6feSJeremy L Thompson   CeedElemRestrictionDestroy(&elem_restriction);
85fa42c6feSJeremy L Thompson   CeedDestroy(&ceed);
86fa42c6feSJeremy L Thompson   return 0;
87fa42c6feSJeremy L Thompson }
88