10930e4e7SJeremy L Thompson /// @file 20930e4e7SJeremy L Thompson /// Test creation, use, and destruction of an element restriction at points for single elements 30930e4e7SJeremy L Thompson /// \test Test creation, use, and destruction of an element restriction at points for single elements 40930e4e7SJeremy L Thompson #include <ceed.h> 50930e4e7SJeremy L Thompson #include <stdio.h> 60930e4e7SJeremy L Thompson 70930e4e7SJeremy L Thompson int main(int argc, char **argv) { 80930e4e7SJeremy L Thompson Ceed ceed; 90930e4e7SJeremy L Thompson CeedInt num_elem = 3, num_points = num_elem * 2; 100930e4e7SJeremy L Thompson CeedInt ind[(num_elem + 1) + num_points]; 110930e4e7SJeremy L Thompson CeedVector x, y; 120930e4e7SJeremy L Thompson CeedElemRestriction elem_restriction; 130930e4e7SJeremy L Thompson 140930e4e7SJeremy L Thompson CeedInit(argv[1], &ceed); 150930e4e7SJeremy L Thompson 160930e4e7SJeremy L Thompson { 170930e4e7SJeremy L Thompson CeedInt offset = num_elem + 1; 180930e4e7SJeremy L Thompson CeedInt point_index = num_elem; 190930e4e7SJeremy L Thompson 200930e4e7SJeremy L Thompson for (CeedInt i = 0; i < num_elem; i++) { 210930e4e7SJeremy L Thompson CeedInt num_points_in_elem = (i + 1) % num_elem + 1; 220930e4e7SJeremy L Thompson 230930e4e7SJeremy L Thompson ind[i] = offset; 240930e4e7SJeremy L Thompson for (CeedInt j = 0; j < num_points_in_elem; j++) { 250930e4e7SJeremy L Thompson ind[offset + j] = point_index; 260930e4e7SJeremy L Thompson point_index = (point_index + 1) % num_points; 270930e4e7SJeremy L Thompson } 280930e4e7SJeremy L Thompson offset += num_points_in_elem; 290930e4e7SJeremy L Thompson } 300930e4e7SJeremy L Thompson ind[num_elem] = offset; 310930e4e7SJeremy L Thompson } 320930e4e7SJeremy L Thompson CeedElemRestrictionCreateAtPoints(ceed, num_elem, num_points, 1, num_points, CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction); 330930e4e7SJeremy L Thompson 34*f930fbbfSJeremy L Thompson CeedElemRestrictionCreateVector(elem_restriction, &x, NULL); 35*f930fbbfSJeremy L Thompson { 36*f930fbbfSJeremy L Thompson CeedInt point_index = num_elem; 37*f930fbbfSJeremy L Thompson CeedScalar array[num_points]; 38*f930fbbfSJeremy L Thompson 39*f930fbbfSJeremy L Thompson for (CeedInt i = 0; i < num_elem; i++) { 40*f930fbbfSJeremy L Thompson CeedInt num_points_in_elem = (i + 1) % num_elem + 1; 41*f930fbbfSJeremy L Thompson 42*f930fbbfSJeremy L Thompson for (CeedInt j = 0; j < num_points_in_elem; j++) { 43*f930fbbfSJeremy L Thompson array[point_index] = i; 44*f930fbbfSJeremy L Thompson point_index = (point_index + 1) % num_points; 45*f930fbbfSJeremy L Thompson } 46*f930fbbfSJeremy L Thompson } 47*f930fbbfSJeremy L Thompson CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array); 48*f930fbbfSJeremy L Thompson } 49*f930fbbfSJeremy L Thompson 500930e4e7SJeremy L Thompson { 510930e4e7SJeremy L Thompson CeedInt max_points; 520930e4e7SJeremy L Thompson 530930e4e7SJeremy L Thompson CeedElemRestrictionGetMaxPointsInElement(elem_restriction, &max_points); 540930e4e7SJeremy L Thompson CeedVectorCreate(ceed, max_points, &y); 550930e4e7SJeremy L Thompson } 560930e4e7SJeremy L Thompson 570930e4e7SJeremy L Thompson { 580930e4e7SJeremy L Thompson for (CeedInt i = 0; i < num_elem; i++) { 590930e4e7SJeremy L Thompson CeedInt num_points_in_elem = (i + 1) % num_elem + 1; 600930e4e7SJeremy L Thompson const CeedScalar *read_array; 610930e4e7SJeremy L Thompson 620930e4e7SJeremy L Thompson CeedElemRestrictionApplyAtPointsInElement(elem_restriction, i, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 630930e4e7SJeremy L Thompson CeedVectorGetArrayRead(y, CEED_MEM_HOST, &read_array); 640930e4e7SJeremy L Thompson 650930e4e7SJeremy L Thompson for (CeedInt j = 0; j < num_points_in_elem; j++) { 660930e4e7SJeremy L Thompson if (i != read_array[j]) { 672b62239cSJeremy L Thompson // LCOV_EXCL_START 680930e4e7SJeremy 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 700930e4e7SJeremy L Thompson } 710930e4e7SJeremy L Thompson } 720930e4e7SJeremy L Thompson CeedVectorRestoreArrayRead(y, &read_array); 730930e4e7SJeremy L Thompson } 740930e4e7SJeremy L Thompson } 750930e4e7SJeremy L Thompson 760930e4e7SJeremy L Thompson CeedVectorDestroy(&x); 770930e4e7SJeremy L Thompson CeedVectorDestroy(&y); 780930e4e7SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction); 790930e4e7SJeremy L Thompson CeedDestroy(&ceed); 800930e4e7SJeremy L Thompson return 0; 810930e4e7SJeremy L Thompson } 82