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