1 /// @file 2 /// Test creation, use, and destruction of an element restriction oriented 3 /// \test Test creation, use, and destruction of an element restriction oriented 4 #include <ceed.h> 5 6 int main(int argc, char **argv) { 7 Ceed ceed; 8 CeedVector x, y; 9 CeedInt num_elem = 6, p = 2, dim = 1; 10 CeedInt ind[p * num_elem]; 11 bool orient[p * num_elem]; 12 CeedScalar x_array[num_elem + 1]; 13 CeedElemRestriction elem_restriction; 14 15 CeedInit(argv[1], &ceed); 16 17 CeedVectorCreate(ceed, num_elem + 1, &x); 18 for (CeedInt i = 0; i < num_elem + 1; i++) x_array[i] = 10 + i; 19 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array); 20 CeedVectorCreate(ceed, num_elem * 2, &y); 21 22 for (CeedInt i = 0; i < num_elem; i++) { 23 ind[2 * i + 0] = i; 24 ind[2 * i + 1] = i + 1; 25 // flip the dofs on element 1,3,... 26 orient[2 * i + 0] = (i % (2)) * -1 < 0; 27 orient[2 * i + 1] = (i % (2)) * -1 < 0; 28 } 29 CeedElemRestrictionCreateOriented(ceed, num_elem, p, dim, 1, num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, orient, &elem_restriction); 30 31 CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 32 { 33 const CeedScalar *y_array; 34 35 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array); 36 for (CeedInt i = 0; i < num_elem; i++) { 37 for (CeedInt j = 0; j < p; j++) { 38 CeedInt k = j + p * i; 39 if (y_array[k] * CeedIntPow(-1, i % 2) != 10 + (k + 1) / 2) { 40 // LCOV_EXCL_START 41 printf("Error in restricted array y[%" CeedInt_FMT "] = %f\n", k, (CeedScalar)y_array[k]); 42 // LCOV_EXCL_STOP 43 } 44 } 45 } 46 CeedVectorRestoreArrayRead(y, &y_array); 47 } 48 49 CeedVectorDestroy(&x); 50 CeedVectorDestroy(&y); 51 CeedElemRestrictionDestroy(&elem_restriction); 52 CeedDestroy(&ceed); 53 return 0; 54 } 55