diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index 34097581c16bcdcf1dcb901f74f02fc9605f27e7..8310153bf6ce9777c2c271d9ec103315a19ab333 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -62,20 +62,22 @@ Stars: # Parameters for the self-gravity scheme Gravity: - mesh_side_length: 128 # Number of cells along each axis for the periodic gravity mesh. - eta: 0.025 # Constant dimensionless multiplier for time integration. - theta: 0.7 # Opening angle (Multipole acceptance criterion). - comoving_DM_softening: 0.0026994 # Comoving Plummer-equivalent softening length for DM particles (in internal units). - max_physical_DM_softening: 0.0007 # Maximal Plummer-equivalent softening length in physical coordinates for DM particles (in internal units). - comoving_baryon_softening: 0.0026994 # Comoving Plummer-equivalent softening length for baryon particles (in internal units). - max_physical_baryon_softening: 0.0007 # Maximal Plummer-equivalent softening length in physical coordinates for baryon particles (in internal units). - softening_ratio_background: 0.04 # Fraction of the mean inter-particle separation to use as Plummer-equivalent softening for the background DM particles. - rebuild_frequency: 0.01 # (Optional) Frequency of the gravity-tree rebuild in units of the number of g-particles (this is the default value). - a_smooth: 1.25 # (Optional) Smoothing scale in top-level cell sizes to smooth the long-range forces over (this is the default value). - r_cut_max: 4.5 # (Optional) Cut-off in number of top-level cells beyond which no FMM forces are computed (this is the default value). - r_cut_min: 0.1 # (Optional) Cut-off in number of top-level cells below which no truncation of FMM forces are performed (this is the default value). - dithering: 1 # (Optional) Activate the dithering of the gravity mesh at every rebuild (this is the default value). - dithering_ratio: 1.0 # (Optional) Magnitude of each component of the dithering vector in units of the top-level cell sizes (this is the default value). + mesh_side_length: 128 # Number of cells along each axis for the periodic gravity mesh. + eta: 0.025 # Constant dimensionless multiplier for time integration. + mulitpole_acceptance_criterion: adaptive # Choice of mulitpole acceptance criterion: 'adaptive' OR 'geometric'. + epsilon_fmm: 0.01 # Tolerance parameter for the adaptice multipole acceptance criterion. + theta_cr: 0.7 # Opening angle for the purely gemoetric criterion. + comoving_DM_softening: 0.0026994 # Comoving Plummer-equivalent softening length for DM particles (in internal units). + max_physical_DM_softening: 0.0007 # Maximal Plummer-equivalent softening length in physical coordinates for DM particles (in internal units). + comoving_baryon_softening: 0.0026994 # Comoving Plummer-equivalent softening length for baryon particles (in internal units). + max_physical_baryon_softening: 0.0007 # Maximal Plummer-equivalent softening length in physical coordinates for baryon particles (in internal units). + softening_ratio_background: 0.04 # Fraction of the mean inter-particle separation to use as Plummer-equivalent softening for the background DM particles. + rebuild_frequency: 0.01 # (Optional) Frequency of the gravity-tree rebuild in units of the number of g-particles (this is the default value). + a_smooth: 1.25 # (Optional) Smoothing scale in top-level cell sizes to smooth the long-range forces over (this is the default value). + r_cut_max: 4.5 # (Optional) Cut-off in number of top-level cells beyond which no FMM forces are computed (this is the default value). + r_cut_min: 0.1 # (Optional) Cut-off in number of top-level cells below which no truncation of FMM forces are performed (this is the default value). + dithering: 1 # (Optional) Activate the dithering of the gravity mesh at every rebuild (this is the default value). + dithering_ratio: 1.0 # (Optional) Magnitude of each component of the dithering vector in units of the top-level cell sizes (this is the default value). # Parameters when running with SWIFT_GRAVITY_FORCE_CHECKS ForceChecks: diff --git a/src/gravity_properties.c b/src/gravity_properties.c index 9e419807b0dd9f32442aff516addaa623403d0d6..d8ce67b20ba5757ee96379fb166ff19b2197b37b 100644 --- a/src/gravity_properties.c +++ b/src/gravity_properties.c @@ -23,6 +23,7 @@ /* Standard headers */ #include <float.h> #include <math.h> +#include <string.h> /* Local headers. */ #include "adiabatic_index.h" @@ -84,10 +85,32 @@ void gravity_props_init(struct gravity_props *p, struct swift_params *params, /* Time integration */ p->eta = parser_get_param_float(params, "Gravity:eta"); - /* Opening angle */ + /* Read the choice of multipole acceptance criterion */ + char buffer[32] = {0}; + parser_get_param_string(params, "Gravity:mulitpole_acceptance_criterion", + buffer); + + if (strcmp(buffer, "adaptive") == 0) { + p->use_adaptive_tolerance = 1; + } else if (strcmp(buffer, "geometric") == 0) { + p->use_adaptive_tolerance = 0; + } else { + error( + "Invalid choice of multipole acceptance criterion: '%s'. Should be " + "'adaptive' or 'geometric'", + buffer); + } + + /* We always start with the geometric MAC */ + p->use_advanced_mac = 0; + + /* Geometric opening angle */ p->theta_crit = parser_get_param_double(params, "Gravity:theta"); if (p->theta_crit >= 1.) error("Theta too large. FMM won't converge."); + /* Adaptive opening angle tolerance */ + p->adaptive_tolerance = parser_get_param_float(params, "Gravity:epsilon_fmm"); + /* Mesh dithering */ if (periodic && !with_external_potential) { p->with_dithering = @@ -170,6 +193,9 @@ void gravity_props_init(struct gravity_props *p, struct swift_params *params, void gravity_props_update(struct gravity_props *p, const struct cosmology *cosmo) { + /* Choice of MAC */ + if (p->use_adaptive_tolerance) p->use_advanced_mac = 1; + /* Current softening length for the high-res. DM particles. */ double DM_softening, baryon_softening; if (p->epsilon_DM_comoving * cosmo->a > p->epsilon_DM_max_physical) diff --git a/src/gravity_properties.h b/src/gravity_properties.h index 56f69bd253f18f061fceed5ee7d48dfa857073be..07ec862839b9191388f4de91a4de642f5f6a1980 100644 --- a/src/gravity_properties.h +++ b/src/gravity_properties.h @@ -54,6 +54,9 @@ struct gravity_props { /* -------------- Properties of the FFM gravity ---------------------- */ + /*! What MAC are we currently using? */ + int use_advanced_mac; + /*! Are we using the adaptive opening angle? */ int use_adaptive_tolerance; diff --git a/src/multipole_accept.h b/src/multipole_accept.h index ca9f7df3aaff15c4771f90595bf76cd1f7e69364..28e76fda5771453c33efb61799a0770b9a951cfb 100644 --- a/src/multipole_accept.h +++ b/src/multipole_accept.h @@ -89,7 +89,7 @@ __attribute__((nonnull, pure)) INLINE static int gravity_M2L_accept( /* Get the sum of the multipole sizes */ const float rho_sum = rho_A + rho_B; - if (props->use_adaptive_tolerance) { + if (props->use_advanced_mac) { /* Test the different conditions */ @@ -181,7 +181,7 @@ __attribute__((nonnull, pure)) INLINE static int gravity_M2P_accept( const float theta_crit = props->theta_crit; const float theta_crit2 = theta_crit * theta_crit; - if (props->use_adaptive_tolerance) { + if (props->use_advanced_mac) { /* Test the different conditions */