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