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