1 /// @file 2 /// Test creation, use, and destruction of a strided element restriction 3 /// \test Test creation, use, and destruction of a strided 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 CeedScalar a[num_elem * 2]; 12 const CeedScalar *yy; 13 CeedInt strides[3] = {1, 2, 2}; 14 CeedInt layout[3]; 15 CeedElemRestriction r; 16 17 CeedInit(argv[1], &ceed); 18 19 CeedVectorCreate(ceed, num_elem * 2, &x); 20 for (CeedInt i = 0; i < num_elem * 2; i++) a[i] = 10 + i; 21 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 22 23 CeedElemRestrictionCreateStrided(ceed, num_elem, 2, 1, num_elem * 2, strides, &r); 24 CeedVectorCreate(ceed, num_elem * 2, &y); 25 CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 26 27 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 28 CeedElemRestrictionGetELayout(r, &layout); 29 for (CeedInt i = 0; i < 2; i++) { // Node 30 for (CeedInt j = 0; j < 1; j++) { // Component 31 for (CeedInt k = 0; k < num_elem; k++) { // Element 32 if (yy[i * layout[0] + j * layout[1] + k * layout[2]] != a[i * strides[0] + j * strides[1] + k * strides[2]]) { 33 // LCOV_EXCL_START 34 printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, 35 (CeedScalar)yy[i * strides[0] + j * strides[1] + j * strides[2]]); 36 // LCOV_EXCL_STOP 37 } 38 } 39 } 40 } 41 CeedVectorRestoreArrayRead(y, &yy); 42 43 CeedVectorDestroy(&x); 44 CeedVectorDestroy(&y); 45 CeedElemRestrictionDestroy(&r); 46 CeedDestroy(&ceed); 47 return 0; 48 } 49