Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
227273d
Add `FloorPassive_t` arg to header of `AddField`
technic960183 Feb 19, 2025
90f8c4b
Implement `PassiveVar_Floor` to store `Floor`
technic960183 Feb 21, 2025
eb863d8
Implement the use of `PassiveVar_Floor`
technic960183 Feb 24, 2025
73ea875
Fix for .cu to support negative passive scalars
technic960183 Feb 26, 2025
40de83e
Update `Hydro_IsUnphysical` to include `FloorVar`
technic960183 Mar 27, 2025
0aaf871
fix style
technic960183 Apr 30, 2025
4e5e727
fix HDF5 DumpData
technic960183 Apr 30, 2025
587959b
Clarify comment for `Floor` parameter
technic960183 Apr 30, 2025
1537afd
Rename variables
technic960183 May 7, 2025
b7cbf3e
Apply suggestions from code review
technic960183 May 13, 2025
2ce8381
Fix styles and typos.
technic960183 Jul 18, 2025
a8e2804
Fix bugs and apply suggestions from code review.
technic960183 Jul 21, 2025
cf0bff2
Fix global var usage in GPU code 1
technic960183 Jul 23, 2025
4d4568b
Fix global var usage in GPU code 2: dtSolver
technic960183 Jul 23, 2025
5a8bf13
Fix global var usage in GPU code 2: RiemannSolver
technic960183 Jul 23, 2025
f432ddf
Fix global var usage in GPU code 2: DataRecon
technic960183 Jul 23, 2025
d7cbe30
Fix global var usage in GPU code 2: Con2 and Eng
technic960183 Jul 23, 2025
7a10c0d
Fix global var usage in GPU code 2: CUFLU_RTVD
technic960183 Jul 24, 2025
50f1089
styles
technic960183 Jul 27, 2025
2ddafad
Refactor `CPU_dtSolver` to include `PassiveFloor`
technic960183 Jul 27, 2025
7e115dc
Pass `PassiveFloor` to the source term routines
technic960183 Jul 27, 2025
fb19e9b
Add check for `Floor == False` && `Norm == True`
technic960183 Jul 27, 2025
5591fce
Apply suggestions from code review
technic960183 Oct 11, 2025
ace5e82
Fix global var usage in CPU code: CPU_RTVD
technic960183 Oct 11, 2025
e10ac36
Fix global var usage in CPU code: Hydro_Con2Dual
technic960183 Oct 11, 2025
acf258c
Rename `Flag_PassiveFloor` to `PassiveFloorMask`
technic960183 Oct 12, 2025
d86945c
Update wiki for FIXUP_FLUX, FIXUP_REST, and FLOOR
technic960183 Oct 12, 2025
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
17 changes: 14 additions & 3 deletions doc/wiki/Adding-New-Simulations.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ and get the field index. For example,
void AddNewField_NewProblem()
{
if ( NewFieldIdx == Idx_Undefined )
NewFieldIdx = AddField( "NewFieldLabel", NORMALIZE_YES, INTERP_FRAC_YES );
NewFieldIdx = AddField( "NewFieldLabel", FIXUP_FLUX_YES, FIXUP_REST_YES, FLOOR_YES, NORMALIZE_YES, INTERP_FRAC_YES );
}
```

Expand All @@ -253,12 +253,23 @@ in the output files, and the field index `NewFieldIdx` can be used to
access the field data (see the next step). The check `if ( NewFieldIdx == Idx_Undefined )`
is just to avoid redundant assignments to the same field index variable.

The second parameter should be set to either `NORMALIZE_YES` or `NORMALIZE_NO`.
The second parameter should be set to either `FIXUP_FLUX_YES` or `FIXUP_FLUX_NO`.
It controls whether the new field will be corrected by the fluxes across the coarse-fine boundaries
when enabling [[ OPT__FIXUP_FLUX | Runtime-Parameters:-Hydro#OPT__FIXUP_FLUX ]].

The third parameter should be set to either `FIXUP_REST_YES` or `FIXUP_REST_NO`.
It controls whether the new field will be corrected by the volume-weighted average of the fine-grid data
when enabling [[ OPT__FIXUP_RESTRICT | Runtime-Parameters:-Hydro#OPT__FIXUP_RESTRICT ]].

The fourth parameter should be set to either `FLOOR_YES` or `FLOOR_NO`.
It controls whether the new field will be floored to `TINY_NUMBER` to ensure positivity.

The fifth parameter should be set to either `NORMALIZE_YES` or `NORMALIZE_NO`.
It controls whether the new field will be renormalized by the total gas density
after every update when enabling
[[ OPT__NORMALIZE_PASSIVE | Runtime-Parameters:-Hydro#OPT__NORMALIZE_PASSIVE ]].

The third parameter should be set to either `INTERP_FRAC_YES` or `INTERP_FRAC_NO`.
The sixth parameter should be set to either `INTERP_FRAC_YES` or `INTERP_FRAC_NO`.
It controls whether the new field will be converted to mass fraction during interpolation
when enabling
[[ OPT__INT_FRAC_PASSIVE_LR | Runtime-Parameters:-Hydro#OPT__INT_FRAC_PASSIVE_LR ]].
Expand Down
2 changes: 1 addition & 1 deletion include/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern int *BaseP; // table recording the IDs
extern int Flu_ParaBuf; // number of parallel buffers to exchange all fluid
// variables for the fluid solver and fluid refinement

extern long FixUpVar_Flux, FixUpVar_Restrict;
extern long FixUpVar_Flux, FixUpVar_Restrict, PassiveFloorMask;
extern int PassiveNorm_NVar, PassiveNorm_VarIdx[NCOMP_PASSIVE];
extern int PassiveIntFrac_NVar, PassiveIntFrac_VarIdx[NCOMP_PASSIVE];

Expand Down
3 changes: 2 additions & 1 deletion include/HDF5_Typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ struct SymConst_t
// Structure : InputPara_t
// Description : Data structure for outputting the run-time parameters
//
// Note : 1. All run-time parameters are loaded from the files "Input__XXX"
// Note : 1. Most of the run-time parameters are loaded from the files "Input__XXX"
//-------------------------------------------------------------------------------------------------------
struct InputPara_t
{
Expand Down Expand Up @@ -623,6 +623,7 @@ struct InputPara_t
int Opt__FixUp_Restrict;
long FixUpRestrict_Var;
int Opt__CorrAfterAllSync;
long PassiveFloor_Var;
int Opt__NormalizePassive;
int NormalizePassive_NVar;
int NormalizePassive_VarIdx[NCOMP_PASSIVE];
Expand Down
32 changes: 17 additions & 15 deletions include/Prototype.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,55 +103,55 @@ void CPU_FluidSolver( real h_Flu_Array_In[][FLU_NIN][ CUBE(FLU_NXT) ],
const real ELBDM_Eta, real ELBDM_Taylor3_Coeff, const bool ELBDM_Taylor3_Auto,
const double Time, const bool UsePot, const OptExtAcc_t ExtAcc, const MicroPhy_t MicroPhy,
const real MinDens, const real MinPres, const real MinEint,
const real DualEnergySwitch,
const real DualEnergySwitch, const long PassiveFloor,
const bool NormPassive, const int NNorm, const int NormIdx[],
const bool FracPassive, const int NFrac, const int FracIdx[],
const bool JeansMinPres, const real JeansMinPres_Coeff,
const bool UseWaveFlag );
void Hydro_NormalizePassive( const real GasDens, real Passive[], const int NNorm, const int NormIdx[] );
#if ( MODEL == HYDRO )
real Hydro_Con2Pres( const real Dens, const real MomX, const real MomY, const real MomZ, const real Engy,
const real Passive[], const bool CheckMinPres, const real MinPres, const real Emag,
const real Passive[], const bool CheckMinPres, const real MinPres, const long PassiveFloor, const real Emag,
const EoS_DE2P_t EoS_DensEint2Pres, const EoS_GUESS_t EoS_GuessHTilde,
const EoS_H2TEM_t EoS_HTilde2Temp, const double EoS_AuxArray_Flt[],
const int EoS_AuxArray_Int[], const real *const EoS_Table[EOS_NTABLE_MAX], real *EintOut );
real Hydro_Con2Eint( const real Dens, const real MomX, const real MomY, const real MomZ, const real Engy,
const bool CheckMinEint, const real MinEint, const real Emag,
const bool CheckMinEint, const real MinEint, const long PassiveFloor, const real Emag,
const EoS_GUESS_t EoS_GuessHTilde, const EoS_H2TEM_t EoS_HTilde2Temp,
const double EoS_AuxArray_Flt[], const int EoS_AuxArray_Int[],
const real *const EoS_Table[EOS_NTABLE_MAX] );
real Hydro_ConEint2Etot( const real Dens, const real MomX, const real MomY, const real MomZ, const real Eint, const real Emag );
real Hydro_Con2Temp( const real Dens, const real MomX, const real MomY, const real MomZ, const real Engy,
const real Passive[], const bool CheckMinTemp, const real MinTemp, const real Emag,
const real Passive[], const bool CheckMinTemp, const real MinTemp, const long PassiveFloor, const real Emag,
const EoS_DE2T_t EoS_DensEint2Temp, const EoS_GUESS_t EoS_GuessHTilde, const EoS_H2TEM_t EoS_HTilde2Temp,
const double EoS_AuxArray_Flt[], const int EoS_AuxArray_Int[],
const real *const EoS_Table[EOS_NTABLE_MAX] );
real Hydro_Con2Entr( const real Dens, const real MomX, const real MomY, const real MomZ, const real Engy,
const real Passive[], const bool CheckMinEntr, const real MinEntr, const real Emag,
const real Passive[], const bool CheckMinEntr, const real MinEntr, const long PassiveFloor, const real Emag,
const EoS_DE2S_t EoS_DensEint2Entr, const double EoS_AuxArray_Flt[], const int EoS_AuxArray_Int[],
const real *const EoS_Table[EOS_NTABLE_MAX] );
real Hydro_CheckMinPres( const real InPres, const real MinPres );
real Hydro_CheckMinEint( const real InEint, const real MinEint );
real Hydro_CheckMinTemp( const real InTemp, const real MinTemp );
real Hydro_CheckMinEntr( const real InEntr, const real MinEntr );
real Hydro_CheckMinEintInEngy( const real Dens, const real MomX, const real MomY, const real MomZ, const real InEngy,
const real MinEint, const real Emag );
const real MinEint, const long PassiveFloor, const real Emag );
bool Hydro_IsUnphysical( const IsUnphyMode_t Mode, const real Fields[],
const real Emag, const EoS_DE2P_t EoS_DensEint2Pres,
const EoS_GUESS_t EoS_GuessHTilde, const EoS_H2TEM_t EoS_HTilde2Temp,
const double EoS_AuxArray_Flt[], const int EoS_AuxArray_Int[],
const real *const EoS_Table[EOS_NTABLE_MAX],
const real *const EoS_Table[EOS_NTABLE_MAX], const long PassiveFloor,
const char File[], const int Line, const char Function[], const IsUnphVerb_t Verbose );
bool Hydro_IsUnphysical_Single( const real Field, const char SingleFieldName[], const real Min, const real Max,
const char File[], const int Line, const char Function[], const IsUnphVerb_t Verbose );
#ifdef DUAL_ENERGY
void Hydro_DualEnergyFix( const real Dens, const real MomX, const real MomY, const real MomZ,
real &Etot, real &Dual, char &DE_Status, const real Gamma_m1, const real _Gamma_m1,
const bool CheckMinPres, const real MinPres, const real DualEnergySwitch,
const bool CheckMinPres, const real MinPres, const long PassiveFloor, const real DualEnergySwitch,
const real Emag );
real Hydro_Con2Dual( const real Dens, const real MomX, const real MomY, const real MomZ, const real Engy,
const real Emag, const EoS_DE2P_t EoS_DensEint2Pres, const double EoS_AuxArray_Flt[],
const int EoS_AuxArray_Int[], const real *const EoS_Table[EOS_NTABLE_MAX] );
const int EoS_AuxArray_Int[], const real *const EoS_Table[EOS_NTABLE_MAX], const long PassiveFloor );
real Hydro_DensPres2Dual( const real Dens, const real Pres, const real Gamma_m1 );
real Hydro_DensDual2Pres( const real Dens, const real Dual, const real Gamma_m1,
const bool CheckMinPres, const real MinPres );
Expand Down Expand Up @@ -250,7 +250,7 @@ void Init_ByFile();
void Init_UniformGrid( const int lv, const bool FindHomePatchForPar );
void Init_Field();
FieldIdx_t AddField( const char *InputLabel, const FixUpFlux_t FixUp_Flux, const FixUpRestrict_t FixUp_Restrict,
const NormPassive_t Norm, const IntFracPassive_t IntFrac );
const FloorPassive_t Floor, const NormPassive_t Norm, const IntFracPassive_t IntFrac );
FieldIdx_t GetFieldIndex( const char *InputLabel, const Check_t Check );
#ifdef OPENMP
void Init_OpenMP();
Expand Down Expand Up @@ -313,7 +313,7 @@ void dt_Close( const real h_dt_Array_T[], const int NPG );
void CPU_dtSolver( const Solver_t TSolver, real dt_Array[], const real Flu_Array[][FLU_NIN_T][ CUBE(PS1) ],
const real Mag_Array[][NCOMP_MAG][ PS1P1*SQR(PS1) ], const real Pot_Array[][ CUBE(GRA_NXT) ],
const double Corner_Array[][3], const int NPatchGroup, const real dh, const real Safety,
const MicroPhy_t MicroPhy, const real MinPres, const bool P5_Gradient,
const MicroPhy_t MicroPhy, const real MinPres, const long PassiveFloor, const bool P5_Gradient,
const bool UsePot, const OptExtAcc_t ExtAcc, const double TargetTime );


Expand Down Expand Up @@ -528,7 +528,7 @@ void Hydro_BoundaryCondition_Diode( real *Array, const int BC_Face, const int NV
const int ArraySizeX, const int ArraySizeY, const int ArraySizeZ,
const int Idx_Start[], const int Idx_End[], const int TFluVarIdxList[],
const int NVar_Der, const long TDerVarList[] );
void Hydro_Con2Pri( const real In[], real Out[], const real MinPres,
void Hydro_Con2Pri( const real In[], real Out[], const real MinPres, const long PassiveFloor,
const bool FracPassive, const int NFrac, const int FracIdx[],
const bool JeansMinPres, const real JeansMinPres_Coeff,
const EoS_DE2P_t EoS_DensEint2Pres, const EoS_DP2E_t EoS_DensPres2Eint,
Expand Down Expand Up @@ -641,22 +641,24 @@ void CUAPI_Asyn_FluidSolver( real h_Flu_Array_In[][FLU_NIN ][ CUBE(FLU_NXT) ],
const double Time, const bool UsePot, const OptExtAcc_t ExtAcc, const MicroPhy_t MicroPhy,
const real MinDens, const real MinPres, const real MinEint,
const real DualEnergySwitch,
const long PassiveFloor,
const bool NormPassive, const int NNorm,
const bool FracPassive, const int NFrac,
const bool JeansMinPres, const real JeansMinPres_Coeff,
const int GPU_NStream, const bool UseWaveFlag );
void CUAPI_Asyn_dtSolver( const Solver_t TSolver, real h_dt_Array[], const real h_Flu_Array[][FLU_NIN_T][ CUBE(PS1) ],
const real h_Mag_Array[][NCOMP_MAG][ PS1P1*SQR(PS1) ], const real h_Pot_Array[][ CUBE(GRA_NXT) ],
const double h_Corner_Array[][3], const int NPatchGroup, const real dh, const real Safety,
const MicroPhy_t MicroPhy, const real MinPres, const bool P5_Gradient, const bool UsePot,
const MicroPhy_t MicroPhy, const real MinPres, const long PassiveFloor,
const bool P5_Gradient, const bool UsePot,
const OptExtAcc_t ExtAcc, const double TargetTime, const int GPU_NStream );
void CUAPI_Asyn_SrcSolver( const real h_Flu_Array_In [][FLU_NIN_S ][ CUBE(SRC_NXT) ],
real h_Flu_Array_Out[][FLU_NOUT_S][ CUBE(PS1) ],
const real h_Mag_Array_In [][NCOMP_MAG ][ SRC_NXT_P1*SQR(SRC_NXT) ],
const double h_Corner_Array[][3],
const SrcTerms_t SrcTerms, const int NPatchGroup, const real dt, const real dh,
const double TimeNew, const double TimeOld,
const real MinDens, const real MinPres, const real MinEint,
const real MinDens, const real MinPres, const real MinEint, const long PassiveFloor,
const int GPU_NStream );
void CUAPI_DiagnoseDevice();
void CUAPI_MemAllocate();
Expand Down Expand Up @@ -807,7 +809,7 @@ void CPU_SrcSolver( const real h_Flu_Array_In [][FLU_NIN_S ][ CUBE(SRC_NXT)
const double h_Corner_Array[][3],
const SrcTerms_t SrcTerms, const int NPatchGroup, const real dt, const real dh,
const double TimeNew, const double TimeOld,
const real MinDens, const real MinPres, const real MinEint );
const real MinDens, const real MinPres, const real MinEint, const long PassiveFloor );


// Grackle
Expand Down
2 changes: 1 addition & 1 deletion include/SrcTerms.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef void (*SrcFunc_t)( real fluid[], const real B[],
const SrcTerms_t *SrcTerms, const real dt, const real dh,
const double x, const double y, const double z,
const double TimeNew, const double TimeOld,
const real MinDens, const real MinPres, const real MinEint,
const real MinDens, const real MinPres, const real MinEint, const long PassiveFloor,
const EoS_t *EoS, const double AuxArray_Flt[], const int AuxArray_Int[] );


Expand Down
6 changes: 6 additions & 0 deletions include/Typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ const FixUpRestrict_t
FIXUP_REST_NO = 0,
FIXUP_REST_YES = 1;

typedef int FloorPassive_t;
const FloorPassive_t
FLOOR_NULL = -1,
FLOOR_NO = 0,
FLOOR_YES = 1;

typedef int NormPassive_t;
const NormPassive_t
NORMALIZE_NO = 0,
Expand Down
4 changes: 2 additions & 2 deletions src/Auxiliary/Aux_Check_Conservation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void Aux_Check_Conservation( const char *comment )
# endif
# ifndef SRHD
// Hydro_Con2Eint() calculates Eint for both HD and SRHD but we disable SRHD for now
Eint = Hydro_Con2Eint( Dens, MomX, MomY, MomZ, Etot, CheckMinEint_No, NULL_REAL, Emag,
Eint = Hydro_Con2Eint( Dens, MomX, MomY, MomZ, Etot, CheckMinEint_No, NULL_REAL, PassiveFloorMask, Emag,
EoS_GuessHTilde_CPUPtr, EoS_HTilde2Temp_CPUPtr, EoS_AuxArray_Flt,
EoS_AuxArray_Int, h_EoS_Table );
# else
Expand All @@ -253,7 +253,7 @@ void Aux_Check_Conservation( const char *comment )
Cons[3] = MomZ;
Cons[4] = Etot;
for ( int v = NCOMP_FLUID; v < NCOMP_TOTAL; v++ ) Cons[v] = 0.0;
Hydro_Con2Pri( Cons, Prim, (real)-HUGE_NUMBER, NULL_BOOL, NULL_INT, NULL,
Hydro_Con2Pri( Cons, Prim, (real)-HUGE_NUMBER, PassiveFloorMask, NULL_BOOL, NULL_INT, NULL,
NULL_BOOL, NULL_REAL, EoS_DensEint2Pres_CPUPtr, EoS_DensPres2Eint_CPUPtr,
EoS_GuessHTilde_CPUPtr, EoS_HTilde2Temp_CPUPtr, EoS_AuxArray_Flt, EoS_AuxArray_Int, h_EoS_Table, NULL, &Lrtz );
HTilde = Hydro_Con2HTilde( Cons, EoS_GuessHTilde_CPUPtr, EoS_HTilde2Temp_CPUPtr,
Expand Down
2 changes: 1 addition & 1 deletion src/Auxiliary/Aux_Check_Finite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void Aux_Check_Finite( const int lv, const char *comment )
const real Emag = NULL_REAL;
# endif
const real Pres = Hydro_Con2Pres( Data[DENS], Data[MOMX], Data[MOMY], Data[MOMZ], Data[ENGY], Data+NCOMP_FLUID,
false, NULL_REAL, Emag,
false, NULL_REAL, PassiveFloorMask, Emag,
EoS_DensEint2Pres_CPUPtr, EoS_GuessHTilde_CPUPtr, EoS_HTilde2Temp_CPUPtr,
EoS_AuxArray_Flt,
EoS_AuxArray_Int, h_EoS_Table, NULL );
Expand Down
9 changes: 9 additions & 0 deletions src/Auxiliary/Aux_TakeNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,15 @@ void Aux_TakeNote()
fprintf( Note, "\n" ); }

fprintf( Note, "OPT__CORR_AFTER_ALL_SYNC % d\n", OPT__CORR_AFTER_ALL_SYNC );
fprintf( Note, "Passive_Floor_Off % d\n", -1 );

// target passive scalars to NOT be applied floor operations
fprintf( Note, " Target fields " );
for (int v=0; v<NCOMP_TOTAL; v++)
if ( ( PassiveFloorMask & (1L<<v) ) == 0 )
fprintf( Note, " %s", FieldLabel[v] );
fprintf( Note, "\n" );

fprintf( Note, "OPT__NORMALIZE_PASSIVE % d\n", OPT__NORMALIZE_PASSIVE );

// target passive scalars to be normalized
Expand Down
Loading