1 /// @file 2 /// Test creation, transpose use, and destruction of an element restriction at points for single elements 3 /// \test Test creation, transpose use, and destruction of an element restriction at points for single elements 4 #include <ceed.h> 5 #include <math.h> 6 #include <stdio.h> 7 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_COPY_VALUES, ind, &elem_restriction); 34 35 CeedElemRestrictionCreateVector(elem_restriction, &x, NULL); 36 CeedVectorSetValue(x, 0.0); 37 { 38 CeedInt min_points, max_points; 39 40 CeedElemRestrictionGetMinPointsInElement(elem_restriction, &min_points); 41 CeedElemRestrictionGetMaxPointsInElement(elem_restriction, &max_points); 42 if (min_points != 1 || max_points != num_elem) { 43 // LCOV_EXCL_START 44 printf("Error in min/max points: min %" CeedInt_FMT " max %" CeedInt_FMT "\n", min_points, max_points); 45 // LCOV_EXCL_STOP 46 } 47 CeedVectorCreate(ceed, max_points, &y); 48 CeedVectorSetValue(y, 1.0); 49 } 50 51 { 52 for (CeedInt i = 0; i < num_elem; i++) { 53 CeedInt point_index = num_elem; 54 const CeedScalar *read_array; 55 56 CeedVectorSetValue(x, 0.0); 57 CeedElemRestrictionApplyAtPointsInElement(elem_restriction, i, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE); 58 59 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &read_array); 60 for (CeedInt j = 0; j < num_elem; j++) { 61 CeedInt num_points_in_elem = (j + 1) % num_elem + 1; 62 63 for (CeedInt k = 0; k < num_points_in_elem; k++) { 64 if (fabs(read_array[point_index] - (i == j ? 1.0 : 0.0)) > 10 * CEED_EPSILON) { 65 // LCOV_EXCL_START 66 printf("Error in restricted array x[%" CeedInt_FMT "] = %f\n", point_index, (CeedScalar)read_array[point_index]); 67 // LCOV_EXCL_STOP 68 } 69 point_index = (point_index + 1) % num_points; 70 } 71 } 72 CeedVectorRestoreArrayRead(x, &read_array); 73 } 74 } 75 76 CeedVectorDestroy(&x); 77 CeedVectorDestroy(&y); 78 CeedElemRestrictionDestroy(&elem_restriction); 79 CeedDestroy(&ceed); 80 return 0; 81 } 82