Skip to content

Commit

Permalink
Update unit tests to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiangrimberg committed Jul 28, 2023
1 parent 2410b26 commit 85bf8bc
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 36 deletions.
106 changes: 77 additions & 29 deletions tests/t218-elemrestriction.c
Original file line number Diff line number Diff line change
@@ -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 <ceed.h>
#include <stdio.h>

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
Expand All @@ -71,6 +103,7 @@ int main(int argc, char **argv) {
}
}
CeedVectorRestoreArrayRead(y, &y_array);
CeedVectorRestoreArrayRead(y_unsigned, &y_unsigned_array);
}

// Transpose
Expand All @@ -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);
Expand All @@ -90,6 +137,7 @@ int main(int argc, char **argv) {
CeedVectorDestroy(&x);
CeedVectorDestroy(&y);
CeedElemRestrictionDestroy(&elem_restriction);
CeedElemRestrictionDestroy(&elem_restriction_unsigned);
CeedDestroy(&ceed);
return 0;
}
12 changes: 5 additions & 7 deletions tests/t221-elemrestriction.c → tests/t220-elemrestriction.c
Original file line number Diff line number Diff line change
@@ -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 <ceed.h>
#include <ceed/backend.h>
#include <math.h>
Expand All @@ -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);
Expand All @@ -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;

Expand Down

0 comments on commit 85bf8bc

Please sign in to comment.