10b63de31SJeremy L Thompson /// @file
20b63de31SJeremy L Thompson /// Test creation, transpose use, and destruction of an element restriction at points for single elements
30b63de31SJeremy L Thompson /// \test Test creation, transpose use, and destruction of an element restriction at points for single elements
40b63de31SJeremy L Thompson #include <ceed.h>
50b63de31SJeremy L Thompson #include <math.h>
60b63de31SJeremy L Thompson #include <stdio.h>
70b63de31SJeremy L Thompson
main(int argc,char ** argv)80b63de31SJeremy L Thompson int main(int argc, char **argv) {
90b63de31SJeremy L Thompson Ceed ceed;
100b63de31SJeremy L Thompson CeedInt num_elem = 3, num_points = num_elem * 2;
110b63de31SJeremy L Thompson CeedInt ind[(num_elem + 1) + num_points];
120b63de31SJeremy L Thompson CeedVector x, y;
130b63de31SJeremy L Thompson CeedElemRestriction elem_restriction;
140b63de31SJeremy L Thompson
150b63de31SJeremy L Thompson CeedInit(argv[1], &ceed);
160b63de31SJeremy L Thompson
170b63de31SJeremy L Thompson {
180b63de31SJeremy L Thompson CeedInt offset = num_elem + 1;
190b63de31SJeremy L Thompson CeedInt point_index = num_elem;
200b63de31SJeremy L Thompson
210b63de31SJeremy L Thompson for (CeedInt i = 0; i < num_elem; i++) {
220b63de31SJeremy L Thompson CeedInt num_points_in_elem = (i + 1) % num_elem + 1;
230b63de31SJeremy L Thompson
240b63de31SJeremy L Thompson ind[i] = offset;
250b63de31SJeremy L Thompson for (CeedInt j = 0; j < num_points_in_elem; j++) {
260b63de31SJeremy L Thompson ind[offset + j] = point_index;
270b63de31SJeremy L Thompson point_index = (point_index + 1) % num_points;
280b63de31SJeremy L Thompson }
290b63de31SJeremy L Thompson offset += num_points_in_elem;
300b63de31SJeremy L Thompson }
310b63de31SJeremy L Thompson ind[num_elem] = offset;
320b63de31SJeremy L Thompson }
330b63de31SJeremy L Thompson CeedElemRestrictionCreateAtPoints(ceed, num_elem, num_points, 1, num_points, CEED_MEM_HOST, CEED_COPY_VALUES, ind, &elem_restriction);
340b63de31SJeremy L Thompson
350b63de31SJeremy L Thompson CeedElemRestrictionCreateVector(elem_restriction, &x, NULL);
360b63de31SJeremy L Thompson CeedVectorSetValue(x, 0.0);
370b63de31SJeremy L Thompson {
38*4ed2b277SZach Atkins CeedInt min_points, max_points;
390b63de31SJeremy L Thompson
40*4ed2b277SZach Atkins CeedElemRestrictionGetMinPointsInElement(elem_restriction, &min_points);
410b63de31SJeremy L Thompson CeedElemRestrictionGetMaxPointsInElement(elem_restriction, &max_points);
42*4ed2b277SZach Atkins if (min_points != 1 || max_points != num_elem) {
43*4ed2b277SZach Atkins // LCOV_EXCL_START
44*4ed2b277SZach Atkins printf("Error in min/max points: min %" CeedInt_FMT " max %" CeedInt_FMT "\n", min_points, max_points);
45*4ed2b277SZach Atkins // LCOV_EXCL_STOP
46*4ed2b277SZach Atkins }
470b63de31SJeremy L Thompson CeedVectorCreate(ceed, max_points, &y);
480b63de31SJeremy L Thompson CeedVectorSetValue(y, 1.0);
490b63de31SJeremy L Thompson }
500b63de31SJeremy L Thompson
510b63de31SJeremy L Thompson {
520b63de31SJeremy L Thompson for (CeedInt i = 0; i < num_elem; i++) {
530b63de31SJeremy L Thompson CeedInt point_index = num_elem;
540b63de31SJeremy L Thompson const CeedScalar *read_array;
550b63de31SJeremy L Thompson
560b63de31SJeremy L Thompson CeedVectorSetValue(x, 0.0);
570b63de31SJeremy L Thompson CeedElemRestrictionApplyAtPointsInElement(elem_restriction, i, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE);
580b63de31SJeremy L Thompson
590b63de31SJeremy L Thompson CeedVectorGetArrayRead(x, CEED_MEM_HOST, &read_array);
600b63de31SJeremy L Thompson for (CeedInt j = 0; j < num_elem; j++) {
610b63de31SJeremy L Thompson CeedInt num_points_in_elem = (j + 1) % num_elem + 1;
620b63de31SJeremy L Thompson
630b63de31SJeremy L Thompson for (CeedInt k = 0; k < num_points_in_elem; k++) {
640b63de31SJeremy L Thompson if (fabs(read_array[point_index] - (i == j ? 1.0 : 0.0)) > 10 * CEED_EPSILON) {
650b63de31SJeremy L Thompson // LCOV_EXCL_START
660b63de31SJeremy L Thompson printf("Error in restricted array x[%" CeedInt_FMT "] = %f\n", point_index, (CeedScalar)read_array[point_index]);
670b63de31SJeremy L Thompson // LCOV_EXCL_STOP
680b63de31SJeremy L Thompson }
690b63de31SJeremy L Thompson point_index = (point_index + 1) % num_points;
700b63de31SJeremy L Thompson }
710b63de31SJeremy L Thompson }
720b63de31SJeremy L Thompson CeedVectorRestoreArrayRead(x, &read_array);
730b63de31SJeremy L Thompson }
740b63de31SJeremy L Thompson }
750b63de31SJeremy L Thompson
760b63de31SJeremy L Thompson CeedVectorDestroy(&x);
770b63de31SJeremy L Thompson CeedVectorDestroy(&y);
780b63de31SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction);
790b63de31SJeremy L Thompson CeedDestroy(&ceed);
800b63de31SJeremy L Thompson return 0;
810b63de31SJeremy L Thompson }
82