From 602abd1bb09e9fa4efbe868674b3d50cc0414c52 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 12 Apr 2020 17:08:41 +0200 Subject: [PATCH] Clean up the gravity-only disc-patch example --- .../DiscPatch/GravityOnly/disc-patch.yml | 22 +-- .../DiscPatch/GravityOnly/makeIC.py | 70 ++++---- .../GravityTests/DiscPatch/GravityOnly/run.sh | 4 + .../DiscPatch/GravityOnly/test.pro | 158 ------------------ .../DiscPatch/GravityOnly/test.py | 92 ++++++++++ examples/parameter_example.yml | 8 +- 6 files changed, 139 insertions(+), 215 deletions(-) delete mode 100644 examples/GravityTests/DiscPatch/GravityOnly/test.pro create mode 100644 examples/GravityTests/DiscPatch/GravityOnly/test.py diff --git a/examples/GravityTests/DiscPatch/GravityOnly/disc-patch.yml b/examples/GravityTests/DiscPatch/GravityOnly/disc-patch.yml index bcc7d1a3d..34dcfdf4a 100644 --- a/examples/GravityTests/DiscPatch/GravityOnly/disc-patch.yml +++ b/examples/GravityTests/DiscPatch/GravityOnly/disc-patch.yml @@ -1,8 +1,8 @@ # Define the system of units to use internally. InternalUnitSystem: - UnitMass_in_cgs: 1.98848e33 # M_sun in grams - UnitLength_in_cgs: 3.08567758e18 # parsec in centimeters - UnitVelocity_in_cgs: 1e5 # km/s in cm/s + UnitMass_in_cgs: 1.98841e33 # M_sun in grams + UnitLength_in_cgs: 3.08567758149e18 # parsec in centimeters + UnitVelocity_in_cgs: 1e5 # km/s in cm/s UnitCurrent_in_cgs: 1 # Amperes UnitTemp_in_cgs: 1 # Kelvin @@ -23,14 +23,6 @@ Snapshots: time_first: 0. # Time of the first output (in internal units) delta_time: 8. # Time difference between consecutive outputs (in internal units) -# Parameters for the hydrodynamics scheme -SPH: - resolution_eta: 1.2349 # Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel). - delta_neighbours: 1. # The tolerance for the targetted number of neighbours. - CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration. - max_ghost_iterations: 30 # Maximal number of iterations allowed to converge towards the smoothing length. - max_smoothing_length: 40. # Maximal smoothing length allowed (in internal units). - # Parameters related to the initial conditions InitialConditions: file_name: Disc-Patch.hdf5 # The file to read @@ -40,5 +32,9 @@ InitialConditions: DiscPatchPotential: surface_density: 10. scale_height: 100. - z_disc: 300. - timestep_mult: 0.03 + x_disc: 300. + timestep_mult: 0.01 + +Scheduler: + max_top_level_cells: 8 + tasks_per_cell: 5 diff --git a/examples/GravityTests/DiscPatch/GravityOnly/makeIC.py b/examples/GravityTests/DiscPatch/GravityOnly/makeIC.py index 3abf4f87f..baeb2f359 100644 --- a/examples/GravityTests/DiscPatch/GravityOnly/makeIC.py +++ b/examples/GravityTests/DiscPatch/GravityOnly/makeIC.py @@ -19,29 +19,32 @@ ############################################################################## import h5py -import sys import numpy +import sys import math -import random -# Generates N particles in a box of [0:BoxSize,0:BoxSize,-2scale_height:2scale_height] +# Generates N particles in a box of [-2scale_height:2scale_height, 0:BoxSize, 0:BoxSize] +# +# The potential is long the x-axis. +# # see Creasey, Theuns & Bower, 2013, for the equations: # disc parameters are: surface density sigma # scale height b -# density: rho(z) = (sigma/2b) sech^2(z/b) -# isothermal velocity dispersion = . +# +############################################################################## + +import h5py as h5 +import numpy as np +import math + +num_snapshots = 61 + +# physical constants in cgs +NEWTON_GRAVITY_CGS = 6.67430e-8 +SOLAR_MASS_IN_CGS = 1.98841e33 +PARSEC_IN_CGS = 3.08567758149e18 +YEAR_IN_CGS = 3.15569251e7 + +# choice of units +const_unit_length_in_cgs = PARSEC_IN_CGS +const_unit_mass_in_cgs = SOLAR_MASS_IN_CGS +const_unit_velocity_in_cgs = 1e5 + +# parameters of potential +surface_density = 10.0 +scale_height = 100.0 +centre = np.array([300.0, 300.0, 300.0]) + +# constants +const_unit_time_in_cgs = const_unit_length_in_cgs / const_unit_velocity_in_cgs +const_G = ( + NEWTON_GRAVITY_CGS + * const_unit_mass_in_cgs + * const_unit_time_in_cgs + * const_unit_time_in_cgs + / (const_unit_length_in_cgs * const_unit_length_in_cgs * const_unit_length_in_cgs) +) + + +t = np.zeros(num_snapshots) +E_k = np.zeros(num_snapshots) +E_p = np.zeros(num_snapshots) +E_tot = np.zeros(num_snapshots) + +# loop over the snapshots +for i in range(num_snapshots): + + filename = "Disc-Patch_%04d.hdf5" % i + f = h5.File(filename, "r") + + # time + t[i] = f["/Header"].attrs.get("Time")[0] + + # positions and velocities of the particles + p = f["/PartType1/Coordinates"][:] + v = f["/PartType1/Velocities"][:] + + # Kinetic energy + E_k[i] = np.sum(0.5 * (v[:, 0] ** 2 + v[:, 1] ** 2 + v[:, 2] ** 2)) + + # Potential energy + d = p[:, 0] - centre[0] + E_p[i] = np.sum( + 2.0 + * math.pi + * const_G + * surface_density + * scale_height + * np.log(np.cosh(np.abs(d) / scale_height)) + ) + + # Total energy + E_tot[i] = E_k[i] + E_p[i] + + +# Maximal change +delta_E = np.max(np.abs(E_tot - E_tot[0])) / E_tot[0] + +print("Maximal relative energy change :", delta_E * 100, "%") diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index 831619622..962c806b6 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -280,13 +280,13 @@ NFWPotential: critical_density: 127.4 # Critical density (internal units). timestep_mult: 0.01 # Dimensionless pre-factor for the time-step condition, basically determines fraction of orbital time we need to do an integration step -# Disk-patch potential parameters +# Disk-patch potential parameters. The potential is along the x-axis. DiscPatchPotential: surface_density: 10. # Surface density of the disc (internal units) scale_height: 100. # Scale height of the disc (internal units) - z_disc: 400. # Position of the disc along the z-axis (internal units) - z_trunc: 300. # (Optional) Distance from the disc along z-axis above which the potential gets truncated. - z_max: 380. # (Optional) Distance from the disc along z-axis above which the potential is set to 0. + x_disc: 400. # Position of the disc along the z-axis (internal units) + x_trunc: 300. # (Optional) Distance from the disc along z-axis above which the potential gets truncated. + x_max: 380. # (Optional) Distance from the disc along z-axis above which the potential is set to 0. timestep_mult: 0.03 # Dimensionless pre-factor for the time-step condition growth_time: 5. # (Optional) Time for the disc to grow to its final size (multiple of the dynamical time) -- 2.26.2