1 /// @file 2 /// Test creation, use, and destruction of an oriented element restriction with unsigned application 3 /// \test Test creation, use, and destruction of an oriented element restriction with unsigned application 4 #include <ceed.h> 5 #include <ceed/backend.h> 6 #include <math.h> 7 #include <stdio.h> 8 9 int main(int argc, char **argv) { 10 Ceed ceed; 11 CeedVector x, y_oriented, y_unsigned, y_unsigned_copy; 12 CeedInt num_elem = 6, p = 2, dim = 1; 13 CeedInt ind[p * num_elem]; 14 bool orient[p * num_elem]; 15 CeedScalar x_array[num_elem + 1]; 16 CeedElemRestriction elem_restriction, elem_restriction_unsigned, elem_restriction_copy; 17 18 CeedInit(argv[1], &ceed); 19 20 CeedVectorCreate(ceed, num_elem + 1, &x); 21 for (CeedInt i = 0; i < num_elem + 1; i++) x_array[i] = 10 + i; 22 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array); 23 CeedVectorCreate(ceed, num_elem * 2, &y_oriented); 24 CeedVectorCreate(ceed, num_elem * 2, &y_unsigned); 25 CeedVectorCreate(ceed, num_elem * 2, &y_unsigned_copy); 26 27 for (CeedInt i = 0; i < num_elem; i++) { 28 ind[2 * i + 0] = i; 29 ind[2 * i + 1] = i + 1; 30 orient[2 * i + 0] = (i % (2)) * -1 < 0; // flip the dofs on element 1, 3, ... 31 orient[2 * i + 1] = (i % (2)) * -1 < 0; 32 } 33 CeedElemRestrictionCreateOriented(ceed, num_elem, p, dim, 1, num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, orient, &elem_restriction); 34 CeedElemRestrictionCreate(ceed, num_elem, p, dim, 1, num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction_unsigned); 35 CeedElemRestrictionCreateUnsignedCopy(elem_restriction, &elem_restriction_copy); 36 37 CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y_oriented, CEED_REQUEST_IMMEDIATE); 38 CeedElemRestrictionApply(elem_restriction_unsigned, CEED_NOTRANSPOSE, x, y_unsigned, CEED_REQUEST_IMMEDIATE); 39 CeedElemRestrictionApply(elem_restriction_copy, CEED_NOTRANSPOSE, x, y_unsigned_copy, CEED_REQUEST_IMMEDIATE); 40 { 41 const CeedScalar *y_oriented_array, *y_unsigned_array, *y_unsigned_copy_array; 42 43 CeedVectorGetArrayRead(y_oriented, CEED_MEM_HOST, &y_oriented_array); 44 CeedVectorGetArrayRead(y_unsigned, CEED_MEM_HOST, &y_unsigned_array); 45 CeedVectorGetArrayRead(y_unsigned_copy, CEED_MEM_HOST, &y_unsigned_copy_array); 46 for (CeedInt i = 0; i < num_elem; i++) { 47 for (CeedInt j = 0; j < p; j++) { 48 CeedInt k = j + p * i; 49 // unsigned application should match oriented application, but with no sign change 50 if (y_oriented_array[k] * CeedIntPow(-1, i % 2) != 10 + (k + 1) / 2) { 51 // LCOV_EXCL_START 52 printf("Error in oriented restricted array y[%" CeedInt_FMT "] = %f\n", k, (CeedScalar)y_oriented_array[k]); 53 // LCOV_EXCL_STOP 54 } 55 if (y_unsigned_array[k] != 10 + (k + 1) / 2) { 56 // LCOV_EXCL_START 57 printf("Error in unsigned restricted array y[%" CeedInt_FMT "] = %f\n", k, (CeedScalar)y_unsigned_array[k]); 58 // LCOV_EXCL_STOP 59 } 60 if (y_unsigned_array[k] != y_unsigned_copy_array[k]) { 61 // LCOV_EXCL_START 62 printf("Error in copy restricted array y[%" CeedInt_FMT "] = %f\n", k, (CeedScalar)y_unsigned_copy_array[k]); 63 // LCOV_EXCL_STOP 64 } 65 } 66 } 67 CeedVectorRestoreArrayRead(y_oriented, &y_oriented_array); 68 CeedVectorRestoreArrayRead(y_unsigned, &y_unsigned_array); 69 CeedVectorRestoreArrayRead(y_unsigned_copy, &y_unsigned_copy_array); 70 } 71 72 CeedVectorDestroy(&x); 73 CeedVectorDestroy(&y_oriented); 74 CeedVectorDestroy(&y_unsigned); 75 CeedVectorDestroy(&y_unsigned_copy); 76 CeedElemRestrictionDestroy(&elem_restriction); 77 CeedElemRestrictionDestroy(&elem_restriction_unsigned); 78 CeedElemRestrictionDestroy(&elem_restriction_copy); 79 CeedDestroy(&ceed); 80 return 0; 81 } 82