Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions tests/math/test_omp_consistency.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,8 @@ void test_cg_omp_vs_scalar(void) {
TEST_ASSERT_EQUAL(CFD_SUCCESS, status);
TEST_ASSERT_EQUAL(POISSON_CONVERGED, stats_scalar.status);

/* OMP backend requires OpenMP - skip if not compiled in */
#ifndef CFD_ENABLE_OPENMP
cfd_free(x_scalar);
cfd_free(x_omp);
cfd_free(x_temp);
cfd_free(rhs);
poisson_solver_destroy(solver_scalar);
TEST_IGNORE_MESSAGE("OMP test skipped: OpenMP not enabled in this build");
return;
#endif

bool omp_available = poisson_solver_backend_available(POISSON_BACKEND_OMP);
if (!omp_available) {
/* OMP backend requires OpenMP - skip at runtime if unavailable */
if (!poisson_solver_backend_available(POISSON_BACKEND_OMP)) {
cfd_free(x_scalar);
cfd_free(x_omp);
cfd_free(x_temp);
Expand Down Expand Up @@ -245,19 +234,8 @@ void test_redblack_omp_vs_scalar(void) {
TEST_ASSERT_EQUAL(CFD_SUCCESS, status);
TEST_ASSERT_EQUAL(POISSON_CONVERGED, stats_scalar.status);

/* OMP backend requires OpenMP - skip if not compiled in */
#ifndef CFD_ENABLE_OPENMP
cfd_free(x_scalar);
cfd_free(x_omp);
cfd_free(x_temp);
cfd_free(rhs);
poisson_solver_destroy(solver_scalar);
TEST_IGNORE_MESSAGE("OMP test skipped: OpenMP not enabled in this build");
return;
#endif

bool omp_available = poisson_solver_backend_available(POISSON_BACKEND_OMP);
if (!omp_available) {
/* OMP backend requires OpenMP - skip at runtime if unavailable */
if (!poisson_solver_backend_available(POISSON_BACKEND_OMP)) {
cfd_free(x_scalar);
cfd_free(x_omp);
cfd_free(x_temp);
Expand Down
23 changes: 15 additions & 8 deletions tests/validation/test_cavity_reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ void test_grid_convergence(void) {

size_t sizes[] = {17, 25, 33};
double errors[3];
double prev_error = 1.0;

for (int i = 0; i < 3; i++) {
size_t n = sizes[i];
Expand Down Expand Up @@ -279,18 +278,26 @@ void test_grid_convergence(void) {
}
printf("\n");

/* Error should decrease or stay similar with refinement */
TEST_ASSERT_TRUE_MESSAGE(errors[i] <= prev_error + 0.02,
"Error increased significantly with grid refinement");
prev_error = errors[i];
/* Error must strictly decrease with grid refinement */
if (i > 0) {
TEST_ASSERT_TRUE_MESSAGE(errors[i] < errors[i - 1],
"Error must decrease with grid refinement (strict monotonicity)");
Comment thread
shaia marked this conversation as resolved.
}

free_centerline_data(&data);
cavity_context_destroy(ctx);
}

/* Finest grid should have lowest error */
TEST_ASSERT_TRUE_MESSAGE(errors[2] <= errors[0] + 0.02,
"Grid convergence: finest grid should have lower or similar error");
/* Finest grid must have lowest error */
TEST_ASSERT_TRUE_MESSAGE(errors[2] < errors[0],
"Grid convergence: finest grid must have lower error than coarsest");

/* Report convergence rates (informational — first-order BCs limit to ~O(h^1.5)) */
double h[] = {1.0 / 17, 1.0 / 25, 1.0 / 33};
for (int i = 0; i < 2; i++) {
double rate = log(errors[i] / errors[i + 1]) / log(h[i] / h[i + 1]);
printf(" Rate (%zu->%zu): %.2f\n", sizes[i], sizes[i + 1], rate);
}
}

/* ============================================================================
Expand Down
24 changes: 17 additions & 7 deletions tests/validation/test_ghia_projection_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void test_projection_cpu_grid_convergence(void) {
printf("\n Grid convergence study...\n");

size_t sizes[] = {17, 25, 33};
double prev_rms = 1.0;
double errors[3];

for (int i = 0; i < 3; i++) {
size_t n = sizes[i];
Expand All @@ -79,16 +79,26 @@ void test_projection_cpu_grid_convergence(void) {

TEST_ASSERT_TRUE_MESSAGE(result.success, result.error_msg);

printf(" %zux%zu: RMS_u=%.4f", n, n, result.rms_u_error);
if (result.rms_u_error > GHIA_TOLERANCE_MEDIUM) {
errors[i] = result.rms_u_error;

printf(" %zux%zu: RMS_u=%.4f", n, n, errors[i]);
if (errors[i] > GHIA_TOLERANCE_MEDIUM) {
printf(" [ABOVE TARGET]");
}
printf("\n");

/* Error should decrease or stay similar with refinement */
TEST_ASSERT_TRUE_MESSAGE(result.rms_u_error <= prev_rms + 0.02,
"Error increased significantly with grid refinement");
prev_rms = result.rms_u_error;
/* Error must strictly decrease with grid refinement */
if (i > 0) {
TEST_ASSERT_TRUE_MESSAGE(errors[i] < errors[i - 1],
"Error must decrease with grid refinement (strict monotonicity)");
}
}

/* Report convergence rates (informational — first-order BCs limit to ~O(h^1.5)) */
double h[] = {1.0 / 17, 1.0 / 25, 1.0 / 33};
for (int i = 0; i < 2; i++) {
double rate = log(errors[i] / errors[i + 1]) / log(h[i] / h[i + 1]);
printf(" Rate (%zu->%zu): %.2f\n", sizes[i], sizes[i + 1], rate);
}
}

Expand Down
Loading