1 /// @file
2 /// Test creation, use, and destruction of an element restriction at points
3 /// \test Test creation, use, and destruction of an element restriction at points
4 #include <ceed.h>
5 #include <ceed/backend.h>
6 #include <stdio.h>
7
main(int argc,char ** argv)8 int main(int argc, char **argv) {
9 Ceed ceed;
10 CeedInt num_elem = 3, num_points = num_elem * 2;
11 CeedInt ind[(num_elem + 1) + num_points];
12 CeedVector x, y;
13 CeedElemRestriction elem_restriction;
14
15 CeedInit(argv[1], &ceed);
16
17 {
18 CeedInt offset = num_elem + 1;
19 CeedInt point_index = num_elem;
20
21 for (CeedInt i = 0; i < num_elem; i++) {
22 CeedInt num_points_in_elem = (i + 1) % num_elem + 1;
23
24 ind[i] = offset;
25 for (CeedInt j = 0; j < num_points_in_elem; j++) {
26 ind[offset + j] = point_index;
27 point_index = (point_index + 1) % num_points;
28 }
29 offset += num_points_in_elem;
30 }
31 ind[num_elem] = offset;
32 }
33 CeedElemRestrictionCreateAtPoints(ceed, num_elem, num_points, 1, num_points, CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction);
34
35 CeedElemRestrictionCreateVector(elem_restriction, &x, &y);
36 CeedVectorSetValue(y, 0.0);
37 {
38 CeedInt point_index = num_elem;
39 CeedScalar array[num_points];
40
41 for (CeedInt i = 0; i < num_elem; i++) {
42 CeedInt num_points_in_elem = (i + 1) % num_elem + 1;
43
44 for (CeedInt j = 0; j < num_points_in_elem; j++) {
45 array[point_index] = i;
46 point_index = (point_index + 1) % num_points;
47 }
48 }
49 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array);
50 }
51
52 CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
53 CeedElemRestrictionApply(elem_restriction, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE);
54 {
55 CeedInt point_index = num_elem;
56 const CeedScalar *read_array;
57
58 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &read_array);
59 for (CeedInt i = 0; i < num_elem; i++) {
60 CeedInt num_points_in_elem = (i + 1) % num_elem + 1;
61
62 for (CeedInt j = 0; j < num_points_in_elem; j++) {
63 if (read_array[point_index] != 2 * i) {
64 // LCOV_EXCL_START
65 printf("Error in restricted array x[%" CeedInt_FMT "] = %f != %f\n", point_index, read_array[point_index], 2.0 * i);
66 // LCOV_EXCL_STOP
67 }
68 point_index = (point_index + 1) % num_points;
69 }
70 }
71 CeedVectorRestoreArrayRead(x, &read_array);
72 }
73
74 CeedVectorDestroy(&x);
75 CeedVectorDestroy(&y);
76 CeedElemRestrictionDestroy(&elem_restriction);
77 CeedDestroy(&ceed);
78 return 0;
79 }
80