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