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, num_elem + 1, num_comp * (num_elem + 1), CEED_MEM_HOST, 36 CEED_USE_POINTER, ind, &r); 37 CeedVectorCreate(ceed, num_comp * num_blk * blk_size * elem_size, &y); 38 39 // NoTranspose 40 CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 41 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 42 CeedElemRestrictionGetELayout(r, &layout); 43 for (CeedInt i = 0; i < elem_size; i++) { // Node 44 for (CeedInt j = 0; j < num_comp; j++) { // Component 45 for (CeedInt k = 0; k < num_elem; k++) { // Element 46 CeedInt block = k / blk_size; 47 CeedInt elem = k % blk_size; 48 CeedInt index = (i * blk_size + elem) * layout[0] + j * layout[1] * blk_size + block * layout[2] * blk_size; 49 if (yy[index] != a[ind[k * elem_size + i] + j * (num_elem + 1)]) { 50 // LCOV_EXCL_START 51 printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, (double)yy[index]); 52 // LCOV_EXCL_STOP 53 } 54 } 55 } 56 } 57 CeedVectorRestoreArrayRead(y, &yy); 58 59 // Transpose 60 CeedVectorSetValue(x, 0); 61 CeedElemRestrictionApply(r, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE); 62 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &xx); 63 for (CeedInt i = 0; i < num_elem + 1; i++) { 64 for (CeedInt j = 0; j < num_comp; j++) { 65 if (xx[i + j * (num_elem + 1)] != ((j + 1) * 10 + i) * (i > 0 && i < num_elem ? 2.0 : 1.0)) { 66 // LCOV_EXCL_START 67 printf("Error in restricted array x[%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", j, i, (double)xx[i + j * (num_elem + 1)]); 68 // LCOV_EXCL_STOP 69 } 70 } 71 } 72 CeedVectorRestoreArrayRead(x, &xx); 73 74 CeedVectorDestroy(&x); 75 CeedVectorDestroy(&y); 76 CeedElemRestrictionDestroy(&r); 77 CeedDestroy(&ceed); 78 return 0; 79 } 80