Skip to content
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

Filter func tests #424

Merged
merged 7 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/py21cmfast/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,10 @@ def validate_all_inputs(
The input params may be modified in-place in this function, but if so, a warning
should be emitted.
"""
if global_params.HII_FILTER not in [0, 1, 2]:
raise ValueError(
"global_params.HII_FITLER is not within the available options, 0: real space top-hat, 1: sharp k-space, 2: Gaussian."
)
if astro_params is not None:
if astro_params.R_BUBBLE_MAX > user_params.BOX_LEN:
astro_params.update(R_BUBBLE_MAX=user_params.BOX_LEN)
Expand Down
4 changes: 2 additions & 2 deletions src/py21cmfast/src/HaloField.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ int ComputeHaloField(float redshift_desc, float redshift, UserParams *user_param

// now filter the box on scale R
// 0 = top hat in real space, 1 = top hat in k space
filter_box(density_field, 0, global_params.HALO_FILTER, R);
filter_box(density_field, 0, global_params.HALO_FILTER, R, 0.);

// do the FFT to get delta_m box
dft_c2r_cube(user_params->USE_FFTW_WISDOM, grid_dim, z_dim, user_params->N_THREADS, density_field);
Expand Down Expand Up @@ -341,7 +341,7 @@ int ComputeHaloField(float redshift_desc, float redshift, UserParams *user_param
dft_r2c_cube(user_params->USE_FFTW_WISDOM, grid_dim, z_dim, user_params->N_THREADS, density_field);
if (user_params->DIM != user_params->HII_DIM) {
//the tophat filter here will smoothe the grid to HII_DIM
filter_box(density_field, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0));
filter_box(density_field, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0), 0.);
}
dft_c2r_cube(user_params->USE_FFTW_WISDOM, user_params->DIM, D_PARA, user_params->N_THREADS, density_field);

Expand Down
8 changes: 4 additions & 4 deletions src/py21cmfast/src/InitialConditions.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ int ComputeInitialConditions(
// Only filter if we are perturbing on the low-resolution grid
if(!user_params->PERTURB_ON_HIGH_RES) {
if (user_params->DIM != user_params->HII_DIM) {
filter_box(HIRES_box, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0));
filter_box(HIRES_box, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0), 0.);
}

// FFT back to real space
Expand Down Expand Up @@ -344,7 +344,7 @@ int ComputeInitialConditions(

//we only care about the lowres vcb box, so we filter it directly.
if (user_params->DIM != user_params->HII_DIM) {
filter_box(HIRES_box, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0));
filter_box(HIRES_box, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0), 0.);
}

//fft each velocity component back to real space
Expand Down Expand Up @@ -428,7 +428,7 @@ int ComputeInitialConditions(
// Filter only if we require perturbing on the low-res grid
if(!user_params->PERTURB_ON_HIGH_RES) {
if (user_params->DIM != user_params->HII_DIM) {
filter_box(HIRES_box, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0));
filter_box(HIRES_box, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0), 0.);
}
}

Expand Down Expand Up @@ -783,7 +783,7 @@ int ComputeInitialConditions(
// Filter only if we require perturbing on the low-res grid
if(!user_params->PERTURB_ON_HIGH_RES) {
if (user_params->DIM != user_params->HII_DIM) {
filter_box(HIRES_box, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0));
filter_box(HIRES_box, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0), 0.);
}
}

Expand Down
23 changes: 9 additions & 14 deletions src/py21cmfast/src/IonisationBox.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,26 +790,21 @@ LOG_SUPER_DEBUG("excursion set normalisation, mean_f_coll_MINI: %e", box->mean_f
((R - cell_length_factor * (user_params->BOX_LEN / (double) (user_params->HII_DIM))) >
FRACT_FLOAT_ERR)) {
if (flag_options->USE_TS_FLUCT) {
filter_box(xe_filtered, 1, global_params.HII_FILTER, R);
filter_box(xe_filtered, 1, global_params.HII_FILTER, R, 0.);
}
if (recomb_filter_flag) {
filter_box(N_rec_filtered, 1, global_params.HII_FILTER, R);
filter_box(N_rec_filtered, 1, global_params.HII_FILTER, R, 0.);
}
if (flag_options->USE_HALO_FIELD) {
if(flag_options->USE_EXP_FILTER){
filter_box_mfp(stars_filtered, 1, R, exp_mfp);
filter_box_mfp(sfr_filtered, 1, R, exp_mfp);
}
else{
filter_box(stars_filtered, 1, global_params.HII_FILTER, R);
filter_box(sfr_filtered, 1, global_params.HII_FILTER, R);
}
int filter_hf = flag_options->USE_EXP_FILTER ? 3 : global_params.HII_FILTER;
filter_box(stars_filtered, 1, filter_hf, R, exp_mfp);
filter_box(sfr_filtered, 1, filter_hf, R, exp_mfp);
}
filter_box(deltax_filtered, 1, global_params.HII_FILTER, R);
filter_box(deltax_filtered, 1, global_params.HII_FILTER, R, 0.);
if(flag_options->USE_MINI_HALOS){
filter_box(prev_deltax_filtered, 1, global_params.HII_FILTER, R);
filter_box(log10_Mturnover_MINI_filtered, 1, global_params.HII_FILTER, R);
filter_box(log10_Mturnover_filtered, 1, global_params.HII_FILTER, R);
filter_box(prev_deltax_filtered, 1, global_params.HII_FILTER, R, 0.);
filter_box(log10_Mturnover_MINI_filtered, 1, global_params.HII_FILTER, R, 0.);
filter_box(log10_Mturnover_filtered, 1, global_params.HII_FILTER, R, 0.);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/py21cmfast/src/PerturbField.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void compute_perturbed_velocities(

// smooth the high resolution field ready for resampling
if (user_params->DIM != user_params->HII_DIM)
filter_box(HIRES_density_perturb, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0));
filter_box(HIRES_density_perturb, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0), 0.);

dft_c2r_cube(user_params->USE_FFTW_WISDOM, user_params->DIM, D_PARA, user_params->N_THREADS, HIRES_density_perturb);

Expand Down Expand Up @@ -592,7 +592,7 @@ int ComputePerturbField(

// Now filter the box
if (user_params->DIM != user_params->HII_DIM) {
filter_box(HIRES_density_perturb, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0));
filter_box(HIRES_density_perturb, 0, 0, L_FACTOR*user_params->BOX_LEN/(user_params->HII_DIM+0.0), 0.);
}

// FFT back to real space
Expand Down Expand Up @@ -647,7 +647,7 @@ int ComputePerturbField(

//smooth the field
if (!global_params.EVOLVE_DENSITY_LINEARLY && global_params.SMOOTH_EVOLVED_DENSITY_FIELD){
filter_box(LOWRES_density_perturb, 1, 2, global_params.R_smooth_density*user_params->BOX_LEN/(float)user_params->HII_DIM);
filter_box(LOWRES_density_perturb, 1, 2, global_params.R_smooth_density*user_params->BOX_LEN/(float)user_params->HII_DIM, 0.);
}

LOG_SUPER_DEBUG("LOWRES_density_perturb after smoothing: ");
Expand Down
5 changes: 3 additions & 2 deletions src/py21cmfast/src/SpinTemperatureBox.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ void fill_Rbox_table(float **result, fftwf_complex *unfiltered_box, double * R_a

// don't filter on cell size
if (R > L_FACTOR*(user_params_global->BOX_LEN / user_params_global->HII_DIM)){
filter_box(box, 1, global_params.HEAT_FILTER, R);
filter_box(box, 1, global_params.HEAT_FILTER, R, 0.);
}

// now fft back to real space
Expand Down Expand Up @@ -608,6 +608,7 @@ void fill_Rbox_table(float **result, fftwf_complex *unfiltered_box, double * R_a

//NOTE: I've moved this to a function to help in simplicity, it is not clear whether it is faster
// to do all of one radii at once (more clustered FFT and larger thread blocks) or all of one box (better memory locality)
//TODO: filter speed tests
void one_annular_filter(float *input_box, float *output_box, double R_inner, double R_outer, double *u_avg, double *f_avg){
int i,j,k;
unsigned long long int ct;
Expand Down Expand Up @@ -652,7 +653,7 @@ void one_annular_filter(float *input_box, float *output_box, double R_inner, dou

// Don't filter on the cell scale
if(R_inner > 0){
filter_box_annulus(filtered_box, 1, R_inner, R_outer);
filter_box(filtered_box, 1, 4, R_inner, R_outer);
}

// now fft back to real space
Expand Down
2 changes: 2 additions & 0 deletions src/py21cmfast/src/_functionprototypes_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ int single_test_sample( UserParams *user_params, CosmoParams *cosmo_params, As
int test_halo_props(double redshift, UserParams *user_params, CosmoParams *cosmo_params, AstroParams *astro_params,
FlagOptions * flag_options, float * vcb_grid, float *J21_LW_grid, float *z_re_grid, float *Gamma12_ion_grid,
PerturbHaloField *halos, float *halo_props_out);
int test_filter(UserParams *user_params, CosmoParams *cosmo_params, AstroParams *astro_params, FlagOptions *flag_options
, float *input_box, double R, double R_param, int filter_flag, double *result);

/* Miscellaneous exposed functions for testing */
double dicke(double z);
Expand Down
Loading
Loading