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