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 CeedScalar a[2 * (num_elem * 2)]; 15 const CeedScalar *yy; 16 CeedElemRestriction r; 17 18 CeedInit(argv[1], &ceed); 19 20 // Setup 21 CeedVectorCreate(ceed, 2 * (num_elem * 2), &x); 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, &r); 28 CeedVectorCreate(ceed, 2 * (num_elem + 1), &y); 29 CeedVectorSetValue(y, 0); // Allocates array 30 31 // Set x data in backend E-layout 32 CeedElemRestrictionGetELayout(r, &layout); 33 for (CeedInt i = 0; i < 2; i++) { // Node 34 for (CeedInt j = 0; j < 2; j++) { // Component 35 for (CeedInt k = 0; k < num_elem; k++) { // Element 36 a[i * layout[0] + j * layout[1] + k * layout[2]] = 10 * j + (2 * k + i + 1) / 2; 37 } 38 } 39 } 40 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 41 42 // Restrict 43 CeedElemRestrictionApply(r, CEED_TRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 44 45 // Check 46 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 47 for (CeedInt i = 0; i < num_elem + 1; i++) { 48 mult = i > 0 && i < num_elem ? 2 : 1; 49 if (yy[i] != i * mult) printf("Error in restricted array y[%" CeedInt_FMT "] = %f != %f\n", i, (CeedScalar)yy[i], i * mult); 50 if (yy[i + num_elem + 1] != (10 + i) * mult) { 51 // LCOV_EXCL_START 52 printf("Error in restricted array y[%" CeedInt_FMT "] = %f != %f\n", i + num_elem + 1, (CeedScalar)yy[i + num_elem + 1], (10. + i) * mult); 53 // LCOV_EXCL_STOP 54 } 55 } 56 57 CeedVectorRestoreArrayRead(y, &yy); 58 CeedVectorDestroy(&x); 59 CeedVectorDestroy(&y); 60 CeedElemRestrictionDestroy(&r); 61 CeedDestroy(&ceed); 62 return 0; 63 } 64