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