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 6 int main(int argc, char **argv) { 7 Ceed ceed; 8 CeedVector x, y; 9 CeedInt num_elem = 3; 10 CeedInt ind[2 * num_elem]; 11 CeedScalar a[num_elem + 1]; 12 const CeedScalar *yy; 13 CeedElemRestriction r; 14 15 CeedInit(argv[1], &ceed); 16 17 CeedVectorCreate(ceed, num_elem + 1, &x); 18 for (CeedInt i = 0; i < num_elem + 1; i++) a[i] = 10 + i; 19 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 20 21 for (CeedInt i = 0; i < num_elem; i++) { 22 ind[2 * i + 0] = i; 23 ind[2 * i + 1] = i + 1; 24 } 25 CeedElemRestrictionCreate(ceed, num_elem, 2, 1, 1, num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, &r); 26 CeedVectorCreate(ceed, num_elem * 2, &y); 27 CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 28 29 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 30 for (CeedInt i = 0; i < num_elem * 2; i++) { 31 if (10 + (i + 1) / 2 != yy[i]) printf("Error in restricted array y[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)yy[i]); 32 } 33 CeedVectorRestoreArrayRead(y, &yy); 34 35 CeedVectorDestroy(&x); 36 CeedVectorDestroy(&y); 37 CeedElemRestrictionDestroy(&r); 38 CeedDestroy(&ceed); 39 return 0; 40 } 41