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