testSelectOutput.py 1.92 KB
Newer Older
lhausamm's avatar
lhausamm committed
1
###############################################################################
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# 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/>.
#
##############################################################################
lhausamm's avatar
lhausamm committed
20 21 22 23 24 25

# Check the output done with swift

import h5py

filename = "testSelectOutput_0000.hdf5"
26
log_filename = "select_output.log"
lhausamm's avatar
lhausamm committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

# Read the simulation data
sim = h5py.File(filename, "r")
part0 = sim["/PartType0"]

# check presence / absence fields
if "Velocities" in part0:
    raise Exception("`Velocities` present in HDF5 but should not be written")

if "Coordinates" not in part0:
    raise Exception("`Coordinates` not present in HDF5 but should be written")

if "Masses" not in part0:
    raise Exception("`Masses` not present in HDF5 but should be written")

42 43
if "Densities" not in part0:
    raise Exception("`Densities` not present in HDF5 but should be written")
lhausamm's avatar
lhausamm committed
44 45 46 47 48 49


# check error detection
with open(log_filename, "r") as f:
    data = f.read()

50 51
if "Default:Masses_Gas" not in data:
    raise Exception("Input error in `Default:Masses_Gas` not detected")
lhausamm's avatar
lhausamm committed
52

53
if "Default:Pot_Gas" not in data:
lhausamm's avatar
lhausamm committed
54
    raise Exception("Parameter name error not detected for `SelectOutput:Pot_Gas`")