diff --git a/.gitignore b/.gitignore index 43173e221df354638af24ee1979fc7e286b50352..5a1118350fb7bf07d2d001b9953bcb963d5d68bd 100644 --- a/.gitignore +++ b/.gitignore @@ -32,11 +32,14 @@ examples/*/*/*.dat examples/*/*/*.png examples/*/*/*.pdf examples/*/*/*.mp4 -examples/*/*/*.txt examples/*/*/*.rst examples/*/*/*.hdf5 examples/*/*/*.csv examples/*/*/*.dot +examples/*/*/energy.txt +examples/*/*/task_level.txt +examples/*/*/timesteps_*.txt +examples/*/*/SFR.txt examples/*/*/partition_fixed_costs.h examples/*/*/memuse_report-step*.dat examples/*/*/memuse_report-step*.log diff --git a/configure.ac b/configure.ac index 0f8feb9907441e4ca6943f7786c70f7c2104e6d0..e7fe0da15242ecbe254e118f69d227770fefbfab 100644 --- a/configure.ac +++ b/configure.ac @@ -2077,8 +2077,8 @@ AC_MSG_RESULT([ Make gravity glass : $gravity_glass_making External potential : $with_potential - Entropy floor : $with_entropy_floor Pressure floor : $with_pressure_floor + Entropy floor : $with_entropy_floor Cooling function : $with_cooling Chemistry : $with_chemistry Tracers : $with_tracers diff --git a/examples/Cooling/ConstantCosmoTempEvolution/plot_thermal_history.py b/examples/Cooling/ConstantCosmoTempEvolution/plot_thermal_history.py index 1494102531104b252e3edaa467920db7383ac6e6..1f9ae6557d1a55bd75d3440679ae42d653da3399 100644 --- a/examples/Cooling/ConstantCosmoTempEvolution/plot_thermal_history.py +++ b/examples/Cooling/ConstantCosmoTempEvolution/plot_thermal_history.py @@ -68,21 +68,21 @@ for snap in snap_list: z = np.append(z, data.metadata.z) # Convert gas temperatures and densities to right units - data.gas.temperature.convert_to_cgs() + data.gas.temperatures.convert_to_cgs() # Get mean and standard deviation of temperature - T_mean.append(np.mean(data.gas.temperature) * data.gas.temperature.units) - T_std.append(np.std(data.gas.temperature) * data.gas.temperature.units) + T_mean.append(np.mean(data.gas.temperatures) * data.gas.temperatures.units) + T_std.append(np.std(data.gas.temperatures) * data.gas.temperatures.units) # Get mean and standard deviation of density - rho_mean.append(np.mean(data.gas.density) * data.gas.density.units) - rho_std.append(np.std(data.gas.density) * data.gas.density.units) + rho_mean.append(np.mean(data.gas.densities) * data.gas.densities.units) + rho_std.append(np.std(data.gas.densities) * data.gas.densities.units) ## Turn into numpy arrays -T_mean = np.array(T_mean) * data.gas.temperature.units -T_std = np.array(T_std) * data.gas.temperature.units -rho_mean = np.array(rho_mean) * data.gas.density.units -rho_std = np.array(rho_std) * data.gas.density.units +T_mean = np.array(T_mean) * data.gas.temperatures.units +T_std = np.array(T_std) * data.gas.temperatures.units +rho_mean = np.array(rho_mean) * data.gas.densities.units +rho_std = np.array(rho_std) * data.gas.densities.units ## Put Density into units of mean baryon density today diff --git a/examples/Cooling/CoolingBox/plotEnergy.py b/examples/Cooling/CoolingBox/plotEnergy.py index 9c7af57d3d9dfdcfa222e9f77701f230d25f9ddc..6234c319a3001fa4e364639bb2c5480a31cf99dd 100644 --- a/examples/Cooling/CoolingBox/plotEnergy.py +++ b/examples/Cooling/CoolingBox/plotEnergy.py @@ -87,7 +87,7 @@ temp_snap = np.zeros(N) time_snap_cgs = np.zeros(N) for i in range(N): snap = File(files[i], 'r') - u = snap["/PartType0/InternalEnergy"][:] * snap["/PartType0/Masses"][:] + u = snap["/PartType0/InternalEnergies"][:] * snap["/PartType0/Masses"][:] u = sum(u) / total_mass[0] temp_snap[i] = energyUnits(u) time_snap_cgs[i] = snap["/Header"].attrs["Time"] * unit_time diff --git a/examples/Cooling/CoolingRedshiftDependence/plotSolution.py b/examples/Cooling/CoolingRedshiftDependence/plotSolution.py index 9cde36cb05b88e60b3bf3527f3857a3774bf5dca..cb624be3cfb1f0f803cfce7a14fb1a772cccf515 100644 --- a/examples/Cooling/CoolingRedshiftDependence/plotSolution.py +++ b/examples/Cooling/CoolingRedshiftDependence/plotSolution.py @@ -94,15 +94,17 @@ def get_data(handle: float, n_snaps: int): t0 = data.metadata.t.to(Myr).value times.append(data.metadata.t.to(Myr).value - t0) - temps.append(np.mean(data.gas.temperature.to(K).value)) + temps.append(np.mean(data.gas.temperatures.to(K).value)) densities.append( - np.mean(data.gas.density.to(mh / cm ** 3).value) + np.mean(data.gas.densities.to(mh / cm ** 3).value) / (data.metadata.scale_factor ** 3) ) try: energies.append( - np.mean((data.gas.internal_energy * data.gas.masses).to(erg).value) + np.mean( + (data.gas.internal_energies * data.gas.masses).to(erg).value + ) * data.metadata.scale_factor ** (2) ) radiated_energies.append( diff --git a/examples/Cooling/FeedbackEvent_3D/plotSolution.py b/examples/Cooling/FeedbackEvent_3D/plotSolution.py index fe6f93996dafee2b6e81a70d4786374d86355f6f..6631fff2244e73244d0311f4e823c42dfcea7609 100644 --- a/examples/Cooling/FeedbackEvent_3D/plotSolution.py +++ b/examples/Cooling/FeedbackEvent_3D/plotSolution.py @@ -50,7 +50,6 @@ except: plt.rcParams.update(rcParams) - def get_data_dump(metadata): """ Gets a big data dump from the SWIFT metadata @@ -104,10 +103,10 @@ r = r.to(kpc).value data = dict( x=r, v_r=v_r, - u=sim.gas.temperature.to(K).value, - S=sim.gas.entropy.to(keV / K).value, - P=sim.gas.pressure.to(kPa).value, - rho=sim.gas.density.to(mh / (cm ** 3)).value, + u=sim.gas.temperatures.to(K).value, + S=sim.gas.entropies.to(keV / K).value, + P=sim.gas.pressures.to(kPa).value, + rho=sim.gas.densities.to(mh / (cm ** 3)).value, ) # Try to add on the viscosity and diffusion. @@ -156,8 +155,13 @@ log = dict( v_r=False, v_phi=False, u=False, S=False, P=False, rho=False, visc=False, diff=False ) ylim = dict( - v_r=[-4, 25], u=[4750, 6000], rho=[0.09, 0.16], visc=[0, 2.0], diff=[0, 0.25], - P=[3e-18, 10e-18], S=[-0.5e60, 4e60] + v_r=[-4, 25], + u=[4750, 6000], + rho=[0.09, 0.16], + visc=[0, 2.0], + diff=[0, 0.25], + P=[3e-18, 10e-18], + S=[-0.5e60, 4e60], ) current_axis = 0 diff --git a/examples/Cosmology/ComovingSodShock_1D/plotSolution.py b/examples/Cosmology/ComovingSodShock_1D/plotSolution.py index 95674c04bfafd0cd549b69814df82f9a4f80a949..b09873339fc4ded024c70f66301c5cce762b97fc 100644 --- a/examples/Cosmology/ComovingSodShock_1D/plotSolution.py +++ b/examples/Cosmology/ComovingSodShock_1D/plotSolution.py @@ -82,12 +82,12 @@ git = str(sim["Code"].attrs["Git Revision"]) x = sim["/PartType0/Coordinates"][:,0] v = sim["/PartType0/Velocities"][:,0] * anow -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] try: - alpha = sim["/PartType0/Viscosity"][:] + alpha = sim["/PartType0/ViscosityParameters"][:] plot_alpha = True except: plot_alpha = False diff --git a/examples/Cosmology/ComovingSodShock_2D/plotSolution.py b/examples/Cosmology/ComovingSodShock_2D/plotSolution.py index 8adb3cf5c550ab9724f6a8f34c1a1260a25712e1..ec28b9449bfa6b00d3088952a6b1bf871462f86c 100644 --- a/examples/Cosmology/ComovingSodShock_2D/plotSolution.py +++ b/examples/Cosmology/ComovingSodShock_2D/plotSolution.py @@ -83,10 +83,10 @@ git = sim["Code"].attrs["Git Revision"] x = sim["/PartType0/Coordinates"][:,0] v = sim["/PartType0/Velocities"][:,0] * anow -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] N = 1000 # Number of points x_min = -1. diff --git a/examples/Cosmology/ComovingSodShock_3D/plotSolution.py b/examples/Cosmology/ComovingSodShock_3D/plotSolution.py index d85f4be9a49d108d133928a81ea4482fa9099792..34abae364f5421a0436352b9564537f2f31e8742 100644 --- a/examples/Cosmology/ComovingSodShock_3D/plotSolution.py +++ b/examples/Cosmology/ComovingSodShock_3D/plotSolution.py @@ -83,19 +83,19 @@ git = sim["Code"].attrs["Git Revision"] x = sim["/PartType0/Coordinates"][:,0] v = sim["/PartType0/Velocities"][:,0] * anow -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] try: - diffusion = sim["/PartType0/Diffusion"][:] + diffusion = sim["/PartType0/DiffusionParameters"][:] plot_diffusion = True except: plot_diffusion = False try: - viscosity = sim["/PartType0/Viscosity"][:] + viscosity = sim["/PartType0/ViscosityParameters"][:] plot_viscosity = True except: plot_viscosity = False diff --git a/examples/Cosmology/ConstantCosmoVolume/plotSolution.py b/examples/Cosmology/ConstantCosmoVolume/plotSolution.py index f77889d7cb19c230accf25290b88a321e0f59616..6df0bfa4e1f7c4932f652d82a8ca95f5c54b0e9f 100644 --- a/examples/Cosmology/ConstantCosmoVolume/plotSolution.py +++ b/examples/Cosmology/ConstantCosmoVolume/plotSolution.py @@ -109,19 +109,19 @@ for i in range(119): z[i] = sim["/Cosmology"].attrs["Redshift"][0] a[i] = sim["/Cosmology"].attrs["Scale-factor"][0] - S = sim["/PartType0/Entropy"][:] + S = sim["/PartType0/Entropies"][:] S_mean[i] = np.mean(S) S_std[i] = np.std(S) - u = sim["/PartType0/InternalEnergy"][:] + u = sim["/PartType0/InternalEnergies"][:] u_mean[i] = np.mean(u) u_std[i] = np.std(u) - P = sim["/PartType0/Pressure"][:] + P = sim["/PartType0/Pressures"][:] P_mean[i] = np.mean(P) P_std[i] = np.std(P) - rho = sim["/PartType0/Density"][:] + rho = sim["/PartType0/Densities"][:] rho_mean[i] = np.mean(rho) rho_std[i] = np.std(rho) diff --git a/examples/Cosmology/ZeldovichPancake_3D/plotSolution.py b/examples/Cosmology/ZeldovichPancake_3D/plotSolution.py index eef247fb761e75f8dde8e8abe84075efbd7cb46a..285ed3ae218549468c309e9109ef53f10a2f66ab 100644 --- a/examples/Cosmology/ZeldovichPancake_3D/plotSolution.py +++ b/examples/Cosmology/ZeldovichPancake_3D/plotSolution.py @@ -78,10 +78,10 @@ gas_gamma = sim["/HydroScheme"].attrs["Adiabatic index"][0] x = sim["/PartType0/Coordinates"][:,0] v = sim["/PartType0/Velocities"][:,0] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] m = sim["/PartType0/Masses"][:] try: phi = sim["/PartType0/Potential"][:] @@ -98,8 +98,8 @@ if os.path.exists(filename_g): sim_g = h5py.File(filename_g, "r") x_g = sim_g["/PartType0/Coordinates"][:,0] v_g = sim_g["/PartType0/Velocities"][:,0] - u_g = sim_g["/PartType0/InternalEnergy"][:] - rho_g = sim_g["/PartType0/Density"][:] + u_g = sim_g["/PartType0/InternalEnergies"][:] + rho_g = sim_g["/PartType0/Densities"][:] phi_g = sim_g["/PartType0/Potential"][:] a_g = sim_g["/Header"].attrs["Time"] print("Gadget Scale-factor:", a_g, "redshift:", 1/a_g - 1.) diff --git a/examples/EAGLE_ICs/EAGLE_12/eagle_12.yml b/examples/EAGLE_ICs/EAGLE_12/eagle_12.yml index b5122afdba28ffaed1e52cdd8bd2db8a4e566c03..97ed3e4ee1299fd25a148c9c2de6f6af6547882c 100644 --- a/examples/EAGLE_ICs/EAGLE_12/eagle_12.yml +++ b/examples/EAGLE_ICs/EAGLE_12/eagle_12.yml @@ -27,8 +27,8 @@ TimeIntegration: # Parameters governing the snapshots Snapshots: basename: eagle # Common part of the name of output files - scale_factor_first: 0.05 - delta_time: 1.02 + output_list_on: 1 + output_list: ./output_list.txt # Parameters governing the conserved quantities statistics Statistics: @@ -66,6 +66,7 @@ Scheduler: tasks_per_cell: 5 Restarts: + onexit: 1 delta_hours: 1.0 # Parameters related to the initial conditions @@ -92,7 +93,7 @@ EAGLEChemistry: EAGLECooling: dir_name: ./coolingtables/ - H_reion_z: 11.5 + H_reion_z: 7.5 # Planck 2018 H_reion_eV_p_H: 2.0 He_reion_z_centre: 3.5 He_reion_z_sigma: 0.5 diff --git a/examples/EAGLE_ICs/EAGLE_12/output_list.txt b/examples/EAGLE_ICs/EAGLE_12/output_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..592ab8483d015fe1bfafe5cc603fabc230b25589 --- /dev/null +++ b/examples/EAGLE_ICs/EAGLE_12/output_list.txt @@ -0,0 +1,38 @@ +# Redshift +18.08 +15.28 +13.06 +11.26 +9.79 +8.57 +7.54 +6.67 +5.92 +5.28 +4.72 +4.24 +3.81 +3.43 +3.09 +2.79 +2.52 +2.28 +2.06 +1.86 +1.68 +1.51 +1.36 +1.21 +1.08 +0.96 +0.85 +0.74 +0.64 +0.55 +0.46 +0.37 +0.29 +0.21 +0.14 +0.07 +0.00 diff --git a/examples/EAGLE_ICs/EAGLE_25/eagle_25.yml b/examples/EAGLE_ICs/EAGLE_25/eagle_25.yml index 888009f27761feda91d3cb70df2366b9f04fd3eb..d83bbd38fbb0d4e572d17e5107f94425d4427b31 100644 --- a/examples/EAGLE_ICs/EAGLE_25/eagle_25.yml +++ b/examples/EAGLE_ICs/EAGLE_25/eagle_25.yml @@ -27,8 +27,8 @@ TimeIntegration: # Parameters governing the snapshots Snapshots: basename: eagle # Common part of the name of output files - scale_factor_first: 0.05 - delta_time: 1.02 + output_list_on: 1 + output_list: ./output_list.txt # Parameters governing the conserved quantities statistics Statistics: @@ -66,6 +66,7 @@ Scheduler: tasks_per_cell: 5 Restarts: + onexit: 1 delta_hours: 1.0 # Parameters related to the initial conditions @@ -93,7 +94,7 @@ EAGLEChemistry: # EAGLE cooling parameters EAGLECooling: dir_name: ./coolingtables/ - H_reion_z: 11.5 + H_reion_z: 7.5 # Planck 2018 H_reion_eV_p_H: 2.0 He_reion_z_centre: 3.5 He_reion_z_sigma: 0.5 diff --git a/examples/EAGLE_ICs/EAGLE_25/output_list.txt b/examples/EAGLE_ICs/EAGLE_25/output_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..592ab8483d015fe1bfafe5cc603fabc230b25589 --- /dev/null +++ b/examples/EAGLE_ICs/EAGLE_25/output_list.txt @@ -0,0 +1,38 @@ +# Redshift +18.08 +15.28 +13.06 +11.26 +9.79 +8.57 +7.54 +6.67 +5.92 +5.28 +4.72 +4.24 +3.81 +3.43 +3.09 +2.79 +2.52 +2.28 +2.06 +1.86 +1.68 +1.51 +1.36 +1.21 +1.08 +0.96 +0.85 +0.74 +0.64 +0.55 +0.46 +0.37 +0.29 +0.21 +0.14 +0.07 +0.00 diff --git a/examples/EAGLE_ICs/EAGLE_50/eagle_50.yml b/examples/EAGLE_ICs/EAGLE_50/eagle_50.yml index f2e3b0656541ca698c20a85a308e538871d4fdc4..a3130edcffe01566d34cf19d39976aff94b65907 100644 --- a/examples/EAGLE_ICs/EAGLE_50/eagle_50.yml +++ b/examples/EAGLE_ICs/EAGLE_50/eagle_50.yml @@ -27,8 +27,8 @@ TimeIntegration: # Parameters governing the snapshots Snapshots: basename: eagle # Common part of the name of output files - scale_factor_first: 0.05 - delta_time: 1.02 + output_list_on: 1 + output_list: ./output_list.txt # Parameters governing the conserved quantities statistics Statistics: @@ -66,6 +66,7 @@ Scheduler: tasks_per_cell: 5 Restarts: + onexit: 1 delta_hours: 1.0 # Parameters related to the initial conditions @@ -93,7 +94,7 @@ EAGLEChemistry: # EAGLE cooling parameters EAGLECooling: dir_name: ./coolingtables/ - H_reion_z: 11.5 + H_reion_z: 7.5 # Planck 2018 H_reion_eV_p_H: 2.0 He_reion_z_centre: 3.5 He_reion_z_sigma: 0.5 diff --git a/examples/EAGLE_ICs/EAGLE_50/output_list.txt b/examples/EAGLE_ICs/EAGLE_50/output_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..592ab8483d015fe1bfafe5cc603fabc230b25589 --- /dev/null +++ b/examples/EAGLE_ICs/EAGLE_50/output_list.txt @@ -0,0 +1,38 @@ +# Redshift +18.08 +15.28 +13.06 +11.26 +9.79 +8.57 +7.54 +6.67 +5.92 +5.28 +4.72 +4.24 +3.81 +3.43 +3.09 +2.79 +2.52 +2.28 +2.06 +1.86 +1.68 +1.51 +1.36 +1.21 +1.08 +0.96 +0.85 +0.74 +0.64 +0.55 +0.46 +0.37 +0.29 +0.21 +0.14 +0.07 +0.00 diff --git a/examples/HydroTests/BlobTest_3D/makeMovie.py b/examples/HydroTests/BlobTest_3D/makeMovie.py index 9ae4a538e000fa7006f093b67d325ff433e97089..55acdaab01e22ecf8bae0dd24967a348ceabf34b 100644 --- a/examples/HydroTests/BlobTest_3D/makeMovie.py +++ b/examples/HydroTests/BlobTest_3D/makeMovie.py @@ -24,7 +24,7 @@ resolution = 1024 snapshot_name = "blob" cmap = "Spectral_r" text_args = dict(color="black") -# plot = "pressure" +# plot = "pressures" # name = "Pressure $P$" plot = "density" name = "Fluid Density $\\rho$" diff --git a/examples/HydroTests/Diffusion_1D/plotSolution.py b/examples/HydroTests/Diffusion_1D/plotSolution.py index 66c8ffc6418f06589a2918ae4d8ed460b0081972..a394e919b4e2e80728c97499c3c3544256a6ad2c 100644 --- a/examples/HydroTests/Diffusion_1D/plotSolution.py +++ b/examples/HydroTests/Diffusion_1D/plotSolution.py @@ -24,6 +24,7 @@ import numpy as np try: from scipy.integrate import solve_ivp + solve_ode = True except: solve_ode = False @@ -32,6 +33,7 @@ from swiftsimio import load matplotlib.use("Agg") + def solve_analytic(u_0, u_1, t_0, t_1, alpha=0.1): """ Solves the analytic equation: @@ -63,7 +65,12 @@ def solve_analytic(u_0, u_1, t_0, t_1, alpha=0.1): return np.array([-1.0 * common, 1.0 * common]) - ret = solve_ivp(gradient, t_span=[t_0.value, t_1.value], y0=[u_0.value, u_1.value], t_eval=np.linspace(t_0.value, t_1.value, 100)) + ret = solve_ivp( + gradient, + t_span=[t_0.value, t_1.value], + y0=[u_0.value, u_1.value], + t_eval=np.linspace(t_0.value, t_1.value, 100), + ) t = ret.t high = ret.y[1] @@ -81,7 +88,7 @@ def get_data_dump(metadata): viscosity = metadata.viscosity_info except: viscosity = "No info" - + try: diffusion = metadata.diffusion_info except: @@ -136,6 +143,7 @@ def setup_axes(size=[8, 8], dpi=300): return fig, ax + def mean_std_max_min(data): """ Returns: @@ -157,7 +165,7 @@ def extract_plottables_u(data_list): """ data = [ - np.diff(x.gas.internal_energy.value) / np.mean(x.gas.internal_energy.value) + np.diff(x.gas.internal_energies.value) / np.mean(x.gas.internal_energies.value) for x in data_list ] @@ -175,8 +183,10 @@ def extract_plottables_x(data_list): dx = boxsize / n_part original_x = np.arange(n_part, dtype=float) * dx + (0.5 * dx) - - deviations = [1e6 * abs(original_x - x.gas.coordinates.value[:, 0]) / dx for x in data_list] + + deviations = [ + 1e6 * abs(original_x - x.gas.coordinates.value[:, 0]) / dx for x in data_list + ] return mean_std_max_min(deviations) @@ -187,7 +197,7 @@ def extract_plottables_rho(data_list): mean, stdev, max, min * 1e6 deviations from mean density """ - P = [x.gas.density.value for x in data_list] + P = [x.gas.densities.value for x in data_list] mean_P = [np.mean(x) for x in P] deviations = [1e6 * (x - y) / x for x, y in zip(mean_P, P)] @@ -241,28 +251,34 @@ def make_plot(start: int, stop: int, handle: str): if solve_ode: times_ode, diff = solve_analytic( - u_0=data_list[0].gas.internal_energy.min(), - u_1=data_list[0].gas.internal_energy.max(), + u_0=data_list[0].gas.internal_energies.min(), + u_1=data_list[0].gas.internal_energies.max(), t_0=t[0], t_1=t[-1], alpha=( - np.sqrt(5.0/3.0 * (5.0/3.0 - 1.0)) * - alpha / data_list[0].gas.smoothing_length[0].value - ) + np.sqrt(5.0 / 3.0 * (5.0 / 3.0 - 1.0)) + * alpha + / data_list[0].gas.smoothing_length[0].value + ), ) ax[1].plot( times_ode, - (diff) / np.mean(data_list[0].gas.internal_energy), + (diff) / np.mean(data_list[0].gas.internal_energies), label="Analytic", linestyle="dotted", - c="C3" + c="C3", ) - #import pdb;pdb.set_trace() + # import pdb;pdb.set_trace() ax[2].fill_between( - t, x_means - x_stdevs, x_means + x_stdevs, color="C0", alpha=0.5, edgecolor="none" + t, + x_means - x_stdevs, + x_means + x_stdevs, + color="C0", + alpha=0.5, + edgecolor="none", ) ax[2].plot(t, x_means, label="Mean", c="C0") ax[2].plot(t, x_maxs, label="Max", linestyle="dashed", c="C1") @@ -270,11 +286,18 @@ def make_plot(start: int, stop: int, handle: str): try: # Give diffusion info a go; this may not be present - diff_means, diff_stdevs, diff_maxs, diff_mins = extract_plottables_diff(data_list) + diff_means, diff_stdevs, diff_maxs, diff_mins = extract_plottables_diff( + data_list + ) ax[3].set_ylabel(r"Diffusion parameter $\alpha_{diff}$") ax[3].fill_between( - t, diff_means - diff_stdevs, diff_means + diff_stdevs, color="C0", alpha=0.5, edgecolor="none" + t, + diff_means - diff_stdevs, + diff_means + diff_stdevs, + color="C0", + alpha=0.5, + edgecolor="none", ) ax[3].plot(t, diff_means, label="Mean", c="C0") ax[3].plot(t, diff_maxs, label="Max", linestyle="dashed", c="C1") @@ -284,9 +307,16 @@ def make_plot(start: int, stop: int, handle: str): # Diffusion info must not be present. rho_means, rho_stdevs, rho_maxs, rho_mins = extract_plottables_rho(data_list) - ax[3].set_ylabel("Deviation from mean density $(\\rho_i - \\bar{\\rho}) / \\bar{\\rho}$ [$\\times 10^{6}$]") + ax[3].set_ylabel( + "Deviation from mean density $(\\rho_i - \\bar{\\rho}) / \\bar{\\rho}$ [$\\times 10^{6}$]" + ) ax[3].fill_between( - t, rho_means - rho_stdevs, rho_means + rho_stdevs, color="C0", alpha=0.5, edgecolor="none" + t, + rho_means - rho_stdevs, + rho_means + rho_stdevs, + color="C0", + alpha=0.5, + edgecolor="none", ) ax[3].plot(t, rho_means, label="Mean", c="C0") ax[3].plot(t, rho_maxs, label="Max", linestyle="dashed", c="C1") diff --git a/examples/HydroTests/EvrardCollapse_3D/plotSolution.py b/examples/HydroTests/EvrardCollapse_3D/plotSolution.py index 8422b9c45fd573f3d0ae36324d6e39ab23cceb25..b405771a4792e5ca4fef181b3787952bf0078d67 100644 --- a/examples/HydroTests/EvrardCollapse_3D/plotSolution.py +++ b/examples/HydroTests/EvrardCollapse_3D/plotSolution.py @@ -75,10 +75,10 @@ x = sqrt((coords[:,0] - 0.5 * boxSize)**2 + (coords[:,1] - 0.5 * boxSize)**2 + \ (coords[:,2] - 0.5 * boxSize)**2) vels = sim["/PartType0/Velocities"] v = sqrt(vels[:,0]**2 + vels[:,1]**2 + vels[:,2]**2) -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] # Bin the data x_bin_edge = logspace(-3., log10(2.), 100) diff --git a/examples/HydroTests/Gradients/plot.py b/examples/HydroTests/Gradients/plot.py index d6750ffc581437ebbf402ec44bcb1d14cb82a698..7b4248c9fc9c9d6b9c5b15410185d6489849bed8 100644 --- a/examples/HydroTests/Gradients/plot.py +++ b/examples/HydroTests/Gradients/plot.py @@ -30,7 +30,7 @@ inputfile = sys.argv[1] outputfile = "gradients_{0}.png".format(sys.argv[2]) f = h5py.File(inputfile, "r") -rho = np.array(f["/PartType0/Density"]) +rho = np.array(f["/PartType0/Densities"]) gradrho = np.array(f["/PartType0/GradDensity"]) coords = np.array(f["/PartType0/Coordinates"]) diff --git a/examples/HydroTests/GreshoVortex_2D/plotSolution.py b/examples/HydroTests/GreshoVortex_2D/plotSolution.py index d497a6b297bf38b39cf85a9107a769c20f815b77..2d4697b6ffaac0639da67ee90d824c75791ea573 100644 --- a/examples/HydroTests/GreshoVortex_2D/plotSolution.py +++ b/examples/HydroTests/GreshoVortex_2D/plotSolution.py @@ -100,10 +100,10 @@ r = sqrt(x**2 + y**2) v_r = (x * vel[:,0] + y * vel[:,1]) / r v_phi = (-y * vel[:,0] + x * vel[:,1]) / r v_norm = sqrt(vel[:,0]**2 + vel[:,1]**2) -rho = sim["/PartType0/Density"][:] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] +rho = sim["/PartType0/Densities"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] # Bin te data r_bin_edge = np.arange(0., 1., 0.02) diff --git a/examples/HydroTests/GreshoVortex_3D/plotSolution.py b/examples/HydroTests/GreshoVortex_3D/plotSolution.py index 545440c997d9ebc3ab11562d0a7d9fa143e23ed2..20beab7514759c764f5ca7c379183506b764a819 100644 --- a/examples/HydroTests/GreshoVortex_3D/plotSolution.py +++ b/examples/HydroTests/GreshoVortex_3D/plotSolution.py @@ -103,19 +103,19 @@ r = sqrt(x**2 + y**2) v_r = (x * vel[:,0] + y * vel[:,1]) / r v_phi = (-y * vel[:,0] + x * vel[:,1]) / r v_norm = sqrt(vel[:,0]**2 + vel[:,1]**2) -rho = sim["/PartType0/Density"][:] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] +rho = sim["/PartType0/Densities"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] try: - diffusion = sim["/PartType0/Diffusion"][:] + diffusion = sim["/PartType0/DiffusionParameters"][:] plot_diffusion = True except: plot_diffusion = False try: - viscosity = sim["/PartType0/Viscosity"][:] + viscosity = sim["/PartType0/ViscosityParameters"][:] plot_viscosity = True except: plot_viscosity = False diff --git a/examples/HydroTests/InteractingBlastWaves_1D/plotSolution.py b/examples/HydroTests/InteractingBlastWaves_1D/plotSolution.py index 1719162dec34626d6f4ecb8267c4d06f85b3db26..d617fb239ce21acab73b5cb057dd3cdf4b260d59 100644 --- a/examples/HydroTests/InteractingBlastWaves_1D/plotSolution.py +++ b/examples/HydroTests/InteractingBlastWaves_1D/plotSolution.py @@ -55,11 +55,11 @@ snap = int(sys.argv[1]) # Open the file and read the relevant data file = h5py.File("interactingBlastWaves_{0:04d}.hdf5".format(snap), "r") x = file["/PartType0/Coordinates"][:,0] -rho = file["/PartType0/Density"] +rho = file["/PartType0/Densities"] v = file["/PartType0/Velocities"][:,0] -u = file["/PartType0/InternalEnergy"] -S = file["/PartType0/Entropy"] -P = file["/PartType0/Pressure"] +u = file["/PartType0/InternalEnergies"] +S = file["/PartType0/Entropies"] +P = file["/PartType0/Pressures"] time = file["/Header"].attrs["Time"][0] scheme = file["/HydroScheme"].attrs["Scheme"] diff --git a/examples/HydroTests/KelvinHelmholtz_2D/plotSolution.py b/examples/HydroTests/KelvinHelmholtz_2D/plotSolution.py index 77ab6fb244da25d13760f90653fac7eac11a0ee7..f599fcb784633b2d6765ea79767fc658196faa5f 100644 --- a/examples/HydroTests/KelvinHelmholtz_2D/plotSolution.py +++ b/examples/HydroTests/KelvinHelmholtz_2D/plotSolution.py @@ -77,10 +77,10 @@ x = pos[:,0] - boxSize / 2 y = pos[:,1] - boxSize / 2 vel = sim["/PartType0/Velocities"][:,:] v_norm = sqrt(vel[:,0]**2 + vel[:,1]**2) -rho = sim["/PartType0/Density"][:] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] +rho = sim["/PartType0/Densities"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] # Plot the interesting quantities figure() diff --git a/examples/HydroTests/Noh_1D/plotSolution.py b/examples/HydroTests/Noh_1D/plotSolution.py index 25b9b2f16b24cba5def592a5cf00dbae82195ef7..7f0b5d403ef816b0dda57823010472476a7ecc32 100644 --- a/examples/HydroTests/Noh_1D/plotSolution.py +++ b/examples/HydroTests/Noh_1D/plotSolution.py @@ -69,10 +69,10 @@ git = sim["Code"].attrs["Git Revision"] x = sim["/PartType0/Coordinates"][:,0] v = sim["/PartType0/Velocities"][:,0] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] N = 1001 # Number of points x_min = -1 diff --git a/examples/HydroTests/Noh_2D/plotSolution.py b/examples/HydroTests/Noh_2D/plotSolution.py index 775ddf4e8a7954c14034ad51a6b66622c41a6996..b53212c4688ec790ad8f3f83f81243f9ec52266d 100644 --- a/examples/HydroTests/Noh_2D/plotSolution.py +++ b/examples/HydroTests/Noh_2D/plotSolution.py @@ -71,10 +71,10 @@ x = sim["/PartType0/Coordinates"][:,0] y = sim["/PartType0/Coordinates"][:,1] vx = sim["/PartType0/Velocities"][:,0] vy = sim["/PartType0/Velocities"][:,1] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] r = np.sqrt((x-1)**2 + (y-1)**2) v = -np.sqrt(vx**2 + vy**2) diff --git a/examples/HydroTests/Noh_3D/plotSolution.py b/examples/HydroTests/Noh_3D/plotSolution.py index 386b9f728b5e8d8e38fb7ec9aeaa336d194e35dd..20e8ca805de1cb700b8b462ae27495080f5d3268 100644 --- a/examples/HydroTests/Noh_3D/plotSolution.py +++ b/examples/HydroTests/Noh_3D/plotSolution.py @@ -74,10 +74,10 @@ z = sim["/PartType0/Coordinates"][:,2] vx = sim["/PartType0/Velocities"][:,0] vy = sim["/PartType0/Velocities"][:,1] vz = sim["/PartType0/Velocities"][:,2] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] r = np.sqrt((x-1)**2 + (y-1)**2 + (z-1)**2) v = -np.sqrt(vx**2 + vy**2 + vz**2) diff --git a/examples/HydroTests/Rayleigh-Taylor_2D/plotInitialProfile.py b/examples/HydroTests/Rayleigh-Taylor_2D/plotInitialProfile.py index e89c4e8525fe4c88e517acbd453b0941f8f573c8..8928a6e597adbe4e52f905ba95fa68f424b6cabb 100644 --- a/examples/HydroTests/Rayleigh-Taylor_2D/plotInitialProfile.py +++ b/examples/HydroTests/Rayleigh-Taylor_2D/plotInitialProfile.py @@ -12,8 +12,8 @@ f = load(filename) # Get data from snapshot x, y, _ = f.gas.coordinates.value.T -rho = f.gas.density.value -a = f.gas.entropy.value +rho = f.gas.densities.value +a = f.gas.entropies.value # Get analytical solution y_an = np.linspace(0, makeIC.box_size[1], N) diff --git a/examples/HydroTests/SedovBlast_1D/plotSolution.py b/examples/HydroTests/SedovBlast_1D/plotSolution.py index c6d4a989da7493f7b500946610eea8832696bf6f..d82ad9e94610a916d900ea93863b2881757e73b3 100644 --- a/examples/HydroTests/SedovBlast_1D/plotSolution.py +++ b/examples/HydroTests/SedovBlast_1D/plotSolution.py @@ -78,13 +78,13 @@ x = pos[:,0] - boxSize / 2 vel = sim["/PartType0/Velocities"][:,:] r = abs(x) v_r = x * vel[:,0] / r -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] try: - alpha = sim["/PartType0/Viscosity"][:] + alpha = sim["/PartType0/ViscosityParameters"][:] plot_alpha = True except: plot_alpha = False diff --git a/examples/HydroTests/SedovBlast_2D/plotSolution.py b/examples/HydroTests/SedovBlast_2D/plotSolution.py index 2b5de6f32b8673bbc825fbb5236f4e2ab3b4f408..6f504a09c9432368ce141ec0d28c28699f5ba7f3 100644 --- a/examples/HydroTests/SedovBlast_2D/plotSolution.py +++ b/examples/HydroTests/SedovBlast_2D/plotSolution.py @@ -80,10 +80,10 @@ y = pos[:,1] - boxSize / 2 vel = sim["/PartType0/Velocities"][:,:] r = sqrt(x**2 + y**2) v_r = (x * vel[:,0] + y * vel[:,1]) / r -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] # Bin te data r_bin_edge = np.arange(0., 0.5, 0.01) diff --git a/examples/HydroTests/SedovBlast_3D/plotSolution.py b/examples/HydroTests/SedovBlast_3D/plotSolution.py index b0f2e08441b3fa550e61602ba852228a04362fbc..fec4f1101406be5803a3f1601812d1cb85275409 100644 --- a/examples/HydroTests/SedovBlast_3D/plotSolution.py +++ b/examples/HydroTests/SedovBlast_3D/plotSolution.py @@ -81,19 +81,19 @@ z = pos[:,2] - boxSize / 2 vel = sim["/PartType0/Velocities"][:,:] r = sqrt(x**2 + y**2 + z**2) v_r = (x * vel[:,0] + y * vel[:,1] + z * vel[:,2]) / r -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] try: - diffusion = sim["/PartType0/Diffusion"][:] + diffusion = sim["/PartType0/DiffusionParameters"][:] plot_diffusion = True except: plot_diffusion = False try: - viscosity = sim["/PartType0/Viscosity"][:] + viscosity = sim["/PartType0/ViscosityParameters"][:] plot_viscosity = True except: plot_viscosity = False diff --git a/examples/HydroTests/SineWavePotential_1D/plotSolution.py b/examples/HydroTests/SineWavePotential_1D/plotSolution.py index 3bb889aaabd3cdac0274afb09647d0e3aebb02cc..ae99d98aaaa11d9c68473b74106054963a075895 100644 --- a/examples/HydroTests/SineWavePotential_1D/plotSolution.py +++ b/examples/HydroTests/SineWavePotential_1D/plotSolution.py @@ -43,9 +43,9 @@ fileName = sys.argv[1] file = h5py.File(fileName, 'r') coords = np.array(file["/PartType0/Coordinates"]) -rho = np.array(file["/PartType0/Density"]) -P = np.array(file["/PartType0/Pressure"]) -u = np.array(file["/PartType0/InternalEnergy"]) +rho = np.array(file["/PartType0/Densities"]) +P = np.array(file["/PartType0/Pressures"]) +u = np.array(file["/PartType0/InternalEnergies"]) m = np.array(file["/PartType0/Masses"]) vs = np.array(file["/PartType0/Velocities"]) ids = np.array(file["/PartType0/ParticleIDs"]) diff --git a/examples/HydroTests/SineWavePotential_2D/plotSolution.py b/examples/HydroTests/SineWavePotential_2D/plotSolution.py index ee02f59c404db87a790465d2786e6296525e36b0..5c87b0f4f3682d486063522715517763b1035567 100644 --- a/examples/HydroTests/SineWavePotential_2D/plotSolution.py +++ b/examples/HydroTests/SineWavePotential_2D/plotSolution.py @@ -38,8 +38,8 @@ fileName = sys.argv[1] file = h5py.File(fileName, 'r') coords = np.array(file["/PartType0/Coordinates"]) -rho = np.array(file["/PartType0/Density"]) -u = np.array(file["/PartType0/InternalEnergy"]) +rho = np.array(file["/PartType0/Densities"]) +u = np.array(file["/PartType0/InternalEnergies"]) agrav = np.array(file["/PartType0/GravAcceleration"]) m = np.array(file["/PartType0/Masses"]) ids = np.array(file["/PartType0/ParticleIDs"]) diff --git a/examples/HydroTests/SineWavePotential_3D/plotSolution.py b/examples/HydroTests/SineWavePotential_3D/plotSolution.py index 13cae037b64eff4ad4fec0003bf0f5ad3ce94896..7bfa82a5990572c478976614c50107e5254f0e00 100644 --- a/examples/HydroTests/SineWavePotential_3D/plotSolution.py +++ b/examples/HydroTests/SineWavePotential_3D/plotSolution.py @@ -38,8 +38,8 @@ fileName = sys.argv[1] file = h5py.File(fileName, 'r') coords = np.array(file["/PartType0/Coordinates"]) -rho = np.array(file["/PartType0/Density"]) -u = np.array(file["/PartType0/InternalEnergy"]) +rho = np.array(file["/PartType0/Densities"]) +u = np.array(file["/PartType0/InternalEnergies"]) agrav = np.array(file["/PartType0/GravAcceleration"]) m = np.array(file["/PartType0/Masses"]) ids = np.array(file["/PartType0/ParticleIDs"]) diff --git a/examples/HydroTests/SodShockSpherical_2D/plotSolution.py b/examples/HydroTests/SodShockSpherical_2D/plotSolution.py index 57b7f7ddc64bc25df031eb0cba7547f40d46b31a..61060631eea1a7320ef207457d35031318bceccf 100644 --- a/examples/HydroTests/SodShockSpherical_2D/plotSolution.py +++ b/examples/HydroTests/SodShockSpherical_2D/plotSolution.py @@ -74,10 +74,10 @@ coords = sim["/PartType0/Coordinates"] x = sqrt((coords[:,0] - 0.5)**2 + (coords[:,1] - 0.5)**2) vels = sim["/PartType0/Velocities"] v = sqrt(vels[:,0]**2 + vels[:,1]**2) -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] # Bin the data rho_bin,x_bin_edge,_ = \ diff --git a/examples/HydroTests/SodShockSpherical_3D/plotSolution.py b/examples/HydroTests/SodShockSpherical_3D/plotSolution.py index 539bfba799e3231bd26ae2eb39c271baa1fa6a4b..0a92f3aaf1831d67cb59dd71bc08cd8d973d9def 100644 --- a/examples/HydroTests/SodShockSpherical_3D/plotSolution.py +++ b/examples/HydroTests/SodShockSpherical_3D/plotSolution.py @@ -75,10 +75,10 @@ x = sqrt((coords[:,0] - 0.5)**2 + (coords[:,1] - 0.5)**2 + \ (coords[:,2] - 0.5)**2) vels = sim["/PartType0/Velocities"] v = sqrt(vels[:,0]**2 + vels[:,1]**2 + vels[:,2]**2) -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] # Bin the data rho_bin,x_bin_edge,_ = \ diff --git a/examples/HydroTests/SodShock_1D/plotSolution.py b/examples/HydroTests/SodShock_1D/plotSolution.py index a7e6d374bac616440dace666b85c3e7ade479bcd..770d05ac0493323c2cdd0f5905e409113d1a9eae 100644 --- a/examples/HydroTests/SodShock_1D/plotSolution.py +++ b/examples/HydroTests/SodShock_1D/plotSolution.py @@ -79,12 +79,12 @@ git = str(sim["Code"].attrs["Git Revision"]) x = sim["/PartType0/Coordinates"][:,0] v = sim["/PartType0/Velocities"][:,0] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] try: - alpha = sim["/PartType0/Viscosity"][:] + alpha = sim["/PartType0/ViscosityParameters"][:] plot_alpha = True except: plot_alpha = False diff --git a/examples/HydroTests/SodShock_2D/plotSolution.py b/examples/HydroTests/SodShock_2D/plotSolution.py index 19cbe0ffb766845c051ffb6cea81bd918d890e36..769079da8824d58535e239bd8b54b592ce981a37 100644 --- a/examples/HydroTests/SodShock_2D/plotSolution.py +++ b/examples/HydroTests/SodShock_2D/plotSolution.py @@ -79,10 +79,10 @@ git = sim["Code"].attrs["Git Revision"] x = sim["/PartType0/Coordinates"][:,0] v = sim["/PartType0/Velocities"][:,0] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] N = 1000 # Number of points x_min = -1. diff --git a/examples/HydroTests/SodShock_3D/plotSolution.py b/examples/HydroTests/SodShock_3D/plotSolution.py index 69b2fe4887e986156ed01e0f4177d01ccbed6035..c2028cedcea820e56c07962fe3ca2f1fe1347d40 100644 --- a/examples/HydroTests/SodShock_3D/plotSolution.py +++ b/examples/HydroTests/SodShock_3D/plotSolution.py @@ -79,19 +79,19 @@ git = sim["Code"].attrs["Git Revision"] x = sim["/PartType0/Coordinates"][:,0] v = sim["/PartType0/Velocities"][:,0] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] try: - diffusion = sim["/PartType0/Diffusion"][:] + diffusion = sim["/PartType0/DiffusionParameters"][:] plot_diffusion = True except: plot_diffusion = False try: - viscosity = sim["/PartType0/Viscosity"][:] + viscosity = sim["/PartType0/ViscosityParameters"][:] plot_viscosity = True except: plot_viscosity = False diff --git a/examples/HydroTests/SodShock_BCC_3D/plotSolution.py b/examples/HydroTests/SodShock_BCC_3D/plotSolution.py index 365b679991e9a3a5bbb9e9d5108066c04e497c2f..9660e12a3d226bd6b0e3c152031c93cedb345933 100644 --- a/examples/HydroTests/SodShock_BCC_3D/plotSolution.py +++ b/examples/HydroTests/SodShock_BCC_3D/plotSolution.py @@ -94,10 +94,10 @@ time = sim.metadata.t.value data = dict( x=sim.gas.coordinates.value[:, 0], v=sim.gas.velocities.value[:, 0], - u=sim.gas.internal_energy.value, - S=sim.gas.entropy.value, - P=sim.gas.pressure.value, - rho=sim.gas.density.value, + u=sim.gas.internal_energies.value, + S=sim.gas.entropies.value, + P=sim.gas.pressures.value, + rho=sim.gas.densities.value, y=sim.gas.coordinates.value[:, 1], z=sim.gas.coordinates.value[:, 2], ) @@ -164,12 +164,9 @@ for key, label in plot.items(): zorder=-1, ) - mask_noraster = np.logical_and.reduce([ - data["y"] < 0.52, - data["y"] > 0.48, - data["z"] < 0.52, - data["z"] > 0.48 - ]) + mask_noraster = np.logical_and.reduce( + [data["y"] < 0.52, data["y"] > 0.48, data["z"] < 0.52, data["z"] > 0.48] + ) axis.plot( data["x"][mask_noraster], diff --git a/examples/HydroTests/SquareTest_2D/plotSolutionLegacy.py b/examples/HydroTests/SquareTest_2D/plotSolutionLegacy.py index 956da800c9096232d2e82cf4cff4c780672e0a8f..d8701c3d44390f1d2637f798c0e9af23531c4600 100644 --- a/examples/HydroTests/SquareTest_2D/plotSolutionLegacy.py +++ b/examples/HydroTests/SquareTest_2D/plotSolutionLegacy.py @@ -88,10 +88,10 @@ while centre_y < 0.: pos = sim["/PartType0/Coordinates"][:,:] vel = sim["/PartType0/Velocities"][:,:] v_norm = sqrt(vel[:,0]**2 + vel[:,1]**2) -rho = sim["/PartType0/Density"][:] -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] +rho = sim["/PartType0/Densities"][:] +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] x = pos[:,0] - centre_x y = pos[:,1] - centre_y diff --git a/examples/HydroTests/VacuumSpherical_2D/plotSolution.py b/examples/HydroTests/VacuumSpherical_2D/plotSolution.py index 6a65206ae20ccf79392054d047ba6be04f169f3e..de551c0ef4a5f4e027402c881069b7b4780f43d8 100644 --- a/examples/HydroTests/VacuumSpherical_2D/plotSolution.py +++ b/examples/HydroTests/VacuumSpherical_2D/plotSolution.py @@ -63,12 +63,12 @@ snap = int(sys.argv[1]) file = h5py.File("vacuum_{0:04d}.hdf5".format(snap), "r") coords = file["/PartType0/Coordinates"] x = np.sqrt((coords[:,0] - 0.5)**2 + (coords[:,1] - 0.5)**2) -rho = file["/PartType0/Density"][:] +rho = file["/PartType0/Densities"][:] vels = file["/PartType0/Velocities"] v = np.sqrt(vels[:,0]**2 + vels[:,1]**2) -u = file["/PartType0/InternalEnergy"][:] -S = file["/PartType0/Entropy"][:] -P = file["/PartType0/Pressure"][:] +u = file["/PartType0/InternalEnergies"][:] +S = file["/PartType0/Entropies"][:] +P = file["/PartType0/Pressures"][:] time = file["/Header"].attrs["Time"][0] scheme = file["/HydroScheme"].attrs["Scheme"] diff --git a/examples/HydroTests/VacuumSpherical_3D/plotSolution.py b/examples/HydroTests/VacuumSpherical_3D/plotSolution.py index c73e48ee2d311692cdf4aa3b0e52f4766b339df8..4a04acde575eae46de67c70b536b8774befd96ae 100644 --- a/examples/HydroTests/VacuumSpherical_3D/plotSolution.py +++ b/examples/HydroTests/VacuumSpherical_3D/plotSolution.py @@ -64,12 +64,12 @@ file = h5py.File("vacuum_{0:04d}.hdf5".format(snap), "r") coords = file["/PartType0/Coordinates"] x = np.sqrt((coords[:,0] - 0.5)**2 + (coords[:,1] - 0.5)**2 + \ (coords[:,2] - 0.5)**2) -rho = file["/PartType0/Density"][:] +rho = file["/PartType0/Densities"][:] vels = file["/PartType0/Velocities"] v = np.sqrt(vels[:,0]**2 + vels[:,1]**2 + vels[:,2]**2) -u = file["/PartType0/InternalEnergy"][:] -S = file["/PartType0/Entropy"][:] -P = file["/PartType0/Pressure"][:] +u = file["/PartType0/InternalEnergies"][:] +S = file["/PartType0/Entropies"][:] +P = file["/PartType0/Pressures"][:] time = file["/Header"].attrs["Time"][0] scheme = file["/HydroScheme"].attrs["Scheme"] diff --git a/examples/HydroTests/Vacuum_1D/plotSolution.py b/examples/HydroTests/Vacuum_1D/plotSolution.py index fceac10c25fd58b5bbcb6e31884cd62b4cfd61f5..eac7dc9e3ac43822ad167372f9f33bf2f5af0e2a 100644 --- a/examples/HydroTests/Vacuum_1D/plotSolution.py +++ b/examples/HydroTests/Vacuum_1D/plotSolution.py @@ -61,11 +61,11 @@ snap = int(sys.argv[1]) # Open the file and read the relevant data file = h5py.File("vacuum_{0:04d}.hdf5".format(snap), "r") x = file["/PartType0/Coordinates"][:,0] -rho = file["/PartType0/Density"] +rho = file["/PartType0/Densities"] v = file["/PartType0/Velocities"][:,0] -u = file["/PartType0/InternalEnergy"] -S = file["/PartType0/Entropy"] -P = file["/PartType0/Pressure"] +u = file["/PartType0/InternalEnergies"] +S = file["/PartType0/Entropies"] +P = file["/PartType0/Pressures"] time = file["/Header"].attrs["Time"][0] scheme = file["/HydroScheme"].attrs["Scheme"] diff --git a/examples/HydroTests/Vacuum_2D/plotSolution.py b/examples/HydroTests/Vacuum_2D/plotSolution.py index 4d197234237df10b8cdbf197048a65991da023cf..ffd0eb1cdd857764f7ecc4e2d0c93fee3c5f29e8 100644 --- a/examples/HydroTests/Vacuum_2D/plotSolution.py +++ b/examples/HydroTests/Vacuum_2D/plotSolution.py @@ -62,11 +62,11 @@ snap = int(sys.argv[1]) # Open the file and read the relevant data file = h5py.File("vacuum_{0:04d}.hdf5".format(snap), "r") x = file["/PartType0/Coordinates"][:,0] -rho = file["/PartType0/Density"][:] +rho = file["/PartType0/Densities"][:] v = file["/PartType0/Velocities"][:,0] -u = file["/PartType0/InternalEnergy"][:] -S = file["/PartType0/Entropy"][:] -P = file["/PartType0/Pressure"][:] +u = file["/PartType0/InternalEnergies"][:] +S = file["/PartType0/Entropies"][:] +P = file["/PartType0/Pressures"][:] time = file["/Header"].attrs["Time"][0] scheme = file["/HydroScheme"].attrs["Scheme"] diff --git a/examples/HydroTests/Vacuum_3D/plotSolution.py b/examples/HydroTests/Vacuum_3D/plotSolution.py index 4d197234237df10b8cdbf197048a65991da023cf..ffd0eb1cdd857764f7ecc4e2d0c93fee3c5f29e8 100644 --- a/examples/HydroTests/Vacuum_3D/plotSolution.py +++ b/examples/HydroTests/Vacuum_3D/plotSolution.py @@ -62,11 +62,11 @@ snap = int(sys.argv[1]) # Open the file and read the relevant data file = h5py.File("vacuum_{0:04d}.hdf5".format(snap), "r") x = file["/PartType0/Coordinates"][:,0] -rho = file["/PartType0/Density"][:] +rho = file["/PartType0/Densities"][:] v = file["/PartType0/Velocities"][:,0] -u = file["/PartType0/InternalEnergy"][:] -S = file["/PartType0/Entropy"][:] -P = file["/PartType0/Pressure"][:] +u = file["/PartType0/InternalEnergies"][:] +S = file["/PartType0/Entropies"][:] +P = file["/PartType0/Pressures"][:] time = file["/Header"].attrs["Time"][0] scheme = file["/HydroScheme"].attrs["Scheme"] diff --git a/examples/IsolatedGalaxy/IsolatedGalaxy_feedback/plotSolution.py b/examples/IsolatedGalaxy/IsolatedGalaxy_feedback/plotSolution.py index 89a87923148cb6872ab17b6d7229aef597ef3287..1ff8df3569f25590e5acb8046edeca0a1333d556 100644 --- a/examples/IsolatedGalaxy/IsolatedGalaxy_feedback/plotSolution.py +++ b/examples/IsolatedGalaxy/IsolatedGalaxy_feedback/plotSolution.py @@ -29,7 +29,7 @@ rcParams.update(params) rc("font", **{"family": "sans-serif", "sans-serif": ["Times"]}) snap = int(sys.argv[1]) -filename = "output_%.4d.hdf5"%snap +filename = "output_%.4d.hdf5" % snap f = h5.File(filename, "r") @@ -40,7 +40,7 @@ year_in_cgs = 3600.0 * 24 * 365.0 Msun_in_cgs = 1.98848e33 G_in_cgs = 6.67259e-8 pc_in_cgs = 3.08567758e18 -Msun_p_pc2 = Msun_in_cgs / pc_in_cgs**2 +Msun_p_pc2 = Msun_in_cgs / pc_in_cgs ** 2 # Gemoetry info boxsize = f["/Header"].attrs["BoxSize"] @@ -52,66 +52,94 @@ unit_mass_in_cgs = f["/Units"].attrs["Unit mass in cgs (U_M)"] unit_time_in_cgs = f["/Units"].attrs["Unit time in cgs (U_t)"] # Calculate Gravitational constant in internal units -G = G_in_cgs * ( unit_length_in_cgs**3 / unit_mass_in_cgs / unit_time_in_cgs**2)**(-1) +G = G_in_cgs * (unit_length_in_cgs ** 3 / unit_mass_in_cgs / unit_time_in_cgs ** 2) ** ( + -1 +) # Read parameters of the SF model KS_law_slope = float(f["/Parameters"].attrs["EAGLEStarFormation:KS_exponent"]) KS_law_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:KS_normalisation"]) KS_thresh_Z0 = float(f["/Parameters"].attrs["EAGLEStarFormation:threshold_Z0"]) KS_thresh_slope = float(f["/Parameters"].attrs["EAGLEStarFormation:threshold_slope"]) -KS_thresh_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:threshold_norm_H_p_cm3"]) +KS_thresh_norm = float( + f["/Parameters"].attrs["EAGLEStarFormation:threshold_norm_H_p_cm3"] +) KS_gas_fraction = float(f["/Parameters"].attrs["EAGLEStarFormation:gas_fraction"]) -KS_thresh_max_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:threshold_max_density_H_p_cm3"]) -KS_high_den_thresh = float(f["/Parameters"].attrs["EAGLEStarFormation:KS_high_density_threshold_H_p_cm3"]) -KS_law_slope_high_den = float(f["/Parameters"].attrs["EAGLEStarFormation:KS_high_density_exponent"]) -EOS_gamma_effective = float(f["/Parameters"].attrs["EAGLEStarFormation:EOS_gamma_effective"]) -EOS_density_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:EOS_density_norm_H_p_cm3"]) -EOS_temp_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:EOS_temperature_norm_K"]) +KS_thresh_max_norm = float( + f["/Parameters"].attrs["EAGLEStarFormation:threshold_max_density_H_p_cm3"] +) +KS_high_den_thresh = float( + f["/Parameters"].attrs["EAGLEStarFormation:KS_high_density_threshold_H_p_cm3"] +) +KS_law_slope_high_den = float( + f["/Parameters"].attrs["EAGLEStarFormation:KS_high_density_exponent"] +) +EOS_gamma_effective = float( + f["/Parameters"].attrs["EAGLEStarFormation:EOS_gamma_effective"] +) +EOS_density_norm = float( + f["/Parameters"].attrs["EAGLEStarFormation:EOS_density_norm_H_p_cm3"] +) +EOS_temp_norm = float( + f["/Parameters"].attrs["EAGLEStarFormation:EOS_temperature_norm_K"] +) # Read reference metallicity EAGLE_Z = float(f["/Parameters"].attrs["EAGLEChemistry:init_abundance_metal"]) # Read parameters of the entropy floor -EAGLEfloor_Jeans_rho_norm = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_density_threshold_H_p_cm3"]) -EAGLEfloor_Jeans_temperature_norm_K = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_temperature_norm_K"]) -EAGLEfloor_Jeans_gamma_effective = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_gamma_effective"]) -EAGLEfloor_cool_rho_norm = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_density_threshold_H_p_cm3"]) -EAGLEfloor_cool_temperature_norm_K = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_temperature_norm_K"]) -EAGLEfloor_cool_gamma_effective = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_gamma_effective"]) +EAGLEfloor_Jeans_rho_norm = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_density_threshold_H_p_cm3"] +) +EAGLEfloor_Jeans_temperature_norm_K = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_temperature_norm_K"] +) +EAGLEfloor_Jeans_gamma_effective = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_gamma_effective"] +) +EAGLEfloor_cool_rho_norm = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_density_threshold_H_p_cm3"] +) +EAGLEfloor_cool_temperature_norm_K = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_temperature_norm_K"] +) +EAGLEfloor_cool_gamma_effective = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_gamma_effective"] +) # Properties of the KS law -KS_law_norm_cgs = KS_law_norm * Msun_in_cgs / ( 1e6 * pc_in_cgs**2 * year_in_cgs ) -gamma = 5./3. +KS_law_norm_cgs = KS_law_norm * Msun_in_cgs / (1e6 * pc_in_cgs ** 2 * year_in_cgs) +gamma = 5.0 / 3.0 EOS_press_norm = k_in_cgs * EOS_temp_norm * EOS_density_norm # Star formation threshold -SF_thresh = KS_thresh_norm * (EAGLE_Z / KS_thresh_Z0)**(KS_thresh_slope) +SF_thresh = KS_thresh_norm * (EAGLE_Z / KS_thresh_Z0) ** (KS_thresh_slope) # Read gas properties gas_pos = f["/PartType0/Coordinates"][:, :] gas_mass = f["/PartType0/Masses"][:] -gas_rho = f["/PartType0/Density"][:] +gas_rho = f["/PartType0/Densities"][:] gas_T = f["/PartType0/Temperature"][:] gas_SFR = f["/PartType0/SFR"][:] -gas_XH = f["/PartType0/ElementAbundance"][:, 0] -gas_Z = f["/PartType0/Metallicity"][:] -gas_hsml = f["/PartType0/SmoothingLength"][:] +gas_XH = f["/PartType0/ElementMassFractions"][:, 0] +gas_Z = f["/PartType0/Metallicities"][:] +gas_hsml = f["/PartType0/SmoothingLengths"][:] gas_sSFR = gas_SFR / gas_mass # Read the Star properties stars_pos = f["/PartType4/Coordinates"][:, :] stars_BirthDensity = f["/PartType4/BirthDensity"][:] stars_BirthTime = f["/PartType4/BirthTime"][:] -stars_XH = f["/PartType4/ElementAbundance"][:,0] +stars_XH = f["/PartType4/ElementAbundance"][:, 0] # Centre the box gas_pos[:, 0] -= centre[0] gas_pos[:, 1] -= centre[1] gas_pos[:, 2] -= centre[2] -stars_pos[:,0] -= centre[0] -stars_pos[:,1] -= centre[1] -stars_pos[:,2] -= centre[2] +stars_pos[:, 0] -= centre[0] +stars_pos[:, 1] -= centre[1] +stars_pos[:, 2] -= centre[2] # Turn the mass into better units gas_mass *= unit_mass_in_cgs / Msun_in_cgs @@ -132,9 +160,13 @@ stars_BirthDensity *= stars_XH # Equations of state eos_cool_rho = np.logspace(-5, 5, 1000) -eos_cool_T = EAGLEfloor_cool_temperature_norm_K * (eos_cool_rho / EAGLEfloor_cool_rho_norm) ** ( EAGLEfloor_cool_gamma_effective - 1.0 ) +eos_cool_T = EAGLEfloor_cool_temperature_norm_K * ( + eos_cool_rho / EAGLEfloor_cool_rho_norm +) ** (EAGLEfloor_cool_gamma_effective - 1.0) eos_Jeans_rho = np.logspace(-1, 5, 1000) -eos_Jeans_T = EAGLEfloor_Jeans_temperature_norm_K * (eos_Jeans_rho / EAGLEfloor_Jeans_rho_norm) ** (EAGLEfloor_Jeans_gamma_effective - 1.0 ) +eos_Jeans_T = EAGLEfloor_Jeans_temperature_norm_K * ( + eos_Jeans_rho / EAGLEfloor_Jeans_rho_norm +) ** (EAGLEfloor_Jeans_gamma_effective - 1.0) ########################################################################3 @@ -156,7 +188,15 @@ subplot(111, xscale="log", yscale="log") plot(eos_cool_rho, eos_cool_T, "k--", lw=0.6) plot(eos_Jeans_rho, eos_Jeans_T, "k--", lw=0.6) plot([SF_thresh, SF_thresh], [1, 1e10], "k:", lw=0.6) -text(SF_thresh*0.9, 2e4, "$n_{\\rm H, thresh}=%.3f~{\\rm cm^{-3}}$"%SF_thresh, fontsize=8, rotation=90, ha="right", va="bottom") +text( + SF_thresh * 0.9, + 2e4, + "$n_{\\rm H, thresh}=%.3f~{\\rm cm^{-3}}$" % SF_thresh, + fontsize=8, + rotation=90, + ha="right", + va="bottom", +) scatter(gas_nH[gas_SFR > 0.0], gas_T[gas_SFR > 0.0], s=0.2) xlabel("${\\rm Density}~n_{\\rm H}~[{\\rm cm^{-3}}]$", labelpad=0) ylabel("${\\rm Temperature}~T~[{\\rm K}]$", labelpad=2) @@ -188,37 +228,61 @@ star_mask = ( & (stars_pos[:, 2] > -1.0) ) -stars_BirthDensity = stars_BirthDensity[star_mask] -#stars_BirthFlag = stars_BirthFlag[star_mask] +stars_BirthDensity = stars_BirthDensity[star_mask] +# stars_BirthFlag = stars_BirthFlag[star_mask] stars_BirthTime = stars_BirthTime[star_mask] # Histogram of the birth density figure() subplot(111, xscale="linear", yscale="linear") -hist(np.log10(stars_BirthDensity),density=True,bins=20,range=[-2,5]) +hist(np.log10(stars_BirthDensity), density=True, bins=20, range=[-2, 5]) xlabel("${\\rm Stellar~birth~density}~n_{\\rm H}~[{\\rm cm^{-3}}]$", labelpad=0) ylabel("${\\rm Probability}$", labelpad=-7) savefig("BirthDensity.png", dpi=200) # Plot of the specific star formation rate in the galaxy -rhos = 10**np.linspace(-1,np.log10(KS_high_den_thresh),100) -rhoshigh = 10**np.linspace(np.log10(KS_high_den_thresh),5,100) +rhos = 10 ** np.linspace(-1, np.log10(KS_high_den_thresh), 100) +rhoshigh = 10 ** np.linspace(np.log10(KS_high_den_thresh), 5, 100) -P_effective = EOS_press_norm * ( rhos / EOS_density_norm)**(EOS_gamma_effective) -P_norm_high = EOS_press_norm * (KS_high_den_thresh / EOS_density_norm)**(EOS_gamma_effective) -sSFR = KS_law_norm_cgs * (Msun_p_pc2)**(-KS_law_slope) * (gamma/G_in_cgs * KS_gas_fraction *P_effective)**((KS_law_slope-1.)/2.) -KS_law_norm_high_den_cgs = KS_law_norm_cgs * (Msun_p_pc2)**(-KS_law_slope) * (gamma/G_in_cgs * KS_gas_fraction * P_norm_high)**((KS_law_slope-1.)/2.) -sSFR_high_den = KS_law_norm_high_den_cgs * ((rhoshigh/KS_high_den_thresh)**EOS_gamma_effective)**((KS_law_slope_high_den-1)/2.) +P_effective = EOS_press_norm * (rhos / EOS_density_norm) ** (EOS_gamma_effective) +P_norm_high = EOS_press_norm * (KS_high_den_thresh / EOS_density_norm) ** ( + EOS_gamma_effective +) +sSFR = ( + KS_law_norm_cgs + * (Msun_p_pc2) ** (-KS_law_slope) + * (gamma / G_in_cgs * KS_gas_fraction * P_effective) ** ((KS_law_slope - 1.0) / 2.0) +) +KS_law_norm_high_den_cgs = ( + KS_law_norm_cgs + * (Msun_p_pc2) ** (-KS_law_slope) + * (gamma / G_in_cgs * KS_gas_fraction * P_norm_high) ** ((KS_law_slope - 1.0) / 2.0) +) +sSFR_high_den = KS_law_norm_high_den_cgs * ( + (rhoshigh / KS_high_den_thresh) ** EOS_gamma_effective +) ** ((KS_law_slope_high_den - 1) / 2.0) # density - sSFR plane figure() subplot(111) -hist2d(np.log10(gas_nH), np.log10(gas_sSFR), bins=50,range=[[-1.5,5],[-.5,2.5]]) -plot(np.log10(rhos),np.log10(sSFR)+np.log10(year_in_cgs)+9.,'k--',label='sSFR low density EAGLE') -plot(np.log10(rhoshigh),np.log10(sSFR_high_den)+np.log10(year_in_cgs)+9.,'k--',label='sSFR high density EAGLE') +hist2d(np.log10(gas_nH), np.log10(gas_sSFR), bins=50, range=[[-1.5, 5], [-0.5, 2.5]]) +plot( + np.log10(rhos), + np.log10(sSFR) + np.log10(year_in_cgs) + 9.0, + "k--", + label="sSFR low density EAGLE", +) +plot( + np.log10(rhoshigh), + np.log10(sSFR_high_den) + np.log10(year_in_cgs) + 9.0, + "k--", + label="sSFR high density EAGLE", +) xlabel("${\\rm Density}~n_{\\rm H}~[{\\rm cm^{-3}}]$", labelpad=2) ylabel("${\\rm sSFR}~[{\\rm Gyr^{-1}}]$", labelpad=0) -xticks([-1, 0, 1, 2, 3, 4], ["$10^{-1}$", "$10^0$", "$10^1$", "$10^2$", "$10^3$", "$10^4$"]) +xticks( + [-1, 0, 1, 2, 3, 4], ["$10^{-1}$", "$10^0$", "$10^1$", "$10^2$", "$10^3$", "$10^4$"] +) yticks([0, 1, 2], ["$10^0$", "$10^1$", "$10^2$"]) xlim(-1.4, 4.9) ylim(-0.5, 2.2) diff --git a/examples/IsolatedGalaxy/IsolatedGalaxy_feedback/plot_box_evolution.py b/examples/IsolatedGalaxy/IsolatedGalaxy_feedback/plot_box_evolution.py index 67da3c390be1240323941b835e056dcd6e27feed..94f27c87ff46c48ffc6b0df8c3e02c7abb6df875 100644 --- a/examples/IsolatedGalaxy/IsolatedGalaxy_feedback/plot_box_evolution.py +++ b/examples/IsolatedGalaxy/IsolatedGalaxy_feedback/plot_box_evolution.py @@ -1,24 +1,25 @@ ############################################################################### - # This file is part of SWIFT. - # Copyright (c) 2015 Bert Vandenbroucke (bert.vandenbroucke@ugent.be) - # Matthieu Schaller (matthieu.schaller@durham.ac.uk) - # - # This program is free software: you can redistribute it and/or modify - # it under the terms of the GNU Lesser General Public License as published - # by the Free Software Foundation, either version 3 of the License, or - # (at your option) any later version. - # - # This program is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - # GNU General Public License for more details. - # - # You should have received a copy of the GNU Lesser General Public License - # along with this program. If not, see <http://www.gnu.org/licenses/>. - # - ############################################################################## +# This file is part of SWIFT. +# Copyright (c) 2015 Bert Vandenbroucke (bert.vandenbroucke@ugent.be) +# Matthieu Schaller (matthieu.schaller@durham.ac.uk) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## import matplotlib + matplotlib.use("Agg") from pylab import * from scipy import stats @@ -27,40 +28,42 @@ import numpy as np import glob import os.path -def find_indices(a,b): - result = np.zeros(len(b)) - for i in range(len(b)): - result[i] = ((np.where(a == b[i]))[0])[0] - return result +def find_indices(a, b): + result = np.zeros(len(b)) + for i in range(len(b)): + result[i] = ((np.where(a == b[i]))[0])[0] + + return result # Plot parameters -params = {'axes.labelsize': 10, -'axes.titlesize': 10, -'font.size': 12, -'legend.fontsize': 12, -'xtick.labelsize': 10, -'ytick.labelsize': 10, -'text.usetex': True, - 'figure.figsize' : (9.90,6.45), -'figure.subplot.left' : 0.1, -'figure.subplot.right' : 0.99, -'figure.subplot.bottom' : 0.1, -'figure.subplot.top' : 0.95, -'figure.subplot.wspace' : 0.2, -'figure.subplot.hspace' : 0.2, -'lines.markersize' : 6, -'lines.linewidth' : 3., -'text.latex.unicode': True +params = { + "axes.labelsize": 10, + "axes.titlesize": 10, + "font.size": 12, + "legend.fontsize": 12, + "xtick.labelsize": 10, + "ytick.labelsize": 10, + "text.usetex": True, + "figure.figsize": (9.90, 6.45), + "figure.subplot.left": 0.1, + "figure.subplot.right": 0.99, + "figure.subplot.bottom": 0.1, + "figure.subplot.top": 0.95, + "figure.subplot.wspace": 0.2, + "figure.subplot.hspace": 0.2, + "lines.markersize": 6, + "lines.linewidth": 3.0, + "text.latex.unicode": True, } rcParams.update(params) -rc('font',**{'family':'sans-serif','sans-serif':['Times']}) +rc("font", **{"family": "sans-serif", "sans-serif": ["Times"]}) # Number of snapshots and elements -newest_snap_name = max(glob.glob('output_*.hdf5'), key=os.path.getctime) -n_snapshots = int(newest_snap_name.replace('output_','').replace('.hdf5','')) + 1 +newest_snap_name = max(glob.glob("output_*.hdf5"), key=os.path.getctime) +n_snapshots = int(newest_snap_name.replace("output_", "").replace(".hdf5", "")) + 1 n_elements = 9 # Read the simulation data @@ -84,10 +87,10 @@ unit_energy_in_cgs = unit_mass_in_cgs * unit_vel_in_cgs * unit_vel_in_cgs unit_length_in_si = 0.01 * unit_length_in_cgs unit_mass_in_si = 0.001 * unit_mass_in_cgs unit_time_in_si = unit_time_in_cgs -unit_density_in_cgs = unit_mass_in_cgs*unit_length_in_cgs**-3 -unit_pressure_in_cgs = unit_mass_in_cgs/unit_length_in_cgs*unit_time_in_cgs**-2 -unit_int_energy_in_cgs = unit_energy_in_cgs/unit_mass_in_cgs -unit_entropy_in_cgs = unit_energy_in_cgs/unit_temp_in_cgs +unit_density_in_cgs = unit_mass_in_cgs * unit_length_in_cgs ** -3 +unit_pressure_in_cgs = unit_mass_in_cgs / unit_length_in_cgs * unit_time_in_cgs ** -2 +unit_int_energy_in_cgs = unit_energy_in_cgs / unit_mass_in_cgs +unit_entropy_in_cgs = unit_energy_in_cgs / unit_temp_in_cgs Gyr_in_cgs = 3.155e16 Msun_in_cgs = 1.989e33 @@ -95,61 +98,111 @@ box_energy = zeros(n_snapshots) box_mass = zeros(n_snapshots) box_star_mass = zeros(n_snapshots) box_metal_mass = zeros(n_snapshots) -element_mass = zeros((n_snapshots,n_elements)) +element_mass = zeros((n_snapshots, n_elements)) t = zeros(n_snapshots) # Read data from snapshots for i in range(n_snapshots): - print("reading snapshot "+str(i)) - # Read the simulation data - sim = h5py.File("output_%04d.hdf5"%i, "r") - t[i] = sim["/Header"].attrs["Time"][0] - #ids = sim["/PartType0/ParticleIDs"][:] - - masses = sim["/PartType0/Masses"][:] - box_mass[i] = np.sum(masses) - - star_masses = sim["/PartType4/Masses"][:] - box_star_mass[i] = np.sum(star_masses) - - metallicities = sim["/PartType0/Metallicity"][:] - box_metal_mass[i] = np.sum(metallicities * masses) - - internal_energies = sim["/PartType0/InternalEnergy"][:] - box_energy[i] = np.sum(masses * internal_energies) + print("reading snapshot " + str(i)) + # Read the simulation data + sim = h5py.File("output_%04d.hdf5" % i, "r") + t[i] = sim["/Header"].attrs["Time"][0] + # ids = sim["/PartType0/ParticleIDs"][:] + + masses = sim["/PartType0/Masses"][:] + box_mass[i] = np.sum(masses) + + star_masses = sim["/PartType4/Masses"][:] + box_star_mass[i] = np.sum(star_masses) + + metallicities = sim["/PartType0/Metallicities"][:] + box_metal_mass[i] = np.sum(metallicities * masses) + + internal_energies = sim["/PartType0/InternalEnergies"][:] + box_energy[i] = np.sum(masses * internal_energies) # Plot the interesting quantities figure() # Box mass -------------------------------- subplot(221) -plot(t[1:] * unit_time_in_cgs / Gyr_in_cgs, (box_mass[1:] - box_mass[0])* unit_mass_in_cgs / Msun_in_cgs, linewidth=0.5, color='k', marker = "*", ms=0.5, label='swift') +plot( + t[1:] * unit_time_in_cgs / Gyr_in_cgs, + (box_mass[1:] - box_mass[0]) * unit_mass_in_cgs / Msun_in_cgs, + linewidth=0.5, + color="k", + marker="*", + ms=0.5, + label="swift", +) xlabel("${\\rm{Time}} (Gyr)$", labelpad=0) ylabel("Change in total gas particle mass (Msun)", labelpad=2) -ticklabel_format(style='sci', axis='y', scilimits=(0,0)) +ticklabel_format(style="sci", axis="y", scilimits=(0, 0)) # Box metal mass -------------------------------- subplot(222) -plot(t[1:] * unit_time_in_cgs / Gyr_in_cgs, (box_metal_mass[1:] - box_metal_mass[0])* unit_mass_in_cgs / Msun_in_cgs, linewidth=0.5, color='k', ms=0.5, label='swift') +plot( + t[1:] * unit_time_in_cgs / Gyr_in_cgs, + (box_metal_mass[1:] - box_metal_mass[0]) * unit_mass_in_cgs / Msun_in_cgs, + linewidth=0.5, + color="k", + ms=0.5, + label="swift", +) xlabel("${\\rm{Time}} (Gyr)$", labelpad=0) ylabel("Change in total metal mass of gas particles (Msun)", labelpad=2) -ticklabel_format(style='sci', axis='y', scilimits=(0,0)) +ticklabel_format(style="sci", axis="y", scilimits=(0, 0)) # Box energy -------------------------------- subplot(223) -plot(t[1:] * unit_time_in_cgs / Gyr_in_cgs, (box_energy[1:] - box_energy[0])* unit_energy_in_cgs, linewidth=0.5, color='k', ms=0.5, label='swift') +plot( + t[1:] * unit_time_in_cgs / Gyr_in_cgs, + (box_energy[1:] - box_energy[0]) * unit_energy_in_cgs, + linewidth=0.5, + color="k", + ms=0.5, + label="swift", +) xlabel("${\\rm{Time}} (Gyr)$", labelpad=0) ylabel("Change in total energy of gas particles (erg)", labelpad=2) -ticklabel_format(style='sci', axis='y', scilimits=(0,0)) +ticklabel_format(style="sci", axis="y", scilimits=(0, 0)) # Box mass -------------------------------- subplot(224) -plot(t[1:] * unit_time_in_cgs / Gyr_in_cgs, (box_mass[1:] - box_mass[0])* unit_mass_in_cgs / Msun_in_cgs, linewidth=0.5, color='k', marker = "*", ms=0.5, label='gas') -plot(t[1:] * unit_time_in_cgs / Gyr_in_cgs, (box_star_mass[1:] - box_star_mass[n_snapshots-1])* unit_mass_in_cgs / Msun_in_cgs, linewidth=0.5, color='r', marker = "*", ms=0.5, label='stars') -plot(t[1:] * unit_time_in_cgs / Gyr_in_cgs, (box_star_mass[1:] - box_star_mass[n_snapshots-1] + box_mass[1:] - box_mass[0])* unit_mass_in_cgs / Msun_in_cgs, linewidth=0.5, color='g', marker = "*", ms=0.5, label='total') +plot( + t[1:] * unit_time_in_cgs / Gyr_in_cgs, + (box_mass[1:] - box_mass[0]) * unit_mass_in_cgs / Msun_in_cgs, + linewidth=0.5, + color="k", + marker="*", + ms=0.5, + label="gas", +) +plot( + t[1:] * unit_time_in_cgs / Gyr_in_cgs, + (box_star_mass[1:] - box_star_mass[n_snapshots - 1]) + * unit_mass_in_cgs + / Msun_in_cgs, + linewidth=0.5, + color="r", + marker="*", + ms=0.5, + label="stars", +) +plot( + t[1:] * unit_time_in_cgs / Gyr_in_cgs, + (box_star_mass[1:] - box_star_mass[n_snapshots - 1] + box_mass[1:] - box_mass[0]) + * unit_mass_in_cgs + / Msun_in_cgs, + linewidth=0.5, + color="g", + marker="*", + ms=0.5, + label="total", +) xlabel("${\\rm{Time}} (Gyr)$", labelpad=0) ylabel("Change in total gas particle mass (Msun)", labelpad=2) -ticklabel_format(style='sci', axis='y', scilimits=(0,0)) +ticklabel_format(style="sci", axis="y", scilimits=(0, 0)) legend() savefig("box_evolution.png", dpi=200) diff --git a/examples/IsolatedGalaxy/IsolatedGalaxy_starformation/plotSolution.py b/examples/IsolatedGalaxy/IsolatedGalaxy_starformation/plotSolution.py index 73e4878e8e00a35fe19c359652be0d57153dea62..044ad2bc78958cbf669c7257122b1ff80a94ba1a 100644 --- a/examples/IsolatedGalaxy/IsolatedGalaxy_starformation/plotSolution.py +++ b/examples/IsolatedGalaxy/IsolatedGalaxy_starformation/plotSolution.py @@ -49,7 +49,7 @@ rcParams.update(params) rc("font", **{"family": "sans-serif", "sans-serif": ["Times"]}) snap = int(sys.argv[1]) -filename = "output_%.4d.hdf5"%snap +filename = "output_%.4d.hdf5" % snap f = h5.File(filename, "r") @@ -60,7 +60,7 @@ year_in_cgs = 3600.0 * 24 * 365.0 Msun_in_cgs = 1.98848e33 G_in_cgs = 6.67259e-8 pc_in_cgs = 3.08567758e18 -Msun_p_pc2 = Msun_in_cgs / pc_in_cgs**2 +Msun_p_pc2 = Msun_in_cgs / pc_in_cgs ** 2 # Gemoetry info boxsize = f["/Header"].attrs["BoxSize"] @@ -72,57 +72,85 @@ unit_mass_in_cgs = f["/Units"].attrs["Unit mass in cgs (U_M)"] unit_time_in_cgs = f["/Units"].attrs["Unit time in cgs (U_t)"] # Calculate Gravitational constant in internal units -G = G_in_cgs * ( unit_length_in_cgs**3 / unit_mass_in_cgs / unit_time_in_cgs**2)**(-1) +G = G_in_cgs * (unit_length_in_cgs ** 3 / unit_mass_in_cgs / unit_time_in_cgs ** 2) ** ( + -1 +) # Read parameters of the SF model KS_law_slope = float(f["/Parameters"].attrs["EAGLEStarFormation:KS_exponent"]) KS_law_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:KS_normalisation"]) KS_thresh_Z0 = float(f["/Parameters"].attrs["EAGLEStarFormation:threshold_Z0"]) KS_thresh_slope = float(f["/Parameters"].attrs["EAGLEStarFormation:threshold_slope"]) -KS_thresh_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:threshold_norm_H_p_cm3"]) +KS_thresh_norm = float( + f["/Parameters"].attrs["EAGLEStarFormation:threshold_norm_H_p_cm3"] +) KS_gas_fraction = float(f["/Parameters"].attrs["EAGLEStarFormation:gas_fraction"]) -KS_thresh_max_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:threshold_max_density_H_p_cm3"]) -KS_high_den_thresh = float(f["/Parameters"].attrs["EAGLEStarFormation:KS_high_density_threshold_H_p_cm3"]) -KS_law_slope_high_den = float(f["/Parameters"].attrs["EAGLEStarFormation:KS_high_density_exponent"]) -EOS_gamma_effective = float(f["/Parameters"].attrs["EAGLEStarFormation:EOS_gamma_effective"]) -EOS_density_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:EOS_density_norm_H_p_cm3"]) -EOS_temp_norm = float(f["/Parameters"].attrs["EAGLEStarFormation:EOS_temperature_norm_K"]) +KS_thresh_max_norm = float( + f["/Parameters"].attrs["EAGLEStarFormation:threshold_max_density_H_p_cm3"] +) +KS_high_den_thresh = float( + f["/Parameters"].attrs["EAGLEStarFormation:KS_high_density_threshold_H_p_cm3"] +) +KS_law_slope_high_den = float( + f["/Parameters"].attrs["EAGLEStarFormation:KS_high_density_exponent"] +) +EOS_gamma_effective = float( + f["/Parameters"].attrs["EAGLEStarFormation:EOS_gamma_effective"] +) +EOS_density_norm = float( + f["/Parameters"].attrs["EAGLEStarFormation:EOS_density_norm_H_p_cm3"] +) +EOS_temp_norm = float( + f["/Parameters"].attrs["EAGLEStarFormation:EOS_temperature_norm_K"] +) # Read reference metallicity EAGLE_Z = float(f["/Parameters"].attrs["EAGLEChemistry:init_abundance_metal"]) # Read parameters of the entropy floor -EAGLEfloor_Jeans_rho_norm = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_density_threshold_H_p_cm3"]) -EAGLEfloor_Jeans_temperature_norm_K = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_temperature_norm_K"]) -EAGLEfloor_Jeans_gamma_effective = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_gamma_effective"]) -EAGLEfloor_cool_rho_norm = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_density_threshold_H_p_cm3"]) -EAGLEfloor_cool_temperature_norm_K = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_temperature_norm_K"]) -EAGLEfloor_cool_gamma_effective = float(f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_gamma_effective"]) +EAGLEfloor_Jeans_rho_norm = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_density_threshold_H_p_cm3"] +) +EAGLEfloor_Jeans_temperature_norm_K = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_temperature_norm_K"] +) +EAGLEfloor_Jeans_gamma_effective = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Jeans_gamma_effective"] +) +EAGLEfloor_cool_rho_norm = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_density_threshold_H_p_cm3"] +) +EAGLEfloor_cool_temperature_norm_K = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_temperature_norm_K"] +) +EAGLEfloor_cool_gamma_effective = float( + f["/Parameters"].attrs["EAGLEEntropyFloor:Cool_gamma_effective"] +) # Properties of the KS law -KS_law_norm_cgs = KS_law_norm * Msun_in_cgs / ( 1e6 * pc_in_cgs**2 * year_in_cgs ) -gamma = 5./3. +KS_law_norm_cgs = KS_law_norm * Msun_in_cgs / (1e6 * pc_in_cgs ** 2 * year_in_cgs) +gamma = 5.0 / 3.0 EOS_press_norm = k_in_cgs * EOS_temp_norm * EOS_density_norm # Star formation threshold -SF_thresh = KS_thresh_norm * (EAGLE_Z / KS_thresh_Z0)**(KS_thresh_slope) +SF_thresh = KS_thresh_norm * (EAGLE_Z / KS_thresh_Z0) ** (KS_thresh_slope) # Read gas properties gas_pos = f["/PartType0/Coordinates"][:, :] gas_mass = f["/PartType0/Masses"][:] -gas_rho = f["/PartType0/Density"][:] +gas_rho = f["/PartType0/Densities"][:] gas_T = f["/PartType0/Temperature"][:] gas_SFR = f["/PartType0/SFR"][:] -gas_XH = f["/PartType0/ElementAbundance"][:, 0] -gas_Z = f["/PartType0/Metallicity"][:] -gas_hsml = f["/PartType0/SmoothingLength"][:] +gas_XH = f["/PartType0/ElementMassFractions"][:, 0] +gas_Z = f["/PartType0/Metallicities"][:] +gas_hsml = f["/PartType0/SmoothingLengths"][:] gas_sSFR = gas_SFR / gas_mass # Read the Star properties stars_pos = f["/PartType4/Coordinates"][:, :] stars_BirthDensity = f["/PartType4/BirthDensity"][:] stars_BirthTime = f["/PartType4/BirthTime"][:] -stars_XH = f["/PartType4/ElementAbundance"][:,0] +stars_XH = f["/PartType4/ElementAbundance"][:, 0] stars_BirthTemperature = f["/PartType4/BirthTemperature"][:] # Centre the box @@ -130,9 +158,9 @@ gas_pos[:, 0] -= centre[0] gas_pos[:, 1] -= centre[1] gas_pos[:, 2] -= centre[2] -stars_pos[:,0] -= centre[0] -stars_pos[:,1] -= centre[1] -stars_pos[:,2] -= centre[2] +stars_pos[:, 0] -= centre[0] +stars_pos[:, 1] -= centre[1] +stars_pos[:, 2] -= centre[2] # Turn the mass into better units gas_mass *= unit_mass_in_cgs / Msun_in_cgs @@ -156,9 +184,13 @@ stars_BirthDensity *= stars_XH # Equations of state eos_cool_rho = np.logspace(-5, 5, 1000) -eos_cool_T = EAGLEfloor_cool_temperature_norm_K * (eos_cool_rho / EAGLEfloor_cool_rho_norm) ** ( EAGLEfloor_cool_gamma_effective - 1.0 ) +eos_cool_T = EAGLEfloor_cool_temperature_norm_K * ( + eos_cool_rho / EAGLEfloor_cool_rho_norm +) ** (EAGLEfloor_cool_gamma_effective - 1.0) eos_Jeans_rho = np.logspace(-1, 5, 1000) -eos_Jeans_T = EAGLEfloor_Jeans_temperature_norm_K * (eos_Jeans_rho / EAGLEfloor_Jeans_rho_norm) ** (EAGLEfloor_Jeans_gamma_effective - 1.0 ) +eos_Jeans_T = EAGLEfloor_Jeans_temperature_norm_K * ( + eos_Jeans_rho / EAGLEfloor_Jeans_rho_norm +) ** (EAGLEfloor_Jeans_gamma_effective - 1.0) ########################################################################3 @@ -180,7 +212,15 @@ subplot(111, xscale="log", yscale="log") plot(eos_cool_rho, eos_cool_T, "k--", lw=0.6) plot(eos_Jeans_rho, eos_Jeans_T, "k--", lw=0.6) plot([SF_thresh, SF_thresh], [1, 1e10], "k:", lw=0.6) -text(SF_thresh*0.9, 2e4, "$n_{\\rm H, thresh}=%.3f~{\\rm cm^{-3}}$"%SF_thresh, fontsize=8, rotation=90, ha="right", va="bottom") +text( + SF_thresh * 0.9, + 2e4, + "$n_{\\rm H, thresh}=%.3f~{\\rm cm^{-3}}$" % SF_thresh, + fontsize=8, + rotation=90, + ha="right", + va="bottom", +) scatter(gas_nH[gas_SFR > 0.0], gas_T[gas_SFR > 0.0], s=0.2) xlabel("${\\rm Density}~n_{\\rm H}~[{\\rm cm^{-3}}]$", labelpad=0) ylabel("${\\rm Temperature}~T~[{\\rm K}]$", labelpad=2) @@ -199,66 +239,92 @@ star_mask = ( & (stars_pos[:, 2] > -1.0) ) -stars_BirthDensity = stars_BirthDensity[star_mask] -#stars_BirthFlag = stars_BirthFlag[star_mask] +stars_BirthDensity = stars_BirthDensity[star_mask] +# stars_BirthFlag = stars_BirthFlag[star_mask] stars_BirthTime = stars_BirthTime[star_mask] # Histogram of the birth density figure() subplot(111, xscale="linear", yscale="linear") -hist(np.log10(stars_BirthDensity),density=True,bins=20,range=[-2,5]) +hist(np.log10(stars_BirthDensity), density=True, bins=20, range=[-2, 5]) xlabel("${\\rm Stellar~birth~density}~n_{\\rm H}~[{\\rm cm^{-3}}]$", labelpad=0) ylabel("${\\rm Probability}$", labelpad=3) savefig("BirthDensity.png", dpi=200) -# Histogram of the birth temperature +# Histogram of the birth temperature figure() subplot(111, xscale="linear", yscale="linear") -hist(np.log10(stars_BirthTemperature),density=True,bins=20,range=[3.5,5.0]) +hist(np.log10(stars_BirthTemperature), density=True, bins=20, range=[3.5, 5.0]) xlabel("${\\rm Stellar~birth~temperature}~[{\\rm K}]$", labelpad=0) ylabel("${\\rm Probability}$", labelpad=3) savefig("BirthTemperature.png", dpi=200) # Plot of the specific star formation rate in the galaxy -rhos = 10**np.linspace(-1,np.log10(KS_high_den_thresh),100) -rhoshigh = 10**np.linspace(np.log10(KS_high_den_thresh),5,100) +rhos = 10 ** np.linspace(-1, np.log10(KS_high_den_thresh), 100) +rhoshigh = 10 ** np.linspace(np.log10(KS_high_den_thresh), 5, 100) -P_effective = EOS_press_norm * ( rhos / EOS_density_norm)**(EOS_gamma_effective) -P_norm_high = EOS_press_norm * (KS_high_den_thresh / EOS_density_norm)**(EOS_gamma_effective) -sSFR = KS_law_norm_cgs * (Msun_p_pc2)**(-KS_law_slope) * (gamma/G_in_cgs * KS_gas_fraction *P_effective)**((KS_law_slope-1.)/2.) -KS_law_norm_high_den_cgs = KS_law_norm_cgs * (Msun_p_pc2)**(-KS_law_slope) * (gamma/G_in_cgs * KS_gas_fraction * P_norm_high)**((KS_law_slope-1.)/2.) -sSFR_high_den = KS_law_norm_high_den_cgs * ((rhoshigh/KS_high_den_thresh)**EOS_gamma_effective)**((KS_law_slope_high_den-1)/2.) +P_effective = EOS_press_norm * (rhos / EOS_density_norm) ** (EOS_gamma_effective) +P_norm_high = EOS_press_norm * (KS_high_den_thresh / EOS_density_norm) ** ( + EOS_gamma_effective +) +sSFR = ( + KS_law_norm_cgs + * (Msun_p_pc2) ** (-KS_law_slope) + * (gamma / G_in_cgs * KS_gas_fraction * P_effective) ** ((KS_law_slope - 1.0) / 2.0) +) +KS_law_norm_high_den_cgs = ( + KS_law_norm_cgs + * (Msun_p_pc2) ** (-KS_law_slope) + * (gamma / G_in_cgs * KS_gas_fraction * P_norm_high) ** ((KS_law_slope - 1.0) / 2.0) +) +sSFR_high_den = KS_law_norm_high_den_cgs * ( + (rhoshigh / KS_high_den_thresh) ** EOS_gamma_effective +) ** ((KS_law_slope_high_den - 1) / 2.0) # density - sSFR plane figure() subplot(111) -hist2d(np.log10(gas_nH), np.log10(gas_sSFR), bins=50,range=[[-1.5,5],[-.5,2.5]]) -plot(np.log10(rhos),np.log10(sSFR)+np.log10(year_in_cgs)+9.,'k--',label='sSFR low density EAGLE') -plot(np.log10(rhoshigh),np.log10(sSFR_high_den)+np.log10(year_in_cgs)+9.,'k--',label='sSFR high density EAGLE') +hist2d(np.log10(gas_nH), np.log10(gas_sSFR), bins=50, range=[[-1.5, 5], [-0.5, 2.5]]) +plot( + np.log10(rhos), + np.log10(sSFR) + np.log10(year_in_cgs) + 9.0, + "k--", + label="sSFR low density EAGLE", +) +plot( + np.log10(rhoshigh), + np.log10(sSFR_high_den) + np.log10(year_in_cgs) + 9.0, + "k--", + label="sSFR high density EAGLE", +) xlabel("${\\rm Density}~n_{\\rm H}~[{\\rm cm^{-3}}]$", labelpad=2) ylabel("${\\rm sSFR}~[{\\rm Gyr^{-1}}]$", labelpad=0) -xticks([-1, 0, 1, 2, 3, 4], ["$10^{-1}$", "$10^0$", "$10^1$", "$10^2$", "$10^3$", "$10^4$"]) +xticks( + [-1, 0, 1, 2, 3, 4], ["$10^{-1}$", "$10^0$", "$10^1$", "$10^2$", "$10^3$", "$10^4$"] +) yticks([0, 1, 2], ["$10^0$", "$10^1$", "$10^2$"]) xlim(-1.4, 4.9) ylim(-0.5, 2.2) savefig("density-sSFR.png", dpi=200) -SFR_low = 10**(np.log10(sSFR)+np.log10(year_in_cgs)+np.log10(median_gas_mass)) -SFR_high = 10**(np.log10(sSFR_high_den)+np.log10(year_in_cgs)+np.log10(median_gas_mass)) -SFR_low_min = np.floor(np.log10(.75*np.min(SFR_low))) -SFR_high_max = np.ceil(np.log10(1.25*np.max(SFR_high))) +SFR_low = 10 ** (np.log10(sSFR) + np.log10(year_in_cgs) + np.log10(median_gas_mass)) +SFR_high = 10 ** ( + np.log10(sSFR_high_den) + np.log10(year_in_cgs) + np.log10(median_gas_mass) +) +SFR_low_min = np.floor(np.log10(0.75 * np.min(SFR_low))) +SFR_high_max = np.ceil(np.log10(1.25 * np.max(SFR_high))) # 3D Density vs SFR rcParams.update({"figure.subplot.left": 0.18}) figure() subplot(111, xscale="log", yscale="log") scatter(gas_nH, gas_SFR, s=0.2) -plot(rhos,SFR_low,'k--',lw=1,label='SFR low density EAGLE') -plot(rhoshigh,SFR_high,'k--',lw=1,label='SFR high density EAGLE') +plot(rhos, SFR_low, "k--", lw=1, label="SFR low density EAGLE") +plot(rhoshigh, SFR_high, "k--", lw=1, label="SFR high density EAGLE") xlabel("${\\rm Density}~n_{\\rm H}~[{\\rm cm^{-3}}]$", labelpad=0) ylabel("${\\rm SFR}~[{\\rm M_\\odot~\\cdot~yr^{-1}}]$", labelpad=2) xlim(1e-2, 1e5) -ylim(10**SFR_low_min, 10**(SFR_high_max+0.1)) +ylim(10 ** SFR_low_min, 10 ** (SFR_high_max + 0.1)) savefig("rho_SFR.png", dpi=200) rcParams.update({"figure.subplot.left": 0.15}) ########################################################################3 diff --git a/examples/SantaBarbara/SantaBarbara-256/plotTempEvolution.py b/examples/SantaBarbara/SantaBarbara-256/plotTempEvolution.py index dab4b2c90a7b751c8d143ed38c614473c951988a..63e46ccaee7be9ea18090e13ae15bb0a1fae4bef 100644 --- a/examples/SantaBarbara/SantaBarbara-256/plotTempEvolution.py +++ b/examples/SantaBarbara/SantaBarbara-256/plotTempEvolution.py @@ -128,7 +128,7 @@ for i in range(n_snapshots): z[i] = sim["/Cosmology"].attrs["Redshift"][0] a[i] = sim["/Cosmology"].attrs["Scale-factor"][0] - u = sim["/PartType0/InternalEnergy"][:] + u = sim["/PartType0/InternalEnergies"][:] # Compute the temperature u *= unit_length_in_si ** 2 / unit_time_in_si ** 2 diff --git a/examples/SantaBarbara/SantaBarbara-256/rhoTPlot.py b/examples/SantaBarbara/SantaBarbara-256/rhoTPlot.py index c290268eaa548e188bb652104ea9e726ea88a267..3bcf01d2a49bc1c53b243ffcff12359201d26d87 100644 --- a/examples/SantaBarbara/SantaBarbara-256/rhoTPlot.py +++ b/examples/SantaBarbara/SantaBarbara-256/rhoTPlot.py @@ -28,10 +28,10 @@ def get_data(filename): data = SWIFTDataset(filename) - data.gas.density.convert_to_units(mh / (cm ** 3)) - data.gas.temperature.convert_to_cgs() + data.gas.densities.convert_to_units(mh / (cm ** 3)) + data.gas.temperatures.convert_to_cgs() - return data.gas.density, data.gas.temperature + return data.gas.densities, data.gas.temperatures def make_hist(filename, density_bounds, temperature_bounds, bins): @@ -155,10 +155,8 @@ def make_movie(args, density_bounds, temperature_bounds, bins): def format_metadata(metadata: SWIFTMetadata): t = metadata.t * units.units["Unit time in cgs (U_t)"] t.convert_to_units(Gyr) - - x = "$a$: {:2.2f}\n$z$: {:2.2f}\n$t$: {:2.2f}".format( - metadata.a, metadata.z, t - ) + + x = "$a$: {:2.2f}\n$z$: {:2.2f}\n$t$: {:2.2f}".format(metadata.a, metadata.z, t) return x diff --git a/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/plotRhoT.py b/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/plotRhoT.py index 4ba8ad66daca1d9614be8917a77407dd99209dea..4f02213ec2a66700d28ad5f8e57e00c30f3019d7 100644 --- a/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/plotRhoT.py +++ b/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/plotRhoT.py @@ -112,8 +112,8 @@ def T(u, H_frac=H_mass_fraction, T_trans=H_transition_temp): return ret -rho = sim["/PartType0/Density"][:] -u = sim["/PartType0/InternalEnergy"][:] +rho = sim["/PartType0/Densities"][:] +u = sim["/PartType0/InternalEnergies"][:] # Compute the temperature u *= unit_length_in_si ** 2 / unit_time_in_si ** 2 diff --git a/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/plotTempEvolution.py b/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/plotTempEvolution.py index a3458ac1598e5657f3f597dfb10b36a7a641e68f..1e8cf9ea1082372d8e395c352f908c7ce693d99f 100644 --- a/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/plotTempEvolution.py +++ b/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/plotTempEvolution.py @@ -126,7 +126,7 @@ for i in range(n_snapshots): z[i] = sim["/Cosmology"].attrs["Redshift"][0] a[i] = sim["/Cosmology"].attrs["Scale-factor"][0] - u = sim["/PartType0/InternalEnergy"][:] + u = sim["/PartType0/InternalEnergies"][:] # Compute the temperature u *= (unit_length_in_si**2 / unit_time_in_si**2) diff --git a/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/small_cosmo_volume.yml b/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/small_cosmo_volume.yml index 94a9082af95e96b161cf5fe469eb082774e5007f..5050f9e05e278df25b050c10d9897e29d4e21804 100644 --- a/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/small_cosmo_volume.yml +++ b/examples/SmallCosmoVolume/SmallCosmoVolume_cooling/small_cosmo_volume.yml @@ -85,6 +85,16 @@ EAGLEChemistry: init_abundance_Silicon: 0.0 init_abundance_Iron: 0.0 +EAGLEEntropyFloor: + Jeans_density_threshold_H_p_cm3: 0.1 # Physical density above which the EAGLE Jeans limiter entropy floor kicks in expressed in Hydrogen atoms per cm^3. + Jeans_over_density_threshold: 10. # Overdensity above which the EAGLE Jeans limiter entropy floor can kick in. + Jeans_temperature_norm_K: 8000 # Temperature of the EAGLE Jeans limiter entropy floor at the density threshold expressed in Kelvin. + Jeans_gamma_effective: 1.3333333 # Slope the of the EAGLE Jeans limiter entropy floor + Cool_density_threshold_H_p_cm3: 1e-5 # Physical density above which the EAGLE Cool limiter entropy floor kicks in expressed in Hydrogen atoms per cm^3. + Cool_over_density_threshold: 10. # Overdensity above which the EAGLE Cool limiter entropy floor can kick in. + Cool_temperature_norm_K: 8000 # Temperature of the EAGLE Cool limiter entropy floor at the density threshold expressed in Kelvin. + Cool_gamma_effective: 1. # Slope the of the EAGLE Cool limiter entropy floor + # Cooling with Grackle 3.0 GrackleCooling: CloudyTable: CloudyData_UVB=HM2012.h5 # Name of the Cloudy Table (available on the grackle bitbucket repository) diff --git a/examples/SmallCosmoVolume/SmallCosmoVolume_hydro/plotTempEvolution.py b/examples/SmallCosmoVolume/SmallCosmoVolume_hydro/plotTempEvolution.py index aa6c5df5fe5ff5c7d0944a45bb11344f70c57844..d707f70450471f2d2fc589dbc382366280e0e7f3 100644 --- a/examples/SmallCosmoVolume/SmallCosmoVolume_hydro/plotTempEvolution.py +++ b/examples/SmallCosmoVolume/SmallCosmoVolume_hydro/plotTempEvolution.py @@ -123,7 +123,7 @@ for i in range(n_snapshots): z[i] = sim["/Cosmology"].attrs["Redshift"][0] a[i] = sim["/Cosmology"].attrs["Scale-factor"][0] - u = sim["/PartType0/InternalEnergy"][:] + u = sim["/PartType0/InternalEnergies"][:] # Compute the temperature u *= (unit_length_in_si**2 / unit_time_in_si**2) diff --git a/examples/SubgridTests/BlackHoleSwallowing/check_masses.py b/examples/SubgridTests/BlackHoleSwallowing/check_masses.py index c7f1d7b2c1f90efa285c13c75f0e5243f36e49ea..a5b55ed00df0851f989858ddffd00ea34df88a27 100644 --- a/examples/SubgridTests/BlackHoleSwallowing/check_masses.py +++ b/examples/SubgridTests/BlackHoleSwallowing/check_masses.py @@ -66,5 +66,5 @@ for i in range(np.size(ids_removed)): result = np.where(ids_gas == ids_removed) print result -#rho_gas = f["/PartType0/Density"][:] +#rho_gas = f["/PartType0/Densities"][:] #print np.mean(rho_gas), np.std(rho_gas) diff --git a/examples/SubgridTests/SmoothedMetallicity/plotSolution.py b/examples/SubgridTests/SmoothedMetallicity/plotSolution.py index e5bca3dfb7fe1e43c836733894c9e297cdd468ca..068fe5378e19c34ee8a68398f4e0ed096d0982e0 100644 --- a/examples/SubgridTests/SmoothedMetallicity/plotSolution.py +++ b/examples/SubgridTests/SmoothedMetallicity/plotSolution.py @@ -3,20 +3,20 @@ # This file is part of SWIFT. # Copyright (c) 2015 Bert Vandenbroucke (bert.vandenbroucke@ugent.be) # Matthieu Schaller (matthieu.schaller@durham.ac.uk) -# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# +# ############################################################################## # Computes the analytical solution of the 3D Smoothed Metallicity example. @@ -25,12 +25,13 @@ import h5py import sys import numpy as np import matplotlib + matplotlib.use("Agg") import matplotlib.pyplot as plt # Parameters -low_metal = -6 # low metal abundance -high_metal = -5 # High metal abundance +low_metal = -6 # low metal abundance +high_metal = -5 # High metal abundance sigma_metal = 0.1 # relative standard deviation for Z Nelem = 9 @@ -44,27 +45,27 @@ high_metal = [high_metal] * Nelem + np.linspace(0, 3, Nelem) # Plot parameters params = { - 'axes.labelsize': 10, - 'axes.titlesize': 10, - 'font.size': 12, - 'legend.fontsize': 12, - 'xtick.labelsize': 10, - 'ytick.labelsize': 10, - 'text.usetex': True, - 'figure.figsize': (9.90, 6.45), - 'figure.subplot.left': 0.045, - 'figure.subplot.right': 0.99, - 'figure.subplot.bottom': 0.05, - 'figure.subplot.top': 0.99, - 'figure.subplot.wspace': 0.15, - 'figure.subplot.hspace': 0.12, - 'lines.markersize': 6, - 'lines.linewidth': 3., - 'text.latex.unicode': True + "axes.labelsize": 10, + "axes.titlesize": 10, + "font.size": 12, + "legend.fontsize": 12, + "xtick.labelsize": 10, + "ytick.labelsize": 10, + "text.usetex": True, + "figure.figsize": (9.90, 6.45), + "figure.subplot.left": 0.045, + "figure.subplot.right": 0.99, + "figure.subplot.bottom": 0.05, + "figure.subplot.top": 0.99, + "figure.subplot.wspace": 0.15, + "figure.subplot.hspace": 0.12, + "lines.markersize": 6, + "lines.linewidth": 3.0, + "text.latex.unicode": True, } plt.rcParams.update(params) -plt.rc('font', **{'family': 'sans-serif', 'sans-serif': ['Times']}) +plt.rc("font", **{"family": "sans-serif", "sans-serif": ["Times"]}) snap = int(sys.argv[1]) @@ -83,18 +84,17 @@ git = sim["Code"].attrs["Git Revision"] pos = sim["/PartType0/Coordinates"][:, :] d = pos[:, 0] - boxSize / 2 -smooth_metal = sim["/PartType0/SmoothedElementAbundance"][:, :] -metal = sim["/PartType0/ElementAbundance"][:, :] -h = sim["/PartType0/SmoothingLength"][:] +smooth_metal = sim["/PartType0/SmoothedElementMassFractions"][:, :] +metal = sim["/PartType0/ElementMassFractions"][:, :] +h = sim["/PartType0/SmoothingLengths"][:] h = np.mean(h) -if (Nelem != metal.shape[1]): - print("Unexpected number of element, please check makeIC.py" - " and plotSolution.py") +if Nelem != metal.shape[1]: + print("Unexpected number of element, please check makeIC.py" " and plotSolution.py") exit(1) N = 1000 -d_a = np.linspace(-boxSize / 2., boxSize / 2., N) +d_a = np.linspace(-boxSize / 2.0, boxSize / 2.0, N) # Now, work our the solution.... @@ -142,14 +142,14 @@ def calc_a(d, high_metal, low_metal, std_dev, h): m = (high_metal[i] - low_metal[i]) / (2.0 * h) c = (high_metal[i] + low_metal[i]) / 2.0 # compute left linear part - s = d < - boxSize / 2.0 + h - a[s, i] = - m * (d[s] + boxSize / 2.0) + c + s = d < -boxSize / 2.0 + h + a[s, i] = -m * (d[s] + boxSize / 2.0) + c # compute middle linear part s = np.logical_and(d >= -h, d <= h) a[s, i] = m * d[s] + c # compute right linear part s = d > boxSize / 2.0 - h - a[s, i] = - m * (d[s] - boxSize / 2.0) + c + a[s, i] = -m * (d[s] - boxSize / 2.0) + c sigma[:, :, 0] = a * (1 + std_dev) sigma[:, :, 1] = a * (1 - std_dev) @@ -165,7 +165,7 @@ plt.figure() # Metallicity -------------------------------- plt.subplot(221) for e in range(Nelem): - plt.plot(metal[:, e], smooth_metal[:, e], '.', ms=0.5, alpha=0.2) + plt.plot(metal[:, e], smooth_metal[:, e], ".", ms=0.5, alpha=0.2) xmin, xmax = metal.min(), metal.max() ymin, ymax = smooth_metal.min(), smooth_metal.max() @@ -178,27 +178,28 @@ plt.ylabel("${\\rm{Smoothed~Metallicity}}~Z_\\textrm{sm}$", labelpad=0) # Metallicity -------------------------------- e = 0 plt.subplot(223) -plt.plot(d, smooth_metal[:, e], '.', color='r', ms=0.5, alpha=0.2) -plt.plot(d_a, sol[:, e], '--', color='b', alpha=0.8, lw=1.2) -plt.fill_between(d_a, sig[:, e, 0], sig[:, e, 1], facecolor="b", - interpolate=True, alpha=0.5) +plt.plot(d, smooth_metal[:, e], ".", color="r", ms=0.5, alpha=0.2) +plt.plot(d_a, sol[:, e], "--", color="b", alpha=0.8, lw=1.2) +plt.fill_between( + d_a, sig[:, e, 0], sig[:, e, 1], facecolor="b", interpolate=True, alpha=0.5 +) plt.xlabel("${\\rm{Distance}}~r$", labelpad=0) plt.ylabel("${\\rm{Smoothed~Metallicity}}~Z_\\textrm{sm}$", labelpad=0) plt.xlim(-0.5, 0.5) -plt.ylim(low_metal[e]-1, high_metal[e]+1) +plt.ylim(low_metal[e] - 1, high_metal[e] + 1) # Information ------------------------------------- plt.subplot(222, frameon=False) -plt.text(-0.49, 0.9, "Smoothed Metallicity in 3D at $t=%.2f$" % time, - fontsize=10) -plt.plot([-0.49, 0.1], [0.82, 0.82], 'k-', lw=1) +plt.text(-0.49, 0.9, "Smoothed Metallicity in 3D at $t=%.2f$" % time, fontsize=10) +plt.plot([-0.49, 0.1], [0.82, 0.82], "k-", lw=1) plt.text(-0.49, 0.7, "$\\textsc{Swift}$ %s" % git, fontsize=10) plt.text(-0.49, 0.6, scheme, fontsize=10) plt.text(-0.49, 0.5, kernel, fontsize=10) plt.text(-0.49, 0.4, chemistry + "'s Chemistry", fontsize=10) -plt.text(-0.49, 0.3, "$%.2f$ neighbours ($\\eta=%.3f$)" % (neighbours, eta), - fontsize=10) +plt.text( + -0.49, 0.3, "$%.2f$ neighbours ($\\eta=%.3f$)" % (neighbours, eta), fontsize=10 +) plt.xlim(-0.5, 0.5) plt.ylim(0, 1) plt.xticks([]) diff --git a/examples/SubgridTests/StellarEvolution/check_continuous_heating.py b/examples/SubgridTests/StellarEvolution/check_continuous_heating.py index f3c1b5d7fd682d914f2dbc05259c2dab0baf1e32..b5940eba43c89b8af4a883cc8f7022e33293b869 100644 --- a/examples/SubgridTests/StellarEvolution/check_continuous_heating.py +++ b/examples/SubgridTests/StellarEvolution/check_continuous_heating.py @@ -93,7 +93,7 @@ for i in range(n_snapshots): sim = h5py.File("stellar_evolution_%04d.hdf5"%i, "r") print('reading snapshot '+str(i)) masses[:,i] = sim["/PartType0/Masses"] - internal_energy[:,i] = sim["/PartType0/InternalEnergy"] + internal_energy[:,i] = sim["/PartType0/InternalEnergies"] velocity_parts[:,:,i] = sim["/PartType0/Velocities"] time[i] = sim["/Header"].attrs["Time"][0] diff --git a/examples/SubgridTests/StellarEvolution/check_stellar_evolution.py b/examples/SubgridTests/StellarEvolution/check_stellar_evolution.py index 02c1e9343de7b58cfddc8dee3bf0215a4b80ccf4..5680eb4d64f29ab32831d995e31ae9c27de82a71 100644 --- a/examples/SubgridTests/StellarEvolution/check_stellar_evolution.py +++ b/examples/SubgridTests/StellarEvolution/check_stellar_evolution.py @@ -1,4 +1,5 @@ import matplotlib + matplotlib.use("Agg") from pylab import * import h5py @@ -7,32 +8,35 @@ import numpy as np import glob # Number of snapshots and elements -newest_snap_name = max(glob.glob('stellar_evolution_*.hdf5'), key=os.path.getctime) -n_snapshots = int(newest_snap_name.replace('stellar_evolution_','').replace('.hdf5','')) + 1 +newest_snap_name = max(glob.glob("stellar_evolution_*.hdf5"), key=os.path.getctime) +n_snapshots = ( + int(newest_snap_name.replace("stellar_evolution_", "").replace(".hdf5", "")) + 1 +) n_elements = 9 # Plot parameters -params = {'axes.labelsize': 10, -'axes.titlesize': 10, -'font.size': 9, -'legend.fontsize': 9, -'xtick.labelsize': 10, -'ytick.labelsize': 10, -'text.usetex': True, - 'figure.figsize' : (3.15,3.15), -'figure.subplot.left' : 0.3, -'figure.subplot.right' : 0.99, -'figure.subplot.bottom' : 0.18, -'figure.subplot.top' : 0.92, -'figure.subplot.wspace' : 0.21, -'figure.subplot.hspace' : 0.19, -'lines.markersize' : 6, -'lines.linewidth' : 2., -'text.latex.unicode': True +params = { + "axes.labelsize": 10, + "axes.titlesize": 10, + "font.size": 9, + "legend.fontsize": 9, + "xtick.labelsize": 10, + "ytick.labelsize": 10, + "text.usetex": True, + "figure.figsize": (3.15, 3.15), + "figure.subplot.left": 0.3, + "figure.subplot.right": 0.99, + "figure.subplot.bottom": 0.18, + "figure.subplot.top": 0.92, + "figure.subplot.wspace": 0.21, + "figure.subplot.hspace": 0.19, + "lines.markersize": 6, + "lines.linewidth": 2.0, + "text.latex.unicode": True, } rcParams.update(params) -rc('font',**{'family':'sans-serif','sans-serif':['Times']}) +rc("font", **{"family": "sans-serif", "sans-serif": ["Times"]}) # Read the simulation data sim = h5py.File("stellar_evolution_0000.hdf5", "r") @@ -43,7 +47,9 @@ neighbours = sim["/HydroScheme"].attrs["Kernel target N_ngb"][0] eta = sim["/HydroScheme"].attrs["Kernel eta"][0] alpha = sim["/HydroScheme"].attrs["Alpha viscosity"][0] H_mass_fraction = sim["/HydroScheme"].attrs["Hydrogen mass fraction"][0] -H_transition_temp = sim["/HydroScheme"].attrs["Hydrogen ionization transition temperature"][0] +H_transition_temp = sim["/HydroScheme"].attrs[ + "Hydrogen ionization transition temperature" +][0] T_initial = sim["/HydroScheme"].attrs["Initial temperature"][0] T_minimal = sim["/HydroScheme"].attrs["Minimal temperature"][0] git = sim["Code"].attrs["Git Revision"] @@ -68,136 +74,245 @@ n_parts = sim["/Header"].attrs["NumPart_Total"][0] n_sparts = sim["/Header"].attrs["NumPart_Total"][4] # Declare arrays for data -masses = zeros((n_parts,n_snapshots)) -star_masses = zeros((n_sparts,n_snapshots)) -mass_from_AGB = zeros((n_parts,n_snapshots)) -metal_mass_frac_from_AGB = zeros((n_parts,n_snapshots)) -mass_from_SNII = zeros((n_parts,n_snapshots)) -metal_mass_frac_from_SNII = zeros((n_parts,n_snapshots)) -mass_from_SNIa = zeros((n_parts,n_snapshots)) -metal_mass_frac_from_SNIa = zeros((n_parts,n_snapshots)) -iron_mass_frac_from_SNIa = zeros((n_parts,n_snapshots)) -metallicity = zeros((n_parts,n_snapshots)) -abundances = zeros((n_parts,n_elements,n_snapshots)) -internal_energy = zeros((n_parts,n_snapshots)) -coord_parts = zeros((n_parts,3)) -velocity_parts = zeros((n_parts,3,n_snapshots)) +masses = zeros((n_parts, n_snapshots)) +star_masses = zeros((n_sparts, n_snapshots)) +mass_from_AGB = zeros((n_parts, n_snapshots)) +metal_mass_frac_from_AGB = zeros((n_parts, n_snapshots)) +mass_from_SNII = zeros((n_parts, n_snapshots)) +metal_mass_frac_from_SNII = zeros((n_parts, n_snapshots)) +mass_from_SNIa = zeros((n_parts, n_snapshots)) +metal_mass_frac_from_SNIa = zeros((n_parts, n_snapshots)) +iron_mass_frac_from_SNIa = zeros((n_parts, n_snapshots)) +metallicity = zeros((n_parts, n_snapshots)) +abundances = zeros((n_parts, n_elements, n_snapshots)) +internal_energy = zeros((n_parts, n_snapshots)) +coord_parts = zeros((n_parts, 3)) +velocity_parts = zeros((n_parts, 3, n_snapshots)) coord_sparts = zeros(3) time = zeros(n_snapshots) # Read fields we are checking from snapshots for i in range(n_snapshots): - sim = h5py.File("stellar_evolution_%04d.hdf5"%i, "r") - print('reading snapshot '+str(i)) - abundances[:,:,i] = sim["/PartType0/ElementAbundance"] - metallicity[:,i] = sim["/PartType0/Metallicity"] - masses[:,i] = sim["/PartType0/Masses"] - star_masses[:,i] = sim["/PartType4/Masses"] - mass_from_AGB[:,i] = sim["/PartType0/TotalMassFromAGB"] - metal_mass_frac_from_AGB[:,i] = sim["/PartType0/MetalMassFracFromAGB"] - mass_from_SNII[:,i] = sim["/PartType0/TotalMassFromSNII"] - metal_mass_frac_from_SNII[:,i] = sim["/PartType0/MetalMassFracFromSNII"] - mass_from_SNIa[:,i] = sim["/PartType0/TotalMassFromSNIa"] - metal_mass_frac_from_SNIa[:,i] = sim["/PartType0/MetalMassFracFromSNIa"] - iron_mass_frac_from_SNIa[:,i] = sim["/PartType0/IronMassFracFromSNIa"] - internal_energy[:,i] = sim["/PartType0/InternalEnergy"] - velocity_parts[:,:,i] = sim["/PartType0/Velocities"] - time[i] = sim["/Header"].attrs["Time"][0] + sim = h5py.File("stellar_evolution_%04d.hdf5" % i, "r") + print("reading snapshot " + str(i)) + abundances[:, :, i] = sim["/PartType0/ElementMassFractions"] + metallicity[:, i] = sim["/PartType0/Metallicities"] + masses[:, i] = sim["/PartType0/Masses"] + star_masses[:, i] = sim["/PartType4/Masses"] + mass_from_AGB[:, i] = sim["/PartType0/TotalMassFromAGB"] + metal_mass_frac_from_AGB[:, i] = sim["/PartType0/MetalMassFracFromAGB"] + mass_from_SNII[:, i] = sim["/PartType0/TotalMassFromSNII"] + metal_mass_frac_from_SNII[:, i] = sim["/PartType0/MetalMassFracFromSNII"] + mass_from_SNIa[:, i] = sim["/PartType0/TotalMassFromSNIa"] + metal_mass_frac_from_SNIa[:, i] = sim["/PartType0/MetalMassFracFromSNIa"] + iron_mass_frac_from_SNIa[:, i] = sim["/PartType0/IronMassFracFromSNIa"] + internal_energy[:, i] = sim["/PartType0/InternalEnergies"] + velocity_parts[:, :, i] = sim["/PartType0/Velocities"] + time[i] = sim["/Header"].attrs["Time"][0] # Define ejecta factor ejecta_factor = 1.0e-2 -ejecta_factor_metallicity = 1.0 - 2.0/n_elements -ejecta_factor_abundances = 1.0/n_elements +ejecta_factor_metallicity = 1.0 - 2.0 / n_elements +ejecta_factor_abundances = 1.0 / n_elements ejected_mass = star_initial_mass -energy_per_SNe = 1.0e51/unit_energy_in_cgs +energy_per_SNe = 1.0e51 / unit_energy_in_cgs # Check that the total amount of enrichment is as expected. # Define tolerance eps = 0.01 # Total mass -total_part_mass = np.sum(masses,axis = 0) -if abs((total_part_mass[n_snapshots-1] - total_part_mass[0])/total_part_mass[0] - ejected_mass/total_part_mass[0])*total_part_mass[0]/ejected_mass < eps: - print("total mass released consistent with expectation") +total_part_mass = np.sum(masses, axis=0) +if ( + abs( + (total_part_mass[n_snapshots - 1] - total_part_mass[0]) / total_part_mass[0] + - ejected_mass / total_part_mass[0] + ) + * total_part_mass[0] + / ejected_mass + < eps +): + print("total mass released consistent with expectation") else: - print("mass increase "+str(total_part_mass[n_snapshots-1]/total_part_mass[0])+" expected "+ str(1.0+ejected_mass/total_part_mass[0])) + print( + "mass increase " + + str(total_part_mass[n_snapshots - 1] / total_part_mass[0]) + + " expected " + + str(1.0 + ejected_mass / total_part_mass[0]) + ) # Check that mass is conserved (i.e. total star mass decreases by same amount as total gas mass increases) -total_spart_mass = np.sum(star_masses,axis = 0) -if abs((total_part_mass[n_snapshots-1] + total_spart_mass[n_snapshots-1]) / (total_part_mass[0] + total_spart_mass[0]) - 1.0) < eps**3: - print("total mass conserved") +total_spart_mass = np.sum(star_masses, axis=0) +if ( + abs( + (total_part_mass[n_snapshots - 1] + total_spart_mass[n_snapshots - 1]) + / (total_part_mass[0] + total_spart_mass[0]) + - 1.0 + ) + < eps ** 3 +): + print("total mass conserved") else: - print("initial part, spart mass " + str(total_part_mass[0]) + " " + str(total_spart_mass[0]) + " final mass " + str(total_part_mass[n_snapshots-1]) + " " + str(total_spart_mass[n_snapshots-1])) + print( + "initial part, spart mass " + + str(total_part_mass[0]) + + " " + + str(total_spart_mass[0]) + + " final mass " + + str(total_part_mass[n_snapshots - 1]) + + " " + + str(total_spart_mass[n_snapshots - 1]) + ) # Total metal mass from AGB -total_metal_mass_AGB = np.sum(np.multiply(metal_mass_frac_from_AGB,masses),axis = 0) -expected_metal_mass_AGB = ejecta_factor*ejected_mass -if abs(total_metal_mass_AGB[n_snapshots-1] - expected_metal_mass_AGB)/expected_metal_mass_AGB < eps: - print("total AGB metal mass released consistent with expectation") +total_metal_mass_AGB = np.sum(np.multiply(metal_mass_frac_from_AGB, masses), axis=0) +expected_metal_mass_AGB = ejecta_factor * ejected_mass +if ( + abs(total_metal_mass_AGB[n_snapshots - 1] - expected_metal_mass_AGB) + / expected_metal_mass_AGB + < eps +): + print("total AGB metal mass released consistent with expectation") else: - print("total AGB metal mass "+str(total_metal_mass_AGB[n_snapshots-1])+" expected "+ str(expected_metal_mass_AGB)) + print( + "total AGB metal mass " + + str(total_metal_mass_AGB[n_snapshots - 1]) + + " expected " + + str(expected_metal_mass_AGB) + ) # Total mass from AGB -total_AGB_mass = np.sum(mass_from_AGB,axis = 0) -expected_AGB_mass = ejecta_factor*ejected_mass -if abs(total_AGB_mass[n_snapshots-1] - expected_AGB_mass)/expected_AGB_mass < eps: - print("total AGB mass released consistent with expectation") +total_AGB_mass = np.sum(mass_from_AGB, axis=0) +expected_AGB_mass = ejecta_factor * ejected_mass +if abs(total_AGB_mass[n_snapshots - 1] - expected_AGB_mass) / expected_AGB_mass < eps: + print("total AGB mass released consistent with expectation") else: - print("total AGB mass "+str(total_AGB_mass[n_snapshots-1])+" expected "+ str(expected_AGB_mass)) + print( + "total AGB mass " + + str(total_AGB_mass[n_snapshots - 1]) + + " expected " + + str(expected_AGB_mass) + ) # Total metal mass from SNII -total_metal_mass_SNII = np.sum(np.multiply(metal_mass_frac_from_SNII,masses),axis = 0) -expected_metal_mass_SNII = ejecta_factor*ejected_mass -if abs(total_metal_mass_SNII[n_snapshots-1] - expected_metal_mass_SNII)/expected_metal_mass_SNII < eps: - print("total SNII metal mass released consistent with expectation") +total_metal_mass_SNII = np.sum(np.multiply(metal_mass_frac_from_SNII, masses), axis=0) +expected_metal_mass_SNII = ejecta_factor * ejected_mass +if ( + abs(total_metal_mass_SNII[n_snapshots - 1] - expected_metal_mass_SNII) + / expected_metal_mass_SNII + < eps +): + print("total SNII metal mass released consistent with expectation") else: - print("total SNII metal mass "+str(total_metal_mass_SNII[n_snapshots-1])+" expected "+ str(expected_metal_mass_SNII)) + print( + "total SNII metal mass " + + str(total_metal_mass_SNII[n_snapshots - 1]) + + " expected " + + str(expected_metal_mass_SNII) + ) # Total mass from SNII -total_SNII_mass = np.sum(mass_from_SNII,axis = 0) -expected_SNII_mass = ejecta_factor*ejected_mass -if abs(total_SNII_mass[n_snapshots-1] - expected_SNII_mass)/expected_SNII_mass < eps: - print("total SNII mass released consistent with expectation") +total_SNII_mass = np.sum(mass_from_SNII, axis=0) +expected_SNII_mass = ejecta_factor * ejected_mass +if ( + abs(total_SNII_mass[n_snapshots - 1] - expected_SNII_mass) / expected_SNII_mass + < eps +): + print("total SNII mass released consistent with expectation") else: - print("total SNII mass "+str(total_SNII_mass[n_snapshots-1])+" expected "+ str(expected_SNII_mass)) + print( + "total SNII mass " + + str(total_SNII_mass[n_snapshots - 1]) + + " expected " + + str(expected_SNII_mass) + ) # Total metal mass from SNIa -total_metal_mass_SNIa = np.sum(np.multiply(metal_mass_frac_from_SNIa,masses),axis = 0) -expected_metal_mass_SNIa = ejecta_factor*ejected_mass -if abs(total_metal_mass_SNIa[n_snapshots-1] - expected_metal_mass_SNIa)/expected_metal_mass_SNIa < eps: - print("total SNIa metal mass released consistent with expectation") +total_metal_mass_SNIa = np.sum(np.multiply(metal_mass_frac_from_SNIa, masses), axis=0) +expected_metal_mass_SNIa = ejecta_factor * ejected_mass +if ( + abs(total_metal_mass_SNIa[n_snapshots - 1] - expected_metal_mass_SNIa) + / expected_metal_mass_SNIa + < eps +): + print("total SNIa metal mass released consistent with expectation") else: - print("total SNIa metal mass "+str(total_metal_mass_SNIa[n_snapshots-1])+" expected "+ str(expected_metal_mass_SNIa)) + print( + "total SNIa metal mass " + + str(total_metal_mass_SNIa[n_snapshots - 1]) + + " expected " + + str(expected_metal_mass_SNIa) + ) # Total iron mass from SNIa -total_iron_mass_SNIa = np.sum(np.multiply(iron_mass_frac_from_SNIa,masses),axis = 0) -expected_iron_mass_SNIa = ejecta_factor*ejected_mass -if abs(total_iron_mass_SNIa[n_snapshots-1] - expected_iron_mass_SNIa)/expected_iron_mass_SNIa < eps: - print("total SNIa iron mass released consistent with expectation") +total_iron_mass_SNIa = np.sum(np.multiply(iron_mass_frac_from_SNIa, masses), axis=0) +expected_iron_mass_SNIa = ejecta_factor * ejected_mass +if ( + abs(total_iron_mass_SNIa[n_snapshots - 1] - expected_iron_mass_SNIa) + / expected_iron_mass_SNIa + < eps +): + print("total SNIa iron mass released consistent with expectation") else: - print("total SNIa iron mass "+str(total_iron_mass_SNIa[n_snapshots-1])+" expected "+ str(expected_iron_mass_SNIa)) + print( + "total SNIa iron mass " + + str(total_iron_mass_SNIa[n_snapshots - 1]) + + " expected " + + str(expected_iron_mass_SNIa) + ) # Total mass from SNIa -total_SNIa_mass = np.sum(mass_from_SNIa,axis = 0) -expected_SNIa_mass = ejecta_factor*ejected_mass -if abs(total_SNIa_mass[n_snapshots-1] - expected_SNIa_mass)/expected_SNIa_mass < eps: - print("total SNIa mass released consistent with expectation") +total_SNIa_mass = np.sum(mass_from_SNIa, axis=0) +expected_SNIa_mass = ejecta_factor * ejected_mass +if ( + abs(total_SNIa_mass[n_snapshots - 1] - expected_SNIa_mass) / expected_SNIa_mass + < eps +): + print("total SNIa mass released consistent with expectation") else: - print("total SNIa mass "+str(total_SNIa_mass[n_snapshots-1])+" expected "+ str(expected_SNIa_mass)) + print( + "total SNIa mass " + + str(total_SNIa_mass[n_snapshots - 1]) + + " expected " + + str(expected_SNIa_mass) + ) # Total metal mass -total_metal_mass = np.sum(np.multiply(metallicity,masses),axis = 0) -expected_metal_mass = ejecta_factor_metallicity*ejected_mass -if abs(total_metal_mass[n_snapshots-1] - expected_metal_mass)/expected_metal_mass < eps: - print("total metal mass released consistent with expectation") +total_metal_mass = np.sum(np.multiply(metallicity, masses), axis=0) +expected_metal_mass = ejecta_factor_metallicity * ejected_mass +if ( + abs(total_metal_mass[n_snapshots - 1] - expected_metal_mass) / expected_metal_mass + < eps +): + print("total metal mass released consistent with expectation") else: - print("total metal mass "+str(total_metal_mass[n_snapshots-1])+" expected "+ str(expected_metal_mass)) + print( + "total metal mass " + + str(total_metal_mass[n_snapshots - 1]) + + " expected " + + str(expected_metal_mass) + ) # Total mass for each element -expected_element_mass = ejecta_factor_abundances*ejected_mass +expected_element_mass = ejecta_factor_abundances * ejected_mass for i in range(n_elements): - total_element_mass = np.sum(np.multiply(abundances[:,i,:],masses),axis = 0) - if abs(total_element_mass[n_snapshots-1] - expected_element_mass)/expected_element_mass < eps: - print("total element mass released consistent with expectation for element "+str(i)) - else: - print("total element mass "+str(total_element_mass[n_snapshots-1])+" expected "+ str(expected_element_mass) + " for element "+ str(i)) + total_element_mass = np.sum(np.multiply(abundances[:, i, :], masses), axis=0) + if ( + abs(total_element_mass[n_snapshots - 1] - expected_element_mass) + / expected_element_mass + < eps + ): + print( + "total element mass released consistent with expectation for element " + + str(i) + ) + else: + print( + "total element mass " + + str(total_element_mass[n_snapshots - 1]) + + " expected " + + str(expected_element_mass) + + " for element " + + str(i) + ) + diff --git a/examples/SubgridTests/StellarEvolution/check_stochastic_heating.py b/examples/SubgridTests/StellarEvolution/check_stochastic_heating.py index da837540041a9295a33b55e16b5e996394576cd7..1cacc13653d821da3abd2a09566be347608c64f7 100644 --- a/examples/SubgridTests/StellarEvolution/check_stochastic_heating.py +++ b/examples/SubgridTests/StellarEvolution/check_stochastic_heating.py @@ -93,7 +93,7 @@ for i in range(n_snapshots): sim = h5py.File("stellar_evolution_%04d.hdf5"%i, "r") print('reading snapshot '+str(i)) masses[:,i] = sim["/PartType0/Masses"] - internal_energy[:,i] = sim["/PartType0/InternalEnergy"] + internal_energy[:,i] = sim["/PartType0/InternalEnergies"] velocity_parts[:,:,i] = sim["/PartType0/Velocities"] time[i] = sim["/Header"].attrs["Time"][0] diff --git a/examples/SubgridTests/StellarEvolution/plot_box_evolution.py b/examples/SubgridTests/StellarEvolution/plot_box_evolution.py index a46db721e153ade2d386a5790e26a290cead4f90..bcfa85a1afac021e280a797641dd677bccd291d3 100644 --- a/examples/SubgridTests/StellarEvolution/plot_box_evolution.py +++ b/examples/SubgridTests/StellarEvolution/plot_box_evolution.py @@ -112,16 +112,16 @@ for i in range(n_snapshots): star_masses = sim["/PartType4/Masses"][:] swift_box_star_mass[i] = np.sum(star_masses) - metallicities = sim["/PartType0/Metallicity"][:] + metallicities = sim["/PartType0/Metallicities"][:] swift_box_gas_metal_mass[i] = np.sum(metallicities * masses) - element_abundances = sim["/PartType0/ElementAbundance"][:][:] + element_abundances = sim["/PartType0/ElementMassFractions"][:][:] for j in range(n_elements): swift_element_mass[i,j] = np.sum(element_abundances[:,j] * masses) v = sim["/PartType0/Velocities"][:,:] v2 = v[:,0]**2 + v[:,1]**2 + v[:,2]**2 - u = sim["/PartType0/InternalEnergy"][:] + u = sim["/PartType0/InternalEnergies"][:] swift_internal_energy[i] = np.sum(masses * u) swift_kinetic_energy[i] = np.sum(0.5 * masses * v2) swift_total_energy[i] = swift_kinetic_energy[i] + swift_internal_energy[i] diff --git a/examples/SubgridTests/StellarEvolution/plot_particle_evolution.py b/examples/SubgridTests/StellarEvolution/plot_particle_evolution.py index 8b935e537b14a9d1d9cc4eec7c5cd0794c6fc489..be1588f9b707d448b2905611defd9e760c5f91de 100644 --- a/examples/SubgridTests/StellarEvolution/plot_particle_evolution.py +++ b/examples/SubgridTests/StellarEvolution/plot_particle_evolution.py @@ -1,29 +1,30 @@ ############################################################################### - # This file is part of SWIFT. - # Copyright (c) 2015 Bert Vandenbroucke (bert.vandenbroucke@ugent.be) - # Matthieu Schaller (matthieu.schaller@durham.ac.uk) - # - # This program is free software: you can redistribute it and/or modify - # it under the terms of the GNU Lesser General Public License as published - # by the Free Software Foundation, either version 3 of the License, or - # (at your option) any later version. - # - # This program is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - # GNU General Public License for more details. - # - # You should have received a copy of the GNU Lesser General Public License - # along with this program. If not, see <http://www.gnu.org/licenses/>. - # - ############################################################################## - -# Assuming output snapshots contain evolution of box of gas with star at its -# centre, this script will plot the evolution of the radial velocities, internal -# energies, mass and metallicities of the nearest n particles to the star over -# the duration of the simulation. +# This file is part of SWIFT. +# Copyright (c) 2015 Bert Vandenbroucke (bert.vandenbroucke@ugent.be) +# Matthieu Schaller (matthieu.schaller@durham.ac.uk) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +# Assuming output snapshots contain evolution of box of gas with star at its +# centre, this script will plot the evolution of the radial velocities, internal +# energies, mass and metallicities of the nearest n particles to the star over +# the duration of the simulation. import matplotlib + matplotlib.use("Agg") from pylab import * from scipy import stats @@ -33,38 +34,42 @@ import glob import os.path # Function to find index in array a for each element in array b -def find_indices(a,b): - result = np.zeros(len(b)) - for i in range(len(b)): - result[i] = ((np.where(a == b[i]))[0])[0] - return result +def find_indices(a, b): + result = np.zeros(len(b)) + for i in range(len(b)): + result[i] = ((np.where(a == b[i]))[0])[0] + return result + # Plot parameters -params = {'axes.labelsize': 10, -'axes.titlesize': 10, -'font.size': 12, -'legend.fontsize': 12, -'xtick.labelsize': 10, -'ytick.labelsize': 10, -'text.usetex': True, - 'figure.figsize' : (9.90,6.45), -'figure.subplot.left' : 0.1, -'figure.subplot.right' : 0.99, -'figure.subplot.bottom' : 0.1, -'figure.subplot.top' : 0.95, -'figure.subplot.wspace' : 0.2, -'figure.subplot.hspace' : 0.2, -'lines.markersize' : 6, -'lines.linewidth' : 3., -'text.latex.unicode': True +params = { + "axes.labelsize": 10, + "axes.titlesize": 10, + "font.size": 12, + "legend.fontsize": 12, + "xtick.labelsize": 10, + "ytick.labelsize": 10, + "text.usetex": True, + "figure.figsize": (9.90, 6.45), + "figure.subplot.left": 0.1, + "figure.subplot.right": 0.99, + "figure.subplot.bottom": 0.1, + "figure.subplot.top": 0.95, + "figure.subplot.wspace": 0.2, + "figure.subplot.hspace": 0.2, + "lines.markersize": 6, + "lines.linewidth": 3.0, + "text.latex.unicode": True, } rcParams.update(params) -rc('font',**{'family':'sans-serif','sans-serif':['Times']}) +rc("font", **{"family": "sans-serif", "sans-serif": ["Times"]}) # Number of snapshots and elements -newest_snap_name = max(glob.glob('stellar_evolution_*.hdf5'), key=os.path.getctime) -n_snapshots = int(newest_snap_name.replace('stellar_evolution_','').replace('.hdf5','')) + 1 +newest_snap_name = max(glob.glob("stellar_evolution_*.hdf5"), key=os.path.getctime) +n_snapshots = ( + int(newest_snap_name.replace("stellar_evolution_", "").replace(".hdf5", "")) + 1 +) n_particles_to_plot = 500 # Read the simulation data @@ -87,25 +92,25 @@ unit_energy_in_cgs = unit_mass_in_cgs * unit_vel_in_cgs * unit_vel_in_cgs unit_length_in_si = 0.01 * unit_length_in_cgs unit_mass_in_si = 0.001 * unit_mass_in_cgs unit_time_in_si = unit_time_in_cgs -unit_density_in_cgs = unit_mass_in_cgs*unit_length_in_cgs**-3 -unit_pressure_in_cgs = unit_mass_in_cgs/unit_length_in_cgs*unit_time_in_cgs**-2 -unit_int_energy_in_cgs = unit_energy_in_cgs/unit_mass_in_cgs -unit_entropy_in_cgs = unit_energy_in_cgs/unit_temp_in_cgs +unit_density_in_cgs = unit_mass_in_cgs * unit_length_in_cgs ** -3 +unit_pressure_in_cgs = unit_mass_in_cgs / unit_length_in_cgs * unit_time_in_cgs ** -2 +unit_int_energy_in_cgs = unit_energy_in_cgs / unit_mass_in_cgs +unit_entropy_in_cgs = unit_energy_in_cgs / unit_temp_in_cgs Myr_in_cgs = 3.154e13 Msun_in_cgs = 1.989e33 # Read data of zeroth snapshot -pos = sim["/PartType0/Coordinates"][:,:] -x = pos[:,0] - boxSize / 2 -y = pos[:,1] - boxSize / 2 -z = pos[:,2] - boxSize / 2 -vel = sim["/PartType0/Velocities"][:,:] -r = sqrt(x**2 + y**2 + z**2) -v_r = (x * vel[:,0] + y * vel[:,1] + z * vel[:,2]) / r -u = sim["/PartType0/InternalEnergy"][:] -S = sim["/PartType0/Entropy"][:] -P = sim["/PartType0/Pressure"][:] -rho = sim["/PartType0/Density"][:] +pos = sim["/PartType0/Coordinates"][:, :] +x = pos[:, 0] - boxSize / 2 +y = pos[:, 1] - boxSize / 2 +z = pos[:, 2] - boxSize / 2 +vel = sim["/PartType0/Velocities"][:, :] +r = sqrt(x ** 2 + y ** 2 + z ** 2) +v_r = (x * vel[:, 0] + y * vel[:, 1] + z * vel[:, 2]) / r +u = sim["/PartType0/InternalEnergies"][:] +S = sim["/PartType0/Entropies"][:] +P = sim["/PartType0/Pressures"][:] +rho = sim["/PartType0/Densities"][:] mass = sim["/PartType0/Masses"][:] IDs = sim["/PartType0/ParticleIDs"][:] @@ -123,34 +128,34 @@ t = zeros(n_snapshots) # Read data from rest of snapshots for i in range(n_snapshots): - print("reading snapshot "+str(i)) - # Read the simulation data - sim = h5py.File("stellar_evolution_%04d.hdf5"%i, "r") - t[i] = sim["/Header"].attrs["Time"][0] - - pos = sim["/PartType0/Coordinates"][:,:] - x = pos[:,0] - boxSize / 2 - y = pos[:,1] - boxSize / 2 - z = pos[:,2] - boxSize / 2 - vel = sim["/PartType0/Velocities"][:,:] - r = sqrt(x**2 + y**2 + z**2) - v_r = (x * vel[:,0] + y * vel[:,1] + z * vel[:,2]) / r - u = sim["/PartType0/InternalEnergy"][:] - S = sim["/PartType0/Entropy"][:] - P = sim["/PartType0/Pressure"][:] - rho = sim["/PartType0/Density"][:] - mass = sim["/PartType0/Masses"][:] - metallicity = sim["/PartType0/Metallicity"][:] - internal_energy = sim["/PartType0/InternalEnergy"][:] - IDs = sim["/PartType0/ParticleIDs"][:] - - # Find which particles we want to plot and store their data - indices = (find_indices(IDs,part_IDs_to_plot)).astype(int) - masses_to_plot[:,i] = mass[indices[:]] - v_r_to_plot[:,i] = v_r[indices[:]] - metallicities_to_plot[:,i] = metallicity[indices[:]] - internal_energies_to_plot[:,i] = internal_energy[indices[:]] - + print("reading snapshot " + str(i)) + # Read the simulation data + sim = h5py.File("stellar_evolution_%04d.hdf5" % i, "r") + t[i] = sim["/Header"].attrs["Time"][0] + + pos = sim["/PartType0/Coordinates"][:, :] + x = pos[:, 0] - boxSize / 2 + y = pos[:, 1] - boxSize / 2 + z = pos[:, 2] - boxSize / 2 + vel = sim["/PartType0/Velocities"][:, :] + r = sqrt(x ** 2 + y ** 2 + z ** 2) + v_r = (x * vel[:, 0] + y * vel[:, 1] + z * vel[:, 2]) / r + u = sim["/PartType0/InternalEnergies"][:] + S = sim["/PartType0/Entropies"][:] + P = sim["/PartType0/Pressures"][:] + rho = sim["/PartType0/Densities"][:] + mass = sim["/PartType0/Masses"][:] + metallicity = sim["/PartType0/Metallicities"][:] + internal_energy = sim["/PartType0/InternalEnergies"][:] + IDs = sim["/PartType0/ParticleIDs"][:] + + # Find which particles we want to plot and store their data + indices = (find_indices(IDs, part_IDs_to_plot)).astype(int) + masses_to_plot[:, i] = mass[indices[:]] + v_r_to_plot[:, i] = v_r[indices[:]] + metallicities_to_plot[:, i] = metallicity[indices[:]] + internal_energies_to_plot[:, i] = internal_energy[indices[:]] + # Plot the interesting quantities figure() @@ -158,33 +163,61 @@ figure() # Radial velocity -------------------------------- subplot(221) for j in range(n_particles_to_plot): - plot(t * unit_time_in_cgs / Myr_in_cgs, v_r_to_plot[j,:] * unit_vel_in_cgs, linewidth=0.5, color='k', ms=0.5, alpha=0.1) + plot( + t * unit_time_in_cgs / Myr_in_cgs, + v_r_to_plot[j, :] * unit_vel_in_cgs, + linewidth=0.5, + color="k", + ms=0.5, + alpha=0.1, + ) xlabel("Time (Myr)", labelpad=0) ylabel("Radial velocity $(\\rm{cm} \cdot \\rm{s}^{-1})$", labelpad=0) -ticklabel_format(style='sci', axis='y', scilimits=(0,0)) +ticklabel_format(style="sci", axis="y", scilimits=(0, 0)) # Internal energy -------------------------------- subplot(222) for j in range(n_particles_to_plot): - plot(t * unit_time_in_cgs / Myr_in_cgs, internal_energies_to_plot[j,:] * unit_energy_in_cgs / unit_mass_in_cgs, linewidth=0.5, color='k', ms=0.5, alpha=0.1) + plot( + t * unit_time_in_cgs / Myr_in_cgs, + internal_energies_to_plot[j, :] * unit_energy_in_cgs / unit_mass_in_cgs, + linewidth=0.5, + color="k", + ms=0.5, + alpha=0.1, + ) xlabel("Time (Myr)", labelpad=0) ylabel("Internal energy $(\\rm{erg} \cdot \\rm{g}^{-1})$", labelpad=2) -ticklabel_format(style='sci', axis='y', scilimits=(0,0)) +ticklabel_format(style="sci", axis="y", scilimits=(0, 0)) # Masses -------------------------------- subplot(223) for j in range(n_particles_to_plot): - plot(t * unit_time_in_cgs / Myr_in_cgs, masses_to_plot[j,:] * unit_mass_in_cgs / Msun_in_cgs, linewidth=0.5, color='k', ms=0.5, alpha=0.1) + plot( + t * unit_time_in_cgs / Myr_in_cgs, + masses_to_plot[j, :] * unit_mass_in_cgs / Msun_in_cgs, + linewidth=0.5, + color="k", + ms=0.5, + alpha=0.1, + ) xlabel("Time (Myr)", labelpad=0) ylabel("Mass (Msun)", labelpad=2) -ticklabel_format(style='sci', axis='y', scilimits=(0,0)) +ticklabel_format(style="sci", axis="y", scilimits=(0, 0)) # Metallicities -------------------------------- subplot(224) for j in range(n_particles_to_plot): - plot(t * unit_time_in_cgs / Myr_in_cgs, metallicities_to_plot[j,:] , linewidth=0.5, color='k', ms=0.5, alpha=0.1) + plot( + t * unit_time_in_cgs / Myr_in_cgs, + metallicities_to_plot[j, :], + linewidth=0.5, + color="k", + ms=0.5, + alpha=0.1, + ) xlabel("Time (Myr)", labelpad=0) ylabel("Metallicity", labelpad=2) -ticklabel_format(style='sci', axis='y', scilimits=(0,0)) +ticklabel_format(style="sci", axis="y", scilimits=(0, 0)) savefig("particle_evolution.png", dpi=200) diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index 3607690f7cbf07c86eb2d84cd742c734b33bd266..4a463bcbb55f95956a78c0f835899cb6161c460d 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -407,6 +407,8 @@ EAGLEFeedback: SNII_yield_factor_Silicon: 1.0 # (Optional) Correction factor to apply to the Silicon yield from the SNII channel. SNII_yield_factor_Iron: 0.5 # (Optional) Correction factor to apply to the Iron yield from the SNII channel. +# Parameters related to AGN models ----------------------------------------------- + # EAGLE AGN model EAGLEAGN: subgrid_seed_mass_Msun: 1.5e5 # Black hole subgrid mass at creation time in solar masses. diff --git a/src/Makefile.am b/src/Makefile.am index 3d748b135c93cf409464a199232b243c699fabe1..4710f3c99371f3bd585c328db51426363651e04e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -50,8 +50,9 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \ chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h space_getsid.h utilities.h \ mesh_gravity.h cbrt.h exp10.h velociraptor_interface.h swift_velociraptor_part.h outputlist.h \ logger_io.h tracers_io.h tracers.h tracers_struct.h star_formation_io.h fof.h fof_struct.h fof_io.h \ - star_formation_struct.h star_formation.h star_formation_iact.h \ + star_formation_struct.h star_formation.h \ star_formation_logger.h star_formation_logger_struct.h \ + pressure_floor.h pressure_floor_struct.h pressure_floor_iact.h \ velociraptor_struct.h velociraptor_io.h random.h memuse.h black_holes.h black_holes_io.h \ black_holes_properties.h black_holes_struct.h feedback.h feedback_struct.h feedback_properties.h @@ -172,11 +173,11 @@ nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h potential/isothermal/potential.h potential/disc_patch/potential.h \ potential/sine_wave/potential.h \ star_formation/none/star_formation.h star_formation/none/star_formation_struct.h \ - star_formation/none/star_formation_io.h star_formation/none/star_formation_iact.h \ + star_formation/none/star_formation_io.h \ star_formation/EAGLE/star_formation.h star_formation/EAGLE/star_formation_struct.h \ - star_formation/EAGLE/star_formation_io.h star_formation/EAGLE/star_formation_iact.h \ + star_formation/EAGLE/star_formation_io.h \ star_formation/GEAR/star_formation.h star_formation/GEAR/star_formation_struct.h \ - star_formation/GEAR/star_formation_io.h star_formation/GEAR/star_formation_iact.h \ + star_formation/GEAR/star_formation_io.h \ star_formation/EAGLE/star_formation_logger.h star_formation/EAGLE/star_formation_logger_struct.h \ star_formation/GEAR/star_formation_logger.h star_formation/GEAR/star_formation_logger_struct.h \ star_formation/none/star_formation_logger.h star_formation/none/star_formation_logger_struct.h \ @@ -223,8 +224,9 @@ nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h black_holes/EAGLE/black_holes_part.h black_holes/EAGLE/black_holes_iact.h \ black_holes/EAGLE/black_holes_properties.h \ black_holes/EAGLE/black_holes_struct.h \ - pressure_floor.h \ - pressure_floor/GEAR/pressure_floor.h pressure_floor/none/pressure_floor.h + pressure_floor/GEAR/pressure_floor.h pressure_floor/none/pressure_floor.h \ + pressure_floor/GEAR/pressure_floor_iact.h pressure_floor/none/pressure_floor_iact.h \ + pressure_floor/GEAR/pressure_floor_struct.h pressure_floor/none/pressure_floor_struct.h # Sources and flags for regular library diff --git a/src/adiabatic_index.h b/src/adiabatic_index.h index de7c3871cfb6e42739edf45a7d5b4882547d3cc2..d64968d736df0f0539a568632e8cf9c50a85145e 100644 --- a/src/adiabatic_index.h +++ b/src/adiabatic_index.h @@ -545,4 +545,38 @@ pow_three_gamma_minus_five_over_two(float x) { #endif } +/** + * @brief Return the argument to the power three (adiabatic index - 1). + * + * Computes \f$x^{3(\gamma - 1)}\f$. + * + * @param x Argument + */ +__attribute__((always_inline, const)) INLINE static float +pow_three_gamma_minus_one(float x) { + +#if defined(HYDRO_GAMMA_5_3) + + return x * x; /* x^(2) */ + +#elif defined(HYDRO_GAMMA_7_5) + + return powf(x, 1.2f); /* x^(6/5) */ + +#elif defined(HYDRO_GAMMA_4_3) + + return x; /* x^(1) */ + +#elif defined(HYDRO_GAMMA_2_1) + + return x * x * x; /* x^(3) */ + +#else + + error("The adiabatic index is not defined !"); + return 0.f; + +#endif +} + #endif /* SWIFT_ADIABATIC_INDEX_H */ diff --git a/src/cell.c b/src/cell.c index 3aa95a72c5e3c1af29b3f1180ea9f37d8e219020..bbc9da0ce3f64e66322bb8a278ebefa5a75bd5d3 100644 --- a/src/cell.c +++ b/src/cell.c @@ -61,6 +61,7 @@ #include "hydro_properties.h" #include "memswap.h" #include "minmax.h" +#include "pressure_floor.h" #include "scheduler.h" #include "space.h" #include "space_getsid.h" @@ -4419,7 +4420,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { if (part_is_active(p, e)) { hydro_init_part(p, &e->s->hs); chemistry_init_part(p, e->chemistry); - star_formation_init_part(p, xp, e->star_formation); + pressure_floor_init_part(p, xp); tracers_after_init(p, xp, e->internal_units, e->physical_constants, with_cosmology, e->cosmology, e->hydro_properties, e->cooling_func, e->time); diff --git a/src/chemistry/EAGLE/chemistry.h b/src/chemistry/EAGLE/chemistry.h index a04d7f94e7340a68d25914828de40bb2e1e8020c..a470eef3fafc32c99fe3a853dcf46051a3086441 100644 --- a/src/chemistry/EAGLE/chemistry.h +++ b/src/chemistry/EAGLE/chemistry.h @@ -170,9 +170,10 @@ __attribute__((always_inline)) INLINE static void chemistry_first_init_part( p->chemistry_data.metal_mass_fraction_total = data->initial_metal_mass_fraction_total; - for (int elem = 0; elem < chemistry_element_count; ++elem) + for (int elem = 0; elem < chemistry_element_count; ++elem) { p->chemistry_data.metal_mass_fraction[elem] = data->initial_metal_mass_fraction[elem]; + } } chemistry_init_part(p, data); } @@ -241,4 +242,110 @@ static INLINE void chemistry_print_backend( chemistry_element_count); } +/** + * @brief Updates to the chemistry data after the hydro force loop. + * + * Nothing to do here in EAGLE. + * + * @param p The particle to act upon. + * @param cosmo The current cosmological model. + */ +__attribute__((always_inline)) INLINE static void chemistry_end_force( + struct part* restrict p, const struct cosmology* cosmo) {} + +/** + * @brief Computes the chemistry-related time-step constraint. + * + * No constraints in the EAGLE model (no diffusion etc.) --> FLT_MAX + * + * @param phys_const The physical constants in internal units. + * @param cosmo The current cosmological model. + * @param us The internal system of units. + * @param hydro_props The properties of the hydro scheme. + * @param cd The global properties of the chemistry scheme. + * @param p Pointer to the particle data. + */ +__attribute__((always_inline)) INLINE static float chemistry_timestep( + const struct phys_const* restrict phys_const, + const struct cosmology* restrict cosmo, + const struct unit_system* restrict us, + const struct hydro_props* hydro_props, + const struct chemistry_global_data* cd, const struct part* restrict p) { + return FLT_MAX; +} + +/** + * @brief Returns the total metallicity (metal mass fraction) of the + * star particle to be used in feedback/enrichment related routines. + * + * EAGLE uses smooth abundances for everything. + * + * @param sp Pointer to the particle data. + */ +__attribute__((always_inline)) INLINE static float +chemistry_get_total_metal_mass_fraction_for_feedback( + const struct spart* restrict sp) { + + return sp->chemistry_data.smoothed_metal_mass_fraction_total; +} + +/** + * @brief Returns the total metallicity (metal mass fraction) of the + * gas particle to be used in cooling related routines. + * + * EAGLE uses smooth abundances for everything. + * + * @param p Pointer to the particle data. + */ +__attribute__((always_inline)) INLINE static float +chemistry_get_total_metal_mass_fraction_for_cooling( + const struct part* restrict p) { + + return p->chemistry_data.smoothed_metal_mass_fraction_total; +} + +/** + * @brief Returns the abundance array (metal mass fractions) of the + * gas particle to be used in cooling related routines. + * + * EAGLE uses smooth abundances for everything. + * + * @param p Pointer to the particle data. + */ +__attribute__((always_inline)) INLINE static float const* +chemistry_get_metal_mass_fraction_for_cooling(const struct part* restrict p) { + + return p->chemistry_data.smoothed_metal_mass_fraction; +} + +/** + * @brief Returns the total metallicity (metal mass fraction) of the + * gas particle to be used in star formation related routines. + * + * EAGLE uses smooth abundances for everything. + * + * @param p Pointer to the particle data. + */ +__attribute__((always_inline)) INLINE static float +chemistry_get_total_metal_mass_fraction_for_star_formation( + const struct part* restrict p) { + + return p->chemistry_data.smoothed_metal_mass_fraction_total; +} + +/** + * @brief Returns the abundance array (metal mass fractions) of the + * gas particle to be used in star formation related routines. + * + * EAGLE uses smooth abundances for everything. + * + * @param p Pointer to the particle data. + */ +__attribute__((always_inline)) INLINE static float const* +chemistry_get_metal_mass_fraction_for_star_formation( + const struct part* restrict p) { + + return p->chemistry_data.smoothed_metal_mass_fraction; +} + #endif /* SWIFT_CHEMISTRY_EAGLE_H */ diff --git a/src/chemistry/GEAR/chemistry.h b/src/chemistry/GEAR/chemistry.h index 951d565337eae39bec05c0e142a020e6647811fe..34c4d10e5fb2f491b029c4c8d76cf04ca7a5429a 100644 --- a/src/chemistry/GEAR/chemistry.h +++ b/src/chemistry/GEAR/chemistry.h @@ -135,6 +135,15 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density( } } +/** + * @brief Updates to the chemistry data after the hydro force loop. + * + * @param p The particle to act upon. + * @param cosmo The current cosmological model. + */ +__attribute__((always_inline)) INLINE static void chemistry_end_force( + struct part* restrict p, const struct cosmology* cosmo) {} + /** * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. * @@ -151,6 +160,27 @@ chemistry_part_has_no_neighbours(struct part* restrict p, error("Needs implementing!"); } +/** + * @brief Computes the chemistry-related time-step constraint. + * + * No constraints in the GEAR model (no diffusion) --> FLT_MAX + * + * @param phys_const The physical constants in internal units. + * @param cosmo The current cosmological model. + * @param us The internal system of units. + * @param hydro_props The properties of the hydro scheme. + * @param cd The global properties of the chemistry scheme. + * @param p Pointer to the particle data. + */ +__attribute__((always_inline)) INLINE static float chemistry_timestep( + const struct phys_const* restrict phys_const, + const struct cosmology* restrict cosmo, + const struct unit_system* restrict us, + const struct hydro_props* hydro_props, + const struct chemistry_global_data* cd, const struct part* restrict p) { + return FLT_MAX; +} + /** * @brief Sets the chemistry properties of the (x-)particles to a valid start * state. diff --git a/src/chemistry/none/chemistry.h b/src/chemistry/none/chemistry.h index 543a5e77eea245da9ec18de210c781d5be07d7fb..4e7e790deb86d18a35f2628105da3dd072340747 100644 --- a/src/chemistry/none/chemistry.h +++ b/src/chemistry/none/chemistry.h @@ -87,6 +87,34 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density( struct part* restrict p, const struct chemistry_global_data* cd, const struct cosmology* cosmo) {} +/** + * @brief Updates to the chemistry data after the hydro force loop. + * + * @param p The particle to act upon. + * @param cosmo The current cosmological model. + */ +__attribute__((always_inline)) INLINE static void chemistry_end_force( + struct part* restrict p, const struct cosmology* cosmo) {} + +/** + * @brief Computes the chemistry-related time-step constraint. + * + * @param phys_const The physical constants in internal units. + * @param cosmo The current cosmological model. + * @param us The internal system of units. + * @param hydro_props The properties of the hydro scheme. + * @param cd The global properties of the chemistry scheme. + * @param p Pointer to the particle data. + */ +__attribute__((always_inline)) INLINE static float chemistry_timestep( + const struct phys_const* restrict phys_const, + const struct cosmology* restrict cosmo, + const struct unit_system* restrict us, + const struct hydro_props* hydro_props, + const struct chemistry_global_data* cd, const struct part* restrict p) { + return FLT_MAX; +} + /** * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. * diff --git a/src/cooling/EAGLE/cooling.c b/src/cooling/EAGLE/cooling.c index 674631ae52329611eeddb490df1ed205333c0322..c5595ef514d5a145dd6e9c326c1ff1f2bc9da196 100644 --- a/src/cooling/EAGLE/cooling.c +++ b/src/cooling/EAGLE/cooling.c @@ -423,10 +423,10 @@ void cooling_cool_part(const struct phys_const *phys_const, abundance_ratio_to_solar(p, cooling, abundance_ratio); /* Get the Hydrogen and Helium mass fractions */ - const float XH = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_H]; - const float XHe = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_He]; + const float *const metal_fraction = + chemistry_get_metal_mass_fraction_for_cooling(p); + const float XH = metal_fraction[chemistry_element_H]; + const float XHe = metal_fraction[chemistry_element_He]; /* Get the Helium mass fraction. Note that this is He / (H + He), i.e. a * metal-free Helium mass fraction as per the Wiersma+08 definition */ @@ -600,10 +600,10 @@ float cooling_get_temperature( const double u_cgs = u * cooling->internal_energy_to_cgs; /* Get the Hydrogen and Helium mass fractions */ - const float XH = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_H]; - const float XHe = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_He]; + const float *const metal_fraction = + chemistry_get_metal_mass_fraction_for_cooling(p); + const float XH = metal_fraction[chemistry_element_H]; + const float XHe = metal_fraction[chemistry_element_He]; /* Get the Helium mass fraction. Note that this is He / (H + He), i.e. a * metal-free Helium mass fraction as per the Wiersma+08 definition */ diff --git a/src/cooling/EAGLE/cooling_rates.h b/src/cooling/EAGLE/cooling_rates.h index bf908c3a7cfc6008995b0d60ab911ceedc2f60dc..39978c9bfa8cf2fbea25e8856c2939a8d6ee69e4 100644 --- a/src/cooling/EAGLE/cooling_rates.h +++ b/src/cooling/EAGLE/cooling_rates.h @@ -43,61 +43,57 @@ * We also re-order the elements such that they match the order of the * tables. This is [H, He, C, N, O, Ne, Mg, Si, S, Ca, Fe]. * + * The solar abundances table (from the cooling struct) is arranged as + * [H, He, C, N, O, Ne, Mg, Si, S, Ca, Fe]. + * * @param p Pointer to #part struct. * @param cooling #cooling_function_data struct. * @param ratio_solar (return) Array of ratios to solar abundances. */ -__attribute__((always_inline)) INLINE void abundance_ratio_to_solar( +__attribute__((always_inline)) INLINE static void abundance_ratio_to_solar( const struct part *p, const struct cooling_function_data *cooling, float ratio_solar[eagle_cooling_N_abundances]) { - ratio_solar[0] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_H] * - cooling->SolarAbundances_inv[0 /* H */]; + /* Get the individual metal mass fractions from the particle */ + const float *const metal_fraction = + chemistry_get_metal_mass_fraction_for_cooling(p); + + ratio_solar[0] = metal_fraction[chemistry_element_H] * + cooling->SolarAbundances_inv[0 /* H */]; - ratio_solar[1] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_He] * - cooling->SolarAbundances_inv[1 /* He */]; + ratio_solar[1] = metal_fraction[chemistry_element_He] * + cooling->SolarAbundances_inv[1 /* He */]; - ratio_solar[2] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_C] * - cooling->SolarAbundances_inv[2 /* C */]; + ratio_solar[2] = metal_fraction[chemistry_element_C] * + cooling->SolarAbundances_inv[2 /* C */]; - ratio_solar[3] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_N] * - cooling->SolarAbundances_inv[3 /* N */]; + ratio_solar[3] = metal_fraction[chemistry_element_N] * + cooling->SolarAbundances_inv[3 /* N */]; - ratio_solar[4] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_O] * - cooling->SolarAbundances_inv[4 /* O */]; + ratio_solar[4] = metal_fraction[chemistry_element_O] * + cooling->SolarAbundances_inv[4 /* O */]; - ratio_solar[5] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_Ne] * - cooling->SolarAbundances_inv[5 /* Ne */]; + ratio_solar[5] = metal_fraction[chemistry_element_Ne] * + cooling->SolarAbundances_inv[5 /* Ne */]; - ratio_solar[6] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_Mg] * - cooling->SolarAbundances_inv[6 /* Mg */]; + ratio_solar[6] = metal_fraction[chemistry_element_Mg] * + cooling->SolarAbundances_inv[6 /* Mg */]; - ratio_solar[7] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_Si] * - cooling->SolarAbundances_inv[7 /* Si */]; + ratio_solar[7] = metal_fraction[chemistry_element_Si] * + cooling->SolarAbundances_inv[7 /* Si */]; /* For S, we use the same ratio as Si */ - ratio_solar[8] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_Si] * - cooling->SolarAbundances_inv[7 /* Si */] * - cooling->S_over_Si_ratio_in_solar; + ratio_solar[8] = metal_fraction[chemistry_element_Si] * + cooling->SolarAbundances_inv[7 /* Si */] * + cooling->S_over_Si_ratio_in_solar; /* For Ca, we use the same ratio as Si */ - ratio_solar[9] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_Si] * - cooling->SolarAbundances_inv[7 /* Si */] * - cooling->Ca_over_Si_ratio_in_solar; - - ratio_solar[10] = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_Fe] * - cooling->SolarAbundances_inv[10 /* Fe */]; + ratio_solar[9] = metal_fraction[chemistry_element_Si] * + cooling->SolarAbundances_inv[7 /* Si */] * + cooling->Ca_over_Si_ratio_in_solar; + + ratio_solar[10] = metal_fraction[chemistry_element_Fe] * + cooling->SolarAbundances_inv[10 /* Fe */]; } /** diff --git a/src/cooling/EAGLE/newton_cooling.c b/src/cooling/EAGLE/newton_cooling.c index e86ebb7a2f38c29b2d889fb96c4a7d5f791b699c..50af3294c31dfc2d44a679c26a78629d53d03420 100644 --- a/src/cooling/EAGLE/newton_cooling.c +++ b/src/cooling/EAGLE/newton_cooling.c @@ -621,8 +621,9 @@ INLINE static double eagle_metal_cooling_rate( const float log_table_bound_low = (cooling->Therm[0] + 0.05) / M_LOG10E; /* convert Hydrogen mass fraction in Hydrogen number density */ - const float XH = - p->chemistry_data.smoothed_metal_mass_fraction[chemistry_element_H]; + float const *metal_fraction = + chemistry_get_metal_mass_fraction_for_cooling(p); + const float XH = metal_fraction[chemistry_element_H]; const double n_H = hydro_get_physical_density(p, cosmo) * XH / phys_const->const_proton_mass; const double n_H_cgs = n_H * cooling->number_density_to_cgs; diff --git a/src/engine.c b/src/engine.c index 75ff70b693c121770e7b1331ec3e7e1b87aecbbe..7f6a1639c033ed1e30aefdaced7ae839cb5721e8 100644 --- a/src/engine.c +++ b/src/engine.c @@ -130,6 +130,9 @@ int engine_rank; /** The current step of the engine as a global variable (for messages). */ int engine_current_step; +extern int engine_max_parts_per_ghost; +extern int engine_max_sparts_per_ghost; + /** * @brief Data collected from the cells at the end of a time-step */ @@ -4952,7 +4955,7 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params, e->time_first_snapshot = parser_get_opt_param_double(params, "Snapshots:time_first", 0.); e->delta_time_snapshot = - parser_get_param_double(params, "Snapshots:delta_time"); + parser_get_opt_param_double(params, "Snapshots:delta_time", -1.); e->ti_next_snapshot = 0; parser_get_param_string(params, "Snapshots:basename", e->snapshot_base_name); e->snapshot_compression = @@ -5635,6 +5638,51 @@ void engine_config(int restart, int fof, struct engine *e, e->sched.mpi_message_limit = parser_get_opt_param_int(params, "Scheduler:mpi_message_limit", 4) * 1024; + if (restart) { + + /* Overwrite the constants for the scheduler */ + space_maxsize = parser_get_opt_param_int(params, "Scheduler:cell_max_size", + space_maxsize_default); + space_subsize_pair_hydro = + parser_get_opt_param_int(params, "Scheduler:cell_sub_size_pair_hydro", + space_subsize_pair_hydro_default); + space_subsize_self_hydro = + parser_get_opt_param_int(params, "Scheduler:cell_sub_size_self_hydro", + space_subsize_self_hydro_default); + space_subsize_pair_stars = + parser_get_opt_param_int(params, "Scheduler:cell_sub_size_pair_stars", + space_subsize_pair_stars_default); + space_subsize_self_stars = + parser_get_opt_param_int(params, "Scheduler:cell_sub_size_self_stars", + space_subsize_self_stars_default); + space_subsize_pair_grav = + parser_get_opt_param_int(params, "Scheduler:cell_sub_size_pair_grav", + space_subsize_pair_grav_default); + space_subsize_self_grav = + parser_get_opt_param_int(params, "Scheduler:cell_sub_size_self_grav", + space_subsize_self_grav_default); + space_splitsize = parser_get_opt_param_int( + params, "Scheduler:cell_split_size", space_splitsize_default); + space_subdepth_diff_grav = + parser_get_opt_param_int(params, "Scheduler:cell_subdepth_diff_grav", + space_subdepth_diff_grav_default); + space_extra_parts = parser_get_opt_param_int( + params, "Scheduler:cell_extra_parts", space_extra_parts_default); + space_extra_sparts = parser_get_opt_param_int( + params, "Scheduler:cell_extra_sparts", space_extra_sparts_default); + space_extra_gparts = parser_get_opt_param_int( + params, "Scheduler:cell_extra_gparts", space_extra_gparts_default); + space_extra_bparts = parser_get_opt_param_int( + params, "Scheduler:cell_extra_bparts", space_extra_bparts_default); + + engine_max_parts_per_ghost = + parser_get_opt_param_int(params, "Scheduler:engine_max_parts_per_ghost", + engine_max_parts_per_ghost_default); + engine_max_sparts_per_ghost = parser_get_opt_param_int( + params, "Scheduler:engine_max_sparts_per_ghost", + engine_max_sparts_per_ghost_default); + } + /* Allocate and init the threads. */ if (swift_memalign("runners", (void **)&e->runners, SWIFT_CACHE_ALIGNMENT, e->nr_threads * sizeof(struct runner)) != 0) diff --git a/src/feedback/EAGLE/feedback.c b/src/feedback/EAGLE/feedback.c index cf6848760fb9827718befe48e43ab53cfe77f8ef..69f92fe992a306d018294009abefedb49a7deeae 100644 --- a/src/feedback/EAGLE/feedback.c +++ b/src/feedback/EAGLE/feedback.c @@ -105,15 +105,15 @@ double eagle_feedback_energy_fraction(const struct spart* sp, /* Star properties */ - /* Smoothed metallicity (metal mass fraction) at birth time of the star */ - const double Z_smooth = sp->chemistry_data.smoothed_metal_mass_fraction_total; + /* Metallicity (metal mass fraction) at birth time of the star */ + const double Z = chemistry_get_total_metal_mass_fraction_for_feedback(sp); /* Physical density of the gas at the star's birth time */ const double rho_birth = sp->birth_density; const double n_birth = rho_birth * props->rho_to_n_cgs; /* Calculate f_E */ - const double Z_term = pow(max(Z_smooth, 1e-6) / Z_0, n_Z); + const double Z_term = pow(max(Z, 1e-6) / Z_0, n_Z); const double n_term = pow(n_birth / n_0, -n_n); const double denonimator = 1. + Z_term * n_term; @@ -333,7 +333,7 @@ INLINE static void evolve_SNIa(const float log10_min_mass, * and use updated values for the star's age and timestep in this function */ if (log10_max_mass > props->log10_SNIa_max_mass_msun) { - const float Z = sp->chemistry_data.metal_mass_fraction_total; + const float Z = chemistry_get_total_metal_mass_fraction_for_feedback(sp); const float max_mass = exp10f(props->log10_SNIa_max_mass_msun); const float lifetime_Gyr = lifetime_in_Gyr(max_mass, Z, props); @@ -401,6 +401,9 @@ INLINE static void evolve_SNII(float log10_min_mass, float log10_max_mass, int low_imf_mass_bin_index, high_imf_mass_bin_index, mass_bin_index; + /* Metallicity (metal mass fraction) at birth time of the star */ + const double Z = chemistry_get_total_metal_mass_fraction_for_feedback(sp); + /* If mass at beginning of step is less than tabulated lower bound for IMF, * limit it.*/ if (log10_min_mass < props->log10_SNII_min_mass_msun) @@ -423,9 +426,7 @@ INLINE static void evolve_SNII(float log10_min_mass, float log10_max_mass, int iz_low = 0, iz_high = 0, low_index_3d, high_index_3d, low_index_2d, high_index_2d; float dz = 0.; - determine_bin_yield_SNII(&iz_low, &iz_high, &dz, - log10(sp->chemistry_data.metal_mass_fraction_total), - props); + determine_bin_yield_SNII(&iz_low, &iz_high, &dz, log10(Z), props); /* compute metals produced */ float metal_mass_released[chemistry_element_count], metal_mass_released_total; @@ -557,6 +558,9 @@ INLINE static void evolve_AGB(const float log10_min_mass, float log10_max_mass, int low_imf_mass_bin_index, high_imf_mass_bin_index, mass_bin_index; + /* Metallicity (metal mass fraction) at birth time of the star */ + const double Z = chemistry_get_total_metal_mass_fraction_for_feedback(sp); + /* If mass at end of step is greater than tabulated lower bound for IMF, limit * it.*/ if (log10_max_mass > props->log10_SNII_min_mass_msun) @@ -574,9 +578,7 @@ INLINE static void evolve_AGB(const float log10_min_mass, float log10_max_mass, int iz_low = 0, iz_high = 0, low_index_3d, high_index_3d, low_index_2d, high_index_2d; float dz = 0.f; - determine_bin_yield_AGB(&iz_low, &iz_high, &dz, - log10(sp->chemistry_data.metal_mass_fraction_total), - props); + determine_bin_yield_AGB(&iz_low, &iz_high, &dz, log10(Z), props); /* compute metals produced */ float metal_mass_released[chemistry_element_count], metal_mass_released_total; @@ -718,7 +720,7 @@ void compute_stellar_evolution(const struct feedback_props* feedback_props, const double star_age_Gyr = age * conversion_factor; /* Get the metallicity */ - const float Z = sp->chemistry_data.metal_mass_fraction_total; + const float Z = chemistry_get_total_metal_mass_fraction_for_feedback(sp); /* Properties collected in the stellar density loop. */ const float ngb_gas_mass = sp->feedback_data.to_collect.ngb_mass; diff --git a/src/hydro/AnarchyDU/hydro.h b/src/hydro/AnarchyDU/hydro.h index ac4ed6c2f8176669aa7364109f95de08ddbf722c..a8b84c46aca9a117efe8173c492bbfd678106a5f 100644 --- a/src/hydro/AnarchyDU/hydro.h +++ b/src/hydro/AnarchyDU/hydro.h @@ -822,9 +822,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part *restrict p, const struct xpart *restrict xp) { + struct part *restrict p, const struct xpart *restrict xp, + const struct cosmology *cosmo) { /* Re-set the predicted velocities */ p->v[0] = xp->v_full[0]; diff --git a/src/hydro/AnarchyDU/hydro_iact.h b/src/hydro/AnarchyDU/hydro_iact.h index 19489f7460753b15961603e68c22c039f6de27d3..09ecde01d44cfef1c0edbfe0d3f1aa909d553a95 100644 --- a/src/hydro/AnarchyDU/hydro_iact.h +++ b/src/hydro/AnarchyDU/hydro_iact.h @@ -428,6 +428,12 @@ __attribute__((always_inline)) INLINE static void runner_iact_force( /* Get the time derivative for h. */ pi->force.h_dt -= mj * dvdr * r_inv / rhoj * wi_dr; pj->force.h_dt -= mi * dvdr * r_inv / rhoi * wj_dr; + + /* Update if we need to; this should be guaranteed by the gradient loop but + * due to some possible synchronisation problems this is here as a _quick + * fix_. Added: 14th August 2019. To be removed by 1st Jan 2020. (JB) */ + pi->viscosity.v_sig = max(pi->viscosity.v_sig, v_sig); + pj->viscosity.v_sig = max(pj->viscosity.v_sig, v_sig); } /** @@ -547,6 +553,11 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force( /* Get the time derivative for h. */ pi->force.h_dt -= mj * dvdr * r_inv / rhoj * wi_dr; + + /* Update if we need to; this should be guaranteed by the gradient loop but + * due to some possible synchronisation problems this is here as a _quick + * fix_. Added: 14th August 2019. To be removed by 1st Jan 2020. (JB) */ + pi->viscosity.v_sig = max(pi->viscosity.v_sig, v_sig); } /** diff --git a/src/hydro/AnarchyDU/hydro_io.h b/src/hydro/AnarchyDU/hydro_io.h index d78d16c35bf4ebb561116e1a504d24b248104206..4044a0c1f1cdbf4263de03071b046cd4c0884d2e 100644 --- a/src/hydro/AnarchyDU/hydro_io.h +++ b/src/hydro/AnarchyDU/hydro_io.h @@ -182,7 +182,7 @@ INLINE static void hydro_write_particles(const struct part* parts, list[4] = io_make_output_field( "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - 3. * hydro_gamma_minus_one, parts, u, + -3.f * hydro_gamma_minus_one, parts, u, "Co-moving thermal energies per unit mass of the particles"); list[5] = @@ -198,7 +198,7 @@ INLINE static void hydro_write_particles(const struct part* parts, xparts, convert_S, "Co-moving entropies per unit mass of the particles"); list[8] = io_make_output_field_convert_part( - "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, 3.f * hydro_gamma, parts, + "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, -3.f * hydro_gamma, parts, xparts, convert_P, "Co-moving pressures of the particles"); list[9] = io_make_output_field_convert_part( diff --git a/src/hydro/AnarchyPU/hydro.h b/src/hydro/AnarchyPU/hydro.h index 9ba58828dd84df205539550c221746dfac37ed21..806d4aed204c71d3b9265d1bbea1098fdb83ebb1 100644 --- a/src/hydro/AnarchyPU/hydro.h +++ b/src/hydro/AnarchyPU/hydro.h @@ -828,9 +828,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part *restrict p, const struct xpart *restrict xp) { + struct part *restrict p, const struct xpart *restrict xp, + const struct cosmology *cosmo) { /* Re-set the predicted velocities */ p->v[0] = xp->v_full[0]; diff --git a/src/hydro/AnarchyPU/hydro_io.h b/src/hydro/AnarchyPU/hydro_io.h index 499ef5dc2d79f86f6f76c119b1b421260cf25cea..7dfe61f198163c458ea8ecc22c1cbaa7eb4b99dd 100644 --- a/src/hydro/AnarchyPU/hydro_io.h +++ b/src/hydro/AnarchyPU/hydro_io.h @@ -184,7 +184,7 @@ INLINE static void hydro_write_particles(const struct part* parts, list[4] = io_make_output_field( "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - 3. * hydro_gamma_minus_one, parts, u, + -3.f * hydro_gamma_minus_one, parts, u, "Co-moving thermal energies per unit mass of the particles"); list[5] = @@ -196,7 +196,7 @@ INLINE static void hydro_write_particles(const struct part* parts, "Co-moving mass densities of the particles"); list[7] = io_make_output_field( - "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, 3.f * hydro_gamma, parts, + "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, -3.f * hydro_gamma, parts, pressure_bar, "Co-moving smoothed pressures of the particles"); list[8] = io_make_output_field_convert_part( diff --git a/src/hydro/Default/hydro.h b/src/hydro/Default/hydro.h index 558143f88d07225f5e6bfe5666d345a7891a7534..469fee137ee624ab649718f25c490f61e35cfb59 100644 --- a/src/hydro/Default/hydro.h +++ b/src/hydro/Default/hydro.h @@ -766,9 +766,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part *restrict p, const struct xpart *restrict xp) { + struct part *restrict p, const struct xpart *restrict xp, + const struct cosmology *cosmo) { /* Re-set the predicted velocities */ p->v[0] = xp->v_full[0]; diff --git a/src/hydro/Default/hydro_io.h b/src/hydro/Default/hydro_io.h index 5d923837765c3d4759db37cd67badb40d75763f3..1944f677ff16c5f002aa4ee2f830c84e808ffa63 100644 --- a/src/hydro/Default/hydro_io.h +++ b/src/hydro/Default/hydro_io.h @@ -183,7 +183,7 @@ INLINE static void hydro_write_particles(const struct part* parts, list[4] = io_make_output_field( "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - 3. * hydro_gamma_minus_one, parts, u, + -3.f * hydro_gamma_minus_one, parts, u, "Co-moving thermal energies per unit mass of the particles"); list[5] = @@ -195,7 +195,7 @@ INLINE static void hydro_write_particles(const struct part* parts, "Co-moving mass densities of the particles"); list[7] = io_make_output_field_convert_part( - "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, 3.f * hydro_gamma, parts, + "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, -3.f * hydro_gamma, parts, xparts, convert_P, "Co-moving pressures of the particles"); list[8] = io_make_output_field_convert_part( diff --git a/src/hydro/Gadget2/hydro.h b/src/hydro/Gadget2/hydro.h index 93c0e58068341ab29a7ed0fb6b0d21f76980d952..3fa6f19cc145890feacbd7284368d5378654bf38 100644 --- a/src/hydro/Gadget2/hydro.h +++ b/src/hydro/Gadget2/hydro.h @@ -110,8 +110,7 @@ hydro_get_drifted_physical_internal_energy(const struct part *restrict p, __attribute__((always_inline)) INLINE static float hydro_get_comoving_pressure( const struct part *restrict p) { - const float comoving_pressure = gas_pressure_from_entropy(p->rho, p->entropy); - return pressure_floor_get_pressure(p, p->rho, comoving_pressure); + return gas_pressure_from_entropy(p->rho, p->entropy); } /** @@ -123,10 +122,7 @@ __attribute__((always_inline)) INLINE static float hydro_get_comoving_pressure( __attribute__((always_inline)) INLINE static float hydro_get_physical_pressure( const struct part *restrict p, const struct cosmology *cosmo) { - const float phys_pressure = - gas_pressure_from_entropy(p->rho * cosmo->a3_inv, p->entropy); - const float phys_rho = hydro_get_physical_density(p, cosmo); - return pressure_floor_get_pressure(p, phys_rho, phys_pressure); + return gas_pressure_from_entropy(p->rho * cosmo->a3_inv, p->entropy); } /** @@ -394,7 +390,8 @@ hydro_set_drifted_physical_internal_energy(struct part *p, /* Compute the pressure */ float comoving_pressure = gas_pressure_from_entropy(p->rho, p->entropy); - comoving_pressure = pressure_floor_get_pressure(p, p->rho, comoving_pressure); + comoving_pressure = + pressure_floor_get_comoving_pressure(p, comoving_pressure, cosmo); /* Compute the sound speed */ const float soundspeed = @@ -466,7 +463,7 @@ __attribute__((always_inline)) INLINE static void hydro_timestep_extra( * @brief Prepares a particle for the density calculation. * * Zeroes all the relevant arrays in preparation for the sums taking place in - * the variaous density tasks + * the various density tasks * * @param p The particle to act upon * @param hs #hydro_space containing hydro specific space information. @@ -599,7 +596,8 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force( /* Compute the pressure */ float comoving_pressure = gas_pressure_from_entropy(p->rho, p->entropy); - comoving_pressure = pressure_floor_get_pressure(p, p->rho, comoving_pressure); + comoving_pressure = + pressure_floor_get_comoving_pressure(p, comoving_pressure, cosmo); /* Compute the sound speed */ const float soundspeed = @@ -661,9 +659,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part *restrict p, const struct xpart *restrict xp) { + struct part *restrict p, const struct xpart *restrict xp, + const struct cosmology *cosmo) { /* Re-set the predicted velocities */ p->v[0] = xp->v_full[0]; @@ -675,7 +675,8 @@ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( /* Re-compute the pressure */ float comoving_pressure = gas_pressure_from_entropy(p->rho, p->entropy); - comoving_pressure = pressure_floor_get_pressure(p, p->rho, comoving_pressure); + comoving_pressure = + pressure_floor_get_comoving_pressure(p, comoving_pressure, cosmo); /* Compute the new sound speed */ const float soundspeed = @@ -742,7 +743,8 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra( /* Re-compute the pressure */ float comoving_pressure = gas_pressure_from_entropy(p->rho, p->entropy); - comoving_pressure = pressure_floor_get_pressure(p, p->rho, comoving_pressure); + comoving_pressure = + pressure_floor_get_comoving_pressure(p, comoving_pressure, cosmo); /* Compute the new sound speed */ const float soundspeed = @@ -854,7 +856,8 @@ __attribute__((always_inline)) INLINE static void hydro_convert_quantities( /* Compute the pressure */ float comoving_pressure = gas_pressure_from_entropy(p->rho, p->entropy); - comoving_pressure = pressure_floor_get_pressure(p, p->rho, comoving_pressure); + comoving_pressure = + pressure_floor_get_comoving_pressure(p, comoving_pressure, cosmo); /* Compute the sound speed */ const float soundspeed = diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h index 9715558be39c853ec5a96262d95cdf4fe92309fa..20ad8e2d0c15094101e44999ff643f9d21619622 100644 --- a/src/hydro/Gadget2/hydro_io.h +++ b/src/hydro/Gadget2/hydro_io.h @@ -177,11 +177,11 @@ INLINE static void hydro_write_particles(const struct part* parts, list[7] = io_make_output_field_convert_part( "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - 3. * hydro_gamma_minus_one, parts, xparts, convert_part_u, + -3.f * hydro_gamma_minus_one, parts, xparts, convert_part_u, "Co-moving thermal energies per unit mass of the particles"); list[8] = io_make_output_field_convert_part( - "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, 3.f * hydro_gamma, parts, + "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, -3.f * hydro_gamma, parts, xparts, convert_part_P, "Co-moving pressures of the particles"); list[9] = io_make_output_field_convert_part( diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h index 853d2adf17bc069434562fa96ddb881f760f6830..5f4cca366b101c2341863f47d7a9adce51b860a2 100644 --- a/src/hydro/Gadget2/hydro_part.h +++ b/src/hydro/Gadget2/hydro_part.h @@ -35,6 +35,7 @@ #include "chemistry_struct.h" #include "cooling_struct.h" #include "logger.h" +#include "pressure_floor_struct.h" #include "star_formation_struct.h" #include "tracers_struct.h" @@ -155,8 +156,8 @@ struct part { /*! Black holes information (e.g. swallowing ID) */ struct black_holes_part_data black_holes_data; - /* Additional data used by the star formation */ - struct star_formation_part_data sf_data; + /* Additional data used by the pressure floor */ + struct pressure_floor_part_data pressure_floor_data; /* Time-step length */ timebin_t time_bin; diff --git a/src/hydro/GizmoMFM/hydro.h b/src/hydro/GizmoMFM/hydro.h index eb3d9044baecadeaba9165061fae33c816446042..890c7f4c113e289e167247bb4978c1a362b8ff5d 100644 --- a/src/hydro/GizmoMFM/hydro.h +++ b/src/hydro/GizmoMFM/hydro.h @@ -497,9 +497,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part* restrict p, const struct xpart* restrict xp) { + struct part* restrict p, const struct xpart* restrict xp, + const struct cosmology* cosmo) { // MATTHIEU: Do we need something here? } diff --git a/src/hydro/GizmoMFM/hydro_io.h b/src/hydro/GizmoMFM/hydro_io.h index b1d51cff90de52285abcd63c519aac911dcba7c2..711eee9e3117c220e6ab5a27a6d8f3557ec7ce13 100644 --- a/src/hydro/GizmoMFM/hydro_io.h +++ b/src/hydro/GizmoMFM/hydro_io.h @@ -220,15 +220,15 @@ INLINE static void hydro_write_particles(const struct part* parts, "Co-moving mass densities of the particles"); list[7] = io_make_output_field_convert_part( - "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, 0.f, parts, xparts, convert_A, + "Entropies", FLOAT, 1, UNIT_CONV_ENTROPY, 0.f, parts, xparts, convert_A, "Co-moving entropies of the particles"); - list[8] = io_make_output_field("Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, - 3.f * hydro_gamma, parts, P, + list[8] = io_make_output_field("Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, + -3.f * hydro_gamma, parts, P, "Co-moving pressures of the particles"); list[9] = io_make_output_field_convert_part( - "TotalEnergies", FLOAT, 1, UNIT_CONV_ENERGY, 3.f * hydro_gamma_minus_one, + "TotalEnergies", FLOAT, 1, UNIT_CONV_ENERGY, -3.f * hydro_gamma_minus_one, parts, xparts, convert_Etot, "Total (co-moving) energy of the particles"); list[10] = io_make_output_field_convert_part( diff --git a/src/hydro/GizmoMFV/hydro.h b/src/hydro/GizmoMFV/hydro.h index e6a87b9a86fc7ec03a4bfe055e151ee8c7c580e4..58a8a19dccd2dd102beb2803ec04f1f555cdcec2 100644 --- a/src/hydro/GizmoMFV/hydro.h +++ b/src/hydro/GizmoMFV/hydro.h @@ -539,9 +539,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_gradient( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part* restrict p, const struct xpart* restrict xp) { + struct part* restrict p, const struct xpart* restrict xp, + const struct cosmology* cosmo) { // MATTHIEU: Apply the entropy floor here. } diff --git a/src/hydro/GizmoMFV/hydro_io.h b/src/hydro/GizmoMFV/hydro_io.h index 7288df0c510ea48489353b5be4ef9d3f252d5f59..11b8e95867495ccbc9df6a67b3045a09052fb161 100644 --- a/src/hydro/GizmoMFV/hydro_io.h +++ b/src/hydro/GizmoMFV/hydro_io.h @@ -219,15 +219,15 @@ INLINE static void hydro_write_particles(const struct part* parts, "Co-moving mass densities of the particles"); list[7] = io_make_output_field_convert_part( - "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, 0.f, parts, xparts, convert_A, + "Entropies", FLOAT, 1, UNIT_CONV_ENTROPY, 0.f, parts, xparts, convert_A, "Co-moving entropies of the particles"); - list[8] = io_make_output_field("Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, - 3.f * hydro_gamma, parts, primitives.P, + list[8] = io_make_output_field("Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, + -3.f * hydro_gamma, parts, primitives.P, "Co-moving pressures of the particles"); list[9] = io_make_output_field_convert_part( - "TotalEnergies", FLOAT, 1, UNIT_CONV_ENERGY, 3.f * hydro_gamma_minus_one, + "TotalEnergies", FLOAT, 1, UNIT_CONV_ENERGY, -3.f * hydro_gamma_minus_one, parts, xparts, convert_Etot, "Total (co-moving) energy of the particles"); list[10] = io_make_output_field_convert_part( diff --git a/src/hydro/Minimal/hydro.h b/src/hydro/Minimal/hydro.h index 0cac1de40f258ff9921ea98ddd59a848d4bb7a67..3d7f43579033afd8f5c29e765b31fee145d9c590 100644 --- a/src/hydro/Minimal/hydro.h +++ b/src/hydro/Minimal/hydro.h @@ -642,9 +642,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part *restrict p, const struct xpart *restrict xp) { + struct part *restrict p, const struct xpart *restrict xp, + const struct cosmology *cosmo) { /* Re-set the predicted velocities */ p->v[0] = xp->v_full[0]; diff --git a/src/hydro/Minimal/hydro_io.h b/src/hydro/Minimal/hydro_io.h index a32e2c1a87c3219640ed94d56725632539121dd8..ba62489bcc8a7bff3b9d3cd45d9b9d0881772194 100644 --- a/src/hydro/Minimal/hydro_io.h +++ b/src/hydro/Minimal/hydro_io.h @@ -179,7 +179,7 @@ INLINE static void hydro_write_particles(const struct part* parts, list[4] = io_make_output_field( "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - 3. * hydro_gamma_minus_one, parts, u, + -3.f * hydro_gamma_minus_one, parts, u, "Co-moving thermal energies per unit mass of the particles"); list[5] = @@ -195,7 +195,7 @@ INLINE static void hydro_write_particles(const struct part* parts, xparts, convert_S, "Co-moving entropies per unit mass of the particles"); list[8] = io_make_output_field_convert_part( - "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, 3.f * hydro_gamma, parts, + "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, -3.f * hydro_gamma, parts, xparts, convert_P, "Co-moving pressures of the particles"); } diff --git a/src/hydro/Planetary/hydro.h b/src/hydro/Planetary/hydro.h index ee9aa95d5082e4bf21e8ac1ebf6710530638a974..3891bf3df8245b63ec40985910aa7d827b0c00b7 100644 --- a/src/hydro/Planetary/hydro.h +++ b/src/hydro/Planetary/hydro.h @@ -652,9 +652,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part *restrict p, const struct xpart *restrict xp) { + struct part *restrict p, const struct xpart *restrict xp, + const struct cosmology *cosmo) { /* Re-set the predicted velocities */ p->v[0] = xp->v_full[0]; diff --git a/src/hydro/Planetary/hydro_io.h b/src/hydro/Planetary/hydro_io.h index 6dd84b3e1b00beda160b4b51109b544ac0ad8b86..782e4de6dc05c8d5b485f9f4d2dadd685e44e3a7 100644 --- a/src/hydro/Planetary/hydro_io.h +++ b/src/hydro/Planetary/hydro_io.h @@ -176,7 +176,7 @@ INLINE static void hydro_write_particles(const struct part* parts, "Smoothing lengths (FWHM of the kernel) of the particles"); list[4] = io_make_output_field( "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - 3. * hydro_gamma_minus_one, parts, u, + -3.f * hydro_gamma_minus_one, parts, u, "Thermal energies per unit mass of the particles"); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, 0.f, @@ -190,7 +190,7 @@ INLINE static void hydro_write_particles(const struct part* parts, io_make_output_field("MaterialIDs", INT, 1, UNIT_CONV_NO_UNITS, 0.f, parts, mat_id, "Material IDs of the particles"); list[9] = io_make_output_field_convert_part( - "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, 3.f * hydro_gamma, parts, + "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, -3.f * hydro_gamma, parts, xparts, convert_P, "Pressures of the particles"); list[10] = io_make_output_field_convert_part( "Potentials", FLOAT, 1, UNIT_CONV_POTENTIAL, 0.f, parts, xparts, diff --git a/src/hydro/PressureEnergy/hydro.h b/src/hydro/PressureEnergy/hydro.h index 15f9a958a6c5d4fc199a1c1d7d85d3f909520d23..e49445f59edd7a3a09860bfffe81a56d6a05abd4 100644 --- a/src/hydro/PressureEnergy/hydro.h +++ b/src/hydro/PressureEnergy/hydro.h @@ -213,20 +213,30 @@ hydro_get_drifted_physical_entropy(const struct part *restrict p, } /** - * @brief Returns the comoving sound speed of a particle + * @brief Update the sound speed of a particle * - * @param p The particle of interest + * @param p The particle of interest. + * @param cosmo The cosmological model. */ -__attribute__((always_inline)) INLINE static float -hydro_get_comoving_soundspeed(const struct part *restrict p) { +__attribute__((always_inline)) INLINE static void hydro_update_soundspeed( + struct part *restrict p, const struct cosmology *cosmo) { /* Compute the sound speed -- see theory section for justification */ /* IDEAL GAS ONLY -- P-U does not work with generic EoS. */ const float comoving_pressure = - pressure_floor_get_pressure(p, p->rho, p->pressure_bar); - const float square_rooted = sqrtf(hydro_gamma * comoving_pressure / p->rho); + pressure_floor_get_comoving_pressure(p, p->pressure_bar, cosmo); + p->force.soundspeed = gas_soundspeed_from_pressure(p->rho, comoving_pressure); +} + +/** + * @brief Returns the comoving sound speed of a particle + * + * @param p The particle of interest. + */ +__attribute__((always_inline)) INLINE static float +hydro_get_comoving_soundspeed(const struct part *restrict p) { - return square_rooted; + return p->force.soundspeed; } /** @@ -239,10 +249,8 @@ __attribute__((always_inline)) INLINE static float hydro_get_physical_soundspeed(const struct part *restrict p, const struct cosmology *cosmo) { - const float phys_rho = hydro_get_physical_density(p, cosmo); - - return pressure_floor_get_pressure( - p, phys_rho, cosmo->a_factor_sound_speed * p->force.soundspeed); + /* The pressure floor is already included in p->force.soundspeed */ + return cosmo->a_factor_sound_speed * p->force.soundspeed; } /** @@ -420,11 +428,8 @@ hydro_set_drifted_physical_internal_energy(struct part *p, /* Now recompute the extra quantities */ - /* Compute the sound speed */ - const float soundspeed = hydro_get_comoving_soundspeed(p); - /* Update variables. */ - p->force.soundspeed = soundspeed; + hydro_update_soundspeed(p, cosmo); } /** @@ -503,7 +508,6 @@ __attribute__((always_inline)) INLINE static void hydro_init_part( p->density.wcount = 0.f; p->density.wcount_dh = 0.f; p->rho = 0.f; - p->density.rho_dh = 0.f; p->pressure_bar = 0.f; p->density.pressure_bar_dh = 0.f; @@ -537,7 +541,6 @@ __attribute__((always_inline)) INLINE static void hydro_end_density( /* Final operation on the density (add self-contribution). */ p->rho += p->mass * kernel_root; - p->density.rho_dh -= hydro_dimension * p->mass * kernel_root; p->pressure_bar += p->mass * p->u * kernel_root; p->density.pressure_bar_dh -= hydro_dimension * p->mass * p->u * kernel_root; p->density.wcount += kernel_root; @@ -545,7 +548,6 @@ __attribute__((always_inline)) INLINE static void hydro_end_density( /* Finish the calculation by inserting the missing h-factors */ p->rho *= h_inv_dim; - p->density.rho_dh *= h_inv_dim_plus_one; p->pressure_bar *= (h_inv_dim * hydro_gamma_minus_one); p->density.pressure_bar_dh *= (h_inv_dim_plus_one * hydro_gamma_minus_one); p->density.wcount *= h_inv_dim; @@ -590,7 +592,6 @@ __attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours( p->pressure_bar = p->mass * p->u * hydro_gamma_minus_one * kernel_root * h_inv_dim; p->density.wcount = kernel_root * h_inv_dim; - p->density.rho_dh = 0.f; p->density.wcount_dh = 0.f; p->density.pressure_bar_dh = 0.f; @@ -633,6 +634,7 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force( const float abs_div_v = fabsf(p->density.div_v); /* Compute the sound speed -- see theory section for justification */ + hydro_update_soundspeed(p, cosmo); const float soundspeed = hydro_get_comoving_soundspeed(p); /* Compute the Balsara switch */ @@ -648,11 +650,10 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force( /* Get the pressures */ const float comoving_pressure_with_floor = - pressure_floor_get_pressure(p, p->rho, p->pressure_bar); + pressure_floor_get_comoving_pressure(p, p->pressure_bar, cosmo); /* Update variables. */ p->force.f = grad_h_term; - p->force.soundspeed = soundspeed; p->force.balsara = balsara; p->force.pressure_bar_with_floor = comoving_pressure_with_floor; } @@ -685,9 +686,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part *restrict p, const struct xpart *restrict xp) { + struct part *restrict p, const struct xpart *restrict xp, + const struct cosmology *cosmo) { /* Re-set the predicted velocities */ p->v[0] = xp->v_full[0]; @@ -698,9 +701,7 @@ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( p->u = xp->u_full; /* Compute the sound speed */ - const float soundspeed = hydro_get_comoving_soundspeed(p); - - p->force.soundspeed = soundspeed; + hydro_update_soundspeed(p, cosmo); } /** @@ -763,13 +764,11 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra( } /* Compute the new sound speed */ - const float soundspeed = hydro_get_comoving_soundspeed(p); - - p->force.soundspeed = soundspeed; + hydro_update_soundspeed(p, cosmo); /* update the required variables */ const float comoving_pressure_with_floor = - pressure_floor_get_pressure(p, p->rho, p->pressure_bar); + pressure_floor_get_comoving_pressure(p, p->pressure_bar, cosmo); p->force.pressure_bar_with_floor = comoving_pressure_with_floor; } diff --git a/src/hydro/PressureEnergy/hydro_debug.h b/src/hydro/PressureEnergy/hydro_debug.h index 7ffc370ed4d6abd273fc3d8d5b887f5ccf8e001c..861b16299f824abbee759c80e79d99d449a348c5 100644 --- a/src/hydro/PressureEnergy/hydro_debug.h +++ b/src/hydro/PressureEnergy/hydro_debug.h @@ -30,13 +30,13 @@ __attribute__((always_inline)) INLINE static void hydro_debug_particle( "x=[%.3e,%.3e,%.3e], " "v=[%.3e,%.3e,%.3e],v_full=[%.3e,%.3e,%.3e] \n a=[%.3e,%.3e,%.3e], " "u=%.3e, du/dt=%.3e v_sig=%.3e, P=%.3e\n" - "h=%.3e, dh/dt=%.3e wcount=%d, m=%.3e, dh_drho=%.3e, rho=%.3e, \n" + "h=%.3e, dh/dt=%.3e wcount=%d, m=%.3e, rho=%.3e, \n" "p_dh=%.3e, p_bar=%.3e \n" "time_bin=%d wakeup=%d\n", p->x[0], p->x[1], p->x[2], p->v[0], p->v[1], p->v[2], xp->v_full[0], xp->v_full[1], xp->v_full[2], p->a_hydro[0], p->a_hydro[1], p->a_hydro[2], p->u, p->u_dt, p->force.v_sig, hydro_get_comoving_pressure(p), p->h, - p->force.h_dt, (int)p->density.wcount, p->mass, p->density.rho_dh, p->rho, + p->force.h_dt, (int)p->density.wcount, p->mass, p->rho, p->density.pressure_bar_dh, p->pressure_bar, p->time_bin, p->wakeup); } diff --git a/src/hydro/PressureEnergy/hydro_iact.h b/src/hydro/PressureEnergy/hydro_iact.h index aab8237c7b26c50d9e04610c6c1029f97e5d73ed..62106bb35cd09a0d67d56fb7b8ab58ba7cac7491 100644 --- a/src/hydro/PressureEnergy/hydro_iact.h +++ b/src/hydro/PressureEnergy/hydro_iact.h @@ -69,7 +69,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_density( kernel_deval(ui, &wi, &wi_dx); pi->rho += mj * wi; - pi->density.rho_dh -= mj * (hydro_dimension * wi + ui * wi_dx); pi->pressure_bar += mj * wi * pj->u; pi->density.pressure_bar_dh -= @@ -83,7 +82,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_density( kernel_deval(uj, &wj, &wj_dx); pj->rho += mi * wj; - pj->density.rho_dh -= mi * (hydro_dimension * wj + uj * wj_dx); pj->pressure_bar += mi * wj * pi->u; pj->density.pressure_bar_dh -= mi * pi->u * (hydro_dimension * wj + uj * wj_dx); @@ -149,7 +147,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_density( kernel_deval(ui, &wi, &wi_dx); pi->rho += mj * wi; - pi->density.rho_dh -= mj * (hydro_dimension * wi + ui * wi_dx); pi->pressure_bar += mj * wi * pj->u; diff --git a/src/hydro/PressureEnergy/hydro_io.h b/src/hydro/PressureEnergy/hydro_io.h index e093fe628e5dc8f546fe9be8133692e95b30af2c..896d0137ca7aae2d17159e4dbf335a9263dce3a7 100644 --- a/src/hydro/PressureEnergy/hydro_io.h +++ b/src/hydro/PressureEnergy/hydro_io.h @@ -175,7 +175,7 @@ INLINE static void hydro_write_particles(const struct part* parts, list[4] = io_make_output_field( "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - 3. * hydro_gamma_minus_one, parts, u, + -3.f * hydro_gamma_minus_one, parts, u, "Co-moving thermal energies per unit mass of the particles"); list[5] = @@ -187,7 +187,7 @@ INLINE static void hydro_write_particles(const struct part* parts, "Co-moving mass densities of the particles"); list[7] = io_make_output_field( - "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, 3.f * hydro_gamma, parts, + "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, -3.f * hydro_gamma, parts, pressure_bar, "Co-moving smoothed pressures of the particles"); list[8] = io_make_output_field_convert_part( diff --git a/src/hydro/PressureEnergy/hydro_part.h b/src/hydro/PressureEnergy/hydro_part.h index c8f02f518cfde536965c0e6d000999a0e07e4aab..6231ad4e1356b91c220dad5e992d68c77975e950 100644 --- a/src/hydro/PressureEnergy/hydro_part.h +++ b/src/hydro/PressureEnergy/hydro_part.h @@ -34,6 +34,7 @@ #include "black_holes_struct.h" #include "chemistry_struct.h" #include "cooling_struct.h" +#include "pressure_floor_struct.h" #include "star_formation_struct.h" #include "tracers_struct.h" @@ -132,9 +133,6 @@ struct part { /*! Derivative of the neighbour number with respect to h. */ float wcount_dh; - /*! Derivative of density with respect to h */ - float rho_dh; - /*! Derivative of the weighted pressure with respect to h */ float pressure_bar_dh; @@ -180,6 +178,9 @@ struct part { /*! Black holes information (e.g. swallowing ID) */ struct black_holes_part_data black_holes_data; + /* Additional data used by the pressure floor */ + struct pressure_floor_part_data pressure_floor_data; + /*! Time-step length */ timebin_t time_bin; diff --git a/src/hydro/PressureEnergyMorrisMonaghanAV/hydro.h b/src/hydro/PressureEnergyMorrisMonaghanAV/hydro.h index c23b3467fd0dee575aacf92c108508be7d44ad32..e21750bdf24f19b0f784b8652bcb5a18a6a89e8f 100644 --- a/src/hydro/PressureEnergyMorrisMonaghanAV/hydro.h +++ b/src/hydro/PressureEnergyMorrisMonaghanAV/hydro.h @@ -689,9 +689,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part *restrict p, const struct xpart *restrict xp) { + struct part *restrict p, const struct xpart *restrict xp, + const struct cosmology *cosmo) { /* Re-set the predicted velocities */ p->v[0] = xp->v_full[0]; diff --git a/src/hydro/PressureEnergyMorrisMonaghanAV/hydro_io.h b/src/hydro/PressureEnergyMorrisMonaghanAV/hydro_io.h index d89dc36ad018f89114a8e80eb2abb663e211d762..7da369847a5d684ebe30dbf7428ea3da9a8c216f 100644 --- a/src/hydro/PressureEnergyMorrisMonaghanAV/hydro_io.h +++ b/src/hydro/PressureEnergyMorrisMonaghanAV/hydro_io.h @@ -176,7 +176,7 @@ INLINE static void hydro_write_particles(const struct part* parts, list[4] = io_make_output_field( "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - 3. * hydro_gamma_minus_one, parts, u, + -3.f * hydro_gamma_minus_one, parts, u, "Co-moving thermal energies per unit mass of the particles"); list[5] = @@ -188,7 +188,7 @@ INLINE static void hydro_write_particles(const struct part* parts, "Co-moving mass densities of the particles"); list[7] = io_make_output_field( - "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, 3.f * hydro_gamma, parts, + "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, -3.f * hydro_gamma, parts, pressure_bar, "Co-moving smoothed pressures of the particles"); list[8] = io_make_output_field_convert_part( @@ -196,12 +196,12 @@ INLINE static void hydro_write_particles(const struct part* parts, xparts, convert_S, "Co-moving entropies per unit mass of the particles"); list[9] = io_make_output_field_convert_part( - "Potentials", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, + "Potentials", FLOAT, 1, UNIT_CONV_POTENTIAL, -1.f, parts, xparts, convert_part_potential, "Gravitational potentials of the particles"); - list[10] = io_make_output_field_convert_part( - "ViscosityParameters", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, parts, xparts, - convert_viscosity, "Visosity coefficient (alpha_visc) of the particles"); + list[10] = io_make_output_field( + "ViscosityParameters", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, parts, alpha, + "Visosity coefficient (alpha_visc) of the particles"); } /** diff --git a/src/hydro/PressureEntropy/hydro.h b/src/hydro/PressureEntropy/hydro.h index 66b8e186c82ab1646ffb862ff2d401f0362886c3..83234a7ea145c426767cf4c6d36dc1af8ae490e4 100644 --- a/src/hydro/PressureEntropy/hydro.h +++ b/src/hydro/PressureEntropy/hydro.h @@ -628,9 +628,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part *restrict p, const struct xpart *restrict xp) { + struct part *restrict p, const struct xpart *restrict xp, + const struct cosmology *cosmo) { /* Re-set the predicted velocities */ p->v[0] = xp->v_full[0]; diff --git a/src/hydro/PressureEntropy/hydro_io.h b/src/hydro/PressureEntropy/hydro_io.h index d7591fbdea1576cf6fec645c7a9842f2197b60a3..8ac77f31efde3b708cbf631c792404b135e4c112 100644 --- a/src/hydro/PressureEntropy/hydro_io.h +++ b/src/hydro/PressureEntropy/hydro_io.h @@ -188,11 +188,11 @@ INLINE static void hydro_write_particles(const struct part* parts, list[7] = io_make_output_field_convert_part( "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - 3. * hydro_gamma_minus_one, parts, xparts, convert_u, + -3.f * hydro_gamma_minus_one, parts, xparts, convert_u, "Co-moving thermal energies per unit mass of the particles"); list[8] = io_make_output_field_convert_part( - "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, 3.f * hydro_gamma, parts, + "Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, -3.f * hydro_gamma, parts, xparts, convert_P, "Co-moving smoothed pressures of the particles"); list[9] = io_make_output_field( diff --git a/src/hydro/Shadowswift/hydro.h b/src/hydro/Shadowswift/hydro.h index 955a3db1d4480c43dd2fd57c6d976689d36a5652..8c0454025180598baaeafb4032699cddb44b26d1 100644 --- a/src/hydro/Shadowswift/hydro.h +++ b/src/hydro/Shadowswift/hydro.h @@ -397,9 +397,11 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration( * * @param p The particle. * @param xp The extended data of this particle. + * @param cosmo The cosmological model. */ __attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( - struct part* restrict p, const struct xpart* restrict xp) {} + struct part* restrict p, const struct xpart* restrict xp, + const struct cosmology* cosmo) {} /** * @brief Converts the hydrodynamic variables from the initial condition file to @@ -797,6 +799,7 @@ __attribute__((always_inline)) INLINE static float hydro_get_comoving_density( */ __attribute__((always_inline)) INLINE static float hydro_get_physical_internal_energy(const struct part* restrict p, + const struct xpart* restrict xp, const struct cosmology* cosmo) { return cosmo->a_factor_internal_energy * @@ -874,6 +877,38 @@ hydro_set_drifted_physical_internal_energy(struct part* p, error("Need implementing"); } +/** + * @brief Gets the drifted physical internal energy of a particle + * + * @param p The particle of interest. + * @param cosmo Cosmology data structure + * + * @return The physical internal energy + */ +__attribute__((always_inline)) INLINE static float +hydro_get_drifted_physical_internal_energy(const struct part* p, + const struct cosmology* cosmo) { + error("Need implementing"); + + return 0; +} + +/** + * @brief Gets the drifted physical entropy of a particle + * + * @param p The particle of interest. + * @param cosmo Cosmology data structure + * + * @return The physical entropy + */ +__attribute__((always_inline)) INLINE static float +hydro_get_drifted_physical_entropy(const struct part* p, + const struct cosmology* cosmo) { + error("Need implementing"); + + return 0; +} + /** * @brief Update the value of the viscosity alpha for the scheme. * diff --git a/src/hydro/Shadowswift/hydro_io.h b/src/hydro/Shadowswift/hydro_io.h index 410422331469f980b398139f18ef09d995e0f655..31840a05ee436d5b535ae022bd79118851ef4e5b 100644 --- a/src/hydro/Shadowswift/hydro_io.h +++ b/src/hydro/Shadowswift/hydro_io.h @@ -142,39 +142,42 @@ INLINE static void hydro_write_particles(const struct part* parts, "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, 1.f, parts, xparts, convert_part_pos, "Co-moving positions of the particles"); - list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, - primitives.v); + list[1] = io_make_output_field( + "Velocities", FLOAT, 3, UNIT_CONV_SPEED, 0.f, parts, primitives.v, + "Peculiar velocities of the stars. This is (a * dx/dt) where x is the " + "co-moving positions of the particles"); - list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, - conserved.mass); + list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, 0.f, parts, + conserved.mass, "Masses of the particles"); list[3] = io_make_output_field( "SmoothingLengths", FLOAT, 1, UNIT_CONV_LENGTH, 1.f, parts, h, "Co-moving smoothing lengths (FWHM of the kernel) of the particles"); - list[4] = io_make_output_field_convert_part("InternalEnergies", FLOAT, 1, - UNIT_CONV_ENERGY_PER_UNIT_MASS, - parts, xparts, convert_u); + list[4] = io_make_output_field_convert_part( + "InternalEnergies", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, + -3.f * hydro_gamma_minus_one, parts, xparts, convert_u, + "Co-moving thermal energies per unit mass of the particles"); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, 0.f, parts, id, "Unique IDs of the particles"); list[6] = io_make_output_field("Accelerations", FLOAT, 3, - UNIT_CONV_ACCELERATION, parts, 1.f, a_hydro, + UNIT_CONV_ACCELERATION, 1.f, parts, a_hydro, "Accelerations of the particles(does not " "work in non-cosmological runs)."); - list[7] = io_make_output_field("Densities", FLOAT, 1, UNIT_CONV_DENSITY, - parts, 3.f * hydro_gamma, primitives.rho, + list[7] = io_make_output_field("Densities", FLOAT, 1, UNIT_CONV_DENSITY, -3.f, + parts, primitives.rho, "Co-moving mass densities of the particles"); - list[8] = io_make_output_field("Volumes", FLOAT, 1, UNIT_CONV_VOLUME, parts, - 3.f * hydro_gamma, cell.volume, - "Co-moving volumes of the particles"); + list[8] = + io_make_output_field("Volumes", FLOAT, 1, UNIT_CONV_VOLUME, -3.f, parts, + cell.volume, "Co-moving volumes of the particles"); list[9] = io_make_output_field("GradDensities", FLOAT, 3, UNIT_CONV_DENSITY, - parts, 1.f, primitives.gradients.rho, + 1.f, parts, primitives.gradients.rho, "Gradient densities of the particles"); list[10] = io_make_output_field_convert_part( @@ -182,11 +185,11 @@ INLINE static void hydro_write_particles(const struct part* parts, "Co-moving entropies of the particles"); list[11] = io_make_output_field("Pressures", FLOAT, 1, UNIT_CONV_PRESSURE, - 3.f * hydro_gamma, parts, primitives.P, + -3.f * hydro_gamma, parts, primitives.P, "Co-moving pressures of the particles"); list[12] = io_make_output_field_convert_part( - "TotalEnergies", FLOAT, 1, UNIT_CONV_ENERGY, 3.f * hydro_gamma_minus_one, + "TotalEnergies", FLOAT, 1, UNIT_CONV_ENERGY, -3.f * hydro_gamma_minus_one, parts, xparts, convert_Etot, "Total (co-moving) energy of the particles"); } diff --git a/src/pressure_floor/GEAR/pressure_floor.h b/src/pressure_floor/GEAR/pressure_floor.h index dd715c155a095f9ad5f97b1d14cabfc94d9b11b0..de9ad6cf4450005becade48022be1be481fc1cc9 100644 --- a/src/pressure_floor/GEAR/pressure_floor.h +++ b/src/pressure_floor/GEAR/pressure_floor.h @@ -1,6 +1,6 @@ /******************************************************************************* * This file is part of SWIFT. - * Copyright (c) 2019 Matthieu Schaller (schaller@strw.leidenuniv.nl) + * Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -19,9 +19,19 @@ #ifndef SWIFT_PRESSURE_FLOOR_GEAR_H #define SWIFT_PRESSURE_FLOOR_GEAR_H +/* Forward declaration */ +__attribute__((always_inline)) static INLINE float +pressure_floor_get_comoving_pressure(const struct part* p, const float pressure, + const struct cosmology* cosmo); +__attribute__((always_inline)) static INLINE float +pressure_floor_get_physical_pressure(const struct part* p, const float pressure, + const struct cosmology* cosmo); + #include "adiabatic_index.h" #include "cosmology.h" +#include "dimension.h" #include "equation_of_state.h" +#include "hydro.h" #include "hydro_properties.h" #include "parser.h" #include "part.h" @@ -49,25 +59,54 @@ struct pressure_floor_properties { * * Note that the particle is not updated!! * - * The inputs can be either in physical or comoving coordinates (the output is - * in the same coordinates). + * @param p The #part. + * @param pressure_physical The physical pressure without any pressure floor. + * @param cosmo The #cosmology model. + * + * @return The physical pressure with the floor. + */ +__attribute__((always_inline)) static INLINE float +pressure_floor_get_physical_pressure(const struct part* p, + const float pressure_physical, + const struct cosmology* cosmo) { + + const float H_phys = p->h * cosmo->a_inv * kernel_gamma; + const float rho = hydro_get_physical_density(p, cosmo); + + /* Compute the pressure floor */ + float floor = H_phys * H_phys * rho * pressure_floor_props.constants - + p->pressure_floor_data.sigma2; + floor *= rho * hydro_one_over_gamma; + + return fmaxf(pressure_physical, floor); +} + +/** + * @brief Compute the comoving pressure floor of a given #part. + * + * Note that the particle is not updated!! * * @param p The #part. - * @param rho The physical or comoving density. - * @param pressure The physical or comoving pressure without any pressure floor. + * @param pressure_comoving The comoving pressure without any pressure floor. + * @param cosmo The #cosmology model. * * @return The physical or comoving pressure with the floor. */ -static INLINE float pressure_floor_get_pressure(const struct part *p, - const float rho, - const float pressure) { +__attribute__((always_inline)) static INLINE float +pressure_floor_get_comoving_pressure(const struct part* p, + const float pressure_comoving, + const struct cosmology* cosmo) { - /* Compute pressure floor */ - float floor = p->h * p->h * rho * pressure_floor_props.constants; - // TODO add sigma (will be done once the SF is merged) - floor *= rho * hydro_one_over_gamma; + const float a_coef = pow_three_gamma_minus_one(cosmo->a); + const float rho = hydro_get_comoving_density(p); + + /* Compute the pressure floor */ + float floor = kernel_gamma * kernel_gamma * p->h * p->h * rho * + pressure_floor_props.constants; + floor -= p->pressure_floor_data.sigma2 * cosmo->a * cosmo->a; + floor *= a_coef * rho * hydro_one_over_gamma; - return fmax(pressure, floor); + return fmaxf(pressure_comoving, floor); } /** @@ -83,11 +122,10 @@ static INLINE float pressure_floor_get_pressure(const struct part *p, * @param hydro_props The propoerties of the hydro scheme. * @param props The pressure floor properties to fill. */ -static INLINE void pressure_floor_init(struct pressure_floor_properties *props, - const struct phys_const *phys_const, - const struct unit_system *us, - const struct hydro_props *hydro_props, - struct swift_params *params) { +__attribute__((always_inline)) static INLINE void pressure_floor_init( + struct pressure_floor_properties* props, + const struct phys_const* phys_const, const struct unit_system* us, + const struct hydro_props* hydro_props, struct swift_params* params) { /* Read the Jeans factor */ props->n_jeans = @@ -103,8 +141,8 @@ static INLINE void pressure_floor_init(struct pressure_floor_properties *props, * * @param props The pressure floor properties. */ -static INLINE void pressure_floor_print( - const struct pressure_floor_properties *props) { +__attribute__((always_inline)) static INLINE void pressure_floor_print( + const struct pressure_floor_properties* props) { message("Pressure floor is 'GEAR' with:"); message("Jeans factor: %g", props->n_jeans); @@ -116,9 +154,76 @@ static INLINE void pressure_floor_print( * @brief Writes the current model of pressure floor to the file * @param h_grp The HDF5 group in which to write */ -INLINE static void pressure_floor_print_snapshot(hid_t h_grp) { +__attribute__((always_inline)) INLINE static void pressure_floor_print_snapshot( + hid_t h_grp) { io_write_attribute_s(h_grp, "Pressure floor", "GEAR"); } + +/** + * @brief Finishes the density calculation. + * + * @param p The particle to act upon + * @param cosmo The current cosmological model. + */ +__attribute__((always_inline)) INLINE static void pressure_floor_end_density( + struct part* restrict p, const struct cosmology* cosmo) { + + /* To finish the turbulence estimation we devide by the density */ + p->pressure_floor_data.sigma2 /= + pow_dimension(p->h) * hydro_get_comoving_density(p); + + /* Add the cosmological term */ + p->pressure_floor_data.sigma2 *= cosmo->a2_inv; +} + +/** + * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. + * + * @param p The particle to act upon + * @param xp The extended particle data to act upon + * @param cosmo The current cosmological model. + */ +__attribute__((always_inline)) INLINE static void +pressure_floor_part_has_no_neighbours(struct part* restrict p, + struct xpart* restrict xp, + const struct cosmology* cosmo) { + + /* If part has 0 neighbours, the estimation of turbulence is 0 */ + p->pressure_floor_data.sigma2 = 0.f; +} + +/** + * @brief Sets the pressure_floor properties of the (x-)particles to a valid + * start state. + * + * @param p Pointer to the particle data. + * @param xp Pointer to the extended particle data. + */ +__attribute__((always_inline)) INLINE static void pressure_floor_init_part( + struct part* restrict p, struct xpart* restrict xp) { + p->pressure_floor_data.sigma2 = 0.f; +} + +/** + * @brief Sets the pressure_floor properties of the (x-)particles to a valid + * start state. + * + * @param phys_const The physical constant in internal units. + * @param us The unit system. + * @param cosmo The current cosmological model. + * @param p Pointer to the particle data. + * @param xp Pointer to the extended particle data. + */ +__attribute__((always_inline)) INLINE static void +pressure_floor_first_init_part(const struct phys_const* restrict phys_const, + const struct unit_system* restrict us, + const struct cosmology* restrict cosmo, + struct part* restrict p, + struct xpart* restrict xp) { + + pressure_floor_init_part(p, xp); +} + #endif #endif /* SWIFT_PRESSURE_FLOOR_GEAR_H */ diff --git a/src/star_formation/GEAR/star_formation_iact.h b/src/pressure_floor/GEAR/pressure_floor_iact.h similarity index 72% rename from src/star_formation/GEAR/star_formation_iact.h rename to src/pressure_floor/GEAR/pressure_floor_iact.h index 7325b92af2840b317cf1a924a1e509b34bdffba3..5ffb0b0097bb1d117e024f0e01e7babe1f838c40 100644 --- a/src/star_formation/GEAR/star_formation_iact.h +++ b/src/pressure_floor/GEAR/pressure_floor_iact.h @@ -17,16 +17,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * ******************************************************************************/ -#ifndef SWIFT_GEAR_STAR_FORMATION_IACT_H -#define SWIFT_GEAR_STAR_FORMATION_IACT_H +#ifndef SWIFT_GEAR_PRESSURE_FLOOR_IACT_H +#define SWIFT_GEAR_PRESSURE_FLOOR_IACT_H /** - * @file GEAR/star_formation_iact.h + * @file GEAR/pressure_floor_iact.h * @brief Density computation */ /** - * @brief do star_formation computation after the runner_iact_density (symmetric + * @brief do pressure_floor computation after the runner_iact_density (symmetric * version) * * Compute the velocity dispersion follow eq. 2 in Revaz & Jablonka 2018. @@ -40,7 +40,7 @@ * @param a Current scale factor. * @param H Current Hubble parameter. */ -__attribute__((always_inline)) INLINE static void runner_iact_star_formation( +__attribute__((always_inline)) INLINE static void runner_iact_pressure_floor( float r2, const float *dx, float hi, float hj, struct part *restrict pi, struct part *restrict pj, float a, float H) { @@ -53,20 +53,20 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( /* Delta v */ float dv[3] = {pi->v[0] - pj->v[0], pi->v[1] - pj->v[1], pi->v[2] - pj->v[2]}; - /* Norms at power 2 */ - const float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; - const float norm_x2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]; - /* Compute the velocity dispersion */ - const float sigma2 = norm_v2 + H * norm_x2; + const float a2H = a * a * H; + const float sigma[3] = {dv[0] + a2H * dx[0], dv[1] + a2H * dx[1], + dv[2] + a2H * dx[2]}; + const float sigma2 = + sigma[0] * sigma[0] + sigma[1] * sigma[1] + sigma[2] * sigma[2]; /* Compute the velocity dispersion */ - pi->sf_data.sigma2 += sigma2 * wi * hydro_get_mass(pj); - pj->sf_data.sigma2 += sigma2 * wj * hydro_get_mass(pi); + pi->pressure_floor_data.sigma2 += sigma2 * wi * hydro_get_mass(pj); + pj->pressure_floor_data.sigma2 += sigma2 * wj * hydro_get_mass(pi); } /** - * @brief do star_formation computation after the runner_iact_density (non + * @brief do pressure_floor computation after the runner_iact_density (non * symmetric version) * * @param r2 Comoving square distance between the two particles. @@ -79,7 +79,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( * @param H Current Hubble parameter. */ __attribute__((always_inline)) INLINE static void -runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, +runner_iact_nonsym_pressure_floor(float r2, const float *dx, float hi, float hj, struct part *restrict pi, const struct part *restrict pj, float a, float H) { @@ -90,15 +90,15 @@ runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, /* Delta v */ float dv[3] = {pi->v[0] - pj->v[0], pi->v[1] - pj->v[1], pi->v[2] - pj->v[2]}; - /* Norms at power 2 */ - const float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; - const float norm_x2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]; - /* Compute the velocity dispersion */ - const float sigma2 = norm_v2 + H * norm_x2; + const float a2H = a * a * H; + const float sigma[3] = {dv[0] + a2H * dx[0], dv[1] + a2H * dx[1], + dv[2] + a2H * dx[2]}; + const float sigma2 = + sigma[0] * sigma[0] + sigma[1] * sigma[1] + sigma[2] * sigma[2]; /* Compute the velocity dispersion */ - pi->sf_data.sigma2 += sigma2 * wi * hydro_get_mass(pj); + pi->pressure_floor_data.sigma2 += sigma2 * wi * hydro_get_mass(pj); } -#endif /* SWIFT_GEAR_STAR_FORMATION_IACT_H */ +#endif /* SWIFT_GEAR_PRESSURE_FLOOR_IACT_H */ diff --git a/src/pressure_floor/GEAR/pressure_floor_struct.h b/src/pressure_floor/GEAR/pressure_floor_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..1eb70b86dcfb79ce9818e1d7c598d49d5e654efd --- /dev/null +++ b/src/pressure_floor/GEAR/pressure_floor_struct.h @@ -0,0 +1,32 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2019 Matthieu Schaller (schaller@strw.leidenuniv.nl) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + ******************************************************************************/ +#ifndef SWIFT_PRESSURE_FLOOR_PART_GEAR_H +#define SWIFT_PRESSURE_FLOOR_PART_GEAR_H + +/** + * Structure containing the required variables for the pressure + * floor in the density loop. + */ +struct pressure_floor_part_data { + /*! Estimation of local turbulence (squared) + * Units: length^2 / time^2 (physical) */ + float sigma2; +}; + +#endif // SWIFT_PRESSURE_FLOOR_PART_GEAR_H diff --git a/src/pressure_floor/none/pressure_floor.h b/src/pressure_floor/none/pressure_floor.h index 2d0b95a71f9ccce6697e79760aa43b560933e7bd..84db9cbaf682b36fa68abc7d26273e15cd1da191 100644 --- a/src/pressure_floor/none/pressure_floor.h +++ b/src/pressure_floor/none/pressure_floor.h @@ -42,19 +42,33 @@ struct pressure_floor_properties {}; * * Note that the particle is not updated!! * - * The inputs can be either in physical or comoving coordinates (the output is - * in the same coordinates). + * @param p The #part. + * @param physical_pressure The physical pressure without any pressure floor. + * @param cosmo The #cosmology model. + * + * @return The physical pressure with the floor. + */ +static INLINE float pressure_floor_get_physical_pressure( + const struct part* p, const float physical_pressure, + const struct cosmology* cosmo) { + return physical_pressure; +} + +/** + * @brief Compute the comoving pressure floor of a given #part. + * + * Note that the particle is not updated!! * * @param p The #part. - * @param rho The physical or comoving density. - * @param pressure The physical or comoving pressure without any pressure floor. + * @param comoving_pressure The comoving pressure without any pressure floor. + * @param cosmo The #cosmology model. * - * @return The physical or comoving pressure with the floor. + * @return The comoving pressure with the floor. */ -static INLINE float pressure_floor_get_pressure(const struct part *p, - const float rho, - const float pressure) { - return pressure; +static INLINE float pressure_floor_get_comoving_pressure( + const struct part* p, const float comoving_pressure, + const struct cosmology* cosmo) { + return comoving_pressure; } /** @@ -70,11 +84,11 @@ static INLINE float pressure_floor_get_pressure(const struct part *p, * @param hydro_props The propoerties of the hydro scheme. * @param props The pressure floor properties to fill. */ -static INLINE void pressure_floor_init(struct pressure_floor_properties *props, - const struct phys_const *phys_const, - const struct unit_system *us, - const struct hydro_props *hydro_props, - struct swift_params *params) {} +static INLINE void pressure_floor_init(struct pressure_floor_properties* props, + const struct phys_const* phys_const, + const struct unit_system* us, + const struct hydro_props* hydro_props, + struct swift_params* params) {} /** * @brief Print the properties of the pressure floor to stdout. @@ -82,7 +96,7 @@ static INLINE void pressure_floor_init(struct pressure_floor_properties *props, * @param props The pressure floor properties. */ static INLINE void pressure_floor_print( - const struct pressure_floor_properties *props) {} + const struct pressure_floor_properties* props) {} #ifdef HAVE_HDF5 @@ -96,4 +110,52 @@ INLINE static void pressure_floor_print_snapshot(hid_t h_grp) { } #endif +/** + * @brief Finishes the density calculation. + * + * @param p The particle to act upon + * @param cosmo The current cosmological model. + */ +__attribute__((always_inline)) INLINE static void pressure_floor_end_density( + struct part* restrict p, const struct cosmology* cosmo) {} + +/** + * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. + * + * @param p The particle to act upon + * @param xp The extended particle data to act upon + * @param cosmo The current cosmological model. + */ +__attribute__((always_inline)) INLINE static void +pressure_floor_part_has_no_neighbours(struct part* restrict p, + struct xpart* restrict xp, + const struct cosmology* cosmo) {} + +/** + * @brief Sets the pressure_floor properties of the (x-)particles to a valid + * start state. + * + * @param p Pointer to the particle data. + * @param xp Pointer to the extended particle data. + */ +__attribute__((always_inline)) INLINE static void pressure_floor_init_part( + struct part* restrict p, struct xpart* restrict xp) {} + +/** + * @brief Sets the pressure_floor properties of the (x-)particles to a valid + * start state. + * + * @param phys_const The physical constant in internal units. + * @param us The unit system. + * @param cosmo The current cosmological model. + * @param p Pointer to the particle data. + * @param xp Pointer to the extended particle data. + */ +__attribute__((always_inline)) INLINE static void +pressure_floor_first_init_part(const struct phys_const* restrict phys_const, + const struct unit_system* restrict us, + const struct cosmology* restrict cosmo, + struct part* restrict p, + struct xpart* restrict xp) {} + #endif /* SWIFT_PRESSURE_FLOOR_NONE_H */ diff --git a/src/star_formation/none/star_formation_iact.h b/src/pressure_floor/none/pressure_floor_iact.h similarity index 75% rename from src/star_formation/none/star_formation_iact.h rename to src/pressure_floor/none/pressure_floor_iact.h index dd74115bec699029748806b512c9d6bd7fb829fe..fedacfe06be1a6de2a87f14ce2b5a6306f29ac09 100644 --- a/src/star_formation/none/star_formation_iact.h +++ b/src/pressure_floor/none/pressure_floor_iact.h @@ -1,4 +1,7 @@ /******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -14,18 +17,20 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * ******************************************************************************/ -#ifndef SWIFT_NONE_STAR_FORMATION_IACT_H -#define SWIFT_NONE_STAR_FORMATION_IACT_H +#ifndef SWIFT_NONE_PRESSURE_FLOOR_IACT_H +#define SWIFT_NONE_PRESSURE_FLOOR_IACT_H /** - * @file none/star_formation_iact.h + * @file NONE/pressure_floor_iact.h * @brief Density computation */ /** - * @brief do star_formation computation after the runner_iact_density (symmetric + * @brief do pressure_floor computation after the runner_iact_density (symmetric * version) * + * Compute the velocity dispersion follow eq. 2 in Revaz & Jablonka 2018. + * * @param r2 Comoving square distance between the two particles. * @param dx Comoving vector separating both particles (pi - pj). * @param hi Comoving smoothing-length of particle i. @@ -35,12 +40,12 @@ * @param a Current scale factor. * @param H Current Hubble parameter. */ -__attribute__((always_inline)) INLINE static void runner_iact_star_formation( +__attribute__((always_inline)) INLINE static void runner_iact_pressure_floor( float r2, const float *dx, float hi, float hj, struct part *restrict pi, struct part *restrict pj, float a, float H) {} /** - * @brief do star_formation computation after the runner_iact_density (non + * @brief do pressure_floor computation after the runner_iact_density (non * symmetric version) * * @param r2 Comoving square distance between the two particles. @@ -53,9 +58,9 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( * @param H Current Hubble parameter. */ __attribute__((always_inline)) INLINE static void -runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, +runner_iact_nonsym_pressure_floor(float r2, const float *dx, float hi, float hj, struct part *restrict pi, const struct part *restrict pj, float a, float H) {} -#endif /* SWIFT_NONE_STAR_FORMATION_IACT_H */ +#endif /* SWIFT_NONE_PRESSURE_FLOOR_IACT_H */ diff --git a/src/pressure_floor/none/pressure_floor_struct.h b/src/pressure_floor/none/pressure_floor_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..d2eee232faff5c74f2f4af6597d919a7901c3473 --- /dev/null +++ b/src/pressure_floor/none/pressure_floor_struct.h @@ -0,0 +1,28 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2019 Matthieu Schaller (schaller@strw.leidenuniv.nl) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + ******************************************************************************/ +#ifndef SWIFT_PRESSURE_FLOOR_PART_NONE_H +#define SWIFT_PRESSURE_FLOOR_PART_NONE_H + +/** + * Structure containing the required variables for the pressure + * floor in the density loop. + */ +struct pressure_floor_part_data {}; + +#endif // SWIFT_PRESSURE_FLOOR_PART_NONE_H diff --git a/src/star_formation_iact.h b/src/pressure_floor_iact.h similarity index 59% rename from src/star_formation_iact.h rename to src/pressure_floor_iact.h index ef457214a23102bc33385705db41c89dc29d8b8f..258bf25a5a8429668c30b1d78532159ff32916b9 100644 --- a/src/star_formation_iact.h +++ b/src/pressure_floor_iact.h @@ -1,6 +1,6 @@ /******************************************************************************* * This file is part of SWIFT. - * Copyright (c) 2018 Folkert Nobels (nobels@strw.leidenuniv.nl) + * Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -16,26 +16,24 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * ******************************************************************************/ -#ifndef SWIFT_STAR_FORMATION_IACT_H -#define SWIFT_STAR_FORMATION_IACT_H +#ifndef SWIFT_PRESSURE_FLOOR_IACT_H +#define SWIFT_PRESSURE_FLOOR_IACT_H /** - * @file src/star_formation_iact.h - * @brief Branches between the different star formation iact. + * @file src/pressure_floor_iact.h + * @brief Branches between the different pressure floor iact. */ /* Config parameters. */ #include "../config.h" -/* Import the right star formation law definition */ -#if defined(STAR_FORMATION_NONE) -#include "./star_formation/none/star_formation_iact.h" -#elif defined(STAR_FORMATION_EAGLE) -#include "./star_formation/EAGLE/star_formation_iact.h" -#elif defined(STAR_FORMATION_GEAR) -#include "./star_formation/GEAR/star_formation_iact.h" +/* Import the right pressure floor definition */ +#if defined(PRESSURE_FLOOR_NONE) +#include "./pressure_floor/none/pressure_floor_iact.h" +#elif defined(PRESSURE_FLOOR_GEAR) +#include "./pressure_floor/GEAR/pressure_floor_iact.h" #else -#error "Invalid choice of star formation law" +#error "Invalid choice of pressure floor" #endif -#endif /* SWIFT_STAR_FORMATION_IACT_H */ +#endif /* SWIFT_PRESSURE_FLOOR_IACT_H */ diff --git a/src/pressure_floor_struct.h b/src/pressure_floor_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..e5538b37e03258fab45f9a2cb067f571ff7d16fd --- /dev/null +++ b/src/pressure_floor_struct.h @@ -0,0 +1,39 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + ******************************************************************************/ +#ifndef SWIFT_PRESSURE_FLOOR_STRUCT_H +#define SWIFT_PRESSURE_FLOOR_STRUCT_H + +/** + * @file src/pressure_floor_struct.h + * @brief Branches between the different pressure floor data + */ + +/* Config parameters. */ +#include "../config.h" + +/* Import the right pressure floor definition */ +#if defined(PRESSURE_FLOOR_NONE) +#include "./pressure_floor/none/pressure_floor_struct.h" +#elif defined(PRESSURE_FLOOR_GEAR) +#include "./pressure_floor/GEAR/pressure_floor_struct.h" +#else +#error "Invalid choice of pressure floor structure." +#endif + +#endif /* SWIFT_PRESSURE_FLOOR_STRUCT_H */ diff --git a/src/proxy.c b/src/proxy.c index ee2ba818541fdb874fff9c865ac4bb2ee02b371c..4e7e979a68c311ecdde7d36f214a6d5dcded4f5e 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -69,7 +69,10 @@ void proxy_tags_exchange(struct proxy *proxies, int num_proxies, /* Run through the cells and get the size of the tags that will be sent off. */ int count_out = 0; - int offset_out[s->nr_cells]; + int *offset_out = + (int *)swift_malloc("tags_offsets_out", s->nr_cells * sizeof(int)); + if (offset_out == NULL) error("Error allocating memory for tag offsets"); + for (int k = 0; k < s->nr_cells; k++) { offset_out[k] = count_out; if (s->cells_top[k].mpi.sendto) { @@ -79,7 +82,10 @@ void proxy_tags_exchange(struct proxy *proxies, int num_proxies, /* Run through the proxies and get the count of incoming tags. */ int count_in = 0; - int offset_in[s->nr_cells]; + int *offset_in = + (int *)swift_malloc("tags_offsets_in", s->nr_cells * sizeof(int)); + if (offset_in == NULL) error("Error allocating memory for tag offsets"); + for (int k = 0; k < num_proxies; k++) { for (int j = 0; j < proxies[k].nr_cells_in; j++) { offset_in[proxies[k].cells_in[j] - s->cells_top] = count_in; @@ -170,6 +176,8 @@ void proxy_tags_exchange(struct proxy *proxies, int num_proxies, /* Clean up. */ swift_free("tags_in", tags_in); swift_free("tags_out", tags_out); + swift_free("tags_offsets_in", offset_in); + swift_free("tags_offsets_out", offset_out); free(reqs_in); free(cids_in); @@ -389,7 +397,10 @@ void proxy_cells_exchange(struct proxy *proxies, int num_proxies, s->nr_cells, sizeof(struct cell), /*chunk=*/0, /*extra_data=*/NULL); int count_out = 0; - int offset[s->nr_cells]; + int *offset = + (int *)swift_malloc("proxy_cell_offset", s->nr_cells * sizeof(int)); + if (offset == NULL) error("Error allocating memory for proxy cell offsets"); + for (int k = 0; k < s->nr_cells; k++) { offset[k] = count_out; if (s->cells_top[k].mpi.sendto) count_out += s->cells_top[k].mpi.pcell_size; @@ -472,6 +483,7 @@ void proxy_cells_exchange(struct proxy *proxies, int num_proxies, /* Clean up. */ free(reqs); swift_free("pcells", pcells); + swift_free("proxy_cell_offset", offset); #else error("SWIFT was not compiled with MPI support."); diff --git a/src/runner.c b/src/runner.c index 7d41019ed3dc00364e7c170e3310d93f303e7414..ba9ec9b83c9154c8261f4f559a180da43c154dd3 100644 --- a/src/runner.c +++ b/src/runner.c @@ -60,13 +60,14 @@ #include "logger.h" #include "memuse.h" #include "minmax.h" +#include "pressure_floor.h" +#include "pressure_floor_iact.h" #include "runner_doiact_vec.h" #include "scheduler.h" #include "sort_part.h" #include "space.h" #include "space_getsid.h" #include "star_formation.h" -#include "star_formation_iact.h" #include "star_formation_logger.h" #include "stars.h" #include "task.h" @@ -2032,7 +2033,6 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { const struct hydro_space *hs = &s->hs; const struct cosmology *cosmo = e->cosmology; const struct chemistry_global_data *chemistry = e->chemistry; - const struct star_formation *star_formation = e->star_formation; const int with_cosmology = (e->policy & engine_policy_cosmology); @@ -2129,7 +2129,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Finish the density calculation */ hydro_end_density(p, cosmo); chemistry_end_density(p, chemistry, cosmo); - star_formation_end_density(p, star_formation, cosmo); + pressure_floor_end_density(p, cosmo); /* Compute one step of the Newton-Raphson scheme */ const float n_sum = p->density.wcount * h_old_dim; @@ -2276,7 +2276,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Re-initialise everything */ hydro_init_part(p, hs); chemistry_init_part(p, chemistry); - star_formation_init_part(p, xp, star_formation); + pressure_floor_init_part(p, xp); tracers_after_init(p, xp, e->internal_units, e->physical_constants, with_cosmology, e->cosmology, e->hydro_properties, e->cooling_func, e->time); @@ -2298,8 +2298,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { if (has_no_neighbours) { hydro_part_has_no_neighbours(p, xp, cosmo); chemistry_part_has_no_neighbours(p, xp, chemistry, cosmo); - star_formation_part_has_no_neighbours(p, xp, star_formation, - cosmo); + pressure_floor_part_has_no_neighbours(p, xp, cosmo); } } else { @@ -2964,7 +2963,7 @@ void runner_do_kick2(struct runner *r, struct cell *c, int timer) { #endif /* Prepare the values to be drifted */ - hydro_reset_predicted_values(p, xp); + hydro_reset_predicted_values(p, xp, cosmo); } } @@ -3623,6 +3622,7 @@ void runner_do_end_hydro_force(struct runner *r, struct cell *c, int timer) { /* Finish the force loop */ hydro_end_force(p, cosmo); + chemistry_end_force(p, cosmo); #ifdef SWIFT_BOUNDARY_PARTICLES diff --git a/src/runner_doiact.h b/src/runner_doiact.h index 1a39c8d49f2c4234c04982e255705f06ec1c5d38..8aabb05d177385c6bbee1a91eb2ea231ccbca3e4 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -213,7 +213,7 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } if (r2 < hjg2 && pj_active) { @@ -225,7 +225,7 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } @@ -325,14 +325,14 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (pi_active) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (pj_active) { @@ -343,7 +343,7 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } } @@ -431,14 +431,14 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doi) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doj) { @@ -449,7 +449,7 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over the parts in cj. */ @@ -536,14 +536,14 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doi) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doj) { @@ -554,7 +554,7 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over the parts in cj. */ @@ -640,7 +640,7 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, pj->h, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, pj->h, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -733,7 +733,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -789,7 +789,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -931,7 +931,7 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -1095,7 +1095,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -1183,7 +1183,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over the parts in ci. */ @@ -1483,7 +1483,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over the active parts in cj. */ @@ -1554,13 +1554,13 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } } @@ -1663,7 +1663,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the active parts in ci. */ @@ -1736,13 +1736,13 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } else { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } } @@ -1931,7 +1931,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over all other particles. */ @@ -1983,14 +1983,14 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doi) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doj) { @@ -2000,7 +2000,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } } @@ -2127,7 +2127,7 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over all other particles. */ @@ -2174,13 +2174,13 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } else { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, hj, pi, pj, a, H); #endif } } diff --git a/src/space.c b/src/space.c index 2fd83785451b634b97610bea34fb0bce032f9acc..d67ab9a0bf3cc425b8939ccabdd61a4ec3274e97 100644 --- a/src/space.c +++ b/src/space.c @@ -56,9 +56,9 @@ #include "memuse.h" #include "minmax.h" #include "multipole.h" +#include "pressure_floor.h" #include "restart.h" #include "sort_part.h" -#include "star_formation.h" #include "star_formation_logger.h" #include "stars.h" #include "threadpool.h" @@ -4038,7 +4038,6 @@ void space_first_init_parts_mapper(void *restrict map_data, int count, const int with_gravity = e->policy & engine_policy_self_gravity; const struct chemistry_global_data *chemistry = e->chemistry; - const struct star_formation *star_formation = e->star_formation; const struct cooling_function_data *cool_func = e->cooling_func; /* Check that the smoothing lengths are non-zero */ @@ -4089,9 +4088,8 @@ void space_first_init_parts_mapper(void *restrict map_data, int count, /* Also initialise the chemistry */ chemistry_first_init_part(phys_const, us, cosmo, chemistry, &p[k], &xp[k]); - /* Also initialise the star formation */ - star_formation_first_init_part(phys_const, us, cosmo, star_formation, &p[k], - &xp[k]); + /* Also initialise the pressure floor */ + pressure_floor_first_init_part(phys_const, us, cosmo, &p[k], &xp[k]); /* And the cooling */ cooling_first_init_part(phys_const, us, cosmo, cool_func, &p[k], &xp[k]); @@ -4373,7 +4371,7 @@ void space_init_parts_mapper(void *restrict map_data, int count, for (int k = 0; k < count; k++) { hydro_init_part(&parts[k], hs); chemistry_init_part(&parts[k], e->chemistry); - star_formation_init_part(&parts[k], &xparts[k], e->star_formation); + pressure_floor_init_part(&parts[k], &xparts[k]); tracers_after_init(&parts[k], &xparts[k], e->internal_units, e->physical_constants, with_cosmology, e->cosmology, e->hydro_properties, e->cooling_func, e->time); @@ -4602,8 +4600,9 @@ void space_init(struct space *s, struct swift_params *params, Ngpart = s->nr_gparts; #ifdef SWIFT_DEBUG_CHECKS - part_verify_links(parts, gparts, sparts, bparts, Npart, Ngpart, Nspart, - Nbpart, 1); + if (!dry_run) + part_verify_links(parts, gparts, sparts, bparts, Npart, Ngpart, Nspart, + Nbpart, 1); #endif } diff --git a/src/star_formation/EAGLE/star_formation.h b/src/star_formation/EAGLE/star_formation.h index f2c77e036842b4ca040c58a6bcad1513b03a42bd..851f493801dc5cb0beee9cd07ea5415a5ad1ccf1 100644 --- a/src/star_formation/EAGLE/star_formation.h +++ b/src/star_formation/EAGLE/star_formation.h @@ -232,8 +232,11 @@ INLINE static int star_formation_is_star_forming( * because we also need to check if the physical density exceeded * the appropriate limit */ - const double Z = p->chemistry_data.smoothed_metal_mass_fraction_total; - const double X_H = p->chemistry_data.smoothed_metal_mass_fraction[0]; + const double Z = + chemistry_get_total_metal_mass_fraction_for_star_formation(p); + const float* const metal_fraction = + chemistry_get_metal_mass_fraction_for_star_formation(p); + const double X_H = metal_fraction[chemistry_element_H]; const double n_H = physical_density * X_H; /* Get the density threshold */ @@ -279,7 +282,9 @@ INLINE static void star_formation_compute_SFR( /* Hydrogen number density of this particle */ const double physical_density = hydro_get_physical_density(p, cosmo); - const double X_H = p->chemistry_data.smoothed_metal_mass_fraction[0]; + const float* const metal_fraction = + chemistry_get_metal_mass_fraction_for_star_formation(p); + const double X_H = metal_fraction[chemistry_element_H]; const double n_H = physical_density * X_H / phys_const->const_proton_mass; /* Are we above the threshold for automatic star formation? */ @@ -627,71 +632,4 @@ INLINE static void starformation_print_backend( starform->max_gas_density_HpCM3); } -/** - * @brief Finishes the density calculation. - * - * Nothing to do here. We do not need to compute any quantity in the hydro - * density loop for the EAGLE star formation model. - * - * @param p The particle to act upon - * @param cd The global star_formation information. - * @param cosmo The current cosmological model. - */ -__attribute__((always_inline)) INLINE static void star_formation_end_density( - struct part* restrict p, const struct star_formation* cd, - const struct cosmology* cosmo) {} - -/** - * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. - * - * Nothing to do here. We do not need to compute any quantity in the hydro - * density loop for the EAGLE star formation model. - * - * @param p The particle to act upon - * @param xp The extended particle data to act upon - * @param cd #star_formation containing star_formation informations. - * @param cosmo The current cosmological model. - */ -__attribute__((always_inline)) INLINE static void -star_formation_part_has_no_neighbours(struct part* restrict p, - struct xpart* restrict xp, - const struct star_formation* cd, - const struct cosmology* cosmo) {} - -/** - * @brief Sets the star_formation properties of the (x-)particles to a valid - * start state. - * - * Nothing to do here. - * - * @param phys_const The physical constant in internal units. - * @param us The unit system. - * @param cosmo The current cosmological model. - * @param data The global star_formation information used for this run. - * @param p Pointer to the particle data. - * @param xp Pointer to the extended particle data. - */ -__attribute__((always_inline)) INLINE static void -star_formation_first_init_part(const struct phys_const* restrict phys_const, - const struct unit_system* restrict us, - const struct cosmology* restrict cosmo, - const struct star_formation* data, - const struct part* restrict p, - struct xpart* restrict xp) {} - -/** - * @brief Sets the star_formation properties of the (x-)particles to a valid - * start state. - * - * Nothing to do here. We do not need to compute any quantity in the hydro - * density loop for the EAGLE star formation model. - * - * @param p Pointer to the particle data. - * @param xp Pointer to the extended particle data. - * @param data The global star_formation information. - */ -__attribute__((always_inline)) INLINE static void star_formation_init_part( - struct part* restrict p, struct xpart* restrict xp, - const struct star_formation* data) {} - #endif /* SWIFT_EAGLE_STAR_FORMATION_H */ diff --git a/src/star_formation/EAGLE/star_formation_iact.h b/src/star_formation/EAGLE/star_formation_iact.h deleted file mode 100644 index ab917cbe7aa67cad93a92a4b24212c5f1dcf3aeb..0000000000000000000000000000000000000000 --- a/src/star_formation/EAGLE/star_formation_iact.h +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * This file is part of SWIFT. - * Copyright (c) 2018 Matthieu Schaller (matthieu.schaller@durham.ac.uk) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - ******************************************************************************/ -#ifndef SWIFT_EAGLE_STAR_FORMATION_IACT_H -#define SWIFT_EAGLE_STAR_FORMATION_IACT_H - -/** - * @file EAGLE/star_formation_iact.h - * @brief Density computation - */ - -/** - * @brief do star_formation computation after the runner_iact_density (symmetric - * version) - * - * @param r2 Comoving square distance between the two particles. - * @param dx Comoving vector separating both particles (pi - pj). - * @param hi Comoving smoothing-length of particle i. - * @param hj Comoving smoothing-length of particle j. - * @param pi First particle. - * @param pj Second particle. - * @param a Current scale factor. - * @param H Current Hubble parameter. - */ -__attribute__((always_inline)) INLINE static void runner_iact_star_formation( - float r2, const float *dx, float hi, float hj, struct part *restrict pi, - struct part *restrict pj, float a, float H) { - - /* Nothing to do here. We do not need to compute any quantity in the hydro - density loop for the EAGLE star formation model. */ -} - -/** - * @brief do star_formation computation after the runner_iact_density (non - * symmetric version) - * - * @param r2 Comoving square distance between the two particles. - * @param dx Comoving vector separating both particles (pi - pj). - * @param hi Comoving smoothing-length of particle i. - * @param hj Comoving smoothing-length of particle j. - * @param pi First particle. - * @param pj Second particle (not updated). - * @param a Current scale factor. - * @param H Current Hubble parameter. - */ -__attribute__((always_inline)) INLINE static void -runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, - struct part *restrict pi, - const struct part *restrict pj, float a, - float H) { - - /* Nothing to do here. We do not need to compute any quantity in the hydro - density loop for the EAGLE star formation model. */ -} - -#endif /* SWIFT_EAGLE_STAR_FORMATION_IACT_H */ diff --git a/src/star_formation/EAGLE/star_formation_struct.h b/src/star_formation/EAGLE/star_formation_struct.h index 8caac49d4b57652c5db9ae93e3789dc690e6d23f..41247e160a3eddbc9184c59b67cfa2a1d7259a05 100644 --- a/src/star_formation/EAGLE/star_formation_struct.h +++ b/src/star_formation/EAGLE/star_formation_struct.h @@ -29,6 +29,4 @@ struct star_formation_xpart_data { float SFR; }; -struct star_formation_part_data {}; - #endif /* SWIFT_EAGLE_STAR_FORMATION_STRUCT_H */ diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index ac423a51865609460e870f65b1eeeb266182e2ef..5fc3380fe6869bd5bcb9435fb0c129ac6fc0aad2 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -70,7 +70,7 @@ INLINE static int star_formation_is_star_forming( } /* Get the required variables */ - const float sigma2 = p->sf_data.sigma2; + const float sigma2 = p->pressure_floor_data.sigma2 * cosmo->a * cosmo->a; const float n_jeans_2_3 = starform->n_jeans_2_3; const float h = p->h; @@ -223,79 +223,4 @@ INLINE static void starformation_print_backend( message("Star formation law is 'GEAR'"); } -/** - * @brief Finishes the density calculation. - * - * @param p The particle to act upon - * @param xp The extended particle data to act upon - * @param sf The global star_formation information. - * @param cosmo The current cosmological model. - */ -__attribute__((always_inline)) INLINE static void star_formation_end_density( - struct part* restrict p, const struct star_formation* sf, - const struct cosmology* cosmo) { - - // TODO move into pressure floor - /* To finish the turbulence estimation we devide by the density */ - p->sf_data.sigma2 /= - pow_dimension(p->h) * hydro_get_physical_density(p, cosmo); - - /* Add the cosmological factor */ - p->sf_data.sigma2 *= cosmo->a * cosmo->a; -} - -/** - * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. - * - * @param p The particle to act upon - * @param xp The extended particle data to act upon - * @param cd #star_formation containing star_formation informations. - * @param cosmo The current cosmological model. - */ -__attribute__((always_inline)) INLINE static void -star_formation_part_has_no_neighbours(struct part* restrict p, - struct xpart* restrict xp, - const struct star_formation* cd, - const struct cosmology* cosmo) { - - // TODO move into pressure floor - /* If part has 0 neighbours, the estimation of turbulence is 0 */ - p->sf_data.sigma2 = 0.f; -} - -/** - * @brief Sets the star_formation properties of the (x-)particles to a valid - * start state. - * - * @param p Pointer to the particle data. - * @param xp Pointer to extended particle data - * @param data The global star_formation information. - */ -__attribute__((always_inline)) INLINE static void star_formation_init_part( - struct part* restrict p, struct xpart* restrict xp, - const struct star_formation* data) { - p->sf_data.sigma2 = 0.f; -} - -/** - * @brief Sets the star_formation properties of the (x-)particles to a valid - * start state. - * @param phys_const The physical constant in internal units. - * @param us The unit system. - * @param cosmo The current cosmological model. - * @param data The global star_formation information used for this run. - * @param p Pointer to the particle data. - */ -__attribute__((always_inline)) INLINE static void -star_formation_first_init_part(const struct phys_const* restrict phys_const, - const struct unit_system* restrict us, - const struct cosmology* restrict cosmo, - const struct star_formation* data, - struct part* restrict p, - struct xpart* restrict xp) { - - /* Nothing special here */ - star_formation_init_part(p, xp, data); -} - #endif /* SWIFT_GEAR_STAR_FORMATION_H */ diff --git a/src/star_formation/GEAR/star_formation_io.h b/src/star_formation/GEAR/star_formation_io.h index 3e021f7844c1deaeca40d7144d6f7b69cb6c2bdb..7e6dcefce633fd55f421e3c8672eaf8e6f18579c 100644 --- a/src/star_formation/GEAR/star_formation_io.h +++ b/src/star_formation/GEAR/star_formation_io.h @@ -56,11 +56,6 @@ INLINE static void starformation_init_backend( const struct unit_system* us, const struct hydro_props* hydro_props, struct star_formation* starform) { - // TODO move into pressure floor - starform->n_jeans_2_3 = - parser_get_param_float(parameter_file, "GEARStarFormation:NJeans"); - starform->n_jeans_2_3 = pow(starform->n_jeans_2_3, 2. / 3.); - /* Star formation efficiency */ starform->star_formation_efficiency = parser_get_param_double( parameter_file, "GEARStarFormation:star_formation_efficiency"); @@ -69,6 +64,9 @@ INLINE static void starformation_init_backend( starform->maximal_temperature = parser_get_param_double( parameter_file, "GEARStarFormation:maximal_temperature"); + /* Get the jeans factor */ + starform->n_jeans_2_3 = pow(pressure_floor_props.n_jeans, 2. / 3.); + /* Apply unit change */ starform->maximal_temperature *= units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE); diff --git a/src/star_formation/GEAR/star_formation_struct.h b/src/star_formation/GEAR/star_formation_struct.h index 2e9a7548f83ca6ae9bb78ee7bcf4be69a0a31489..50a735ff45f27ccb197ae6089f13237f67a59e3f 100644 --- a/src/star_formation/GEAR/star_formation_struct.h +++ b/src/star_formation/GEAR/star_formation_struct.h @@ -25,20 +25,13 @@ */ struct star_formation_xpart_data {}; -struct star_formation_part_data { - // TODO move it to the pressure floor - /*! Estimation of local turbulence (squared) */ - float sigma2; -}; - /** * @brief Global star formation properties */ struct star_formation { - // TODO move it to pressure floor - /*! Number of particle required to resolved the Jeans criterion (at power 2/3) - */ + /*! Number of particle required to resolved the + * Jeans criterion (at power 2/3) */ float n_jeans_2_3; /*! Maximal temperature for forming a star */ diff --git a/src/star_formation/none/star_formation.h b/src/star_formation/none/star_formation.h index 6b83010ec5f8935778af8c9ad21010ff3452fc0e..0f53e951cb5842e5be3bb9bbe64eb6686f822b1e 100644 --- a/src/star_formation/none/star_formation.h +++ b/src/star_formation/none/star_formation.h @@ -163,64 +163,4 @@ INLINE static void starformation_print_backend( message("Star formation law is 'No Star Formation'"); } -/** - * @brief Finishes the density calculation. - * - * @param p The particle to act upon - * @param cd The global star_formation information. - * @param cosmo The current cosmological model. - */ -__attribute__((always_inline)) INLINE static void star_formation_end_density( - struct part* restrict p, const struct star_formation* cd, - const struct cosmology* cosmo) {} - -/** - * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. - * - * @param p The particle to act upon - * @param xp The extended particle data to act upon - * @param cd #star_formation containing star_formation informations. - * @param cosmo The current cosmological model. - */ -__attribute__((always_inline)) INLINE static void -star_formation_part_has_no_neighbours(struct part* restrict p, - struct xpart* restrict xp, - const struct star_formation* cd, - const struct cosmology* cosmo) {} - -/** - * @brief Sets the star_formation properties of the (x-)particles to a valid - * start state. - * - * Nothing to do here. - * - * @param phys_const The physical constant in internal units. - * @param us The unit system. - * @param cosmo The current cosmological model. - * @param data The global star_formation information used for this run. - * @param p Pointer to the particle data. - * @param xp Pointer to the extended particle data. - */ -__attribute__((always_inline)) INLINE static void -star_formation_first_init_part(const struct phys_const* restrict phys_const, - const struct unit_system* restrict us, - const struct cosmology* restrict cosmo, - const struct star_formation* data, - const struct part* restrict p, - struct xpart* restrict xp) {} - -/** - * @brief Sets the star_formation properties of the (x-)particles to a valid - * start state. - * - * Nothing to do here. - * - * @param p Pointer to the particle data. - * @param xp Pointer to the extended particle data. - * @param data The global star_formation information. - */ -__attribute__((always_inline)) INLINE static void star_formation_init_part( - struct part* restrict p, struct xpart* restrict xp, - const struct star_formation* data) {} - #endif /* SWIFT_NONE_STAR_FORMATION_H */ diff --git a/src/star_formation/none/star_formation_struct.h b/src/star_formation/none/star_formation_struct.h index 2f5241a58caf1ca70fa98a40d467c8ff5a3237f7..27a2adaf83d0a02a0d08e7eef8b45bea630689e4 100644 --- a/src/star_formation/none/star_formation_struct.h +++ b/src/star_formation/none/star_formation_struct.h @@ -25,10 +25,4 @@ */ struct star_formation_xpart_data {}; -/** - * @brief Star-formation-related properties stored in the particle - * data. - */ -struct star_formation_part_data {}; - #endif /* SWIFT_NONE_STAR_FORMATION_STRUCT_H */ diff --git a/src/star_formation_struct.h b/src/star_formation_struct.h index 2a62d284b435c353525311979b343754856364e8..92386d532fb7e0ad445477bf9e3ec35fe597fe2f 100644 --- a/src/star_formation_struct.h +++ b/src/star_formation_struct.h @@ -27,7 +27,7 @@ /* Config parameters. */ #include "../config.h" -/* Import the right cooling definition */ +/* Import the right star formation definition */ #if defined(STAR_FORMATION_NONE) #include "./star_formation/none/star_formation_struct.h" #elif defined(STAR_FORMATION_EAGLE) diff --git a/src/stars/GEAR/stars_io.h b/src/stars/GEAR/stars_io.h index ebd72aa50a4194bf8c6f747e55d265ace0550c35..dc40e86e29b19a370d549576fd955464bf0e609d 100644 --- a/src/stars/GEAR/stars_io.h +++ b/src/stars/GEAR/stars_io.h @@ -108,7 +108,7 @@ INLINE static void stars_write_particles(const struct spart *sparts, "Temperatures at the time of birth of the gas " "particles that turned into stars"); - list[7] = io_make_output_field("BirthMasses", FLOAT, 1, UNIT_CONV_MASS, 0.f, + list[8] = io_make_output_field("BirthMasses", FLOAT, 1, UNIT_CONV_MASS, 0.f, sparts, birth.mass, "Masses of the star particles at birth time"); diff --git a/src/swift.h b/src/swift.h index 7790ec6f9203a6534e2f569017d90090352d8f28..fe9196a8fcf6d1845c9446c480c7961504a4756f 100644 --- a/src/swift.h +++ b/src/swift.h @@ -55,6 +55,7 @@ #include "map.h" #include "memuse.h" #include "mesh_gravity.h" +#include "minmax.h" #include "multipole.h" #include "outputlist.h" #include "parallel_io.h" diff --git a/src/timestep.h b/src/timestep.h index c2b1a10fcb3b0426e7c34625d65c1fd5353d25e9..cd9faaea612c8a666ae9077ccc5e3d85fd4677f9 100644 --- a/src/timestep.h +++ b/src/timestep.h @@ -146,8 +146,14 @@ __attribute__((always_inline)) INLINE static integertime_t get_part_timestep( new_dt_grav = min(new_dt_self_grav, new_dt_ext_grav); } - /* Final time-step is minimum of hydro and gravity */ - float new_dt = min3(new_dt_hydro, new_dt_cooling, new_dt_grav); + /* Compute the next timestep (chemistry condition, e.g. diffusion) */ + const float new_dt_chemistry = + chemistry_timestep(e->physical_constants, e->cosmology, e->internal_units, + e->hydro_properties, e->chemistry, p); + + /* Final time-step is minimum of hydro, gravity and subgrid */ + float new_dt = + min4(new_dt_hydro, new_dt_cooling, new_dt_grav, new_dt_chemistry); /* Limit change in smoothing length */ const float dt_h_change = diff --git a/src/tools.c b/src/tools.c index bd467e1841b78d45a74b037c63e8ed58dd92183f..0643fb7922c0e3d56b70c6a0d1a30e3ca13154c6 100644 --- a/src/tools.c +++ b/src/tools.c @@ -45,8 +45,8 @@ #include "hydro.h" #include "part.h" #include "periodic.h" +#include "pressure_floor_iact.h" #include "runner.h" -#include "star_formation_iact.h" #include "stars.h" /** @@ -224,7 +224,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { /* Interact */ runner_iact_nonsym_density(r2, dx, hi, pj->h, pi, pj, a, H); runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hi, pj->h, pi, pj, a, H); } } } @@ -257,7 +257,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { /* Interact */ runner_iact_nonsym_density(r2, dx, hj, pi->h, pj, pi, a, H); runner_iact_nonsym_chemistry(r2, dx, hj, pi->h, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, pi->h, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dx, hj, pi->h, pj, pi, a, H); } } } @@ -535,7 +535,7 @@ void self_all_density(struct runner *r, struct cell *ci) { /* Interact */ runner_iact_nonsym_density(r2, dxi, hi, hj, pi, pj, a, H); runner_iact_nonsym_chemistry(r2, dxi, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dxi, hi, hj, pi, pj, a, H); + runner_iact_nonsym_pressure_floor(r2, dxi, hi, hj, pi, pj, a, H); } /* Hit or miss? */ @@ -548,7 +548,7 @@ void self_all_density(struct runner *r, struct cell *ci) { /* Interact */ runner_iact_nonsym_density(r2, dxi, hj, hi, pj, pi, a, H); runner_iact_nonsym_chemistry(r2, dxi, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dxi, hj, hi, pj, pi, a, H); + runner_iact_nonsym_pressure_floor(r2, dxi, hj, hi, pj, pi, a, H); } } } diff --git a/tests/Makefile.am b/tests/Makefile.am index 93a1475363c95850502e4b3d21fa6481fdf09cda..461ed6be5f3740597bd2e8c4469fa82051c21769 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,7 +23,7 @@ AM_LDFLAGS = ../src/.libs/libswiftsim.a $(HDF5_LDFLAGS) $(HDF5_LIBS) $(FFTW_LIBS TESTS = testGreetings testMaths testReading.sh testKernel \ testActivePair.sh test27cells.sh test27cellsPerturbed.sh \ testParser.sh test125cells.sh test125cellsPerturbed.sh testFFT \ - testAdiabaticIndex testRandomSpacing \ + testAdiabaticIndex testRandom testRandomSpacing \ testMatrixInversion testThreadpool testDump testLogger testInteractions.sh \ testVoronoi1D testVoronoi2D testVoronoi3D testGravityDerivatives \ testPeriodicBC.sh testPeriodicBCPerturbed.sh testPotentialSelf \ diff --git a/tests/testRandom.c b/tests/testRandom.c index a550273c63d1cac048e511c8c48908ec8376441e..036f58b29115a2e646cea35e873ccdc9a4164e4e 100644 --- a/tests/testRandom.c +++ b/tests/testRandom.c @@ -255,30 +255,42 @@ int main(int argc, char* argv[]) { /* Verify that the mean and variance match the expected values for a uniform * distribution */ - const double tolmean = 2e-4; - const double tolvar = 1e-3; - const double tolcorr = 4e-4; - - if ((fabs(mean - 0.5) / 0.5 > tolmean) || - (fabs(var - 1. / 12.) / (1. / 12.) > tolvar) || - (correlation > tolcorr) || (correlationID > tolcorr) || - (fabs(meanID - 0.5) / 0.5 > tolmean) || - (fabs(varID - 1. / 12.) / (1. / 12.) > tolvar) || - (corr_star_sf > tolcorr) || (corr_star_se > tolcorr) || - (corr_star_bh > tolcorr) || (corr_sf_se > tolcorr) || - (corr_sf_bh > tolcorr) || (corr_se_bh > tolcorr) || - (fabs(mean_sf - 0.5) / 0.5 > tolmean) || - (fabs(mean_se - 0.5) / 0.5 > tolmean) || - (fabs(mean_bh - 0.5) / 0.5 > tolmean) || - (fabs(var_sf - 1. / 12.) / (1. / 12.) > tolvar) || - (fabs(var_se - 1. / 12.) / (1. / 12.) > tolvar) || - (fabs(var_bh - 1. / 12.) / (1. / 12.) > tolvar)) { + + /* Set the allowed standard deviation */ + const double std_check = 5.; + + /* The mean is expected to deviate a maximum of std_check * std / sqrt(N) */ + const double tolmean = std_check / sqrtf(12.f * count); + + /* the variance is expected to deviate a maximum of std_check * variance + * * sqrt(2/(n-1)) */ + const double tolvar = + std_check * sqrtf(2.f / (12.f * ((double)count - 1.f))); + + /* The correlation coefficient is expected to deviate sqrt(1-R^2) + * / sqrt(n-2), in our case <R> = 0, so we get 1/sqrt(n-2) */ + const double tolcorr = std_check / sqrtf((double)count - 2.); + + if ((fabs(mean - 0.5) > tolmean) || (fabs(var - 1. / 12.) > tolvar) || + (fabs(correlation) > tolcorr) || (fabs(correlationID) > tolcorr) || + (fabs(meanID - 0.5) > tolmean) || (fabs(varID - 1. / 12.) > tolvar) || + (fabs(corr_star_sf) > tolcorr) || (fabs(corr_star_se) > tolcorr) || + (fabs(corr_star_bh) > tolcorr) || (fabs(corr_sf_se) > tolcorr) || + (fabs(corr_sf_bh) > tolcorr) || (fabs(corr_se_bh) > tolcorr) || + (fabs(mean_sf - 0.5) > tolmean) || (fabs(mean_se - 0.5) > tolmean) || + (fabs(mean_bh - 0.5) > tolmean) || (fabs(var_sf - 1. / 12.) > tolvar) || + (fabs(var_se - 1. / 12.) > tolvar) || + (fabs(var_bh - 1. / 12.) > tolvar)) { message("Test failed!"); message("Global result:"); message("Result: count=%d mean=%f var=%f, correlation=%f", count, mean, var, correlation); message("Expected: count=%d mean=%f var=%f, correlation=%f", count, 0.5f, 1. / 12., 0.); + message("Max difference: mean=%f var=%f, correlation=%f", + tolmean, tolvar, tolcorr); + message("Difference: mean=%f var=%f, correlation=%f", + fabs(mean - 0.5f), fabs(var - 1. / 12.), fabs(correlation)); message("ID part"); message( "Result: count=%d mean=%f var=%f" @@ -288,23 +300,47 @@ int main(int argc, char* argv[]) { "Expected: count=%d mean=%f var=%f" " correlation=%f", count, .5f, 1. / 12., 0.); + message("Max difference: mean=%f var=%f, correlation=%f", + tolmean, tolvar, tolcorr); + message("Difference: mean=%f var=%f, correlation=%f", + fabs(meanID - 0.5f), fabs(varID - 1. / 12.), fabs(correlation)); message("Different physical processes:"); message( "Means: stars=%f stellar feedback=%f stellar " - " enrichement=%f black holes=%f", + " enrichment=%f black holes=%f", mean, mean_sf, mean_se, mean_bh); message( "Expected: stars=%f stellar feedback=%f stellar " - " enrichement=%f black holes=%f", + " enrichment=%f black holes=%f", .5f, .5f, .5f, .5f); + message( + "Max diff: stars=%f stellar feedback=%f stellar " + " enrichment=%f black holes=%f", + tolmean, tolmean, tolmean, tolmean); + message( + "Diff: stars=%f stellar feedback=%f stellar " + " enrichment=%f black holes=%f", + fabs(mean - .5f), fabs(mean_sf - .5f), fabs(mean_se - .5f), + fabs(mean_bh - .5f)); + message(" "); message( "Var: stars=%f stellar feedback=%f stellar " - " enrichement=%f black holes=%f", + " enrichment=%f black holes=%f", var, var_sf, var_se, var_bh); message( "Expected: stars=%f stellar feedback=%f stellar " - " enrichement=%f black holes=%f", + " enrichment=%f black holes=%f", 1. / 12., 1. / 12., 1 / 12., 1. / 12.); + message( + "Max diff: stars=%f stellar feedback=%f stellar " + " enrichment=%f black holes=%f", + tolvar, tolvar, tolvar, tolvar); + message( + "Diff: stars=%f stellar feedback=%f stellar " + " enrichment=%f black holes=%f", + fabs(var - 1. / 12.), fabs(var_sf - 1. / 12.), + fabs(var_se - 1. / 12.), fabs(var_bh - 1. / 12.)); + message(" "); message( "Correlation: stars-sf=%f stars-se=%f stars-bh=%f " "sf-se=%f sf-bh=%f se-bh=%f", @@ -314,6 +350,15 @@ int main(int argc, char* argv[]) { "Expected: stars-sf=%f stars-se=%f stars-bh=%f " "sf-se=%f sf-bh=%f se-bh=%f", 0., 0., 0., 0., 0., 0.); + message( + "Max diff: stars-sf=%f stars-se=%f stars-bh=%f " + "sf-se=%f sf-bh=%f se-bh=%f", + tolcorr, tolcorr, tolcorr, tolcorr, tolcorr, tolcorr); + message( + "Diff: stars-sf=%f stars-se=%f stars-bh=%f " + "sf-se=%f sf-bh=%f se-bh=%f", + fabs(corr_star_sf), fabs(corr_star_se), fabs(corr_star_bh), + fabs(corr_sf_se), fabs(corr_sf_bh), fabs(corr_se_bh)); return 1; } } diff --git a/tests/testRandomSpacing.c b/tests/testRandomSpacing.c index 0c30ffcf5c8b493665d4cc1153e573a5836f4eec..0d2777ee702458ccaa6170483c48b83ce1a4fc7e 100644 --- a/tests/testRandomSpacing.c +++ b/tests/testRandomSpacing.c @@ -75,6 +75,7 @@ int main(int argc, char* argv[]) { const double r = random_unit_interval(id, ti_current, random_number_star_formation); + /* Count the number of random numbers below the boundaries */ if (r < boundary[0]) count[0] += 1; if (r < boundary[1]) count[1] += 1; if (r < boundary[2]) count[2] += 1; @@ -83,6 +84,7 @@ int main(int argc, char* argv[]) { if (r < boundary[5]) count[5] += 1; } + /* Print counted number of random numbers below the boundaries */ message("Categories | %6.0e %6.0e %6.0e %6.0e %6.0e %6.0e", boundary[0], boundary[1], boundary[2], boundary[3], boundary[4], boundary[5]); @@ -105,21 +107,40 @@ int main(int argc, char* argv[]) { expected_result_int[4] = (int)expected_result[4]; expected_result_int[5] = (int)expected_result[5]; + /* Print the expected numbers */ message("expected | %6d %6d %6d %6d %6d %6d", expected_result_int[0], expected_result_int[1], expected_result_int[2], expected_result_int[3], expected_result_int[4], expected_result_int[5]); int std_expected_result[6]; - std_expected_result[0] = (int)max(sqrt(expected_result[0]), 1); - std_expected_result[1] = (int)max(sqrt(expected_result[1]), 1); - std_expected_result[2] = (int)max(sqrt(expected_result[2]), 1); - std_expected_result[3] = (int)max(sqrt(expected_result[3]), 1); - std_expected_result[4] = (int)max(sqrt(expected_result[4]), 1); - std_expected_result[5] = (int)max(sqrt(expected_result[5]), 1); + /* Calculate the allowed standard error deviation the maximum of: + * 1. the standard error of the expected number doing sqrt(N_expected) + * 2. The standard error of the counted number doing sqrt(N_count) + * 3. 1 to prevent low number statistics to crash for 1 while expected + * close to zero. + * + * 1 and 2 are for large numbers essentially the same but for small numbers + * it becomes imporatant (e.g. count=6 expected=.9, allowed 5+.9 so 6 + * fails, but sqrt(6) ~ 2.5 so it should be fine) */ + std_expected_result[0] = + (int)max3(sqrt(expected_result[0]), 1, sqrt(count[0])); + std_expected_result[1] = + (int)max3(sqrt(expected_result[1]), 1, sqrt(count[1])); + std_expected_result[2] = + (int)max3(sqrt(expected_result[2]), 1, sqrt(count[2])); + std_expected_result[3] = + (int)max3(sqrt(expected_result[3]), 1, sqrt(count[3])); + std_expected_result[4] = + (int)max3(sqrt(expected_result[4]), 1, sqrt(count[4])); + std_expected_result[5] = + (int)max3(sqrt(expected_result[5]), 1, sqrt(count[5])); + + /* We want 5 sigma (can be changed if necessary) */ const int numb_sigma = 5; + /* Print the differences and the 5 sigma differences */ message("Difference | %6d %6d %6d %6d %6d %6d", abs(expected_result_int[0] - count[0]), abs(expected_result_int[1] - count[1]), @@ -136,6 +157,7 @@ int main(int argc, char* argv[]) { numb_sigma * std_expected_result[4], numb_sigma * std_expected_result[5]); + /* Fail if it is not within numb_sigma (5) of the expected difference. */ if (count[0] > expected_result_int[0] + numb_sigma * std_expected_result[0] || count[0] < diff --git a/theory/SPH/Derivation/sph_derivation.tex b/theory/SPH/Derivation/sph_derivation.tex index c770035df6050afe836d943dbe6538d4eafc262b..af39fb6833ab7a878d4328f8ba7645b5f07bf7ae 100644 --- a/theory/SPH/Derivation/sph_derivation.tex +++ b/theory/SPH/Derivation/sph_derivation.tex @@ -186,7 +186,7 @@ The spatial differential is fairly straightforward and is given by The differential with respect to the smoothing length is also straightforward after remembering that $W_{ij}(h_j) = w(|r_{ij}|/h_j)/h_j^{n_d}$. Then, \begin{align} - \frac{\partial y_i}{\partial h_i} = -\sum_{j=1}^N \frac{x_j}{h_j} + \frac{\partial y_i}{\partial h_i} = -\sum_{j=1}^N \frac{x_j}{h_i} \left[ n_d W_{ij}(h_i) + \frac{|r_{ij}|}{h_i} \left. diff --git a/theory/SPH/Flavours/sph_flavours.tex b/theory/SPH/Flavours/sph_flavours.tex index d84bdcc0b42129e9d5008051dd6e0e212e4e9463..d0fc3196074858c3dc143558279b2bc0003bd5fb 100644 --- a/theory/SPH/Flavours/sph_flavours.tex +++ b/theory/SPH/Flavours/sph_flavours.tex @@ -462,8 +462,8 @@ motion: \frac{\mathrm{d} \mathbf{v}_i}{\mathrm{d} t} = -\sum_j (\gamma - 1)^2 m_j u_j u_i &\left[\frac{f_{ij}}{\bar{P}_i} \nabla_i W_{ij}(h_i) ~+ \right. \nonumber \\ - &\frac{f_{ji}}{\bar{P}_j} \nabla_i W_{ji}(h_j) ~+ \nonumber \\ - & \left.\nu_{ij}\bar{\nabla_i W_{ij}}\right]~. + &\left.\frac{f_{ji}}{\bar{P}_j} \nabla_i W_{ji}(h_j)\right] ~+ \nonumber \\ + & m_j \nu_{ij}\bar{\nabla_i W_{ij}}~. \label{eq:sph:pu:eom} \end{align} which includes the Monaghan artificial viscosity term and Balsara switch in