Improve the handling of unphysical results in Hydro_HancockPredict()#502
Improve the handling of unphysical results in Hydro_HancockPredict()#502hsinhaoHHuang wants to merge 1 commit intogamer-project:mainfrom
Conversation
hyschive
left a comment
There was a problem hiding this comment.
@hsinhaoHHuang This PR looks good. Thanks for the great effort!
One concern is that I’m not sure whether this prediction works properly for MHD. Check the related comments in Hydro_HancockPredict_RescueByLowerSlopes() and Hydro_HancockPredict_RescueByHigherSteps().
| if ( MHM_REPREDICT_ITER_NUM < 1 ) | ||
| Aux_Error( ERROR_INFO, "MHM_REPREDICT_ITER_NUM should be >= 1 for MHM_CHECK_PREDICT !!\n" ); | ||
|
|
||
| if ( MHM_REPREDICT_STEPS_SAFE_FAC <= 0 ) |
There was a problem hiding this comment.
| if ( MHM_REPREDICT_STEPS_SAFE_FAC <= 0 ) | |
| if ( MHM_REPREDICT_STEPS_SAFE_FAC <= (real)0.0 ) |
| { | ||
| // estimate the required numer of sub-steps according to the maximum depletion fraction | ||
| const real safety_factor = MHM_REPREDICT_STEPS_SAFE_FAC/(1<<Iter); // e.g., 0.4 -> 0.2 -> 0.1 | ||
| const int num_substeps_est = (int)ceilf( DeplFracMax/safety_factor ); |
There was a problem hiding this comment.
How about defining CEIL in Macro.h, similar to FLOOR?
| if ( MHM_REPREDICT_SUBSTEPS_MAX < 1 ) | ||
| Aux_Error( ERROR_INFO, "MHM_REPREDICT_SUBSTEPS_MAX should be >= 1 for MHM_CHECK_PREDICT !!\n" ); | ||
|
|
||
| if ( MHM_REPREDICT_SLOPE_SAFE_FAC <= 0 || MHM_REPREDICT_SLOPE_SAFE_FAC >= 1 ) |
There was a problem hiding this comment.
| if ( MHM_REPREDICT_SLOPE_SAFE_FAC <= 0 || MHM_REPREDICT_SLOPE_SAFE_FAC >= 1 ) | |
| if ( MHM_REPREDICT_SLOPE_SAFE_FAC <= (real)0.0 || MHM_REPREDICT_SLOPE_SAFE_FAC >= (real)1.0 ) |
| if ( MHM_REPREDICT_ITER_NUM < 1 ) | ||
| Aux_Error( ERROR_INFO, "MHM_REPREDICT_ITER_NUM should be >= 1 for MHM_CHECK_PREDICT !!\n" ); |
There was a problem hiding this comment.
Always print the incorrect value to facilitate debugging. Update other error messages too.
| if ( MHM_REPREDICT_ITER_NUM < 1 ) | |
| Aux_Error( ERROR_INFO, "MHM_REPREDICT_ITER_NUM should be >= 1 for MHM_CHECK_PREDICT !!\n" ); | |
| if ( MHM_REPREDICT_ITER_NUM < 1 ) | |
| Aux_Error( ERROR_INFO, "MHM_REPREDICT_ITER_NUM (%d) should be >= 1 for MHM_CHECK_PREDICT !!\n", MHM_REPREDICT_ITER_NUM ); |
| GPU_DEVICE | ||
| static bool Hydro_HancockPredict_CheckUnphysical( const real fcCon[][NCOMP_LR], const real dt_dh, | ||
| const EoS_t *EoS, const long PassiveFloor ); | ||
| # ifndef SRHD |
There was a problem hiding this comment.
| # ifndef SRHD | |
| #ifndef SRHD |
| // ReducedSlopeRatio : Reduced slope / original slope | ||
| //------------------------------------------------------------------------------------------------------- | ||
| GPU_DEVICE | ||
| void Hydro_HancockPredict_RescueByLowerSlopes( real fcCon[][NCOMP_LR], |
There was a problem hiding this comment.
IIUC, this routine does NOT change the B field. In other words, it always uses the B field stored in fcCon_init, which is computed using the original data reconstruction scheme. I'm not sure whether this minor inconsistency (i.e., adopting different reconstruction methods for the fluid and B fields) would affect the results.
At a minimum, add a comment about this concern.
This is related to the general comment I made in this review.
| // | ||
| // Parameter : fcCon : Face-centered conserved variables to be updated | ||
| // fcCon_init : Input face-centered conserved variables before update | ||
| // dt_dh2 : 0.5 * Time interval to advance solution / Cell size |
There was a problem hiding this comment.
| // dt_dh2 : 0.5 * Time interval to advance solution / Cell size | |
| // dt_dh2 : 0.5 * time interval to advance solution / cell size |
| // negative density and pressure | ||
| // --> It is just the input array Flu_Array_In[] | ||
| // cc_idx : Index for accessing g_cc_array[] | ||
| // MinPres : Density, pressure, and internal energy floors |
There was a problem hiding this comment.
| // MinPres : Density, pressure, and internal energy floors | |
| // MinPres : Pressure floor |
| // reconstruct the face-centered variables with the reduced slope | ||
| for (int f=0; f<6; f++) | ||
| for (int v=0; v<NCOMP_TOTAL; v++) | ||
| fcCon[f][v] = g_cc_array[v][cc_idx] + ReducedSlopeRatio * ( fcCon_init[f][v] - g_cc_array[v][cc_idx] ); |
There was a problem hiding this comment.
Add a comment somewhere in this routine clarifying that this rescue approach assumes a piecewise linear distribution even when adopting the PPM data reconstruction.
| # define MHM_REPREDICT_ITER_NUM 2 | ||
| # define MHM_REPREDICT_STEPS_SAFE_FAC (real)0.4 | ||
| # define MHM_REPREDICT_SLOPE_SAFE_FAC (real)0.9 | ||
| # define MHM_REPREDICT_SUBSTEPS_MAX 4 |
There was a problem hiding this comment.
Clarify the usage and typical ranges of these parameters.
Motivations
Hydro_HancockPredict()was performed onfcPri[f][4], which is the input value before the update. The negative pressure after the update may not be detected, and a floored value is returned at the end.Goal
Changes
MHM_REPREDICT_ITER_NUM = 2, this will NOT be used.Verification Tests
Hydro/Riemannwith--flu_scheme=MHMRiemann_Prob = [0, 1, 2, 3, 4, 5, 9]was run by ALWAYS triggering the rescuing methods (separately) regardless of whether the original update is unphysical to test the correctness of the repredict solver. With the default parameters for the rescue methods, the results can still match the analytical solutions, and there is not much difference from the original update.Riemann_Prob = 9can produce negative pressure in the default half-step update. The 3-stage rescue methods are triggered for that, and the final results can match the analytical solution as usual.The previous explosions are not found anymore with the new method.
The previous explosions are gone after the negative pressure is properly checked and a lower slope is applied.
Future Work
SRHDMHM_REPREDICT_*into runtime optionsNotes