Skip to content
Snippets Groups Projects
Commit 3cb72fca authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

Merge remote-tracking branch 'origin/master' into faster_rebuilds

Conflicts:
	src/space.c
parents 8596ab82 079f0ea3
Branches
Tags
1 merge request!493Updated cell splitting strategy
Showing
with 1289 additions and 0 deletions
#!/usr/bin/env python
###############################################################################
# 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.
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
sigma_metal = 0.1 # relative standard deviation for Z
Nelem = 9
# shift all metals in order to obtain nicer plots
low_metal = [low_metal] * Nelem + np.linspace(0, 3, Nelem)
high_metal = [high_metal] * Nelem + np.linspace(0, 3, Nelem)
# ---------------------------------------------------------------
# Don't touch anything after this.
# ---------------------------------------------------------------
# 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
}
plt.rcParams.update(params)
plt.rc('font', **{'family': 'sans-serif', 'sans-serif': ['Times']})
snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("smoothed_metallicity_%04d.hdf5" % snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
kernel = sim["/HydroScheme"].attrs["Kernel function"]
neighbours = sim["/HydroScheme"].attrs["Kernel target N_ngb"]
eta = sim["/HydroScheme"].attrs["Kernel eta"]
chemistry = sim["/SubgridScheme"].attrs["Chemistry Model"]
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"][:]
h = np.mean(h)
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)
# Now, work our the solution....
def calc_a(d, high_metal, low_metal, std_dev, h):
"""
Compute analytical solution:
___ High Metallicity
Low Metallicity ___/
where the linear part length is given by the smoothing length.
Parameters
----------
d: np.array
Position to compute
high_metal: float
Value on the high metallicity side
low_metal: float
Value on the low metallicity side
std_dev: float
Standard deviation of the noise added
h: float
Mean smoothing length
"""
# solution
a = np.zeros([len(d), Nelem])
# function at +- 1 sigma
sigma = np.zeros([len(d), Nelem, 2])
for i in range(Nelem):
# compute low metallicity side
s = d < -h
a[s, i] = low_metal[i]
# compute high metallicity side
s = d > h
a[s, i] = high_metal[i]
# compute non constant parts
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
# 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
sigma[:, :, 0] = a * (1 + std_dev)
sigma[:, :, 1] = a * (1 - std_dev)
return a, sigma
# compute solution
sol, sig = calc_a(d_a, high_metal, low_metal, sigma_metal, h)
# Plot the interesting quantities
plt.figure()
# Metallicity --------------------------------
plt.subplot(221)
for e in range(Nelem):
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()
x = max(xmin, ymin)
y = min(xmax, ymax)
plt.plot([x, y], [x, y], "--k", lw=1.0)
plt.xlabel("${\\rm{Metallicity}}~Z_\\textrm{part}$", labelpad=0)
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.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)
# 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.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.xlim(-0.5, 0.5)
plt.ylim(0, 1)
plt.xticks([])
plt.yticks([])
plt.tight_layout()
plt.savefig("SmoothedMetallicity.png", dpi=200)
#!/bin/bash
# Generate the initial conditions if they are not present.
if [ ! -e glassCube_32.hdf5 ]
then
echo "Fetching initial glass file for the SmoothedMetallicity example..."
./getGlass.sh
fi
if [ ! -e smoothed_metallicity.hdf5 ]
then
echo "Generating initial conditions for the SmoothedMetallicity example..."
python makeIC.py
fi
# Run SWIFT
../swift -n 1 -s -t 4 smoothed_metallicity.yml 2>&1 | tee output.log
# Plot the solution
python plotSolution.py 1
# Define the system of units to use internally.
InternalUnitSystem:
UnitMass_in_cgs: 1 # Grams
UnitLength_in_cgs: 1 # Centimeters
UnitVelocity_in_cgs: 1 # Centimeters per second
UnitCurrent_in_cgs: 1 # Amperes
UnitTemp_in_cgs: 1 # Kelvin
# Parameters governing the time integration
TimeIntegration:
time_begin: 0. # The starting time of the simulation (in internal units).
time_end: 2e-4 # The end time of the simulation (in internal units).
dt_min: 1e-7 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-4 # The maximal time-step size of the simulation (in internal units).
# Parameters governing the snapshots
Snapshots:
basename: smoothed_metallicity # Common part of the name of output files
time_first: 0. # Time of the first output (in internal units)
delta_time: 5e-5 # Time difference between consecutive outputs (in internal units)
# Parameters governing the conserved quantities statistics
Statistics:
delta_time: 1e-5 # Time between statistics output
# Parameters for the hydrodynamics scheme
SPH:
resolution_eta: 1.2348 # Target smoothing length in units of the mean inter-particle separation (1.2348 == 48Ngbs with the cubic spline kernel).
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
# Parameters related to the initial conditions
InitialConditions:
file_name: ./smoothed_metallicity.hdf5 # The file to read
#!/bin/bash
wget http://virgodb.cosma.dur.ac.uk/swift-webstorage/ICs/glassPlane_128.hdf5
wget http://virgodb.cosma.dur.ac.uk/swift-webstorage/ICs/glassPlane_48.hdf5
#!/bin/bash
wget http://virgodb.cosma.dur.ac.uk/swift-webstorage/ReferenceSolutions/sodShockSpherical2D_exact.txt
###############################################################################
# This file is part of SWIFT.
# Copyright (c) 2016 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 h5py
from numpy import *
# Generates a swift IC file for the 2D Sod Shock in a periodic box
# Parameters
gamma = 5./3. # Gas adiabatic index
x_min = -1.
x_max = 1.
rho_L = 1. # Density left state
rho_R = 0.140625 # Density right state
v_L = 0. # Velocity left state
v_R = 0. # Velocity right state
P_L = 1. # Pressure left state
P_R = 0.1 # Pressure right state
fileName = "sodShock.hdf5"
#---------------------------------------------------
boxSize = (x_max - x_min)
glass_L = h5py.File("glassPlane_128.hdf5", "r")
glass_R = h5py.File("glassPlane_48.hdf5", "r")
pos_L = glass_L["/PartType0/Coordinates"][:,:]
pos_R = glass_R["/PartType0/Coordinates"][:,:]
h_L = glass_L["/PartType0/SmoothingLength"][:]
h_R = glass_R["/PartType0/SmoothingLength"][:]
radius_L = sqrt((pos_L[:,0] - 0.5)**2 + (pos_L[:,1] - 0.5)**2)
index_L = radius_L < 0.25
pos_LL = pos_L[index_L]
h_LL = h_L[index_L]
radius_R = sqrt((pos_R[:,0] - 0.5)**2 + (pos_R[:,1] - 0.5)**2)
index_R = radius_R > 0.25
pos_RR = pos_R[index_R]
h_RR = h_R[index_R]
# Merge things
pos = append(pos_LL, pos_RR, axis=0)
h = append(h_LL, h_RR)
numPart_L = size(h_LL)
numPart_R = size(h_RR)
numPart = size(h)
vol_L = pi * 0.25**2
vol_R = 1. - pi * 0.25**2
# Generate extra arrays
v = zeros((numPart, 3))
ids = linspace(1, numPart, numPart)
m = zeros(numPart)
u = zeros(numPart)
for i in range(numPart):
x = sqrt((pos[i,0]-0.5)**2+(pos[i,1]-0.5)**2)
if x < 0.25: #left
u[i] = P_L / (rho_L * (gamma - 1.))
m[i] = rho_L * vol_L / numPart_L
v[i,0] = v_L
else: #right
u[i] = P_R / (rho_R * (gamma - 1.))
m[i] = rho_R * vol_R / numPart_R
v[i,0] = v_R
#File
file = h5py.File(fileName, 'w')
# Header
grp = file.create_group("/Header")
grp.attrs["BoxSize"] = [1., 1., 1.]
grp.attrs["NumPart_Total"] = [numPart, 0, 0, 0, 0, 0]
grp.attrs["NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
grp.attrs["NumPart_ThisFile"] = [numPart, 0, 0, 0, 0, 0]
grp.attrs["Time"] = 0.0
grp.attrs["NumFilesPerSnapshot"] = 1
grp.attrs["MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
grp.attrs["Flag_Entropy_ICs"] = 0
grp.attrs["Dimension"] = 2
#Runtime parameters
grp = file.create_group("/RuntimePars")
grp.attrs["PeriodicBoundariesOn"] = 1
#Units
grp = file.create_group("/Units")
grp.attrs["Unit length in cgs (U_L)"] = 1.
grp.attrs["Unit mass in cgs (U_M)"] = 1.
grp.attrs["Unit time in cgs (U_t)"] = 1.
grp.attrs["Unit current in cgs (U_I)"] = 1.
grp.attrs["Unit temperature in cgs (U_T)"] = 1.
#Particle group
grp = file.create_group("/PartType0")
grp.create_dataset('Coordinates', data=pos, dtype='d')
grp.create_dataset('Velocities', data=v, dtype='f')
grp.create_dataset('Masses', data=m, dtype='f')
grp.create_dataset('SmoothingLength', data=h, dtype='f')
grp.create_dataset('InternalEnergy', data=u, dtype='f')
grp.create_dataset('ParticleIDs', data=ids, dtype='L')
file.close()
###############################################################################
# This file is part of SWIFT.
# Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
# 2018 Bert Vandenbroucke (bert.vandenbroucke@gmail.com)
#
# 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/>.
#
################################################################################
# Compares the swift result for the 2D spherical Sod shock with a high
# resolution 2D reference result
import matplotlib
matplotlib.use("Agg")
from pylab import *
from scipy import stats
import h5py
# Parameters
gas_gamma = 5./3. # Polytropic index
rho_L = 1. # Density left state
rho_R = 0.140625 # Density right state
v_L = 0. # Velocity left state
v_R = 0. # Velocity right state
P_L = 1. # Pressure left state
P_R = 0.1 # Pressure right state
# 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
}
rcParams.update(params)
rc('font',**{'family':'sans-serif','sans-serif':['Times']})
snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("sodShock_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
kernel = sim["/HydroScheme"].attrs["Kernel function"]
neighbours = sim["/HydroScheme"].attrs["Kernel target N_ngb"]
eta = sim["/HydroScheme"].attrs["Kernel eta"]
git = sim["Code"].attrs["Git Revision"]
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"][:]
# Bin the data
rho_bin,x_bin_edge,_ = \
stats.binned_statistic(x, rho, statistic='mean', bins=100)
x_bin = 0.5*(x_bin_edge[1:] + x_bin_edge[:-1])
v_bin,_,_ = stats.binned_statistic(x, v, statistic='mean', bins=x_bin_edge)
P_bin,_,_ = stats.binned_statistic(x, P, statistic='mean', bins=x_bin_edge)
S_bin,_,_ = stats.binned_statistic(x, S, statistic='mean', bins=x_bin_edge)
u_bin,_,_ = stats.binned_statistic(x, u, statistic='mean', bins=x_bin_edge)
rho2_bin,_,_ = stats.binned_statistic(x, rho**2, statistic='mean', bins=x_bin_edge)
v2_bin,_,_ = stats.binned_statistic(x, v**2, statistic='mean', bins=x_bin_edge)
P2_bin,_,_ = stats.binned_statistic(x, P**2, statistic='mean', bins=x_bin_edge)
S2_bin,_,_ = stats.binned_statistic(x, S**2, statistic='mean', bins=x_bin_edge)
u2_bin,_,_ = stats.binned_statistic(x, u**2, statistic='mean', bins=x_bin_edge)
rho_sigma_bin = np.sqrt(rho2_bin - rho_bin**2)
v_sigma_bin = np.sqrt(v2_bin - v_bin**2)
P_sigma_bin = np.sqrt(P2_bin - P_bin**2)
S_sigma_bin = np.sqrt(S2_bin - S_bin**2)
u_sigma_bin = np.sqrt(u2_bin - u_bin**2)
ref = loadtxt("sodShockSpherical2D_exact.txt")
# Plot the interesting quantities
figure()
# Velocity profile --------------------------------
subplot(231)
plot(x, v, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,2], "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, v_bin, yerr=v_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Velocity}}~v_r$", labelpad=0)
# Density profile --------------------------------
subplot(232)
plot(x, rho, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,1], "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, rho_bin, yerr=rho_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Density}}~\\rho$", labelpad=0)
# Pressure profile --------------------------------
subplot(233)
plot(x, P, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,3], "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, P_bin, yerr=P_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Pressure}}~P$", labelpad=0)
# Internal energy profile -------------------------
subplot(234)
plot(x, u, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,3] / ref[:,1] / (gas_gamma - 1.), "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, u_bin, yerr=u_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Internal~Energy}}~u$", labelpad=0)
# Entropy profile ---------------------------------
subplot(235)
plot(x, S, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,3] / ref[:,1]**gas_gamma, "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, S_bin, yerr=S_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Entropy}}~S$", labelpad=0)
# Information -------------------------------------
subplot(236, frameon=False)
text(-0.49, 0.9, "Sod shock with $\\gamma=%.3f$ in 2D at $t=%.2f$"%(gas_gamma,time), fontsize=10)
text(-0.49, 0.8, "Left:~~ $(P_L, \\rho_L, v_L) = (%.3f, %.3f, %.3f)$"%(P_L, rho_L, v_L), fontsize=10)
text(-0.49, 0.7, "Right: $(P_R, \\rho_R, v_R) = (%.3f, %.3f, %.3f)$"%(P_R, rho_R, v_R), fontsize=10)
plot([-0.49, 0.1], [0.62, 0.62], 'k-', lw=1)
text(-0.49, 0.5, "$\\textsc{Swift}$ %s"%git, fontsize=10)
text(-0.49, 0.4, scheme, fontsize=10)
text(-0.49, 0.3, kernel, fontsize=10)
text(-0.49, 0.2, "$%.2f$ neighbours ($\\eta=%.3f$)"%(neighbours, eta), fontsize=10)
xlim(-0.5, 0.5)
ylim(0, 1)
xticks([])
yticks([])
savefig("SodShock.png", dpi=200)
#!/bin/bash
# Generate the initial conditions if they are not present.
if [ ! -e glassPlane_128.hdf5 ]
then
echo "Fetching initial glass file for the Sod shock example..."
./getGlass.sh
fi
if [ ! -e sodShock.hdf5 ]
then
echo "Generating initial conditions for the Sod shock example..."
python makeIC.py
fi
# Run SWIFT
../swift -s -t 1 sodShock.yml 2>&1 | tee output.log
# Get the high resolution 1D reference solution if not present.
if [ ! -e sodShockSpherical2D_exact.txt ]
then
echo "Fetching reference solution for 2D spherical Sod shock example..."
./getReference.sh
fi
python plotSolution.py 1
# Define the system of units to use internally.
InternalUnitSystem:
UnitMass_in_cgs: 1 # Grams
UnitLength_in_cgs: 1 # Centimeters
UnitVelocity_in_cgs: 1 # Centimeters per second
UnitCurrent_in_cgs: 1 # Amperes
UnitTemp_in_cgs: 1 # Kelvin
# Parameters governing the time integration
TimeIntegration:
time_begin: 0. # The starting time of the simulation (in internal units).
time_end: 0.1 # The end time of the simulation (in internal units).
dt_min: 1e-7 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-2 # The maximal time-step size of the simulation (in internal units).
# Parameters governing the snapshots
Snapshots:
basename: sodShock # Common part of the name of output files
time_first: 0. # Time of the first output (in internal units)
delta_time: 0.1 # Time difference between consecutive outputs (in internal units)
# Parameters governing the conserved quantities statistics
Statistics:
delta_time: 1e-2 # Time between statistics output
# Parameters for the hydrodynamics scheme
SPH:
resolution_eta: 1.2348 # Target smoothing length in units of the mean inter-particle separation (1.2348 == 48Ngbs with the cubic spline kernel).
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
# Parameters related to the initial conditions
InitialConditions:
file_name: ./sodShock.hdf5 # The file to read
#!/bin/bash
wget http://virgodb.cosma.dur.ac.uk/swift-webstorage/ICs/glassCube_64.hdf5
wget http://virgodb.cosma.dur.ac.uk/swift-webstorage/ICs/glassCube_32.hdf5
#!/bin/bash
wget http://virgodb.cosma.dur.ac.uk/swift-webstorage/ReferenceSolutions/sodShockSpherical3D_exact.txt
###############################################################################
# This file is part of SWIFT.
# Copyright (c) 2016 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 h5py
from numpy import *
# Generates a swift IC file for the 3D Sod Shock in a periodic box
# Parameters
gamma = 5./3. # Gas adiabatic index
x_min = -1.
x_max = 1.
rho_L = 1. # Density left state
rho_R = 0.125 # Density right state
v_L = 0. # Velocity left state
v_R = 0. # Velocity right state
P_L = 1. # Pressure left state
P_R = 0.1 # Pressure right state
fileName = "sodShock.hdf5"
#---------------------------------------------------
boxSize = (x_max - x_min)
glass_L = h5py.File("glassCube_64.hdf5", "r")
glass_R = h5py.File("glassCube_32.hdf5", "r")
pos_L = glass_L["/PartType0/Coordinates"][:,:]
pos_R = glass_R["/PartType0/Coordinates"][:,:]
h_L = glass_L["/PartType0/SmoothingLength"][:]
h_R = glass_R["/PartType0/SmoothingLength"][:]
radius_L = sqrt((pos_L[:,0] - 0.5)**2 + (pos_L[:,1] - 0.5)**2 + \
(pos_L[:,2] - 0.5)**2)
index_L = radius_L < 0.25
pos_LL = pos_L[index_L]
h_LL = h_L[index_L]
radius_R = sqrt((pos_R[:,0] - 0.5)**2 + (pos_R[:,1] - 0.5)**2 + \
(pos_R[:,2] - 0.5)**2)
index_R = radius_R > 0.25
pos_RR = pos_R[index_R]
h_RR = h_R[index_R]
# Merge things
pos = append(pos_LL, pos_RR, axis=0)
h = append(h_LL, h_RR)
numPart_L = size(h_LL)
numPart_R = size(h_RR)
numPart = size(h)
vol_L = 4. * pi / 3. * 0.25**3
vol_R = 1. - 4. * pi / 3. * 0.25**3
# Generate extra arrays
v = zeros((numPart, 3))
ids = linspace(1, numPart, numPart)
m = zeros(numPart)
u = zeros(numPart)
for i in range(numPart):
x = sqrt((pos[i,0]-0.5)**2+(pos[i,1]-0.5)**2+(pos[i,2]-0.5)**2)
if x < 0.25: #left
u[i] = P_L / (rho_L * (gamma - 1.))
m[i] = rho_L * vol_L / numPart_L
v[i,0] = v_L
else: #right
u[i] = P_R / (rho_R * (gamma - 1.))
m[i] = rho_R * vol_R / numPart_R
v[i,0] = v_R
#File
file = h5py.File(fileName, 'w')
# Header
grp = file.create_group("/Header")
grp.attrs["BoxSize"] = [1., 1., 1.]
grp.attrs["NumPart_Total"] = [numPart, 0, 0, 0, 0, 0]
grp.attrs["NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
grp.attrs["NumPart_ThisFile"] = [numPart, 0, 0, 0, 0, 0]
grp.attrs["Time"] = 0.0
grp.attrs["NumFilesPerSnapshot"] = 1
grp.attrs["MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
grp.attrs["Flag_Entropy_ICs"] = 0
grp.attrs["Dimension"] = 3
#Runtime parameters
grp = file.create_group("/RuntimePars")
grp.attrs["PeriodicBoundariesOn"] = 1
#Units
grp = file.create_group("/Units")
grp.attrs["Unit length in cgs (U_L)"] = 1.
grp.attrs["Unit mass in cgs (U_M)"] = 1.
grp.attrs["Unit time in cgs (U_t)"] = 1.
grp.attrs["Unit current in cgs (U_I)"] = 1.
grp.attrs["Unit temperature in cgs (U_T)"] = 1.
#Particle group
grp = file.create_group("/PartType0")
grp.create_dataset('Coordinates', data=pos, dtype='d')
grp.create_dataset('Velocities', data=v, dtype='f')
grp.create_dataset('Masses', data=m, dtype='f')
grp.create_dataset('SmoothingLength', data=h, dtype='f')
grp.create_dataset('InternalEnergy', data=u, dtype='f')
grp.create_dataset('ParticleIDs', data=ids, dtype='L')
file.close()
###############################################################################
# This file is part of SWIFT.
# Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
# 2018 Bert Vandenbroucke (bert.vandenbroucke@gmail.com)
#
# 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/>.
#
################################################################################
# Compares the swift result for the 2D spherical Sod shock with a high
# resolution 2D reference result
import matplotlib
matplotlib.use("Agg")
from pylab import *
from scipy import stats
import h5py
# Parameters
gas_gamma = 5./3. # Polytropic index
rho_L = 1. # Density left state
rho_R = 0.125 # Density right state
v_L = 0. # Velocity left state
v_R = 0. # Velocity right state
P_L = 1. # Pressure left state
P_R = 0.1 # Pressure right state
# 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
}
rcParams.update(params)
rc('font',**{'family':'sans-serif','sans-serif':['Times']})
snap = int(sys.argv[1])
# Read the simulation data
sim = h5py.File("sodShock_%04d.hdf5"%snap, "r")
boxSize = sim["/Header"].attrs["BoxSize"][0]
time = sim["/Header"].attrs["Time"][0]
scheme = sim["/HydroScheme"].attrs["Scheme"]
kernel = sim["/HydroScheme"].attrs["Kernel function"]
neighbours = sim["/HydroScheme"].attrs["Kernel target N_ngb"]
eta = sim["/HydroScheme"].attrs["Kernel eta"]
git = sim["Code"].attrs["Git Revision"]
coords = sim["/PartType0/Coordinates"]
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"][:]
# Bin the data
rho_bin,x_bin_edge,_ = \
stats.binned_statistic(x, rho, statistic='mean', bins=100)
x_bin = 0.5*(x_bin_edge[1:] + x_bin_edge[:-1])
v_bin,_,_ = stats.binned_statistic(x, v, statistic='mean', bins=x_bin_edge)
P_bin,_,_ = stats.binned_statistic(x, P, statistic='mean', bins=x_bin_edge)
S_bin,_,_ = stats.binned_statistic(x, S, statistic='mean', bins=x_bin_edge)
u_bin,_,_ = stats.binned_statistic(x, u, statistic='mean', bins=x_bin_edge)
rho2_bin,_,_ = stats.binned_statistic(x, rho**2, statistic='mean', bins=x_bin_edge)
v2_bin,_,_ = stats.binned_statistic(x, v**2, statistic='mean', bins=x_bin_edge)
P2_bin,_,_ = stats.binned_statistic(x, P**2, statistic='mean', bins=x_bin_edge)
S2_bin,_,_ = stats.binned_statistic(x, S**2, statistic='mean', bins=x_bin_edge)
u2_bin,_,_ = stats.binned_statistic(x, u**2, statistic='mean', bins=x_bin_edge)
rho_sigma_bin = np.sqrt(rho2_bin - rho_bin**2)
v_sigma_bin = np.sqrt(v2_bin - v_bin**2)
P_sigma_bin = np.sqrt(P2_bin - P_bin**2)
S_sigma_bin = np.sqrt(S2_bin - S_bin**2)
u_sigma_bin = np.sqrt(u2_bin - u_bin**2)
ref = loadtxt("sodShockSpherical3D_exact.txt")
# Plot the interesting quantities
figure()
# Velocity profile --------------------------------
subplot(231)
plot(x, v, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,2], "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, v_bin, yerr=v_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Velocity}}~v_r$", labelpad=0)
# Density profile --------------------------------
subplot(232)
plot(x, rho, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,1], "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, rho_bin, yerr=rho_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Density}}~\\rho$", labelpad=0)
# Pressure profile --------------------------------
subplot(233)
plot(x, P, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,3], "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, P_bin, yerr=P_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Pressure}}~P$", labelpad=0)
# Internal energy profile -------------------------
subplot(234)
plot(x, u, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,3] / ref[:,1] / (gas_gamma - 1.), "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, u_bin, yerr=u_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Internal~Energy}}~u$", labelpad=0)
# Entropy profile ---------------------------------
subplot(235)
plot(x, S, '.', color='r', ms=0.2)
plot(ref[:,0], ref[:,3] / ref[:,1]**gas_gamma, "k--", alpha=0.8, lw=1.2)
errorbar(x_bin, S_bin, yerr=S_sigma_bin, fmt='.', ms=8.0, color='b', lw=1.2)
xlabel("${\\rm{Radius}}~r$", labelpad=0)
ylabel("${\\rm{Entropy}}~S$", labelpad=0)
# Information -------------------------------------
subplot(236, frameon=False)
text(-0.49, 0.9, "Sod shock with $\\gamma=%.3f$ in 3D at $t=%.2f$"%(gas_gamma,time), fontsize=10)
text(-0.49, 0.8, "Left:~~ $(P_L, \\rho_L, v_L) = (%.3f, %.3f, %.3f)$"%(P_L, rho_L, v_L), fontsize=10)
text(-0.49, 0.7, "Right: $(P_R, \\rho_R, v_R) = (%.3f, %.3f, %.3f)$"%(P_R, rho_R, v_R), fontsize=10)
plot([-0.49, 0.1], [0.62, 0.62], 'k-', lw=1)
text(-0.49, 0.5, "$\\textsc{Swift}$ %s"%git, fontsize=10)
text(-0.49, 0.4, scheme, fontsize=10)
text(-0.49, 0.3, kernel, fontsize=10)
text(-0.49, 0.2, "$%.2f$ neighbours ($\\eta=%.3f$)"%(neighbours, eta), fontsize=10)
xlim(-0.5, 0.5)
ylim(0, 1)
xticks([])
yticks([])
savefig("SodShock.png", dpi=200)
#!/bin/bash
# Generate the initial conditions if they are not present.
if [ ! -e glassCube_64.hdf5 ]
then
echo "Fetching initial glass file for the Sod shock example..."
./getGlass.sh
fi
if [ ! -e sodShock.hdf5 ]
then
echo "Generating initial conditions for the Sod shock example..."
python makeIC.py
fi
# Run SWIFT
../swift -s -t 4 sodShock.yml 2>&1 | tee output.log
# Get the high resolution 1D reference solution if not present.
if [ ! -e sodShockSpherical3D_exact.txt ]
then
echo "Fetching reference solution for 3D spherical Sod shock example..."
./getReference.sh
fi
python plotSolution.py 1
# Define the system of units to use internally.
InternalUnitSystem:
UnitMass_in_cgs: 1 # Grams
UnitLength_in_cgs: 1 # Centimeters
UnitVelocity_in_cgs: 1 # Centimeters per second
UnitCurrent_in_cgs: 1 # Amperes
UnitTemp_in_cgs: 1 # Kelvin
# Parameters governing the time integration
TimeIntegration:
time_begin: 0. # The starting time of the simulation (in internal units).
time_end: 0.1 # The end time of the simulation (in internal units).
dt_min: 1e-7 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-2 # The maximal time-step size of the simulation (in internal units).
# Parameters governing the snapshots
Snapshots:
basename: sodShock # Common part of the name of output files
time_first: 0. # Time of the first output (in internal units)
delta_time: 0.1 # Time difference between consecutive outputs (in internal units)
# Parameters governing the conserved quantities statistics
Statistics:
delta_time: 1e-2 # Time between statistics output
# Parameters for the hydrodynamics scheme
SPH:
resolution_eta: 1.2348 # Target smoothing length in units of the mean inter-particle separation (1.2348 == 48Ngbs with the cubic spline kernel).
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
# Parameters related to the initial conditions
InitialConditions:
file_name: ./sodShock.hdf5 # The file to read
#!/bin/bash
wget http://virgodb.cosma.dur.ac.uk/swift-webstorage/ICs/glassPlane_128.hdf5
#!/bin/bash
wget http://virgodb.cosma.dur.ac.uk/swift-webstorage/ReferenceSolutions/vacuumSpherical2D_exact.txt
###############################################################################
# This file is part of SWIFT.
# Copyright (c) 2018 Bert Vandenbroucke (bert.vandenbroucke@gmail.com)
#
# 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 numpy as np
import h5py
# Generates an overdensity within a vacuum to test the vacuum resolving
# capabilities of the code
# Parameters
gamma = 5. / 3. # Gas adiabatic index
fileName = "vacuum.hdf5"
#---------------------------------------------------
glass = h5py.File("glassPlane_128.hdf5", "r")
# Read particle positions and h from the glass
pos = glass["/PartType0/Coordinates"][:,:]
h = glass["/PartType0/SmoothingLength"][:] * 0.3
# Make 4 copies of the glass to have more particles
pos *= 0.5
h *= 0.5
pos = np.append(pos, pos + np.array([0.5, 0., 0.]), axis = 0)
h = np.append(h, h)
pos = np.append(pos, pos + np.array([0., 0.5, 0.]), axis = 0)
h = np.append(h, h)
radius = np.sqrt((pos[:,0] - 0.5)**2 + (pos[:,1] - 0.5)**2)
index = radius < 0.25
pos = pos[index]
h = h[index]
numPart = len(h)
vol = np.pi * 0.25**2
# Generate extra arrays
v = np.zeros((numPart, 3))
ids = np.linspace(1, numPart, numPart)
m = np.zeros(numPart)
u = np.zeros(numPart)
m[:] = 1. * vol / numPart
u[:] = 1. / (1. * (gamma - 1.))
#--------------------------------------------------
#File
file = h5py.File(fileName, 'w')
# Header
grp = file.create_group("/Header")
grp.attrs["BoxSize"] = [1., 1., 1.]
grp.attrs["NumPart_Total"] = [numPart, 0, 0, 0, 0, 0]
grp.attrs["NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
grp.attrs["NumPart_ThisFile"] = [numPart, 0, 0, 0, 0, 0]
grp.attrs["Time"] = 0.0
grp.attrs["NumFilesPerSnapshot"] = 1
grp.attrs["MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
grp.attrs["Flag_Entropy_ICs"] = 0
grp.attrs["Dimension"] = 2
#Runtime parameters
grp = file.create_group("/RuntimePars")
grp.attrs["PeriodicBoundariesOn"] = 1
#Units
grp = file.create_group("/Units")
grp.attrs["Unit length in cgs (U_L)"] = 1.
grp.attrs["Unit mass in cgs (U_M)"] = 1.
grp.attrs["Unit time in cgs (U_t)"] = 1.
grp.attrs["Unit current in cgs (U_I)"] = 1.
grp.attrs["Unit temperature in cgs (U_T)"] = 1.
#Particle group
grp = file.create_group("/PartType0")
grp.create_dataset('Coordinates', data=pos, dtype='d')
grp.create_dataset('Velocities', data=v, dtype='f')
grp.create_dataset('Masses', data=m, dtype='f')
grp.create_dataset('SmoothingLength', data=h, dtype='f')
grp.create_dataset('InternalEnergy', data=u, dtype='f')
grp.create_dataset('ParticleIDs', data=ids, dtype='L')
file.close()
###############################################################################
# This file is part of SWIFT.
# Copyright (c) 2018 Bert Vandenbroucke (bert.vandenbroucke@gmail.com)
#
# 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 numpy as np
import matplotlib
matplotlib.use("Agg")
import pylab as pl
import h5py
import sys
import scipy.stats as stats
# Parameters
gamma = 5. / 3. # Polytropic index
rhoL = 1. # Initial density in the non vacuum state
vL = 0. # Initial velocity in the non vacuum state
PL = 1. # Initial pressure in the non vacuum state
rhoR = 0. # Initial vacuum density
vR = 0. # Initial vacuum velocity
PR = 0. # Initial vacuum pressure
# 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
}
pl.rcParams.update(params)
pl.rc('font',**{'family':'sans-serif','sans-serif':['Times']})
# Read the snapshot index from the command line argument
snap = int(sys.argv[1])
# Open the file and read the relevant data
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"][:]
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"][:]
time = file["/Header"].attrs["Time"][0]
scheme = file["/HydroScheme"].attrs["Scheme"]
kernel = file["/HydroScheme"].attrs["Kernel function"]
neighbours = file["/HydroScheme"].attrs["Kernel target N_ngb"][0]
eta = file["/HydroScheme"].attrs["Kernel eta"][0]
git = file["Code"].attrs["Git Revision"]
# Bin the data values
# We let scipy choose the bins and then reuse them for all other quantities
rho_bin, x_bin_edge, _ = \
stats.binned_statistic(x, rho, statistic = "mean", bins = 50)
rho2_bin, _, _ = \
stats.binned_statistic(x, rho**2, statistic = "mean", bins = x_bin_edge)
rho_sigma_bin = np.sqrt(rho2_bin - rho_bin**2)
v_bin, _, _ = \
stats.binned_statistic(x, v, statistic = "mean", bins = x_bin_edge)
v2_bin, _, _ = \
stats.binned_statistic(x, v**2, statistic = "mean", bins = x_bin_edge)
v_sigma_bin = np.sqrt(v2_bin - v_bin**2)
P_bin, _, _ = \
stats.binned_statistic(x, P, statistic = "mean", bins = x_bin_edge)
P2_bin, _, _ = \
stats.binned_statistic(x, P**2, statistic = "mean", bins = x_bin_edge)
P_sigma_bin = np.sqrt(P2_bin - P_bin**2)
u_bin, _, _ = \
stats.binned_statistic(x, u, statistic = "mean", bins = x_bin_edge)
u2_bin, _, _ = \
stats.binned_statistic(x, u**2, statistic = "mean", bins = x_bin_edge)
u_sigma_bin = np.sqrt(u2_bin - u_bin**2)
S_bin, _, _ = \
stats.binned_statistic(x, S, statistic = "mean", bins = x_bin_edge)
S2_bin, _, _ = \
stats.binned_statistic(x, S**2, statistic = "mean", bins = x_bin_edge)
S_sigma_bin = np.sqrt(S2_bin - S_bin**2)
x_bin = 0.5 * (x_bin_edge[1:] + x_bin_edge[:-1])
ref = np.loadtxt("vacuumSpherical2D_exact.txt")
# Plot the interesting quantities
fig, ax = pl.subplots(2, 3)
# Velocity profile
ax[0][0].plot(x, v, "r.", markersize = 0.2)
ax[0][0].plot(ref[:,0], ref[:,2], "k--", alpha = 0.8, linewidth = 1.2)
ax[0][0].errorbar(x_bin, v_bin, yerr = v_sigma_bin, fmt = ".",
markersize = 8., color = "b", linewidth = 1.2)
ax[0][0].set_xlabel("${\\rm{Radius}}~r$", labelpad = 0)
ax[0][0].set_ylabel("${\\rm{Velocity}}~v_r$", labelpad = 0)
ax[0][0].set_xlim(0., 0.4)
ax[0][0].set_ylim(-0.1, 3.2)
# Density profile
ax[0][1].plot(x, rho, "r.", markersize = 0.2)
ax[0][1].plot(ref[:,0], ref[:,1], "k--", alpha = 0.8, linewidth = 1.2)
ax[0][1].errorbar(x_bin, rho_bin, yerr = rho_sigma_bin, fmt = ".",
markersize = 8., color = "b", linewidth = 1.2)
ax[0][1].set_xlabel("${\\rm{Radius}}~r$", labelpad = 0)
ax[0][1].set_ylabel("${\\rm{Density}}~\\rho$", labelpad = 0)
ax[0][1].set_xlim(0., 0.4)
# Pressure profile
ax[0][2].plot(x, P, "r.", markersize = 0.2)
ax[0][2].plot(ref[:,0], ref[:,3], "k--", alpha = 0.8, linewidth = 1.2)
ax[0][2].errorbar(x_bin, P_bin, yerr = P_sigma_bin, fmt = ".",
markersize = 8., color = "b", linewidth = 1.2)
ax[0][2].set_xlabel("${\\rm{Radius}}~r$", labelpad = 0)
ax[0][2].set_ylabel("${\\rm{Pressure}}~P$", labelpad = 0)
ax[0][2].set_xlim(0., 0.4)
# Internal energy profile
ax[1][0].plot(x, u, "r.", markersize = 0.2)
ax[1][0].plot(ref[:,0], ref[:,3] / ref[:,1] / (gamma - 1.), "k--", alpha = 0.8,
linewidth = 1.2)
ax[1][0].errorbar(x_bin, u_bin, yerr = u_sigma_bin, fmt = ".",
markersize = 8., color = "b", linewidth = 1.2)
ax[1][0].set_xlabel("${\\rm{Radius}}~r$", labelpad = 0)
ax[1][0].set_ylabel("${\\rm{Internal~Energy}}~u$", labelpad = 0)
ax[1][0].set_xlim(0., 0.4)
# Entropy profile
ax[1][1].plot(x, S, "r.", markersize = 0.2)
ax[1][1].plot(ref[:,0], ref[:,3] / ref[:,1]**gamma, "k--", alpha = 0.8,
linewidth = 1.2)
ax[1][1].errorbar(x_bin, S_bin, yerr = S_sigma_bin, fmt = ".",
markersize = 8., color = "b", linewidth = 1.2)
ax[1][1].set_xlabel("${\\rm{Radius}}~r$", labelpad = 0)
ax[1][1].set_ylabel("${\\rm{Entropy}}~S$", labelpad = 0)
ax[1][1].set_xlim(0., 0.4)
ax[1][1].set_ylim(0., 4.)
# Run information
ax[1][2].set_frame_on(False)
ax[1][2].text(-0.49, 0.9,
"Vacuum test with $\\gamma={0:.3f}$ in 1D at $t = {1:.2f}$".format(
gamma, time), fontsize = 10)
ax[1][2].text(-0.49, 0.8,
"Left:~~ $(P_L, \\rho_L, v_L) = ({0:.3f}, {1:.3f}, {2:.3f})$".format(
PL, rhoL, vL), fontsize = 10)
ax[1][2].text(-0.49, 0.7,
"Right: $(P_R, \\rho_R, v_R) = ({0:.3f}, {1:.3f}, {2:.3f})$".format(
PR, rhoR, vR), fontsize = 10)
ax[1][2].plot([-0.49, 0.1], [0.62, 0.62], "k-", lw = 1)
ax[1][2].text(-0.49, 0.5, "$\\textsc{{Swift}}$ {0}".format(git), fontsize = 10)
ax[1][2].text(-0.49, 0.4, scheme, fontsize = 10)
ax[1][2].text(-0.49, 0.3, kernel, fontsize = 10)
ax[1][2].text(-0.49, 0.2,
"${0:.2f}$ neighbours ($\\eta={1:.3f}$)".format(neighbours, eta),
fontsize = 10)
ax[1][2].set_xlim(-0.5, 0.5)
ax[1][2].set_ylim(0., 1.)
ax[1][2].set_xticks([])
ax[1][2].set_yticks([])
pl.tight_layout()
pl.savefig("Vacuum.png", dpi = 200)
#!/bin/bash
# Generate the initial conditions if they are not present.
if [ ! -e glassPlane_128.hdf5 ]
then
echo "Fetching initial glass file for the 2D vacuum expansion example..."
./getGlass.sh
fi
if [ ! -e vacuum.hdf5 ]
then
echo "Generating initial conditions for the 2D vacuum expansion example..."
python makeIC.py
fi
# Run SWIFT
../swift -s -t 4 vacuum.yml 2>&1 | tee output.log
# Get the 1D high resolution reference result if not present.
if [ ! -e vacuumSpherical2D_exact.txt ]
then
echo "Fetching reference solution for the 2D vacuum expansion test..."
./getReference.sh
fi
# Plot the result
python plotSolution.py 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment