From ae4e5d7f9b3678ba89e9a41268c4c482b95e049e Mon Sep 17 00:00:00 2001 From: Sebastian Grimberg Date: Fri, 28 Jul 2023 16:02:46 -0700 Subject: [PATCH] Update unit tests to improve coverage --- tests/t218-elemrestriction.c | 107 +++++++++++++----- ...emrestriction.c => t220-elemrestriction.c} | 12 +- 2 files changed, 83 insertions(+), 36 deletions(-) rename tests/{t221-elemrestriction.c => t220-elemrestriction.c} (90%) diff --git a/tests/t218-elemrestriction.c b/tests/t218-elemrestriction.c index 82ec7fe561..3494292741 100644 --- a/tests/t218-elemrestriction.c +++ b/tests/t218-elemrestriction.c @@ -1,68 +1,100 @@ /// @file -/// Test creation, use, and destruction of a curl-conforming oriented element restriction -/// \test Test creation, use, and destruction of a curl-conforming oriented element restriction +/// Test creation, use, and destruction of a curl-conforming oriented element restriction with and without unsigned application +/// \test Test creation, use, and destruction of a curl-conforming oriented element restriction with and without unsigned application #include #include int main(int argc, char **argv) { Ceed ceed; - CeedVector x, y; - CeedInt num_elem = 6, elem_size = 2; + CeedVector x, y, y_unsigned; + CeedInt num_elem = 6, elem_size = 4; CeedInt ind[elem_size * num_elem]; CeedInt8 curl_orients[3 * elem_size * num_elem]; - CeedScalar x_array[num_elem + 1]; - CeedElemRestriction elem_restriction; + CeedScalar x_array[3 * num_elem + 1]; + CeedElemRestriction elem_restriction, elem_restriction_unsigned; CeedInit(argv[1], &ceed); - CeedVectorCreate(ceed, num_elem + 1, &x); - for (CeedInt i = 0; i < num_elem + 1; i++) x_array[i] = 10 + i; + CeedVectorCreate(ceed, 3 * num_elem + 1, &x); + for (CeedInt i = 0; i < 3 * num_elem + 1; i++) x_array[i] = 10 + i; CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array); CeedVectorCreate(ceed, num_elem * elem_size, &y); + CeedVectorCreate(ceed, num_elem * elem_size, &y_unsigned); for (CeedInt i = 0; i < num_elem; i++) { - ind[2 * i + 0] = i; - ind[2 * i + 1] = i + 1; - curl_orients[3 * 2 * i] = curl_orients[3 * 2 * (i + 1) - 1] = 0; + ind[4 * i + 0] = 3 * i + 0; + ind[4 * i + 1] = 3 * i + 1; + ind[4 * i + 2] = 3 * i + 2; + ind[4 * i + 3] = 3 * i + 3; if (i % 2 > 0) { - // T = [0 -1] - // [-1 0] - curl_orients[3 * 2 * i + 1] = 0; - curl_orients[3 * 2 * i + 2] = -1; - curl_orients[3 * 2 * i + 3] = -1; - curl_orients[3 * 2 * i + 4] = 0; + // T = [ 1 0 0 0] + // [ 0 1 0 0] + // [ 0 0 0 -1] + // [ 0 0 -1 0] + curl_orients[3 * 4 * i + 0] = 0; + curl_orients[3 * 4 * i + 1] = 1; + curl_orients[3 * 4 * i + 2] = 0; + curl_orients[3 * 3 * i + 3] = 0; + curl_orients[3 * 4 * i + 4] = 1; + curl_orients[3 * 4 * i + 5] = 0; + curl_orients[3 * 4 * i + 6] = 0; + curl_orients[3 * 4 * i + 7] = 0; + curl_orients[3 * 4 * i + 8] = -1; + curl_orients[3 * 4 * i + 9] = -1; + curl_orients[3 * 4 * i + 10] = 0; + curl_orients[3 * 4 * i + 11] = 0; } else { // T = I - curl_orients[3 * 2 * i + 1] = 1; - curl_orients[3 * 2 * i + 2] = 0; - curl_orients[3 * 2 * i + 3] = 0; - curl_orients[3 * 2 * i + 4] = 1; + curl_orients[3 * 4 * i + 0] = 0; + curl_orients[3 * 4 * i + 1] = 1; + curl_orients[3 * 4 * i + 2] = 0; + curl_orients[3 * 4 * i + 3] = 0; + curl_orients[3 * 4 * i + 4] = 1; + curl_orients[3 * 4 * i + 5] = 0; + curl_orients[3 * 4 * i + 6] = 0; + curl_orients[3 * 4 * i + 7] = 1; + curl_orients[3 * 4 * i + 8] = 0; + curl_orients[3 * 4 * i + 9] = 0; + curl_orients[3 * 4 * i + 10] = 1; + curl_orients[3 * 4 * i + 11] = 0; } } - CeedElemRestrictionCreateCurlOriented(ceed, num_elem, elem_size, 1, 1, num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, curl_orients, + CeedElemRestrictionCreateCurlOriented(ceed, num_elem, elem_size, 1, 1, 3 * num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, curl_orients, &elem_restriction); + CeedElemRestrictionCreateUnsignedCopy(elem_restriction, &elem_restriction_unsigned); // NoTranspose CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); + CeedElemRestrictionApply(elem_restriction_unsigned, CEED_NOTRANSPOSE, x, y_unsigned, CEED_REQUEST_IMMEDIATE); { - const CeedScalar *y_array; + const CeedScalar *y_array, *y_unsigned_array; CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array); + CeedVectorGetArrayRead(y_unsigned, CEED_MEM_HOST, &y_unsigned_array); for (CeedInt i = 0; i < num_elem; i++) { for (CeedInt j = 0; j < elem_size; j++) { CeedInt k = j + elem_size * i; - if (i % 2 > 0) { - if (j == 0 && 10 + i + 1 != -y_array[k]) { + if (i % 2 > 0 && j >= 2) { + if (j == 2 && 10 + 3 * i + j + 1 != -y_array[k]) { // LCOV_EXCL_START printf("Error in restricted array y[%" CeedInt_FMT "] = %f\n", k, (CeedScalar)y_array[k]); // LCOV_EXCL_STOP - } else if (j == 1 && 10 + i != -y_array[k]) { + } else if (j == 3 && 10 + 3 * i + j - 1 != -y_array[k]) { // LCOV_EXCL_START printf("Error in restricted array y[%" CeedInt_FMT "] = %f\n", k, (CeedScalar)y_array[k]); // LCOV_EXCL_STOP } + if (j == 2 && 10 + 3 * i + j + 1 != y_unsigned_array[k]) { + // LCOV_EXCL_START + printf("Error in unsigned restricted array y[%" CeedInt_FMT "] = %f\n", k, (CeedScalar)y_unsigned_array[k]); + // LCOV_EXCL_STOP + } else if (j == 3 && 10 + 3 * i + j - 1 != y_unsigned_array[k]) { + // LCOV_EXCL_START + printf("Error in unsigned restricted array y[%" CeedInt_FMT "] = %f\n", k, (CeedScalar)y_unsigned_array[k]); + // LCOV_EXCL_STOP + } } else { - if (10 + (k + 1) / 2 != y_array[k]) { + if (10 + 3 * i + j != y_array[k] || 10 + 3 * i + j != y_unsigned_array[k]) { // LCOV_EXCL_START printf("Error in restricted array y[%" CeedInt_FMT "] = %f\n", k, (CeedScalar)y_array[k]); // LCOV_EXCL_STOP @@ -71,6 +103,7 @@ int main(int argc, char **argv) { } } CeedVectorRestoreArrayRead(y, &y_array); + CeedVectorRestoreArrayRead(y_unsigned, &y_unsigned_array); } // Transpose @@ -80,8 +113,22 @@ int main(int argc, char **argv) { const CeedScalar *x_array; CeedVectorGetArrayRead(x, CEED_MEM_HOST, &x_array); - for (CeedInt i = 0; i < num_elem + 1; i++) { - if (x_array[i] != (10 + i) * (i > 0 && i < num_elem ? 2.0 : 1.0)) + for (CeedInt i = 0; i < 3 * num_elem + 1; i++) { + if (x_array[i] != (10 + i) * (i > 0 && i < 3 * num_elem && i % 3 == 0 ? 2.0 : 1.0)) + printf("Error in restricted array x[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)x_array[i]); + } + CeedVectorRestoreArrayRead(x, &x_array); + } + + // Transpose unsigned + CeedVectorSetValue(x, 0); + CeedElemRestrictionApply(elem_restriction_unsigned, CEED_TRANSPOSE, y_unsigned, x, CEED_REQUEST_IMMEDIATE); + { + const CeedScalar *x_array; + + CeedVectorGetArrayRead(x, CEED_MEM_HOST, &x_array); + for (CeedInt i = 0; i < 3 * num_elem + 1; i++) { + if (x_array[i] != (10 + i) * (i > 0 && i < 3 * num_elem && i % 3 == 0 ? 2.0 : 1.0)) printf("Error in restricted array x[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)x_array[i]); } CeedVectorRestoreArrayRead(x, &x_array); @@ -89,7 +136,9 @@ int main(int argc, char **argv) { CeedVectorDestroy(&x); CeedVectorDestroy(&y); + CeedVectorDestroy(&y_unsigned); CeedElemRestrictionDestroy(&elem_restriction); + CeedElemRestrictionDestroy(&elem_restriction_unsigned); CeedDestroy(&ceed); return 0; } diff --git a/tests/t221-elemrestriction.c b/tests/t220-elemrestriction.c similarity index 90% rename from tests/t221-elemrestriction.c rename to tests/t220-elemrestriction.c index 5ab326eb9e..19e1113ccb 100644 --- a/tests/t221-elemrestriction.c +++ b/tests/t220-elemrestriction.c @@ -1,6 +1,6 @@ /// @file -/// Test creation, use, and destruction of an element restriction oriented with unsigned application -/// \test Test creation, use, and destruction of an element restriction oriented with unsigned application +/// Test creation, use, and destruction of an oriented element restriction with unsigned application +/// \test Test creation, use, and destruction of an oriented element restriction with unsigned application #include #include #include @@ -25,10 +25,9 @@ int main(int argc, char **argv) { CeedVectorCreate(ceed, num_elem * 2, &y_unsigned_copy); for (CeedInt i = 0; i < num_elem; i++) { - ind[2 * i + 0] = i; - ind[2 * i + 1] = i + 1; - // flip the dofs on element 1,3,... - orient[2 * i + 0] = (i % (2)) * -1 < 0; + ind[2 * i + 0] = i; + ind[2 * i + 1] = i + 1; + orient[2 * i + 0] = (i % (2)) * -1 < 0; // flip the dofs on element 1, 3, ... orient[2 * i + 1] = (i % (2)) * -1 < 0; } CeedElemRestrictionCreateOriented(ceed, num_elem, p, dim, 1, num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, orient, &elem_restriction); @@ -38,7 +37,6 @@ int main(int argc, char **argv) { CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y_oriented, CEED_REQUEST_IMMEDIATE); CeedElemRestrictionApply(elem_restriction_unsigned, CEED_NOTRANSPOSE, x, y_unsigned, CEED_REQUEST_IMMEDIATE); CeedElemRestrictionApply(elem_restriction_copy, CEED_NOTRANSPOSE, x, y_unsigned_copy, CEED_REQUEST_IMMEDIATE); - { const CeedScalar *y_oriented_array, *y_unsigned_array, *y_unsigned_copy_array;