-
Notifications
You must be signed in to change notification settings - Fork 76
Support analytical profile in Soliton test #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| break; | ||
| if ( DensRef[b] >= DensCore && DensRef[b+1] <= DensCore ) | ||
| { | ||
| CoreRadiusRef = 0.5*( RadiusRef[b] + RadiusRef[b+1] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CoreRadiusRef = RadiusRef[b] + (DensCore - DensRef[b])*(RadiusRef[b+1]-RadiusRef[b])/(DensRef[b+1]-DensRef[b]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you that it will improve interpolation accuracy.
But the result will be a little different compare to previous version ( about 0.1% )
What do you think? @hyschive
| // Return : fluid | ||
| //------------------------------------------------------------------------------------------------------- | ||
| void SetGridIC( real fluid[], const double x, const double y, const double z, const double Time, | ||
| const int lv, double AuxArray[] ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@boxianliu The format of this comment looks a bit strange and too long. You may consider:
- Using the
Add a suggestionbutton to highlight the differences. - Previewing your comment with the
Previewbutton before submitting.
boxianliu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made the following corrections, which you can refer to:
- Use
CoreRadiusRef = RadiusRef[b] + (DensCore - DensRef[b])*(RadiusRef[b+1]-RadiusRef[b])/(DensRef[b+1]-DensRef[b]);instead ofCoreRadiusRef = 0.5*( RadiusRef[b] + RadiusRef[b+1] );to improve interpolation accuracy. - Make
Aux_Message( stdout, " density profile filename = %s\n", Soliton_DensProf_Filename ); Aux_Message( stdout, " number of bins of the density profile = %d\n", Soliton_DensProf_NBin );only print whenSoliton_InitMode==1. Aux_Message( stdout, " %7s %13s %13s %13s\n", "ID", "CoreRadius", "Center_X", "Center_Y", "Center_Z" );is replaced withAux_Message( stdout, " %7s %13s %13s %13s %13s\n", "ID", "CoreRadius", "Center_X", "Center_Y", "Center_Z" );- Adjust the overall arrangement of
SetGridIC()so thatconst double *Table_Radius = Soliton_DensProf + 0*Soliton_DensProf_NBin; const double *Table_Density = Soliton_DensProf + 1*Soliton_DensProf_NBin;only executes whenSoliton_InitMode==1(whenSoliton_InitMode==2,Soliton_DensProf == NULL). - Change const
double m22 = ELBDM_MASS*UNIT_M/(Const_eV/SQR(Const_c))/1.0e-22;This should be moved outside theforloop.
In addition, I have the following suggestions:
- In
Description : Set the extenral boundary condition,externalwas mistakenly written asextenral. - In
SolitonDensityProfile_Lambda0.0,Densis actually|ψ|^2. InInit_TestProb_ELBDM_Soliton.cpp, it will be converted back toDensusingSCALE_D. This part might need to be noted, otherwise the user-inputted table may be incorrect. - In
Soliton_InitMode==2mode, code units and particle mass must be correctly set.Init_TestProb_ELBDM_Soliton.cppwill first convert the units tokpcandMsun/pc^3, soOPT__UNITmust not be set as 0. This can also be noted to remind users.
| } // if ( Soliton_InitMode == 2 ) | ||
| else | ||
| Aux_Error( ERROR_INFO, "unsupported Soliton_InitMode (%d) !!\n", Soliton_InitMode ); | ||
| } // for (int t=0; t<Soliton_N; t++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double r_tar, r_ref, dens_ref, dens;
// initialize density as zero since there may be multiple solitons
fluid[DENS] = 0.0;
if ( Soliton_InitMode == 1 )
{
if ( Soliton_DensProf == NULL || Soliton_DensProf_NBin < 2 )
Aux_Error( ERROR_INFO, "invalid Soliton_DensProf (ptr=%p, NBin=%d)\n",
(void*)Soliton_DensProf, Soliton_DensProf_NBin );
const double *Table_Radius = Soliton_DensProf + 0*Soliton_DensProf_NBin; // radius
const double *Table_Density = Soliton_DensProf + 1*Soliton_DensProf_NBin; // density
// loop over all solitons to get the total density
for (int t=0; t<Soliton_N; t++)
{
r_tar = sqrt( SQR(x-Soliton_Center[t][0]) + SQR(y-Soliton_Center[t][1]) + SQR(z-Soliton_Center[t][2]) );
// rescale radius (target radius --> reference radius)
r_ref = r_tar / Soliton_ScaleL[t];
// linear interpolation
dens_ref = Mis_InterpolateFromTable( Soliton_DensProf_NBin, Table_Radius, Table_Density, r_ref );
if ( dens_ref == NULL_REAL )
{
if ( r_ref < Table_Radius[0] )
dens_ref = Table_Density[0];
else if ( r_ref >= Table_Radius[Soliton_DensProf_NBin-1] )
dens_ref = Table_Density[Soliton_DensProf_NBin-1];
else
Aux_Error( ERROR_INFO, "interpolation failed at radius %13.7e (min/max radius = %13.7e/%13.7e) !!\n",
r_ref, Table_Radius[0], Table_Radius[Soliton_DensProf_NBin-1] );
}
// rescale density (reference density --> target density) and add to the fluid array
fluid[DENS] += dens_ref*Soliton_ScaleD[t];
} // for (int t=0; t<Soliton_N; t++)
} // if ( Soliton_InitMode == 1 )
else if ( Soliton_InitMode == 2 )
{
const double m22 = ELBDM_MASS*UNIT_M/(Const_eV/SQR(Const_c))/1.0e-22;
// loop over all solitons to get the total density
for (int t=0; t<Soliton_N; t++)
{
r_tar = sqrt( SQR(x-Soliton_Center[t][0]) + SQR(y-Soliton_Center[t][1]) + SQR(z-Soliton_Center[t][2]) );
const double rc_kpc = Soliton_CoreRadius[t]*UNIT_L/Const_kpc;
dens = 1.945/SQR(m22*10)/POW4(rc_kpc) / POW(1 + (POW(2.0,1.0/8.0)-1.0)*SQR(r_tar/Soliton_CoreRadius[t]), 8); // in unit of Msun/pc^3
dens = dens* Const_Msun/CUBE(Const_pc) / UNIT_D ; // code unit
fluid[DENS] += dens;
} // for (int t=0; t<Soliton_N; t++)
} // if ( Soliton_InitMode == 2 )
else
Aux_Error( ERROR_INFO, "unsupported Soliton_InitMode (%d) !!\n", Soliton_InitMode );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your version is way better than mine. Thanks!
By the way, I removed the following error check from the code:
if ( Soliton_DensProf == NULL || Soliton_DensProf_NBin < 2 )
Aux_Error( ERROR_INFO, "invalid Soliton_DensProf (ptr=%p, NBin=%d)\n",
(void*)Soliton_DensProf, Soliton_DensProf_NBin );
This check seemed redundant since the error should already be caught within the Aux_LoadTable function.
|
@boxianliu Thanks for your detailed review! I've updated according to your comments.
Added a note in the
I've added a check if the Please take a look when you are able. |
boxianliu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your revisions. I have checked them and I think there are no other issues!
Summary
Add
Soliton_InitModefor the ELBDM Soliton test:Changes
Soliton_InitModeparameter and handling in initialization