1 /// @file 2 /// Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector 3 /// \test Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector 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 = 8; 11 CeedInt elem_size = 2; 12 CeedInt num_blk = 2; 13 CeedInt blk_size = 5; 14 CeedInt num_comp = 3; 15 CeedInt ind[elem_size*num_elem]; 16 CeedScalar a[num_comp*(num_elem + 1)]; 17 const CeedScalar *xx, *yy; 18 CeedInt layout[3]; 19 CeedElemRestriction r; 20 21 CeedInit(argv[1], &ceed); 22 23 CeedVectorCreate(ceed, num_comp*(num_elem+1), &x); 24 for (CeedInt i=0; i<num_elem+1; i++) { 25 a[i+0*(num_elem+1)] = 10 + i; 26 a[i+1*(num_elem+1)] = 20 + i; 27 a[i+2*(num_elem+1)] = 30 + i; 28 } 29 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 30 31 for (CeedInt i=0; i<num_elem; i++) { 32 ind[2*i+0] = i; 33 ind[2*i+1] = i+1; 34 } 35 CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, num_comp, 36 num_elem+1, num_comp*(num_elem+1), CEED_MEM_HOST, 37 CEED_USE_POINTER, ind, &r); 38 CeedVectorCreate(ceed, num_comp*num_blk*blk_size*elem_size, &y); 39 CeedVectorSetValue(y, 0); // Allocates array 40 41 // NoTranspose 42 CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 43 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 44 CeedElemRestrictionGetELayout(r, &layout); 45 for (CeedInt i=0; i<elem_size; i++) // Node 46 for (CeedInt j=0; j<num_comp; j++) // Component 47 for (CeedInt k=0; k<num_elem; k++) { // Element 48 CeedInt block = k / blk_size; 49 CeedInt elem = k % blk_size; 50 CeedInt index = (i*blk_size+elem)*layout[0] + j*layout[1]*blk_size + 51 block*layout[2]*blk_size; 52 if (yy[index] != a[ind[k*elem_size + i]+j*(num_elem+1)]) 53 // LCOV_EXCL_START 54 printf("Error in restricted array y[%d][%d][%d] = %f\n", 55 i, j, k, (double)yy[index]); 56 // LCOV_EXCL_STOP 57 } 58 CeedVectorRestoreArrayRead(y, &yy); 59 60 // Transpose 61 CeedVectorSetValue(x, 0); 62 CeedElemRestrictionApply(r, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE); 63 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &xx); 64 for (CeedInt i=0; i<num_elem+1; i++) { 65 for (CeedInt j=0; j<num_comp; j++) { 66 if (xx[i+j*(num_elem+1)] != ((j+1)*10+i)*(i > 0 && i < num_elem ? 2.0 : 1.0)) 67 // LCOV_EXCL_START 68 printf("Error in restricted array x[%d][%d] = %f\n", 69 j, i, (double)xx[i+j*(num_elem+1)]); 70 // LCOV_EXCL_STOP 71 } 72 } 73 CeedVectorRestoreArrayRead(x, &xx); 74 75 CeedVectorDestroy(&x); 76 CeedVectorDestroy(&y); 77 CeedElemRestrictionDestroy(&r); 78 CeedDestroy(&ceed); 79 return 0; 80 } 81