Commit 0f84a567 authored by Rainer Weinberger's avatar Rainer Weinberger

added example current_sheet_2d and changed test.sh such that example...

added example current_sheet_2d and changed test.sh such that example simulations are now executed from the run directory directly
parent 2bb6eb54
%---- Relevant files
InitCondFile run/examples/cosmo_box_gravity_only_3d/ics
OutputDir run/examples/cosmo_box_gravity_only_3d/output
InitCondFile ics
OutputDir output
SnapshotFileBase snap
OutputListFilename run/examples/cosmo_box_gravity_only_3d/output_list.txt
OutputListFilename output_list.txt
%---- File formats
ICFormat 1
......
......@@ -72,5 +72,9 @@ data = np.array([outputTimes, ones]).T
np.savetxt(simulation_directory+"/output_list.txt",data, fmt="%g %1.f" )
""" copy treecool file to run directory """
call(['cp', './data/TREECOOL_ep', simulation_directory+'/TREECOOL_ep'])
""" normal exit """
sys.exit(0)
%% parameters for cosmo_box_star_formation_3d
%---- Relevant files
InitCondFile run/examples/cosmo_box_star_formation_3d/ics
OutputDir run/examples/cosmo_box_star_formation_3d/output
InitCondFile ics
OutputDir output
SnapshotFileBase snap
OutputListFilename run/examples/cosmo_box_star_formation_3d/output_list.txt
OutputListFilename output_list.txt
%---- File formats
ICFormat 1
......@@ -120,4 +120,4 @@ FactorEVP 573.0
TemperatureThresh 1e+06
FactorSN 0.1
TreecoolFile ./data/TREECOOL_ep
TreecoolFile TREECOOL_ep
%---- Relevant files
InitCondFile ./run/examples/cosmo_zoom_gravity_only_3d/ics
OutputDir ./run/examples/cosmo_zoom_gravity_only_3d/output
InitCondFile ics
OutputDir output
SnapshotFileBase snap
OutputListFilename ./run/examples/cosmo_zoom_gravity_only_3d/output_list.txt
OutputListFilename output_list.txt
%---- File formats
ICFormat 1
......
%---- Relevant files
InitCondFile ./run/examples/cosmo_zoom_gravity_only_3d/ics_parent
OutputDir ./run/examples/cosmo_zoom_gravity_only_3d/output_parent
InitCondFile ics_parent
OutputDir output_parent
SnapshotFileBase snap
OutputListFilename ./run/examples/cosmo_zoom_gravity_only_3d/output_list.txt
OutputListFilename output_list.txt
%---- File formats
......
#!/bin/bash # this line only there to enable syntax highlighting in this file
## examples/current_sheet_2d/Config.sh
## config file for 2d current sheet probelm
#--------------------------------------- Basic operation mode of code
TWODIMS # 2d simulation
#--------------------------------------- Magnetohydrodynamics
MHD # Master switch for magnetohydrodynamics
MHD_POWELL # Powell div(B) cleaning scheme for magnetohydrodynamics
MHD_POWELL_LIMIT_TIMESTEP # Timestep constraint due to Powell cleaning scheme
#--------------------------------------- Riemann solver
RIEMANN_HLLD # HLLD approximate Riemann solver (required to use for MHD)
#--------------------------------------- Mesh motion and regularization
REGULARIZE_MESH_CM_DRIFT # Mesh regularization; Move mesh generating point towards center of mass to make cells rounder.
REGULARIZE_MESH_CM_DRIFT_USE_SOUNDSPEED # Limit mesh regularization speed by local sound speed
REGULARIZE_MESH_FACE_ANGLE # Use maximum face angle as roundness criterion in mesh regularization
#--------------------------------------- Time integration options
TREE_BASED_TIMESTEPS # non-local timestep criterion (take 'signal speed' into account)
#--------------------------------------- Single/Double Precision
DOUBLEPRECISION=1 # Mode of double precision: not defined: single; 1: full double precision 2: mixed, 3: mixed, fewer single precisions; unless short of memory, use 1.
INPUT_IN_DOUBLEPRECISION # initial conditions are in double precision
#--------------------------------------- Output/Input options
HAVE_HDF5 # needed when HDF5 I/O support is desired; should this be standard?
#--------------------------------------- Testing and Debugging options
DEBUG # enables core-dumps, should this be standard?
#--------------------------------------- Output options
OUTPUT_BFIELD_GRADIENT # gradient estimates of B-field
\ No newline at end of file
""" @package ./examples/current_sheet_2d/check.py
Code that checks results of 2d current sheet problem
created by Rainer Weinberger, last modified 13.03.2019
"""
""" load libraries """
import sys ## system calls
import numpy as np ## load numpy
import h5py ## load h5py; needed to read snapshots
import matplotlib.pyplot as plt
createFigures = True
simulation_directory = str(sys.argv[1])
print("examples/current_sheet_2d/check.py: checking simulation output in directory " + simulation_directory)
FloatType = np.float64 # double precision: np.float64, for single use np.float32
## open initial conditiions to get parameters
try:
data = h5py.File(simulation_directory + "/IC.hdf5", "r")
except:
print("could not open initial conditions!")
exit(-1)
Boxsize = FloatType(data["Header"].attrs["BoxSize"])
NumberOfCells = np.int32(data["Header"].attrs["NumPart_Total"][0])
CellsPerDimension = np.sqrt(NumberOfCells) ## 2d sim
## parameters for initial state
density_0 = 1.0
velocity_radial_0 = -1.0 ## radial inflow velocity
pressure_0 = 1.0e-4
gamma = 5./3. ## note: this has to be consistent with the parameter settings for Arepo!
utherm_0 = pressure_0 / ( gamma - 1.0 ) / density_0
## maximum L1 error after one propagation; based on tests
DeltaMaxAllowed = 0.1 * (FloatType(CellsPerDimension) / 150.0)**-1
Time = []
MagneticEnergy = []
""" loop over all output files """
i_file = 0
while True:
""" try to read in snapshot """
directory = simulation_directory+"/output/"
filename = "snap_%03d.hdf5" % (i_file)
try:
data = h5py.File(directory+filename, "r")
except:
break
""" get simulation data """
B = np.array(data["PartType0"]["MagneticField"], dtype = FloatType)
B2 = B[:,0]*B[:,0] + \
B[:,1]*B[:,1] + \
B[:,2]*B[:,2]
Time.append( FloatType(data["Header"].attrs["Time"]) )
MagneticEnergy.append( np.sum(B2) / 8.0 / np.pi )
i_file += 1
Time = np.array(Time)
MagneticEnergy = np.array(MagneticEnergy)
if createFigures:
fig, ax = plt.subplots(1)
ax.plot(Time, MagneticEnergy/MagneticEnergy[0])
fig.savefig(simulation_directory+'/MagneticEnergy.pdf')
## if everything is ok
if np.min(MagneticEnergy/MagneticEnergy[0]) > 0.92:
sys.exit(0)
else:
sys.exit(1)
\ No newline at end of file
""" @package ./examples/current_sheet_2d/create.py
Code that creates 2d current sheet initial conditions
literature reference: Gardiner and Stone (2005), JCoPh.205..509G
created by Rainer Weinberger, last modified 13.03.2019 -- comments welcome
"""
""" load libraries """
import sys ## system calls
import numpy as np ## load numpy
import h5py ## load h5py; needed to write initial conditions in hdf5 format
simulation_directory = str(sys.argv[1])
print("examples/current_sheet_2d/create.py: creating ICs in directory " + simulation_directory)
""" initial condition parameters """
FilePath = simulation_directory + '/IC.hdf5'
FloatType = np.float64 # double precision: np.float64, for single use np.float32
IntType = np.int32
Boxsize = FloatType(2.0) # quadratic box
CellsPerDimension = IntType(256)
## parameters
density_0 = FloatType(1.0)
velocity_0 = FloatType(0.0) ## velocity boost
vpert = 0.1
pressure_0 = 0.1
gamma = FloatType(5.0/3.0)
gamma_minus_one = FloatType(gamma - 1.0)
b0 = FloatType(1.0)
""" set up grid """
NumberOfCells = CellsPerDimension*CellsPerDimension
dx = Boxsize / FloatType(CellsPerDimension)
pos_first, pos_last = 0.5 * dx, Boxsize - 0.5 * dx
Grid1d = np.linspace(pos_first, pos_last, CellsPerDimension, dtype=FloatType)
xx, yy = np.meshgrid(Grid1d, Grid1d)
Pos = np.zeros([NumberOfCells, 3], dtype=FloatType)
Pos[:,0] = xx.reshape(NumberOfCells)
Pos[:,1] = yy.reshape(NumberOfCells)
""" set up magnetohydrodynamical quantitites """
## mass insetad of density
Mass = np.full(NumberOfCells, density_0*dx*dx, dtype=FloatType)
## velocity
Velocity = np.zeros([NumberOfCells,3], dtype=FloatType)
Velocity[:,0] = velocity_0 + vpert * np.sin(np.pi * Pos[:,1])
Velocity[:,1] = 0.5 * velocity_0
## specific internal energy
Uthermal = np.full(NumberOfCells, (pressure_0/density_0/gamma_minus_one), dtype=FloatType)
## magnetic field strength
Bfield = np.zeros([NumberOfCells, 3], dtype=FloatType)
Bfield[:,1] = b0
i_reverse, = np.where( (Pos[:,0] > 0.5) & (Pos[:,0] < 1.5) )
Bfield[i_reverse, 1] *= -1.0
""" write *.hdf5 file; minimum number of fields required by Arepo """
IC = h5py.File(simulation_directory+'/IC.hdf5', 'w')
## create hdf5 groups
header = IC.create_group("Header")
part0 = IC.create_group("PartType0")
## header entries
NumPart = np.array([NumberOfCells, 0, 0, 0, 0, 0], dtype = IntType)
header.attrs.create("NumPart_ThisFile", NumPart)
header.attrs.create("NumPart_Total", NumPart)
header.attrs.create("NumPart_Total_HighWord", np.zeros(6, dtype = IntType) )
header.attrs.create("MassTable", np.zeros(6, dtype = IntType) )
header.attrs.create("Time", 0.0)
header.attrs.create("Redshift", 0.0)
header.attrs.create("BoxSize", Boxsize)
header.attrs.create("NumFilesPerSnapshot", 1)
header.attrs.create("Omega0", 0.0)
header.attrs.create("OmegaB", 0.0)
header.attrs.create("OmegaLambda", 0.0)
header.attrs.create("HubbleParam", 1.0)
header.attrs.create("Flag_Sfr", 0)
header.attrs.create("Flag_Cooling", 0)
header.attrs.create("Flag_StellarAge", 0)
header.attrs.create("Flag_Metals", 0)
header.attrs.create("Flag_Feedback", 0)
if Pos.dtype == np.float64:
header.attrs.create("Flag_DoublePrecision", 1)
else:
header.attrs.create("Flag_DoublePrecision", 0)
## copy datasets
part0.create_dataset("ParticleIDs", data = np.arange(1, NumberOfCells+1) )
part0.create_dataset("Coordinates", data = Pos)
part0.create_dataset("Masses", data = Mass)
part0.create_dataset("Velocities", data = Velocity)
part0.create_dataset("InternalEnergy", data = Uthermal)
part0.create_dataset("MagneticField", data = Bfield)
## close file
IC.close()
exit(0)
%% examples/current_sheet_2d.txt
% parameter file for 2d current sheet problem
InitCondFile IC
ICFormat 3
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
NumFilesWrittenInParallel 1
ResubmitOn 0
ResubmitCommand my-scriptfile
OutputListFilename ol
OutputListOn 0
CoolingOn 0
StarformationOn 0
Omega0 0.0
OmegaBaryon 0.0
OmegaLambda 0.0
HubbleParam 1.0
BoxSize 2.0
PeriodicBoundariesOn 1
ComovingIntegrationOn 0
MaxMemSize 2500
TimeOfFirstSnapshot 0.0
CpuTimeBetRestartFile 9000
TimeLimitCPU 90000
TimeBetStatistics 0.005
TimeBegin 0.0
TimeMax 4.0
TimeBetSnapshot 0.5
UnitVelocity_in_cm_per_s 1.0
UnitLength_in_cm 1.0
UnitMass_in_g 1.0
GravityConstantInternal 0.0
ErrTolIntAccuracy 0.1
ErrTolTheta 0.1
ErrTolForceAcc 0.1
MaxSizeTimestep 0.2
MinSizeTimestep 1e-5
CourantFac 0.3
LimitUBelowThisDensity 0.0
LimitUBelowCertainDensityToThisValue 0.0
DesNumNgb 64
MultipleDomains 2
TopNodeFactor 4
ActivePartFracForNewDomainDecomp 0.5
MaxNumNgbDeviation 2
TypeOfTimestepCriterion 1
TypeOfOpeningCriterion 1
GasSoftFactor 0.01
SofteningComovingType0 0.1
SofteningComovingType1 0.1
SofteningComovingType2 0.1
SofteningComovingType3 0.1
SofteningComovingType4 0.1
SofteningComovingType5 0.1
SofteningMaxPhysType0 0.1
SofteningMaxPhysType1 0.1
SofteningMaxPhysType2 0.1
SofteningMaxPhysType3 0.1
SofteningMaxPhysType4 0.1
SofteningMaxPhysType5 0.1
SofteningTypeOfPartType0 0
SofteningTypeOfPartType1 0
SofteningTypeOfPartType2 0
SofteningTypeOfPartType3 0
SofteningTypeOfPartType4 0
SofteningTypeOfPartType5 0
InitGasTemp 0.0
MinGasTemp 0.0
MinEgySpec 0.0
MinimumDensityOnStartUp 0.0
CellShapingSpeed 0.5
CellMaxAngleFactor 2.25
......@@ -9,6 +9,7 @@ created by Rainer Weinberger, last modified 09.03.2019
""" load libraries """
import sys # system calls
import os # operating system calls
import numpy as np # scientific computing package
import h5py # hdf5 format
from subprocess import call # execute shell commands
......@@ -29,32 +30,25 @@ data = np.array([outputTimes, ones]).T
np.savetxt(simulation_directory+"/output_list.txt",data, fmt="%g %1.f" )
""" copy treecool file to run directory """
call(['cp', './data/TREECOOL_ep', simulation_directory+'/TREECOOL_ep'])
""" create backgroundgrid ICs from SPH ICs """
## compile Arepo with ADDBACKGROUNDGRID
res = call(["make", "CONFIG=./examples/galaxy_merger_star_formation_3d/Config_ADDBACKGROUNDGRID.sh", \
"BUILD_DIR=./run/examples/galaxy_merger_star_formation_3d/build_ADDBACKGROUNDGRID", \
"EXEC=./run/examples/galaxy_merger_star_formation_3d/Arepo_ADDBACKGRUNDGRID"])
if res != 0:
sys.exit( np.int(res) )
## copy ICs to run directory
res = call(["cp", "./examples/galaxy_merger_star_formation_3d/ICs_1_1_merger_30_15_45_0_rmin10_start320_lowres.dat", \
"./run/examples/galaxy_merger_star_formation_3d/"])
res = call(["make", "CONFIG="+simulation_directory+"/Config_ADDBACKGROUNDGRID.sh", \
"BUILD_DIR="+simulation_directory+"/build_ADDBACKGROUNDGRID", \
"EXEC="+simulation_directory+"/Arepo_ADDBACKGRUNDGRID"])
if res != 0:
sys.exit( np.int(res) )
## execute Arepo with ADDBACKGROUNDGRID
res = call(["mpiexec", "-np", "1","./run/examples/galaxy_merger_star_formation_3d/Arepo_ADDBACKGRUNDGRID", "./examples/galaxy_merger_star_formation_3d/param_ADDBACKGROUNDGRID.txt"])
if res != 0:
sys.exit( np.int(res) )
## clean up
res = call(["make", "CONFIG=./examples/galaxy_merger_star_formation_3d/Config_ADDBACKGROUNDGRID.sh", "clean"])
if res != 0:
sys.exit( np.int(res) )
res = call(["rm", "./examples/galaxy_merger_star_formation_3d/param_ADDBACKGROUNDGRID.txt-usedvalues"])
cwd = os.getcwd()
os.chdir(simulation_directory)
res = call(["mpiexec", "-np", "1","./Arepo_ADDBACKGRUNDGRID", "./param_ADDBACKGROUNDGRID.txt"])
if res != 0:
sys.exit( np.int(res) )
os.chdir(cwd)
""" normal exit """
......
%---- Relevant files
InitCondFile run/examples/galaxy_merger_star_formation_3d/ICs_1_1_merger_30_15_45_0_rmin10_start320_lowres.dat-with-grid
OutputDir run/examples/galaxy_merger_star_formation_3d/output
InitCondFile ICs_1_1_merger_30_15_45_0_rmin10_start320_lowres.dat-with-grid
OutputDir output
SnapshotFileBase snap
OutputListFilename run/examples/galaxy_merger_star_formation_3d/output_list.txt
OutputListFilename output_list.txt
%---- File formats
ICFormat 3
......@@ -118,5 +118,5 @@ FactorEVP 573.0
TemperatureThresh 1e+06
FactorSN 0.1
TreecoolFile ./data/TREECOOL_ep
TreecoolFile TREECOOL_ep
%---- Relevant files
InitCondFile run/examples/galaxy_merger_star_formation_3d/ICs_1_1_merger_30_15_45_0_rmin10_start320_lowres.dat
OutputDir run/examples/galaxy_merger_star_formation_3d/output
InitCondFile ICs_1_1_merger_30_15_45_0_rmin10_start320_lowres.dat
OutputDir output
SnapshotFileBase snap
OutputListFilename run/examples/galaxy_merger_star_formation_3d/output_list.txt
OutputListFilename output_list.txt
%---- File formats
ICFormat 1
......
%% ./examples/gresho_2d/param.txt
% parameter file for 2d Gresho vortex problem
InitCondFile ./run/examples/gresho_2d/IC
InitCondFile IC
ICFormat 3
OutputDir ./run/examples/gresho_2d/output/
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
......
......@@ -7,11 +7,11 @@ CpuTimeBetRestartFile 9000
TimeLimitCPU 90000
%% initial conditions
InitCondFile ./run/examples/interacting_blastwaves_1d/IC
InitCondFile IC
ICFormat 3
%% output options
OutputDir ./run/examples/interacting_blastwaves_1d/output/
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
......
%---- Relevant files
InitCondFile run/examples/isolated_galaxy_collisionless_3d/snap_010
OutputDir run/examples/isolated_galaxy_collisionless_3d/output
InitCondFile snap_010
OutputDir output
SnapshotFileBase snap
OutputListFilename run/examples/isolated_galaxy_collisionless_3d/output_list.txt
OutputListFilename output_list.txt
%---- File formats
ICFormat 1
......
%% examples/mhd_shocktube_1d.txt
% parameter file for 1d mhd shocktube problem
InitCondFile ./run/examples/mhd_shocktube_1d/IC
ICFormat 3
InitCondFile IC
ICFormat 3
OutputDir ./run/examples/mhd_shocktube_1d/output/
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
......
%% examples/noh_2d/param.txt
% parameter file for 2d Noh problem
InitCondFile ./run/examples/noh_2d/IC
InitCondFile IC
ICFormat 3
OutputDir ./run/examples/noh_2d/output/
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
......
%% examples/noh_3d/param.txt
% parameter file for 3d Noh problem
InitCondFile ./run/examples/noh_3d/IC
InitCondFile IC
ICFormat 3
OutputDir ./run/examples/noh_3d/output/
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
......
%% ./examples/polytrope_1d_spherical/param.txt
% parameter file for 1d polytrope test problem
InitCondFile ./run/examples/polytrope_1d_spherical/IC
InitCondFile IC
ICFormat 3
OutputDir ./run/examples/polytrope_1d_spherical/output/
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
......
......@@ -7,11 +7,11 @@ CpuTimeBetRestartFile 9000
TimeLimitCPU 90000
%% initial conditions
InitCondFile ./run/examples/shocktube_1d/IC
InitCondFile IC
ICFormat 3
%% output options
OutputDir ./run/examples/shocktube_1d/output/
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
......
%% ./examples/wave_1d/param.txt
% parameter file for 1d wave propagation problem
InitCondFile ./run/examples/wave_1d/IC
InitCondFile IC
ICFormat 3
OutputDir ./run/examples/wave_1d/output/
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
......
%% ./examples/yee_2d/param.txt
% parameter file for 2d Yee vortex problem
InitCondFile ./run/examples/yee_2d/IC
InitCondFile IC
ICFormat 3
OutputDir ./run/examples/yee_2d/output/
OutputDir output
SnapshotFileBase snap
SnapFormat 3
NumFilesPerSnapshot 1
......
......@@ -23,6 +23,7 @@ TESTS+="polytrope_1d_spherical "
TESTS+="gresho_2d "
TESTS+="noh_2d "
TESTS+="yee_2d "
TESTS+="current_sheet_2d "
## available 3d examples
TESTS+="noh_3d "
......@@ -42,22 +43,19 @@ do
rm -rf ./run
## create run directory
mkdir ./run
mkdir ./run/examples
mkdir ${RUNDIR}
mkdir -p ${RUNDIR}
## copy Config and parameter file to run directory
cp ${DIR}/* ${RUNDIR}
## create ICs in run directory
echo ${DIR}
python ${DIR}/create.py ${RUNDIR}
python ${RUNDIR}/create.py ${RUNDIR}
((return_value=$?)) ## get return value
if [ $return_value != 0 ] ## check return value
then echo "ERROR: test.sh:\t" $DIR "\t python create.py failed!"
exit $return_value
fi
## copy Config and parameter file to run directory
cp ${DIR}/Config.sh ${RUNDIR}
cp ${DIR}/param.txt ${RUNDIR}