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 #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 strides[3] = {1, 2, 2}; 13 CeedInt e_layout[3], l_layout[3]; 14 CeedScalar x_array[num_elem * 2]; 15 CeedElemRestriction elem_restriction; 16 17 CeedInit(argv[1], &ceed); 18 19 CeedVectorCreate(ceed, num_elem * 2, &x); 20 for (CeedInt i = 0; i < num_elem * 2; i++) x_array[i] = 10 + i; 21 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array); 22 CeedVectorCreate(ceed, num_elem * 2, &y); 23 24 CeedElemRestrictionCreateStrided(ceed, num_elem, 2, 1, num_elem * 2, strides, &elem_restriction); 25 CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 26 27 { 28 const CeedScalar *y_array; 29 30 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array); 31 CeedElemRestrictionGetELayout(elem_restriction, e_layout); 32 CeedElemRestrictionGetLLayout(elem_restriction, l_layout); 33 for (CeedInt i = 0; i < 2; i++) { // Node 34 for (CeedInt j = 0; j < 1; j++) { // Component 35 for (CeedInt k = 0; k < num_elem; k++) { // Element 36 if (y_array[i * e_layout[0] + j * e_layout[1] + k * e_layout[2]] != x_array[i * l_layout[0] + j * l_layout[1] + k * l_layout[2]]) { 37 // LCOV_EXCL_START 38 printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, 39 (CeedScalar)y_array[i * strides[0] + j * strides[1] + j * strides[2]]); 40 // LCOV_EXCL_STOP 41 } 42 } 43 } 44 } 45 CeedVectorRestoreArrayRead(y, &y_array); 46 } 47 48 CeedVectorDestroy(&x); 49 CeedVectorDestroy(&y); 50 CeedElemRestrictionDestroy(&elem_restriction); 51 CeedDestroy(&ceed); 52 return 0; 53 } 54