1 /// @file 2 /// Test creation, use, and destruction of an element restriction 3 /// \test Test creation, use, and destruction of an element restriction 4 #include <ceed.h> 5 #include <stdio.h> 6 7 int main(int argc, char **argv) { 8 Ceed ceed; 9 CeedVector x, y; 10 CeedInt num_elem = 3; 11 CeedInt ind[2 * num_elem]; 12 CeedElemRestriction elem_restriction; 13 14 CeedInit(argv[1], &ceed); 15 16 CeedVectorCreate(ceed, num_elem + 1, &x); 17 { 18 CeedScalar array[num_elem + 1]; 19 20 for (CeedInt i = 0; i < num_elem + 1; i++) array[i] = 10 + i; 21 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array); 22 } 23 CeedVectorCreate(ceed, num_elem * 2, &y); 24 25 for (CeedInt i = 0; i < num_elem; i++) { 26 ind[2 * i + 0] = i; 27 ind[2 * i + 1] = i + 1; 28 } 29 CeedElemRestrictionCreate(ceed, num_elem, 2, 1, 1, num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction); 30 CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 31 { 32 const CeedScalar *read_array; 33 34 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &read_array); 35 for (CeedInt i = 0; i < num_elem * 2; i++) { 36 if (10 + (i + 1) / 2 != read_array[i]) printf("Error in restricted array y[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)read_array[i]); 37 } 38 CeedVectorRestoreArrayRead(y, &read_array); 39 } 40 41 CeedVectorDestroy(&x); 42 CeedVectorDestroy(&y); 43 CeedElemRestrictionDestroy(&elem_restriction); 44 CeedDestroy(&ceed); 45 return 0; 46 } 47