1 /// @file 2 /// Test creation, use, and destruction of a multicomponent element restriction 3 /// \test Test creation, use, and destruction of a multicomponent element restriction 4 #include <ceed.h> 5 6 int main(int argc, char **argv) { 7 Ceed ceed; 8 CeedVector x, y; 9 CeedInt ne = 3; 10 CeedInt ind[2*ne]; 11 CeedScalar a[2*(ne+1)]; 12 const CeedScalar *yy; 13 CeedElemRestriction r; 14 15 CeedInit(argv[1], &ceed); 16 17 // Setup 18 CeedVectorCreate(ceed, 2*(ne+1), &x); 19 for (CeedInt i=0; i<ne+1; i++) { 20 a[i] = 10 + i; 21 a[i+ne+1] = 20 + i; 22 } 23 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 24 25 for (CeedInt i=0; i<ne; i++) { 26 ind[2*i+0] = i; 27 ind[2*i+1] = i+1; 28 } 29 CeedElemRestrictionCreate(ceed, ne, 2, 2, ne+1, 2*(ne+1), CEED_MEM_HOST, 30 CEED_USE_POINTER, ind, &r); 31 CeedVectorCreate(ceed, 2*(ne*2), &y); 32 CeedVectorSetValue(y, 0); // Allocates array 33 34 // Restrict 35 CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 36 37 // Check 38 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 39 for (CeedInt i=0; i<ne; i++) 40 for (CeedInt n=0; n<2; n++) { 41 if (yy[i*4+n] != 10+(2*i+n+1)/2) 42 // LCOV_EXCL_START 43 printf("Error in restricted array y[%d] = %f != %f\n", 44 i*4+n, (double)yy[i*4+n], 10.+(2*i+n+1)/2); 45 // LCOV_EXCL_STOP 46 if (yy[i*4+n+2] != 20+(2*i+n+1)/2) 47 // LCOV_EXCL_START 48 printf("Error in restricted array y[%d] = %f != %f\n", 49 i*4+n+2, (double)yy[i*4+n+2], 20.+(2*i+n+1)/2); 50 // LCOV_EXCL_STOP 51 } 52 53 CeedVectorRestoreArrayRead(y, &yy); 54 CeedVectorDestroy(&x); 55 CeedVectorDestroy(&y); 56 CeedElemRestrictionDestroy(&r); 57 CeedDestroy(&ceed); 58 return 0; 59 } 60