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 #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[i] = 10 + i; 23 a[i+num_elem+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] = i; 29 ind[2*i+1] = i+1; 30 } 31 CeedElemRestrictionCreate(ceed, num_elem, 2, 2, num_elem+1, 2*(num_elem+1), 32 CEED_MEM_HOST, 33 CEED_USE_POINTER, ind, &r); 34 CeedVectorCreate(ceed, 2*(num_elem*2), &y); 35 36 // Restrict 37 CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 38 39 // Check 40 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 41 CeedElemRestrictionGetELayout(r, &layout); 42 for (CeedInt i=0; i<2; i++) // Node 43 for (CeedInt j=0; j<2; j++) // Component 44 for (CeedInt k=0; k<num_elem; k++) // Element 45 if (yy[i*layout[0]+j*layout[1]+k*layout[2]] != a[ind[i+k*2]+j*(num_elem+1)]) 46 // LCOV_EXCL_START 47 printf("Error in restricted array y[%" CeedInt_FMT 48 "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %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