Skip to content
Snippets Groups Projects
Commit e240f03b authored by Bert Vandenbroucke's avatar Bert Vandenbroucke
Browse files

Switched disc patch potential direction from z to x to be able to run it in 1D and 2D.

parent ffbf1f31
Branches
Tags
1 merge request!382Disc patch x
...@@ -39,8 +39,8 @@ InitialConditions: ...@@ -39,8 +39,8 @@ InitialConditions:
DiscPatchPotential: DiscPatchPotential:
surface_density: 10. surface_density: 10.
scale_height: 100. scale_height: 100.
z_disc: 400. x_disc: 400.
z_trunc: 300. x_trunc: 300.
z_max: 350. x_max: 350.
timestep_mult: 0.03 timestep_mult: 0.03
growth_time: 5. growth_time: 5.
...@@ -39,7 +39,7 @@ InitialConditions: ...@@ -39,7 +39,7 @@ InitialConditions:
DiscPatchPotential: DiscPatchPotential:
surface_density: 10. surface_density: 10.
scale_height: 100. scale_height: 100.
z_disc: 400. x_disc: 400.
z_trunc: 300. x_trunc: 300.
z_max: 380. x_max: 380.
timestep_mult: 0.03 timestep_mult: 0.03
############################################################################### ###############################################################################
# This file is part of SWIFT. # This file is part of SWIFT.
# Copyright (c) 2016 John A. Regan (john.a.regan@durham.ac.uk) # Copyright (c) 2016 John A. Regan (john.a.regan@durham.ac.uk)
# Tom Theuns (tom.theuns@durham.ac.uk) # Tom Theuns (tom.theuns@durham.ac.uk)
# # 2017 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
# This program is free software: you can redistribute it and/or modify # Bert Vandenbroucke (bert.vandenbroucke@gmail.com)
# 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 # This program is free software: you can redistribute it and/or modify
# (at your option) any later version. # 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
# This program is distributed in the hope that it will be useful, # (at your option) any later version.
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # This program is distributed in the hope that it will be useful,
# GNU General Public License for more details. # but WITHOUT ANY WARRANTY; without even the implied warranty of
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# You should have received a copy of the GNU Lesser General Public License # GNU General Public License for more details.
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# # 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 h5py import h5py
import sys import sys
...@@ -37,16 +39,16 @@ import random ...@@ -37,16 +39,16 @@ import random
# Size of the patch -- side_length # Size of the patch -- side_length
# Parameters of the gas disc # Parameters of the gas disc
surface_density = 10. surface_density = 10.
scale_height = 100. scale_height = 100.
gas_gamma = 5./3. gas_gamma = 5./3.
# Parameters of the problem # Parameters of the problem
z_factor = 2 x_factor = 2
side_length = 400. side_length = 400.
# File # File
fileName = "Disc-Patch.hdf5" fileName = "Disc-Patch.hdf5"
#################################################################### ####################################################################
...@@ -64,30 +66,33 @@ unit_mass_in_cgs = (SOLAR_MASS_IN_CGS) ...@@ -64,30 +66,33 @@ unit_mass_in_cgs = (SOLAR_MASS_IN_CGS)
unit_velocity_in_cgs = (1e5) unit_velocity_in_cgs = (1e5)
unit_time_in_cgs = unit_length_in_cgs / unit_velocity_in_cgs unit_time_in_cgs = unit_length_in_cgs / unit_velocity_in_cgs
print "UnitMass_in_cgs: %.5e"%unit_mass_in_cgs print "UnitMass_in_cgs: %.5e"%unit_mass_in_cgs
print "UnitLength_in_cgs: %.5e"%unit_length_in_cgs print "UnitLength_in_cgs: %.5e"%unit_length_in_cgs
print "UnitVelocity_in_cgs: %.5e"%unit_velocity_in_cgs print "UnitVelocity_in_cgs: %.5e"%unit_velocity_in_cgs
print "UnitTime_in_cgs: %.5e"%unit_time_in_cgs print "UnitTime_in_cgs: %.5e"%unit_time_in_cgs
print "" print ""
# Derived units # Derived units
const_G = NEWTON_GRAVITY_CGS * unit_mass_in_cgs * unit_time_in_cgs**2 * unit_length_in_cgs**-3 const_G = NEWTON_GRAVITY_CGS * unit_mass_in_cgs * unit_time_in_cgs**2 * \
unit_length_in_cgs**-3
const_mp = PROTON_MASS_IN_CGS * unit_mass_in_cgs**-1 const_mp = PROTON_MASS_IN_CGS * unit_mass_in_cgs**-1
const_kb = BOLTZMANN_IN_CGS * unit_mass_in_cgs**-1 * unit_length_in_cgs**-2 * unit_time_in_cgs**2 const_kb = BOLTZMANN_IN_CGS * unit_mass_in_cgs**-1 * unit_length_in_cgs**-2 * \
unit_time_in_cgs**2
print "--- Some constants [internal units] ---" print "--- Some constants [internal units] ---"
print "G_Newton: %.5e"%const_G print "G_Newton: %.5e"%const_G
print "m_proton: %.5e"%const_mp print "m_proton: %.5e"%const_mp
print "k_boltzmann: %.5e"%const_kb print "k_boltzmann: %.5e"%const_kb
print "" print ""
# derived quantities # derived quantities
temp = math.pi * const_G * surface_density * scale_height * const_mp / const_kb temp = math.pi * const_G * surface_density * scale_height * const_mp / \
u_therm = const_kb * temp / ((gas_gamma-1) * const_mp) const_kb
v_disp = math.sqrt(2 * u_therm) u_therm = const_kb * temp / ((gas_gamma-1) * const_mp)
soundspeed = math.sqrt(u_therm / (gas_gamma * (gas_gamma-1.))) v_disp = math.sqrt(2 * u_therm)
t_dyn = math.sqrt(scale_height / (const_G * surface_density)) soundspeed = math.sqrt(u_therm / (gas_gamma * (gas_gamma-1.)))
t_cross = scale_height / soundspeed t_dyn = math.sqrt(scale_height / (const_G * surface_density))
t_cross = scale_height / soundspeed
print "--- Properties of the gas [internal units] ---" print "--- Properties of the gas [internal units] ---"
print "Gas temperature: %.5e"%temp print "Gas temperature: %.5e"%temp
...@@ -101,18 +106,20 @@ print "" ...@@ -101,18 +106,20 @@ print ""
# Problem properties # Problem properties
boxSize_x = side_length boxSize_x = side_length
boxSize_y = boxSize_x boxSize_y = boxSize_x
boxSize_z = boxSize_x * z_factor boxSize_z = boxSize_x
boxSize_x *= x_factor
volume = boxSize_x * boxSize_y * boxSize_z volume = boxSize_x * boxSize_y * boxSize_z
M_tot = boxSize_x * boxSize_y * surface_density * math.tanh(boxSize_z / (2. * scale_height)) M_tot = boxSize_y * boxSize_z * surface_density * \
math.tanh(boxSize_x / (2. * scale_height))
density = M_tot / volume density = M_tot / volume
entropy = (gas_gamma - 1.) * u_therm / density**(gas_gamma - 1.) entropy = (gas_gamma - 1.) * u_therm / density**(gas_gamma - 1.)
print "--- Problem properties [internal units] ---" print "--- Problem properties [internal units] ---"
print "Box: [%.1f, %.1f, %.1f]"%(boxSize_x, boxSize_y, boxSize_z) print "Box: [%.1f, %.1f, %.1f]"%(boxSize_x, boxSize_y, boxSize_z)
print "Volume: %.5e"%volume print "Volume: %.5e"%volume
print "Total mass: %.5e"%M_tot print "Total mass: %.5e"%M_tot
print "Density: %.5e"%density print "Density: %.5e"%density
print "Entropy: %.5e"%entropy print "Entropy: %.5e"%entropy
print "" print ""
#################################################################### ####################################################################
...@@ -123,34 +130,24 @@ one_glass_pos = infile["/PartType0/Coordinates"][:,:] ...@@ -123,34 +130,24 @@ one_glass_pos = infile["/PartType0/Coordinates"][:,:]
one_glass_h = infile["/PartType0/SmoothingLength"][:] one_glass_h = infile["/PartType0/SmoothingLength"][:]
# Rescale to the problem size # Rescale to the problem size
one_glass_pos *= boxSize_x one_glass_pos *= side_length
one_glass_h *= boxSize_x one_glass_h *= side_length
#print min(one_glass_p[:,0]), max(one_glass_p[:,0])
#print min(one_glass_p[:,1]), max(one_glass_p[:,1])
#print min(one_glass_p[:,2]), max(one_glass_p[:,2])
# Now create enough copies to fill the volume in z # Now create enough copies to fill the volume in x
pos = np.copy(one_glass_pos) pos = np.copy(one_glass_pos)
h = np.copy(one_glass_h) h = np.copy(one_glass_h)
for i in range(1, z_factor): for i in range(1, x_factor):
one_glass_pos[:,0] += side_length
one_glass_pos[:,2] += boxSize_x
pos = np.append(pos, one_glass_pos, axis=0) pos = np.append(pos, one_glass_pos, axis=0)
h = np.append(h, one_glass_h, axis=0) h = np.append(h, one_glass_h, axis=0)
#print min(pos[:,0]), max(pos[:,0])
#print min(pos[:,1]), max(pos[:,1])
#print min(pos[:,2]), max(pos[:,2])
# Compute further properties of ICs # Compute further properties of ICs
numPart = np.size(h) numPart = np.size(h)
mass = M_tot / numPart mass = M_tot / numPart
print "--- Particle properties [internal units] ---" print "--- Particle properties [internal units] ---"
print "Number part.: ", numPart print "Number part.: ", numPart
print "Part. mass: %.5e"%mass print "Part. mass: %.5e"%mass
print "" print ""
# Create additional arrays # Create additional arrays
...@@ -159,7 +156,6 @@ mass = np.ones(numPart) * mass ...@@ -159,7 +156,6 @@ mass = np.ones(numPart) * mass
vel = np.zeros((numPart, 3)) vel = np.zeros((numPart, 3))
ids = 1 + np.linspace(0, numPart, numPart, endpoint=False) ids = 1 + np.linspace(0, numPart, numPart, endpoint=False)
#################################################################### ####################################################################
# Create and write output file # Create and write output file
...@@ -169,7 +165,7 @@ file = h5py.File(fileName, 'w') ...@@ -169,7 +165,7 @@ file = h5py.File(fileName, 'w')
#Units #Units
grp = file.create_group("/Units") grp = file.create_group("/Units")
grp.attrs["Unit length in cgs (U_L)"] = unit_length_in_cgs grp.attrs["Unit length in cgs (U_L)"] = unit_length_in_cgs
grp.attrs["Unit mass in cgs (U_M)"] = unit_mass_in_cgs grp.attrs["Unit mass in cgs (U_M)"] = unit_mass_in_cgs
grp.attrs["Unit time in cgs (U_t)"] = unit_time_in_cgs grp.attrs["Unit time in cgs (U_t)"] = unit_time_in_cgs
grp.attrs["Unit current in cgs (U_I)"] = 1. grp.attrs["Unit current in cgs (U_I)"] = 1.
grp.attrs["Unit temperature in cgs (U_T)"] = 1. grp.attrs["Unit temperature in cgs (U_T)"] = 1.
...@@ -200,13 +196,12 @@ ds = grp0.create_dataset('SmoothingLength', (numPart,), 'f', data=h) ...@@ -200,13 +196,12 @@ ds = grp0.create_dataset('SmoothingLength', (numPart,), 'f', data=h)
ds = grp0.create_dataset('InternalEnergy', (numPart,), 'f', data=u) ds = grp0.create_dataset('InternalEnergy', (numPart,), 'f', data=u)
ds = grp0.create_dataset('ParticleIDs', (numPart, ), 'L', data=ids) ds = grp0.create_dataset('ParticleIDs', (numPart, ), 'L', data=ids)
#################################################################### ####################################################################
print "--- Runtime parameters (YAML file): ---" print "--- Runtime parameters (YAML file): ---"
print "DiscPatchPotential:surface_density: ", surface_density print "DiscPatchPotential:surface_density: ", surface_density
print "DiscPatchPotential:scale_height: ", scale_height print "DiscPatchPotential:scale_height: ", scale_height
print "DiscPatchPotential:z_disc: ", boxSize_z / 2. print "DiscPatchPotential:x_disc: ", 0.5 * boxSize_x
print "" print ""
print "--- Constant parameters: ---" print "--- Constant parameters: ---"
......
################################################################################ ################################################################################
# This file is part of SWIFT. # This file is part of SWIFT.
# Copyright (c) 2017 Bert Vandenbroucke (bert.vandenbroucke@gmail.com) # Copyright (c) 2017 Bert Vandenbroucke (bert.vandenbroucke@gmail.com)
# Matthieu Schaller (matthieu.schaller@durham.ac.uk)
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Lesser General Public License as published
...@@ -34,9 +35,9 @@ import sys ...@@ -34,9 +35,9 @@ import sys
# Parameters # Parameters
surface_density = 10. surface_density = 10.
scale_height = 100. scale_height = 100.
z_disc = 400. x_disc = 400.
z_trunc = 300. x_trunc = 300.
z_max = 350. x_max = 350.
utherm = 20.2678457288 utherm = 20.2678457288
gamma = 5. / 3. gamma = 5. / 3.
...@@ -50,14 +51,14 @@ if len(sys.argv) > 2: ...@@ -50,14 +51,14 @@ if len(sys.argv) > 2:
# Get the analytic solution for the density # Get the analytic solution for the density
def get_analytic_density(x): def get_analytic_density(x):
return 0.5 * surface_density / scale_height / \ return 0.5 * surface_density / scale_height / \
np.cosh( (x - z_disc) / scale_height )**2 np.cosh( (x - x_disc) / scale_height )**2
# Get the analytic solution for the (isothermal) pressure # Get the analytic solution for the (isothermal) pressure
def get_analytic_pressure(x): def get_analytic_pressure(x):
return (gamma - 1.) * utherm * get_analytic_density(x) return (gamma - 1.) * utherm * get_analytic_density(x)
# Get the data fields to plot from the snapshot file with the given name: # Get the data fields to plot from the snapshot file with the given name:
# snapshot time, z-coord, density, pressure, velocity norm # snapshot time, x-coord, density, pressure, velocity norm
def get_data(name): def get_data(name):
file = h5py.File(name, "r") file = h5py.File(name, "r")
coords = np.array(file["/PartType0/Coordinates"]) coords = np.array(file["/PartType0/Coordinates"])
...@@ -69,7 +70,7 @@ def get_data(name): ...@@ -69,7 +70,7 @@ def get_data(name):
vtot = np.sqrt( v[:,0]**2 + v[:,1]**2 + v[:,2]**2 ) vtot = np.sqrt( v[:,0]**2 + v[:,1]**2 + v[:,2]**2 )
return float(file["/Header"].attrs["Time"]), coords[:,2], rho, P, vtot return float(file["/Header"].attrs["Time"]), coords[:,0], rho, P, vtot
# scan the folder for snapshot files and plot all of them (within the requested # scan the folder for snapshot files and plot all of them (within the requested
# range) # range)
...@@ -80,38 +81,38 @@ for f in sorted(glob.glob("Disc-Patch_*.hdf5")): ...@@ -80,38 +81,38 @@ for f in sorted(glob.glob("Disc-Patch_*.hdf5")):
print "processing", f, "..." print "processing", f, "..."
zrange = np.linspace(0., 2. * z_disc, 1000) xrange = np.linspace(0., 2. * x_disc, 1000)
time, z, rho, P, v = get_data(f) time, x, rho, P, v = get_data(f)
fig, ax = pl.subplots(3, 1, sharex = True) fig, ax = pl.subplots(3, 1, sharex = True)
ax[0].plot(z, rho, "r.") ax[0].plot(x, rho, "r.")
ax[0].plot(zrange, get_analytic_density(zrange), "k-") ax[0].plot(xrange, get_analytic_density(xrange), "k-")
ax[0].plot([z_disc - z_max, z_disc - z_max], [0, 10], "k--", alpha=0.5) ax[0].plot([x_disc - x_max, x_disc - x_max], [0, 10], "k--", alpha=0.5)
ax[0].plot([z_disc + z_max, z_disc + z_max], [0, 10], "k--", alpha=0.5) ax[0].plot([x_disc + x_max, x_disc + x_max], [0, 10], "k--", alpha=0.5)
ax[0].plot([z_disc - z_trunc, z_disc - z_trunc], [0, 10], "k--", alpha=0.5) ax[0].plot([x_disc - x_trunc, x_disc - x_trunc], [0, 10], "k--", alpha=0.5)
ax[0].plot([z_disc + z_trunc, z_disc + z_trunc], [0, 10], "k--", alpha=0.5) ax[0].plot([x_disc + x_trunc, x_disc + x_trunc], [0, 10], "k--", alpha=0.5)
ax[0].set_ylim(0., 1.2 * get_analytic_density(z_disc)) ax[0].set_ylim(0., 1.2 * get_analytic_density(x_disc))
ax[0].set_ylabel("density") ax[0].set_ylabel("density")
ax[1].plot(z, v, "r.") ax[1].plot(x, v, "r.")
ax[1].plot(zrange, np.zeros(len(zrange)), "k-") ax[1].plot(xrange, np.zeros(len(xrange)), "k-")
ax[1].plot([z_disc - z_max, z_disc - z_max], [0, 10], "k--", alpha=0.5) ax[1].plot([x_disc - x_max, x_disc - x_max], [0, 10], "k--", alpha=0.5)
ax[1].plot([z_disc + z_max, z_disc + z_max], [0, 10], "k--", alpha=0.5) ax[1].plot([x_disc + x_max, x_disc + x_max], [0, 10], "k--", alpha=0.5)
ax[1].plot([z_disc - z_trunc, z_disc - z_trunc], [0, 10], "k--", alpha=0.5) ax[1].plot([x_disc - x_trunc, x_disc - x_trunc], [0, 10], "k--", alpha=0.5)
ax[1].plot([z_disc + z_trunc, z_disc + z_trunc], [0, 10], "k--", alpha=0.5) ax[1].plot([x_disc + x_trunc, x_disc + x_trunc], [0, 10], "k--", alpha=0.5)
ax[1].set_ylim(-0.5, 10.) ax[1].set_ylim(-0.5, 10.)
ax[1].set_ylabel("velocity norm") ax[1].set_ylabel("velocity norm")
ax[2].plot(z, P, "r.") ax[2].plot(x, P, "r.")
ax[2].plot(zrange, get_analytic_pressure(zrange), "k-") ax[2].plot(xrange, get_analytic_pressure(xrange), "k-")
ax[2].plot([z_disc - z_max, z_disc - z_max], [0, 10], "k--", alpha=0.5) ax[2].plot([x_disc - x_max, x_disc - x_max], [0, 10], "k--", alpha=0.5)
ax[2].plot([z_disc + z_max, z_disc + z_max], [0, 10], "k--", alpha=0.5) ax[2].plot([x_disc + x_max, x_disc + x_max], [0, 10], "k--", alpha=0.5)
ax[2].plot([z_disc - z_trunc, z_disc - z_trunc], [0, 10], "k--", alpha=0.5) ax[2].plot([x_disc - x_trunc, x_disc - x_trunc], [0, 10], "k--", alpha=0.5)
ax[2].plot([z_disc + z_trunc, z_disc + z_trunc], [0, 10], "k--", alpha=0.5) ax[2].plot([x_disc + x_trunc, x_disc + x_trunc], [0, 10], "k--", alpha=0.5)
ax[2].set_xlim(0., 2. * z_disc) ax[2].set_xlim(0., 2. * x_disc)
ax[2].set_ylim(0., 1.2 * get_analytic_pressure(z_disc)) ax[2].set_ylim(0., 1.2 * get_analytic_pressure(x_disc))
ax[2].set_xlabel("z") ax[2].set_xlabel("x")
ax[2].set_ylabel("pressure") ax[2].set_ylabel("pressure")
pl.suptitle("t = {0:.2f}".format(time)) pl.suptitle("t = {0:.2f}".format(time))
......
...@@ -56,20 +56,20 @@ struct external_potential { ...@@ -56,20 +56,20 @@ struct external_potential {
/*! Inverse of disc scale-height (1/b) */ /*! Inverse of disc scale-height (1/b) */
float scale_height_inv; float scale_height_inv;
/*! Position of the disc along the z-axis */ /*! Position of the disc along the x-axis */
float z_disc; float x_disc;
/*! Position above which the accelerations get truncated */ /*! Position above which the accelerations get truncated */
float z_trunc; float x_trunc;
/*! Position above which the accelerations are zero */ /*! Position above which the accelerations are zero */
float z_max; float x_max;
/*! The truncated transition regime */ /*! The truncated transition regime */
float z_trans; float x_trans;
/*! Inverse of the truncated transition regime */ /*! Inverse of the truncated transition regime */
float z_trans_inv; float x_trans_inv;
/*! Dynamical time of the system */ /*! Dynamical time of the system */
float dynamical_time; float dynamical_time;
...@@ -115,36 +115,36 @@ __attribute__((always_inline)) INLINE static float external_gravity_timestep( ...@@ -115,36 +115,36 @@ __attribute__((always_inline)) INLINE static float external_gravity_timestep(
const float norm = potential->norm; const float norm = potential->norm;
/* absolute value of height above disc */ /* absolute value of height above disc */
const float dz = fabsf(g->x[2] - potential->z_disc); const float dx = fabsf(g->x[0] - potential->x_disc);
/* vertical acceleration */ /* vertical acceleration */
const float z_accel = norm * tanhf(dz * b_inv); const float x_accel = norm * tanhf(dx * b_inv);
float dt = dt_dyn; float dt = dt_dyn;
/* demand that dt * velocity < fraction of scale height of disc */ /* demand that dt * velocity < fraction of scale height of disc */
if (g->v_full[2] != 0.f) { if (g->v_full[0] != 0.f) {
const float dt1 = b / fabsf(g->v_full[2]); const float dt1 = b / fabsf(g->v_full[0]);
dt = min(dt1, dt); dt = min(dt1, dt);
} }
/* demand that dt^2 * acceleration < fraction of scale height of disc */ /* demand that dt^2 * acceleration < fraction of scale height of disc */
if (z_accel != 0.f) { if (x_accel != 0.f) {
const float dt2 = b / fabsf(z_accel); const float dt2 = b / fabsf(x_accel);
if (dt2 < dt * dt) dt = sqrtf(dt2); if (dt2 < dt * dt) dt = sqrtf(dt2);
} }
/* demand that dt^3 * jerk < fraction of scale height of disc */ /* demand that dt^3 * jerk < fraction of scale height of disc */
if (g->v_full[2] != 0.f) { if (g->v_full[0] != 0.f) {
const float cosh_dz_inv = 1.f / coshf(dz * b_inv); const float cosh_dx_inv = 1.f / coshf(dx * b_inv);
const float cosh_dz_inv2 = cosh_dz_inv * cosh_dz_inv; const float cosh_dx_inv2 = cosh_dx_inv * cosh_dx_inv;
const float dz_accel_over_dt = const float dx_accel_over_dt =
norm * cosh_dz_inv2 * b_inv * fabsf(g->v_full[2]); norm * cosh_dx_inv2 * b_inv * fabsf(g->v_full[0]);
const float dt3 = b / fabsf(dz_accel_over_dt); const float dt3 = b / fabsf(dx_accel_over_dt);
if (dt3 < dt * dt * dt) dt = cbrtf(dt3); if (dt3 < dt * dt * dt) dt = cbrtf(dt3);
} }
...@@ -152,13 +152,13 @@ __attribute__((always_inline)) INLINE static float external_gravity_timestep( ...@@ -152,13 +152,13 @@ __attribute__((always_inline)) INLINE static float external_gravity_timestep(
} }
/** /**
* @brief Computes the gravitational acceleration along z due to a hydrostatic * @brief Computes the gravitational acceleration along x due to a hydrostatic
* disc * disc
* *
* See Creasey, Theuns & Bower, 2013, MNRAS, Volume 429, Issue 3, p.1922-1948, * See Creasey, Theuns & Bower, 2013, MNRAS, Volume 429, Issue 3, p.1922-1948,
* equation 17. * equation 17.
* We truncate the accelerations beyond z_trunc using a 1-cos(z) function * We truncate the accelerations beyond x_trunc using a 1-cos(x) function
* that smoothly brings the accelerations to 0 at z_max. * that smoothly brings the accelerations to 0 at x_max.
* *
* @param time The current time in internal units. * @param time The current time in internal units.
* @param potential The properties of the potential. * @param potential The properties of the potential.
...@@ -169,40 +169,40 @@ __attribute__((always_inline)) INLINE static void external_gravity_acceleration( ...@@ -169,40 +169,40 @@ __attribute__((always_inline)) INLINE static void external_gravity_acceleration(
double time, const struct external_potential* restrict potential, double time, const struct external_potential* restrict potential,
const struct phys_const* restrict phys_const, struct gpart* restrict g) { const struct phys_const* restrict phys_const, struct gpart* restrict g) {
const float dz = g->x[2] - potential->z_disc; const float dx = g->x[0] - potential->x_disc;
const float abs_dz = fabsf(dz); const float abs_dx = fabsf(dx);
const float t_growth = potential->growth_time; const float t_growth = potential->growth_time;
const float t_growth_inv = potential->growth_time_inv; const float t_growth_inv = potential->growth_time_inv;
const float b_inv = potential->scale_height_inv; const float b_inv = potential->scale_height_inv;
const float z_trunc = potential->z_trunc; const float x_trunc = potential->x_trunc;
const float z_max = potential->z_max; const float x_max = potential->x_max;
const float z_trans_inv = potential->z_trans_inv; const float x_trans_inv = potential->x_trans_inv;
const float norm_over_G = potential->norm_over_G; const float norm_over_G = potential->norm_over_G;
/* Are we still growing the disc ? */ /* Are we still growing the disc ? */
const float reduction_factor = time < t_growth ? time * t_growth_inv : 1.f; const float reduction_factor = time < t_growth ? time * t_growth_inv : 1.f;
/* Truncated or not ? */ /* Truncated or not ? */
float a_z; float a_x;
if (abs_dz < z_trunc) { if (abs_dx < x_trunc) {
/* Acc. 2 pi sigma tanh(z/b) */ /* Acc. 2 pi sigma tanh(x/b) */
a_z = reduction_factor * norm_over_G * tanhf(abs_dz * b_inv); a_x = reduction_factor * norm_over_G * tanhf(abs_dx * b_inv);
} else if (abs_dz < z_max) { } else if (abs_dx < x_max) {
/* Acc. 2 pi sigma tanh(z/b) [1/2 + 1/2cos((z-zmax)/(pi z_trans))] */ /* Acc. 2 pi sigma tanh(x/b) [1/2 + 1/2cos((x-xmax)/(pi x_trans))] */
a_z = a_x =
reduction_factor * norm_over_G * tanhf(abs_dz * b_inv) * reduction_factor * norm_over_G * tanhf(abs_dx * b_inv) *
(0.5f + 0.5f * cosf((float)(M_PI) * (abs_dz - z_trunc) * z_trans_inv)); (0.5f + 0.5f * cosf((float)(M_PI) * (abs_dx - x_trunc) * x_trans_inv));
} else { } else {
/* Acc. 0 */ /* Acc. 0 */
a_z = 0.f; a_x = 0.f;
} }
/* Get the correct sign. Recall G is multipiled in later on */ /* Get the correct sign. Recall G is multipiled in later on */
if (dz > 0) g->a_grav[2] -= a_z; if (dx > 0) g->a_grav[0] -= a_x;
if (dz < 0) g->a_grav[2] += a_z; if (dx < 0) g->a_grav[0] += a_x;
} }
/** /**
...@@ -211,8 +211,8 @@ __attribute__((always_inline)) INLINE static void external_gravity_acceleration( ...@@ -211,8 +211,8 @@ __attribute__((always_inline)) INLINE static void external_gravity_acceleration(
* *
* See Creasey, Theuns & Bower, 2013, MNRAS, Volume 429, Issue 3, p.1922-1948, * See Creasey, Theuns & Bower, 2013, MNRAS, Volume 429, Issue 3, p.1922-1948,
* equation 22. * equation 22.
* We truncate the accelerations beyond z_trunc using a 1-cos(z) function * We truncate the accelerations beyond x_trunc using a 1-cos(x) function
* that smoothly brings the accelerations to 0 at z_max. * that smoothly brings the accelerations to 0 at x_max.
* *
* @param time The current time. * @param time The current time.
* @param potential The #external_potential used in the run. * @param potential The #external_potential used in the run.
...@@ -224,28 +224,28 @@ external_gravity_get_potential_energy( ...@@ -224,28 +224,28 @@ external_gravity_get_potential_energy(
double time, const struct external_potential* potential, double time, const struct external_potential* potential,
const struct phys_const* const phys_const, const struct gpart* gp) { const struct phys_const* const phys_const, const struct gpart* gp) {
const float dz = gp->x[2] - potential->z_disc; const float dx = gp->x[0] - potential->x_disc;
const float abs_dz = fabsf(dz); const float abs_dx = fabsf(dx);
const float t_growth = potential->growth_time; const float t_growth = potential->growth_time;
const float t_growth_inv = potential->growth_time_inv; const float t_growth_inv = potential->growth_time_inv;
const float b = potential->scale_height; const float b = potential->scale_height;
const float b_inv = potential->scale_height_inv; const float b_inv = potential->scale_height_inv;
const float norm = potential->norm; const float norm = potential->norm;
const float z_trunc = potential->z_trunc; const float x_trunc = potential->x_trunc;
const float z_max = potential->z_max; const float x_max = potential->x_max;
/* Are we still growing the disc ? */ /* Are we still growing the disc ? */
const float reduction_factor = time < t_growth ? time * t_growth_inv : 1.f; const float reduction_factor = time < t_growth ? time * t_growth_inv : 1.f;
/* Truncated or not ? */ /* Truncated or not ? */
float pot; float pot;
if (abs_dz < z_trunc) { if (abs_dx < x_trunc) {
/* Potential (2 pi G sigma b ln(cosh(z/b)) */ /* Potential (2 pi G sigma b ln(cosh(x/b)) */
pot = b * logf(coshf(dz * b_inv)); pot = b * logf(coshf(dx * b_inv));
} else if (abs_dz < z_max) { } else if (abs_dx < x_max) {
/* Potential. At z>>b, phi(z) = norm * z / b */ /* Potential. At x>>b, phi(x) = norm * x / b */
pot = 0.f; pot = 0.f;
} else { } else {
...@@ -277,14 +277,14 @@ static INLINE void potential_init_backend( ...@@ -277,14 +277,14 @@ static INLINE void potential_init_backend(
parameter_file, "DiscPatchPotential:surface_density"); parameter_file, "DiscPatchPotential:surface_density");
potential->scale_height = parser_get_param_double( potential->scale_height = parser_get_param_double(
parameter_file, "DiscPatchPotential:scale_height"); parameter_file, "DiscPatchPotential:scale_height");
potential->z_disc = potential->x_disc =
parser_get_param_double(parameter_file, "DiscPatchPotential:z_disc"); parser_get_param_double(parameter_file, "DiscPatchPotential:x_disc");
potential->z_trunc = parser_get_opt_param_double( potential->x_trunc = parser_get_opt_param_double(
parameter_file, "DiscPatchPotential:z_trunc", FLT_MAX); parameter_file, "DiscPatchPotential:x_trunc", FLT_MAX);
potential->z_max = parser_get_opt_param_double( potential->x_max = parser_get_opt_param_double(
parameter_file, "DiscPatchPotential:z_max", FLT_MAX); parameter_file, "DiscPatchPotential:x_max", FLT_MAX);
potential->z_disc = potential->x_disc =
parser_get_param_double(parameter_file, "DiscPatchPotential:z_disc"); parser_get_param_double(parameter_file, "DiscPatchPotential:x_disc");
potential->timestep_mult = parser_get_param_double( potential->timestep_mult = parser_get_param_double(
parameter_file, "DiscPatchPotential:timestep_mult"); parameter_file, "DiscPatchPotential:timestep_mult");
potential->growth_time = parser_get_opt_param_double( potential->growth_time = parser_get_opt_param_double(
...@@ -299,22 +299,22 @@ static INLINE void potential_init_backend( ...@@ -299,22 +299,22 @@ static INLINE void potential_init_backend(
potential->growth_time *= potential->dynamical_time; potential->growth_time *= potential->dynamical_time;
/* Some cross-checks */ /* Some cross-checks */
if (potential->z_trunc > potential->z_max) if (potential->x_trunc > potential->x_max)
error("Potential truncation z larger than maximal z"); error("Potential truncation x larger than maximal z");
if (potential->z_trunc < potential->scale_height) if (potential->x_trunc < potential->scale_height)
error("Potential truncation z smaller than scale height"); error("Potential truncation x smaller than scale height");
/* Compute derived quantities */ /* Compute derived quantities */
potential->scale_height_inv = 1. / potential->scale_height; potential->scale_height_inv = 1. / potential->scale_height;
potential->norm = potential->norm =
2. * M_PI * phys_const->const_newton_G * potential->surface_density; 2. * M_PI * phys_const->const_newton_G * potential->surface_density;
potential->norm_over_G = 2 * M_PI * potential->surface_density; potential->norm_over_G = 2 * M_PI * potential->surface_density;
potential->z_trans = potential->z_max - potential->z_trunc; potential->x_trans = potential->x_max - potential->x_trunc;
if (potential->z_trans != 0.f) if (potential->x_trans != 0.f)
potential->z_trans_inv = 1. / potential->z_trans; potential->x_trans_inv = 1. / potential->x_trans;
else else
potential->z_trans_inv = FLT_MAX; potential->x_trans_inv = FLT_MAX;
if (potential->growth_time != 0.) if (potential->growth_time != 0.)
potential->growth_time_inv = 1. / potential->growth_time; potential->growth_time_inv = 1. / potential->growth_time;
...@@ -331,14 +331,14 @@ static INLINE void potential_print_backend( ...@@ -331,14 +331,14 @@ static INLINE void potential_print_backend(
const struct external_potential* potential) { const struct external_potential* potential) {
message( message(
"External potential is 'Disk-patch' with Sigma=%f, z_disc=%f, b=%f and " "External potential is 'Disk-patch' with Sigma=%f, x_disc=%f, b=%f and "
"dt_mult=%f.", "dt_mult=%f.",
potential->surface_density, potential->z_disc, potential->scale_height, potential->surface_density, potential->x_disc, potential->scale_height,
potential->timestep_mult); potential->timestep_mult);
if (potential->z_max < FLT_MAX) if (potential->x_max < FLT_MAX)
message("Potential will be truncated at z_trunc=%f and zeroed at z_max=%f", message("Potential will be truncated at x_trunc=%f and zeroed at x_max=%f",
potential->z_trunc, potential->z_max); potential->x_trunc, potential->x_max);
if (potential->growth_time > 0.) if (potential->growth_time > 0.)
message("Disc will grow for %f [time_units]. (%f dynamical time)", message("Disc will grow for %f [time_units]. (%f dynamical time)",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment