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