From 09cea8b69f46aa14a48666433cb2bb0bc1eff241 Mon Sep 17 00:00:00 2001 From: Leila Ghaffari Date: Thu, 13 Jul 2023 10:23:05 -0600 Subject: [PATCH] Add test with TESTTYPE_POST_PROCESS This is passing locally but we might need to change the *.bin file as there is still a bug in the computed error depending on the number of ranks. --- examples/fluids/navierstokes.c | 1 + examples/fluids/navierstokes.h | 5 +- examples/fluids/src/misc.c | 44 +++++++++++------- examples/fluids/src/setuplibceed.c | 2 +- .../fluids-navierstokes-exact-postprocess.bin | Bin 0 -> 5272 bytes 5 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 examples/fluids/tests-output/fluids-navierstokes-exact-postprocess.bin diff --git a/examples/fluids/navierstokes.c b/examples/fluids/navierstokes.c index 91bae0f722..1a68f2915d 100644 --- a/examples/fluids/navierstokes.c +++ b/examples/fluids/navierstokes.c @@ -38,6 +38,7 @@ //TESTARGS(name="euler_implicit") -ceed {ceed_resource} -test_type solver -problem euler_vortex -degree 3 -dm_plex_box_faces 1,1,2 -dm_plex_box_lower 0,0,0 -dm_plex_box_upper 125,125,250 -dm_plex_dim 3 -units_meter 1e-4 -units_second 1e-4 -mean_velocity 1.4,-2.,0 -bc_inflow 4,6 -bc_outflow 3,5 -bc_slip_z 1,2 -vortex_strength 2 -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -dm_mat_preallocate_skip 0 -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-euler-implicit.bin //TESTARGS(name="euler_explicit") -ceed {ceed_resource} -test_type solver -problem euler_vortex -degree 3 -q_extra 2 -dm_plex_box_faces 2,2,1 -dm_plex_box_lower 0,0,0 -dm_plex_box_upper 125,125,250 -dm_plex_dim 3 -units_meter 1e-4 -units_second 1e-4 -mean_velocity 1.4,-2.,0 -bc_inflow 4,6 -bc_outflow 3,5 -bc_slip_z 1,2 -vortex_strength 2 -ts_dt 1e-7 -ts_rk_type 5bs -ts_rtol 1e-10 -ts_atol 1e-10 -compare_final_state_atol 1E-7 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-euler-explicit.bin //TESTARGS(name="shocktube_explicit_su_yzb") -ceed {ceed_resource} -test_type solver -problem shocktube -degree 1 -q_extra 2 -dm_plex_box_faces 50,1,1 -units_meter 1e-2 units_second 1e-2 -dm_plex_box_lower 0,0,0 -dm_plex_box_upper 1000,20,20 -dm_plex_dim 3 -bc_slip_x 5,6 -bc_slip_y 3,4 -bc_Slip_z 1,2 -yzb -stab su -compare_final_state_atol 1E-11 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-shocktube-explicit-su-yzb.bin +//TESTARGS(name="exact_post_process") -ceed {ceed_resource} -test_type post_process -options_file examples/fluids/tests-output/blasius_test.yaml -ts_dt 1e-9 -compare_final_state_atol 1e-5 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-exact-postprocess.bin /// @file /// Navier-Stokes example using PETSc diff --git a/examples/fluids/navierstokes.h b/examples/fluids/navierstokes.h index 8453acba78..55201ffa78 100644 --- a/examples/fluids/navierstokes.h +++ b/examples/fluids/navierstokes.h @@ -72,8 +72,9 @@ typedef enum { TESTTYPE_SOLVER = 1, TESTTYPE_TURB_SPANSTATS = 2, TESTTYPE_DIFF_FILTER = 3, + TESTTYPE_POST_PROCESS = 4, } TestType; -static const char *const TestTypes[] = {"none", "solver", "turb_spanstats", "diff_filter", "TestType", "TESTTYPE_", NULL}; +static const char *const TestTypes[] = {"none", "solver", "turb_spanstats", "diff_filter", "post_process", "TestType", "TESTTYPE_", NULL}; // Test mode type typedef enum { @@ -391,7 +392,7 @@ PetscErrorCode RegressionTests_NS(AppCtx app_ctx, Vec Q); // Get error for problems with exact solutions PetscErrorCode ComputeL2Error(DM dm, CeedData ceed_data, User user, Vec Q, PetscReal l2_error[5], OperatorApplyContext op_error_ctx, - CeedContextFieldLabel time_label, CeedScalar time); + CeedContextFieldLabel time_label, CeedScalar time, Vec *E); PetscErrorCode GetError_NS(CeedData ceed_data, DM dm, User user, ProblemData *problem, Vec Qsource_soln, PetscScalar final_time); // Post-processing diff --git a/examples/fluids/src/misc.c b/examples/fluids/src/misc.c index 4e3dbe4290..60d2848135 100644 --- a/examples/fluids/src/misc.c +++ b/examples/fluids/src/misc.c @@ -142,8 +142,8 @@ PetscErrorCode RegressionTests_NS(AppCtx app_ctx, Vec Q) { } PetscErrorCode ComputeL2Error(DM dm, CeedData ceed_data, User user, Vec Q, PetscReal l2_error[5], OperatorApplyContext op_error_ctx, - CeedContextFieldLabel time_label, CeedScalar time) { - Vec Q_loc, E_loc, E; + CeedContextFieldLabel time_label, CeedScalar time, Vec *E) { + Vec Q_loc, E_loc; PetscReal l2_norm[5]; PetscFunctionBeginUser; @@ -152,17 +152,15 @@ PetscErrorCode ComputeL2Error(DM dm, CeedData ceed_data, User user, Vec Q, Petsc PetscCall(DMGlobalToLocal(dm, Q, INSERT_VALUES, Q_loc)); PetscCall(UpdateBoundaryValues(user, Q_loc, time)); - PetscCall(VecDuplicate(Q, &E)); PetscCall(VecDuplicate(Q_loc, &E_loc)); PetscCall(VecZeroEntries(E_loc)); - PetscCall(FixMultiplicity_NS(dm, ceed_data, user, op_error_ctx, Q_loc, E_loc, E, time_label, time)); + PetscCall(FixMultiplicity_NS(dm, ceed_data, user, op_error_ctx, Q_loc, E_loc, *E, time_label, time)); PetscCall(VecStrideNormAll(E_loc, NORM_1, l2_norm)); PetscCallMPI(MPI_Allreduce(MPI_IN_PLACE, l2_norm, 5, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD)); for (int i = 0; i < 5; i++) l2_error[i] = sqrt(l2_norm[i]); PetscCall(VecDestroy(&E_loc)); - PetscCall(VecDestroy(&E)); PetscFunctionReturn(PETSC_SUCCESS); }; @@ -170,37 +168,49 @@ PetscErrorCode ComputeL2Error(DM dm, CeedData ceed_data, User user, Vec Q, Petsc // Get error for problems with true solutions PetscErrorCode GetError_NS(CeedData ceed_data, DM dm, User user, ProblemData *problem, Vec Q, PetscScalar final_time) { PetscReal l2_error[5]; + Vec E_source; const char *state_var_source = "Conservative"; PetscFunctionBeginUser; // Compute the L2 error in the source state variables + PetscCall(VecDuplicate(Q, &E_source)); if (user->phys->ics_time_label) PetscCall(UpdateContextLabel(user->comm, final_time, ceed_data->op_ics_ctx->op, user->phys->ics_time_label)); CeedOperatorApply(ceed_data->op_ics_ctx->op, ceed_data->x_coord, ceed_data->q_true, CEED_REQUEST_IMMEDIATE); - PetscCall(ComputeL2Error(dm, ceed_data, user, Q, l2_error, ceed_data->op_error_ctx, user->phys->ics_time_label, final_time)); + PetscCall(ComputeL2Error(dm, ceed_data, user, Q, l2_error, ceed_data->op_error_ctx, user->phys->ics_time_label, final_time, &E_source)); // Print the error - PetscCall(PetscPrintf(PETSC_COMM_WORLD, "\nL2 Error:\n")); - if (user->phys->state_var == STATEVAR_PRIMITIVE) state_var_source = "Primitive"; - for (int i = 0; i < 5; i++) PetscCall(PetscPrintf(PETSC_COMM_WORLD, " %s variables-Component %d: %g\n", state_var_source, i, (double)l2_error[i])); - + if (user->app_ctx->test_type != TESTTYPE_POST_PROCESS) { + PetscCall(PetscPrintf(PETSC_COMM_WORLD, "\nL2 Error:\n")); + if (user->phys->state_var == STATEVAR_PRIMITIVE) state_var_source = "Primitive"; + for (int i = 0; i < 5; i++) { + PetscCall(PetscPrintf(PETSC_COMM_WORLD, " %s variables-Component %d: %g\n", state_var_source, i, (double)l2_error[i])); + } + } if (problem->convert_error.qfunction) { PetscReal l2_error_converted[5]; + Vec E_target; const char *state_var_target = "Primitive"; + if (user->phys->state_var == STATEVAR_PRIMITIVE) state_var_target = "Conservative"; // Convert the L2 error to the target state variable - PetscCall(ComputeL2Error(dm, ceed_data, user, Q, l2_error_converted, ceed_data->op_convert_error_ctx, user->phys->ics_time_label, final_time)); - - // Print the error - if (user->phys->state_var == STATEVAR_PRIMITIVE) state_var_target = "Conservative"; - for (int i = 0; i < 5; i++) { - PetscCall(PetscPrintf(PETSC_COMM_WORLD, " %s variables-Component %d: %g\n", state_var_target, i, (double)l2_error_converted[i])); + PetscCall(VecDuplicate(Q, &E_target)); + PetscCall(ComputeL2Error(dm, ceed_data, user, Q, l2_error_converted, ceed_data->op_convert_error_ctx, user->phys->ics_time_label, final_time, + &E_target)); + if (user->app_ctx->test_type == TESTTYPE_POST_PROCESS) { + PetscCall(RegressionTests_NS(user->app_ctx, E_target)); + } else { + for (int i = 0; i < 5; i++) { + PetscCall(PetscPrintf(PETSC_COMM_WORLD, " %s variables-Component %d: %g\n", state_var_target, i, (double)l2_error_converted[i])); + } } // Cleanup CeedQFunctionDestroy(&ceed_data->qf_convert_error); + PetscCall(VecDestroy(&E_target)); } // Cleanup CeedVectorDestroy(&ceed_data->q_true); + PetscCall(VecDestroy(&E_source)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -212,7 +222,7 @@ PetscErrorCode PostProcess_NS(TS ts, CeedData ceed_data, DM dm, ProblemData *pro PetscFunctionBeginUser; // Print relative error - if (problem->has_true_soln && user->app_ctx->test_type == TESTTYPE_NONE) { + if (problem->has_true_soln && (user->app_ctx->test_type == TESTTYPE_NONE || user->app_ctx->test_type == TESTTYPE_POST_PROCESS)) { PetscCall(GetError_NS(ceed_data, dm, user, problem, Q, final_time)); } diff --git a/examples/fluids/src/setuplibceed.c b/examples/fluids/src/setuplibceed.c index 0b6853e2fc..112d663fbe 100644 --- a/examples/fluids/src/setuplibceed.c +++ b/examples/fluids/src/setuplibceed.c @@ -265,7 +265,7 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, App CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE); // -- Create QFunction for computing the L2 error - if (problem->has_true_soln && user->app_ctx->test_type == TESTTYPE_NONE) { + if (problem->has_true_soln && (user->app_ctx->test_type == TESTTYPE_NONE || user->app_ctx->test_type == TESTTYPE_POST_PROCESS)) { CeedQFunctionCreateInterior(ceed, 1, problem->error.qfunction, problem->error.qfunction_loc, &ceed_data->qf_error); CeedQFunctionSetContext(ceed_data->qf_error, problem->error.qfunction_context); CeedQFunctionContextDestroy(&problem->error.qfunction_context); diff --git a/examples/fluids/tests-output/fluids-navierstokes-exact-postprocess.bin b/examples/fluids/tests-output/fluids-navierstokes-exact-postprocess.bin new file mode 100644 index 0000000000000000000000000000000000000000..749782e14ff68111b916ca8f95eb53d3ccf7e746 GIT binary patch literal 5272 zcmajh`9D?b9spou+7&V+MHG?@rJ2_HdKJnL$`PUvDvESWMG+2VN|HoL#tac68bpaQ zmz~U0>~N(F8A|A$v)8&mv_3iauXvutU%EE2u&^vt)$|DKQ3}Oa1kUNRu&{-r%ac*+ zbdFBYS;jZS&Bcw<97`e__1}V4<+5{um5)$ry=#q2N*U}<4e3%48$_Y*4t+k#&Y)4h zz|U8eK6nZ(!WY08}`ciR-J?HGFv4(cAgQXv0Zl{6XmB9Kpw{lU2;A_F_ z8Rx-lW^k(J$WAzTE{BV*_#Skbq0D^w6a3( z8$WDivE3}ZMFUHyiEw^#^Ayx%!4L@fD^e8{DdayWXwLZRx*SCk(kJWDGwg^lbjDWk2z zSW4R=l{dp|U~8N%s}gCAo(PR>TY8}db`AxdNK|XUd_FeD_Ev8IHygtQNg+e@&MQmu z`n9W|HsPEUQO$z+^tUv-o+tuWU8~T;nHh-wb2h;1`eIQ1A)Rg}8i@Jw6x(d(?gi)I zpN0J^4bh{*{JyT_wE$Z_21x11VZOS0=5}dp@Tc>3fpQ01RI=CbGpDdU==)pp*|~OM zzLrNN^ylvWZm=)f|Dn!;kgs|2l(tzuRG{{Ok+(>g{-}>uH1}IH=tFz@N2JRW!r+B=sFA3c1Sv)*-#UVFC=c=mL-5idebZ!j0y;5gxAJg+KgUQkL_9& zYz7DRerNPtjmIK3LSmVA66jT6=bxvsQaIY$Tt0ZD0()?LK~9d61l(Nw zYPXZC80u~kjF+B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