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