Fix issues with Aux_FindExtrema and Aux_FindWeightedAverageCenter's field preparation time #473
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
The functions
Aux_FindExtrema()andAux_FindWeightedAverageCenter()can produce inconsistent results when called in the middle of a global simulation step. This occurs because of how they access field data:amr->patch[ amr->FluSg[lv] ][lv][PID]->fluidoramr->patch[ amr->PotSg[lv] ][lv][PID]->pot.Prepare_PatchData().The inconsistency arises because
Prepare_PatchData()previously usedTime[lv]as itsPrepTime. While this works correctly when theseAux_functions are called after a complete global step (e.g., inAux_Record_Center()), it fails when they are called mid-step (e.g., between the fluid and Poisson solvers).In a mid-step scenario, the intrinsic fluid fields (
amr->...->fluid) might have already been updated by the fluid solver, butTime[lv](and thus the data used byPrepare_PatchData()for derived fields) has not yet been updated to reflect the current state. This leads to a mismatch where intrinsic fields represent the current state within the step, while derived fields still represent the state from the beginning of the step.Changes
Replace all the
Time[lv]withamr->FluSgTime[lv][ amr->FluSg[lv] ]inside bothAux_FindExtrema()andAux_FindWeightedAverageCenter().This change ensures consistency because
amr->FluSgTime[lv][ amr->FluSg[lv] ]is updated together withamr->patch[ amr->FluSg[lv] ][lv][PID]->fluidin the EvolveLevel.cpp.Verification
One can temporarily add
if ( lv == MAX_LEVEL ) Aux_Record_Center();in somewhere like this between the fluid and Poisson solvers. The realOPT__RECORD_CENTERshould be turned off to avoid confusion.And then run
ELBDM/HaloMergerwithHaloMerger_Halo_Num 0andHaloMerger_Soliton_Num 1inInput__TestProb. It is compiled withPARTICLEbut there is no particle in the simulation.Record__Centerbefore the changes:-> The
MaxDensandMaxTotalDensare different in the same row even though there is no particle. TheMaxTotalDensmatches theMaxDensin the previous row.Record__Centerafter the changes:-> The
MaxDensandMaxTotalDensare the same in the same row as expected now.