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 CeedVectorCreate(ceed, num_points, &x); 17 { 18 CeedInt point_index = num_elem; 19 CeedScalar array[num_points]; 20 21 for (CeedInt i = 0; i < num_elem; i++) { 22 CeedInt num_points_in_elem = (i + 1) % num_elem + 1; 23 24 for (CeedInt j = 0; j < num_points_in_elem; j++) { 25 array[point_index] = i; 26 point_index = (point_index + 1) % num_points; 27 } 28 } 29 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array); 30 } 31 32 { 33 CeedInt offset = num_elem + 1; 34 CeedInt point_index = num_elem; 35 36 for (CeedInt i = 0; i < num_elem; i++) { 37 CeedInt num_points_in_elem = (i + 1) % num_elem + 1; 38 39 ind[i] = offset; 40 for (CeedInt j = 0; j < num_points_in_elem; j++) { 41 ind[offset + j] = point_index; 42 point_index = (point_index + 1) % num_points; 43 } 44 offset += num_points_in_elem; 45 } 46 ind[num_elem] = offset; 47 } 48 CeedElemRestrictionCreateAtPoints(ceed, num_elem, num_points, 1, num_points, CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction); 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 printf("Error in restricted element array %" CeedInt_FMT " y[%" CeedInt_FMT "] = %f\n", i, j, (CeedScalar)read_array[j]); 68 } 69 } 70 CeedVectorRestoreArrayRead(y, &read_array); 71 } 72 } 73 74 CeedVectorDestroy(&x); 75 CeedVectorDestroy(&y); 76 CeedElemRestrictionDestroy(&elem_restriction); 77 CeedDestroy(&ceed); 78 return 0; 79 } 80