Commit fa51a0e6 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'gizmo_new' into 'master'

Merge Gizmo-SPH into the master branch



See merge request !223
parents 880d66a9 566c6efc
...@@ -36,6 +36,7 @@ examples/*/*/*.xmf ...@@ -36,6 +36,7 @@ examples/*/*/*.xmf
examples/*/*/*.hdf5 examples/*/*/*.hdf5
examples/*/*/*.txt examples/*/*/*.txt
examples/*/*/used_parameters.yml examples/*/*/used_parameters.yml
examples/*/*.png
tests/testPair tests/testPair
tests/brute_force_standard.dat tests/brute_force_standard.dat
...@@ -72,7 +73,11 @@ tests/testPair.sh ...@@ -72,7 +73,11 @@ tests/testPair.sh
tests/testPairPerturbed.sh tests/testPairPerturbed.sh
tests/testParser.sh tests/testParser.sh
tests/testReading.sh tests/testReading.sh
tests/testAdiabaticIndex
tests/testRiemannExact
tests/testRiemannTRRS
tests/testRiemannHLLC
tests/testMatrixInversion
theory/latex/swift.pdf theory/latex/swift.pdf
theory/kernel/kernels.pdf theory/kernel/kernels.pdf
......
# 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: 1e-6 # The end time of the simulation (in internal units).
dt_min: 1e-6 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-6 # The maximal time-step size of the simulation (in internal units).
# Parameters governing the snapshots
Snapshots:
basename: gradients_cartesian # Common part of the name of output files
time_first: 0. # Time of the first output (in internal units)
delta_time: 5e-7 # Time difference between consecutive outputs (in internal units)
# Parameters governing the conserved quantities statistics
Statistics:
delta_time: 1e-6 # 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).
delta_neighbours: 0.1 # The tolerance for the targetted number of neighbours.
max_smoothing_length: 0.01 # Maximal smoothing length allowed (in internal units).
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
# Parameters related to the initial conditions
InitialConditions:
file_name: ./Gradients_cartesian.hdf5 # The file to read
# 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: 1e-6 # The end time of the simulation (in internal units).
dt_min: 1e-6 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-6 # The maximal time-step size of the simulation (in internal units).
# Parameters governing the snapshots
Snapshots:
basename: gradients_random # Common part of the name of output files
time_first: 0. # Time of the first output (in internal units)
delta_time: 5e-7 # Time difference between consecutive outputs (in internal units)
# Parameters governing the conserved quantities statistics
Statistics:
delta_time: 1e-6 # 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).
delta_neighbours: 0.1 # The tolerance for the targetted number of neighbours.
max_smoothing_length: 0.01 # Maximal smoothing length allowed (in internal units).
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
# Parameters related to the initial conditions
InitialConditions:
file_name: ./Gradients_random.hdf5 # The file to read
# 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: 1e-6 # The end time of the simulation (in internal units).
dt_min: 1e-6 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-6 # The maximal time-step size of the simulation (in internal units).
# Parameters governing the snapshots
Snapshots:
basename: gradients_stretched # Common part of the name of output files
time_first: 0. # Time of the first output (in internal units)
delta_time: 5e-7 # Time difference between consecutive outputs (in internal units)
# Parameters governing the conserved quantities statistics
Statistics:
delta_time: 1e-6 # 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).
delta_neighbours: 0.1 # The tolerance for the targetted number of neighbours.
max_smoothing_length: 0.01 # Maximal smoothing length allowed (in internal units).
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
# Parameters related to the initial conditions
InitialConditions:
file_name: ./Gradients_stretched.hdf5 # The file to read
################################################################################
# This file is part of SWIFT.
# Copyright (c) 2015 Bert Vandenbroucke (bert.vandenbroucke@ugent.be)
#
# 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
import random
import numpy as np
import sys
# Generates a swift IC file with some density gradients, to check the gradient
# reconstruction
# Parameters
periodic= 1 # 1 For periodic box
gamma = 5./3. # Gas adiabatic index
gridtype = "cartesian"
if len(sys.argv) > 1:
gridtype = sys.argv[1]
# stretched cartesian box ######################################################
if gridtype == "stretched":
fileName = "Gradients_stretched.hdf5"
factor = 8
boxSize = [ 1.0 , 1.0/factor , 1.0/factor ]
L = 20
nx1 = factor*L/2
ny1 = L
nz1 = L
numfac = 2.
nx2 = int(nx1/numfac)
ny2 = int(ny1/numfac)
nz2 = int(nz1/numfac)
npart = nx1*ny1*nz1 + nx2*ny2*nz2
vol = boxSize[0] * boxSize[1] * boxSize[2]
partVol1 = 0.5*vol/(nx1*ny1*nz1)
partVol2 = 0.5*vol/(nx2*ny2*nz2)
coords = np.zeros((npart,3))
h = np.zeros((npart,1))
ids = np.zeros((npart,1), dtype='L')
idx = 0
dcell = 0.5/nx1
for i in range(nx1):
for j in range(ny1):
for k in range(nz1):
coords[idx,0] = (i+0.5)*dcell
coords[idx,1] = (j+0.5)*dcell
coords[idx,2] = (k+0.5)*dcell
h[idx] = 0.56/nx1
ids[idx] = idx
idx += 1
dcell = 0.5/nx2
for i in range(nx2):
for j in range(ny2):
for k in range(nz2):
coords[idx,0] = 0.5+(i+0.5)*dcell
coords[idx,1] = (j+0.5)*dcell
coords[idx,2] = (k+0.5)*dcell
h[idx] = 0.56/nx2
ids[idx] = idx
idx += 1
# cartesian box ################################################################
if gridtype == "cartesian":
fileName = "Gradients_cartesian.hdf5"
boxSize = [ 1.0 , 1.0 , 1.0 ]
nx = 20
npart = nx**3
partVol = 1./npart
coords = np.zeros((npart,3))
h = np.zeros((npart,1))
ids = np.zeros((npart,1), dtype='L')
idx = 0
dcell = 1./nx
for i in range(nx):
for j in range(nx):
for k in range(nx):
coords[idx,0] = (i+0.5)*dcell
coords[idx,1] = (j+0.5)*dcell
coords[idx,2] = (k+0.5)*dcell
h[idx] = 1.12/nx
ids[idx] = idx
idx += 1
# random box ###################################################################
if gridtype == "random":
fileName = "Gradients_random.hdf5"
boxSize = [ 1.0 , 1.0 , 1.0 ]
glass = h5py.File("../Glass/glass_50000.hdf5", "r")
coords = np.array(glass["/PartType0/Coordinates"])
npart = len(coords)
partVol = 1./npart
h = np.zeros((npart,1))
ids = np.zeros((npart,1), dtype='L')
for i in range(npart):
h[i] = 0.019
ids[i] = i
v = np.zeros((npart,3))
m = np.zeros((npart,1))
rho = np.zeros((npart,1))
u = np.zeros((npart,1))
for i in range(npart):
rhox = coords[i,0]
if coords[i,0] < 0.75:
rhox = 0.75
if coords[i,0] < 0.25:
rhox = 1.-coords[i,0]
rhoy = 1.+boxSize[1]-coords[i,1]
if coords[i,1] < 0.75*boxSize[1]:
rhoy = 1. + 0.25*boxSize[1]
if coords[i,1] < 0.25*boxSize[1]:
rhoy = 1.+coords[i,1]
rhoz = 1.
rho[i] = rhox + rhoy + rhoz
P = 1.
u[i] = P / ((gamma-1.)*rho[i])
if gridtype == "stretched":
if coords[i,0] < 0.5:
m[i] = rho[i] * partVol1
else:
m[i] = rho[i] * partVol2
else:
m[i] = rho[i] * partVol
#File
file = h5py.File(fileName, 'w')
# Header
grp = file.create_group("/Header")
grp.attrs["BoxSize"] = boxSize
grp.attrs["NumPart_Total"] = [npart, 0, 0, 0, 0, 0]
grp.attrs["NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
grp.attrs["NumPart_ThisFile"] = [npart, 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, 0, 0, 0, 0, 0]
#Runtime parameters
grp = file.create_group("/RuntimePars")
grp.attrs["PeriodicBoundariesOn"] = periodic
#Particle group
grp = file.create_group("/PartType0")
ds = grp.create_dataset('Coordinates', (npart, 3), 'd')
ds[()] = coords
ds = grp.create_dataset('Velocities', (npart, 3), 'f')
ds[()] = v
ds = grp.create_dataset('Masses', (npart,1), 'f')
ds[()] = m
ds = grp.create_dataset('Density', (npart,1), 'd')
ds[()] = rho
ds = grp.create_dataset('SmoothingLength', (npart,1), 'f')
ds[()] = h
ds = grp.create_dataset('InternalEnergy', (npart,1), 'd')
ds[()] = u
ds = grp.create_dataset('ParticleIDs', (npart,1), 'L')
ds[()] = ids[:]
file.close()
################################################################################
# This file is part of SWIFT.
# Copyright (c) 2015 Bert Vandenbroucke (bert.vandenbroucke@ugent.be)
#
# 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 scipy as sp
import pylab as pl
import numpy as np
import h5py
import sys
# this file plots the gradients of the density in the x and y direction for
# the given input file and saves the result as gradiens_NAME.png
inputfile = sys.argv[1]
outputfile = "gradients_{0}.png".format(sys.argv[2])
f = h5py.File(inputfile, "r")
rho = np.array(f["/PartType0/Density"])
gradrho = np.array(f["/PartType0/GradDensity"])
coords = np.array(f["/PartType0/Coordinates"])
fig, ax = pl.subplots(1,2, sharey=True)
ax[0].plot(coords[:,0], rho, "r.", label="density")
ax[0].plot(coords[:,0], gradrho[:,0], "b.", label="grad density x")
ax[0].set_xlabel("x")
ax[0].legend(loc="best")
ax[1].plot(coords[:,1], rho, "r.", label="density")
ax[1].plot(coords[:,1], gradrho[:,1], "b.", label="grad density y")
ax[1].set_xlabel("y")
ax[1].legend(loc="best")
pl.tight_layout()
pl.savefig(outputfile)
#! /bin/bash
python makeICs.py stretched
../swift -s -t 2 gradientsStretched.yml
python plot.py gradients_stretched_001.hdf5 stretched
python makeICs.py cartesian
../swift -s -t 2 gradientsCartesian.yml
python plot.py gradients_cartesian_001.hdf5 cartesian
python makeICs.py random
../swift -s -t 2 gradientsRandom.yml
python plot.py gradients_random_001.hdf5 random
/******************************************************************************* /*******************************************************************************
* This file is part of SWIFT. * This file is part of SWIFT.
* Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk). * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk).
* Bert Vandenbroucke (bert.vandenbroucke@gmail.com).
* *
* 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
...@@ -42,18 +43,42 @@ ...@@ -42,18 +43,42 @@
#define hydro_gamma 1.66666666666666667f #define hydro_gamma 1.66666666666666667f
#define hydro_gamma_minus_one 0.66666666666666667f #define hydro_gamma_minus_one 0.66666666666666667f
#define hydro_one_over_gamma_minus_one 1.5f #define hydro_one_over_gamma_minus_one 1.5f
#define hydro_gamma_plus_one_over_two_gamma 0.8f
#define hydro_gamma_minus_one_over_two_gamma 0.2f
#define hydro_gamma_minus_one_over_gamma_plus_one 0.25f
#define hydro_two_over_gamma_plus_one 0.75f
#define hydro_two_over_gamma_minus_one 3.0f
#define hydro_gamma_minus_one_over_two 0.33333333333333333f
#define hydro_two_gamma_over_gamma_minus_one 5.0f
#define hydro_one_over_gamma 0.6f
#elif defined(HYDRO_GAMMA_4_3) #elif defined(HYDRO_GAMMA_4_3)
#define hydro_gamma 1.33333333333333333f #define hydro_gamma 1.33333333333333333f
#define hydro_gamma_minus_one 0.33333333333333333f #define hydro_gamma_minus_one 0.33333333333333333f
#define hydro_one_over_gamma_minus_one 3.f #define hydro_one_over_gamma_minus_one 3.f
#define hydro_gamma_plus_one_over_two_gamma 0.875f
#define hydro_gamma_minus_one_over_two_gamma 0.125f
#define hydro_gamma_minus_one_over_gamma_plus_one 0.142857143f
#define hydro_two_over_gamma_plus_one 0.857142857f
#define hydro_two_over_gamma_minus_one 6.0f
#define hydro_gamma_minus_one_over_two 0.166666666666666666f
#define hydro_two_gamma_over_gamma_minus_one 8.0f
#define hydro_one_over_gamma 0.75f
#elif defined(HYDRO_GAMMA_2_1) #elif defined(HYDRO_GAMMA_2_1)
#define hydro_gamma 2.f #define hydro_gamma 2.f
#define hydro_gamma_minus_one 1.f #define hydro_gamma_minus_one 1.f
#define hydro_one_over_gamma_minus_one 1.f #define hydro_one_over_gamma_minus_one 1.f
#define hydro_gamma_plus_one_over_two_gamma 0.75f
#define hydro_gamma_minus_one_over_two_gamma 0.25f
#define hydro_gamma_minus_one_over_gamma_plus_one 0.33333333333333333f
#define hydro_two_over_gamma_plus_one 0.66666666666666666f
#define hydro_two_over_gamma_minus_one 2.0f
#define hydro_gamma_minus_one_over_two 0.5f
#define hydro_two_gamma_over_gamma_minus_one 4.0f
#define hydro_one_over_gamma 0.5f
#else #else
...@@ -149,4 +174,201 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one( ...@@ -149,4 +174,201 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one(
#endif #endif
} }
/**
* @brief Returns one over the argument to the power given by the adiabatic
* index
*
* Computes \f$x^{-\gamma}\f$.
*
* @param x Argument
* @return One over the argument to the power given by the adiabatic index
*/
__attribute__((always_inline)) INLINE static float pow_minus_gamma(float x) {
#if defined(HYDRO_GAMMA_5_3)
const float cbrt_inv = 1.f / cbrtf(x); /* x^(-1/3) */
const float cbrt_inv2 = cbrt_inv * cbrt_inv; /* x^(-2/3) */
return cbrt_inv * cbrt_inv2 * cbrt_inv2; /* x^(-5/3) */
#elif defined(HYDRO_GAMMA_4_3)
const float cbrt_inv = 1.f / cbrtf(x); /* x^(-1/3) */
const float cbrt_inv2 = cbrt_inv * cbrt_inv; /* x^(-2/3) */
return cbrt_inv2 * cbrt_inv2; /* x^(-4/3) */
#elif defined(HYDRO_GAMMA_2_1)
const float inv = 1.f / x;
return inv * inv;
#else
error("The adiabatic index is not defined !");
return 0.f;
#endif
}
/**
* @brief Return the argument to the power given by two divided by the adiabatic
* index minus one
*
* Computes \f$x^{\frac{2}{\gamma - 1}}\f$.
*
* @param x Argument
* @return Argument to the power two divided by the adiabatic index minus one
*/
__attribute__((always_inline)) INLINE static float pow_two_over_gamma_minus_one(
float x) {
#if defined(HYDRO_GAMMA_5_3)
return x * x * x; /* x^3 */
#elif defined(HYDRO_GAMMA_4_3)
return x * x * x * x * x * x; /* x^6 */
#elif defined(HYDRO_GAMMA_2_1)
return x * x; /* x^2 */
#else
error("The adiabatic index is not defined !");
return 0.f;
#endif
}
/**
* @brief Return the argument to the power given by two times the adiabatic
* index divided by the adiabatic index minus one
*
* Computes \f$x^{\frac{2\gamma}{\gamma - 1}}\f$.
*
* @param x Argument
* @return Argument to the power two times the adiabatic index divided by the
* adiabatic index minus one
*/
__attribute__((always_inline)) INLINE static float
pow_two_gamma_over_gamma_minus_one(float x) {
#if defined(HYDRO_GAMMA_5_3)
return x * x * x * x * x; /* x^5 */
#elif defined(HYDRO_GAMMA_4_3)
return x * x * x * x * x * x * x * x; /* x^8 */
#elif defined(HYDRO_GAMMA_2_1)
return x * x * x * x; /* x^4 */
#else
error("The adiabatic index is not defined !");
return 0.f;
#endif
}
/**
* @brief Return the argument to the power given by the adiabatic index minus
* one divided by two times the adiabatic index
*
* Computes \f$x^{\frac{\gamma - 1}{2\gamma}}\f$.
*
* @param x Argument
* @return Argument to the power the adiabatic index minus one divided by two
* times the adiabatic index
*/
__attribute__((always_inline)) INLINE static float
pow_gamma_minus_one_over_two_gamma(float x) {
#if defined(HYDRO_GAMMA_5_3)
return powf(x, 0.2f); /* x^0.2 */
#elif defined(HYDRO_GAMMA_4_3)
return powf(x, 0.125f); /* x^0.125 */
#elif defined(HYDRO_GAMMA_2_1)
return powf(x, 0.25f); /* x^0.25 */
#else
error("The adiabatic index is not defined !");
return 0.f;
#endif
}
/**
* @brief Return the inverse argument to the power given by the adiabatic index
* plus one divided by two times the adiabatic index
*
* Computes \f$x^{-\frac{\gamma + 1}{2\gamma}}\f$.
*
* @param x Argument
* @return Inverse argument to the power the adiabatic index plus one divided by
* two times the adiabatic index
*/
__attribute__((always_inline)) INLINE static float
pow_minus_gamma_plus_one_over_two_gamma(float x) {
#if defined(HYDRO_GAMMA_5_3)
return powf(x, -0.8f); /* x^-0.8 */
#elif defined(HYDRO_GAMMA_4_3)
return powf(x, -0.875f); /* x^-0.875 */
#elif defined(HYDRO_GAMMA_2_1)
return powf(x, -0.75f); /* x^-0.75 */
#else
error("The adiabatic index is not defined !");
return 0.f;