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