1 /// @file 2 /// Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector, and libCEED owns ind pointer 3 /// \test Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector, and libCEED owns ind pointer 4 #include <ceed.h> 5 #include <ceed/backend.h> 6 #include <stdio.h> 7 #include <stdlib.h> 8 #include <string.h> 9 10 int main(int argc, char **argv) { 11 Ceed ceed; 12 CeedVector x, y; 13 CeedInt num_elem = 8; 14 CeedInt elem_size = 2; 15 CeedInt num_blk = 2; 16 CeedInt blk_size = 5; 17 CeedInt num_comp = 3; 18 CeedInt ind[elem_size * num_elem]; 19 CeedInt *ceed_ind = malloc(sizeof(CeedInt) * elem_size * num_elem); 20 CeedScalar x_array[num_comp * (num_elem + 1)]; 21 CeedInt layout[3]; 22 CeedElemRestriction elem_restriction; 23 24 CeedInit(argv[1], &ceed); 25 26 CeedVectorCreate(ceed, num_comp * (num_elem + 1), &x); 27 for (CeedInt i = 0; i < num_elem + 1; i++) { 28 x_array[i + 0 * (num_elem + 1)] = 10 + i; 29 x_array[i + 1 * (num_elem + 1)] = 20 + i; 30 x_array[i + 2 * (num_elem + 1)] = 30 + i; 31 } 32 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array); 33 CeedVectorCreate(ceed, num_comp * num_blk * blk_size * elem_size, &y); 34 35 for (CeedInt i = 0; i < num_elem; i++) { 36 ind[2 * i + 0] = i; 37 ind[2 * i + 1] = i + 1; 38 } 39 memcpy(ceed_ind, ind, sizeof(CeedInt) * elem_size * num_elem); 40 CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, num_comp, num_elem + 1, num_comp * (num_elem + 1), CEED_MEM_HOST, 41 CEED_OWN_POINTER, ceed_ind, &elem_restriction); 42 43 // NoTranspose 44 CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 45 { 46 const CeedScalar *y_array; 47 48 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array); 49 CeedElemRestrictionGetELayout(elem_restriction, &layout); 50 for (CeedInt i = 0; i < elem_size; i++) { // Node 51 for (CeedInt j = 0; j < num_comp; j++) { // Component 52 for (CeedInt k = 0; k < num_elem; k++) { // Element 53 CeedInt block = k / blk_size; 54 CeedInt elem = k % blk_size; 55 CeedInt index = (i * blk_size + elem) * layout[0] + j * layout[1] * blk_size + block * layout[2] * blk_size; 56 if (y_array[index] != x_array[ind[k * elem_size + i] + j * (num_elem + 1)]) 57 // LCOV_EXCL_START 58 printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, (double)y_array[index]); 59 // LCOV_EXCL_STOP 60 } 61 } 62 } 63 CeedVectorRestoreArrayRead(y, &y_array); 64 } 65 66 // Transpose 67 CeedVectorSetValue(x, 0); 68 CeedElemRestrictionApply(elem_restriction, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE); 69 { 70 const CeedScalar *x_array; 71 72 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &x_array); 73 for (CeedInt i = 0; i < num_elem + 1; i++) { 74 for (CeedInt j = 0; j < num_comp; j++) { 75 if (x_array[i + j * (num_elem + 1)] != ((j + 1) * 10 + i) * (i > 0 && i < num_elem ? 2.0 : 1.0)) { 76 // LCOV_EXCL_START 77 printf("Error in restricted array x[%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", j, i, (double)x_array[i + j * (num_elem + 1)]); 78 // LCOV_EXCL_STOP 79 } 80 } 81 } 82 CeedVectorRestoreArrayRead(x, &x_array); 83 } 84 85 CeedVectorDestroy(&x); 86 CeedVectorDestroy(&y); 87 CeedElemRestrictionDestroy(&elem_restriction); 88 CeedDestroy(&ceed); 89 return 0; 90 } 91