1 /// @file 2 /// Test creation, use, and destruction of a multi-component element restriction 3 /// \test Test creation, use, and destruction of a multi-component element restriction 4 #include <ceed.h> 5 #include <ceed/backend.h> 6 #include <stdio.h> 7 8 int main(int argc, char **argv) { 9 Ceed ceed; 10 CeedVector x, y; 11 CeedInt num_elem = 3; 12 CeedInt ind[2 * num_elem]; 13 CeedInt e_layout[3]; 14 CeedScalar x_array[2 * (num_elem + 1)]; 15 CeedElemRestriction elem_restriction; 16 17 CeedInit(argv[1], &ceed); 18 19 // Setup 20 CeedVectorCreate(ceed, 2 * (num_elem + 1), &x); 21 for (CeedInt i = 0; i < num_elem + 1; i++) { 22 x_array[i] = 10 + i; 23 x_array[i + num_elem + 1] = 20 + i; 24 } 25 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array); 26 CeedVectorCreate(ceed, 2 * (num_elem * 2), &y); 27 28 for (CeedInt i = 0; i < num_elem; i++) { 29 ind[2 * i + 0] = i; 30 ind[2 * i + 1] = i + 1; 31 } 32 CeedElemRestrictionCreate(ceed, num_elem, 2, 2, num_elem + 1, 2 * (num_elem + 1), CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction); 33 34 // Restrict 35 CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 36 37 // Check 38 { 39 const CeedScalar *y_array; 40 41 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array); 42 CeedElemRestrictionGetELayout(elem_restriction, e_layout); 43 for (CeedInt i = 0; i < 2; i++) { // Node 44 for (CeedInt j = 0; j < 2; j++) { // Component 45 for (CeedInt k = 0; k < num_elem; k++) { // Element 46 if (y_array[i * e_layout[0] + j * e_layout[1] + k * e_layout[2]] != x_array[ind[i + k * 2] + j * (num_elem + 1)]) { 47 // LCOV_EXCL_START 48 printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f != %f\n", i, j, k, 49 (CeedScalar)y_array[i * e_layout[0] + j * e_layout[1] + k * e_layout[2]], x_array[ind[i + k * 2] + j * (num_elem + 1)]); 50 // LCOV_EXCL_STOP 51 } 52 } 53 } 54 } 55 CeedVectorRestoreArrayRead(y, &y_array); 56 } 57 58 CeedVectorDestroy(&x); 59 CeedVectorDestroy(&y); 60 CeedElemRestrictionDestroy(&elem_restriction); 61 CeedDestroy(&ceed); 62 return 0; 63 } 64