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