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