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++) 20 a[i] = 10 + i; 21 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 22 23 for (CeedInt i=0; i<num_elem; i++) { 24 ind[2*i+0] = i; 25 ind[2*i+1] = i+1; 26 // flip the dofs on element 1,3,... 27 orient[2*i+0] = (i%(2))*-1 < 0; 28 orient[2*i+1] = (i%(2))*-1 < 0; 29 } 30 CeedElemRestrictionCreateOriented(ceed, num_elem, P, dim, 1, 31 num_elem+1, CEED_MEM_HOST, 32 CEED_USE_POINTER, ind, orient, &r); 33 CeedVectorCreate(ceed, num_elem*2, &y); 34 CeedVectorSetValue(y, 0); // Allocates array 35 CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 36 37 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 38 for (CeedInt i=0; i<num_elem; i++) { 39 for (CeedInt j=0; j<P; j++) { 40 CeedInt k = j + P*i; 41 if (10+(k+1)/2 != yy[k] * CeedIntPow(-1, i%2)) 42 // LCOV_EXCL_START 43 printf("Error in restricted array y[%d] = %f", 44 k, (CeedScalar)yy[k]); 45 // LCOV_EXCL_STOP 46 } 47 } 48 CeedVectorRestoreArrayRead(y, &yy); 49 50 CeedVectorDestroy(&x); 51 CeedVectorDestroy(&y); 52 CeedElemRestrictionDestroy(&r); 53 CeedDestroy(&ceed); 54 return 0; 55 } 56