This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
HydDown is a Python package for calculating hydrogen (or other pure gas phase species) pressure vessel filling and discharge incorporating heat transfer effects. It models vessel response (pressure/temperature) to depressurization, pressurization, and external heat loads (e.g., fire scenarios).
Key capabilities:
- Single component two-phase modelling with separate gas/liquid heat transfer
- Multiple thermodynamic calculation methods (isothermal, isenthalpic, isentropic, energy balance)
- Various mass flow equations (orifice, control valve, relief valve, constant mass flow)
- Fire scenario modeling using Stefan-Boltzmann approach
- 1-D transient heat conduction for vessel walls
Python version support: 3.10 to 3.12
Install in development mode:
pip install -e .Install dependencies:
pip install -r requirements.txtMain script execution:
python scripts/hyddown_main.py input.ymlThe default input file is input.yml in the root directory. Example input files are located in src/hyddown/examples/.
Run the interactive web application:
streamlit run scripts/streamlit_app.pyAdditional streamlit apps:
streamlit_genapp.py- General purpose calculatorstreamlit_h2app.py- H2-specific calculatorstreamlit_sbapp.py- Stefan-Boltzmann fire scenariostreamlit_bdv_sbapp.py- Blowdown valve with Stefan-Boltzmann
Run all tests:
cd src/hyddown
pytestRun specific test:
cd src/hyddown
pytest test_all.py::test_orificeRun with coverage:
cd src/hyddown
pytest --cov=. --cov-report=xmlFormat code with Black:
black .Lint with flake8:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --ignore=F821
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statisticshdclass.py (~1900 lines) - Main calculation engine
HydDownclass: Central class managing problem definition, calculations, and results- Implements the time-stepping integration scheme (explicit Euler)
- Handles multiple calculation types: isothermal, isenthalpic, isentropic, energy balance
- Methods for thermodynamic property calculations (PH, UD problems) for both single component and multicomponent fluids
- Key methods:
run(): Main integration loop for mass/energy balancesstep(): Single time step calculationPHproblem(),UDproblem(): Thermodynamic state calculationsplot(): Results visualization
validator.py (~860 lines) - Input validation
- Uses Cerberus for schema-based validation
- Defines required/optional parameters for all calculation modes
- Validates vessel geometry, initial conditions, valve parameters, heat transfer settings
transport.py (~590 lines) - Heat and mass transfer calculations
- Dimensionless numbers: Grashof (Gr), Prandtl (Pr), Nusselt (Nu), Rayleigh (Ra)
- Heat transfer coefficient calculations for natural/forced convection
- Mass flow rate calculations for different valve types:
massflow_rate_mdot(): Constant mass flowmassflow_rate_orifice(): Orifice equationmassflow_rate_control_valve(): Control valve sizing equationmassflow_rate_relief_valve(): Relief valve (API 520/521)
- Boiling heat transfer (pool boiling, film boiling)
fire.py (~130 lines) - Fire heat load modeling
- Stefan-Boltzmann radiation + convection heat transfer
- Predefined fire scenarios:
pool_fire_api521(): 60 kW/m² incident heat fluxpool_fire_scandpower(): 100 kW/m² incident heat fluxjet_fire_api521(): 100 kW/m² incident heat fluxjet_fire_scandpower(): 250 kW/m² incident heat flux
thermesh.py (~430 lines) - 1-D transient heat conduction
- Adapted from https://github.com/wjbg/thermesh
- Finite element method for vessel wall temperature distribution
- Supports composite materials (multi-layer walls)
- Used for Type III/IV vessels with low thermal conductivity
materials.py (~340 lines) - Material property database
- Thermal properties for vessel materials (steel, aluminum, composites)
- Temperature-dependent properties where applicable
- Input: YAML file defines vessel geometry, initial conditions, calculation type, valve parameters, heat transfer settings
- Validation:
validator.pychecks input against schema - Initialization:
HydDown.__init__()reads input, initializes arrays, sets up thermodynamic backend - Time Integration:
HydDown.run()loops through time steps:- Calculate mass flow rate (from
transport.py) - Update mass inventory
- Calculate heat transfer (convection, radiation, fire)
- Solve thermodynamic state (P, T from H/U and ρ)
- Update vessel wall temperature (using
thermesh.pyif enabled)
- Calculate mass flow rate (from
- Output: Results stored in arrays (time, pressure, temperature, mass flow, etc.)
- Plotting:
HydDown.plot()generates matplotlib figures
HydDown relies heavily on CoolProp for fluid property calculations:
- Single component fluids: Uses HEOS (Helmholtz Equation of State) backend
- Multicomponent mixtures: Supported but slower, requires numerical optimization
- Property pairs: P-T, P-H, D-U, D-H, T-S, etc.
- CoolProp syntax:
PropsSI('Property', 'Input1', value1, 'Input2', value2, 'Fluid')
Important: Single component fluids prefixed with HEOS:: (e.g., HEOS::Hydrogen). Multicomponent mixtures use & separator (e.g., HEOS::Methane[0.9]&Ethane[0.1]).
The calculation.type parameter determines the thermodynamic path:
- isothermal: Constant temperature (very slow process with large heat reservoir)
- isenthalpic: Constant enthalpy, adiabatic expansion without work
- isentropic: Constant entropy, adiabatic expansion with PV work
- specified_U: Constant internal energy
- energybalance: Most general case, accounts for heat transfer and work
For energybalance, the heat transfer type is specified separately:
fixed_U: Fixed U-value (overall heat transfer coefficient)fixed_Q: Fixed heat inputspecified_h: Specified internal/external heat transfer coefficientsdetailed: Detailed heat transfer with wall conduction modelfire: Fire heat load from Stefan-Boltzmann equation
The valve.type parameter determines mass flow calculation:
- orifice: Compressible flow through orifice (requires
diameter,discharge_coef) - control_valve: Control valve sizing equation (requires
Cv,N9) - relief_valve: API 520/521 relief valve (requires
diameter,set_pressure) - mdot: Constant mass flow rate (requires
mass_flow)
Flow direction set by valve.flow: "discharge" or "filling"
YAML files define calculations with required sections:
vessel: # Geometry and material properties
initial: # Starting pressure, temperature, fluid
calculation: # Type, time step, end time
valve: # Flow type, size, coefficients
heat_transfer: # Heat transfer model (if energybalance)
validation: # Optional validation data for plottingSee src/hyddown/examples/ for complete examples of different calculation types.
Fluid properties are primarily accessed via CoolProp's PropsSI() function. For custom calculations, follow patterns in transport.py or hdclass.py:
from CoolProp.CoolProp import PropsSI
property = PropsSI('PROPERTY_NAME', 'T', T_value, 'P', P_value, species)Heat transfer correlations are in transport.py. To add new correlations:
- Define the correlation function (following existing Nu, h patterns)
- Update
HydDown.step()inhdclass.pyto call the new correlation - Add corresponding validation schema in
validator.py
Fire scenarios are defined in fire.py as functions returning heat flux [W/m²]:
- Create new function with Stefan-Boltzmann calculation
- Update
HydDown.read_input()to recognize the new scenario - Add schema validation for new parameters
Vessel volumes calculated using fluids.TANK() class. Supported types:
Flat-end: Simple cylinderASME F&D: Torispherical heads (ASME F&D standard)DIN: Torispherical heads (DIN standard)Semi-elliptical: Elliptical heads
Orientation: horizontal or vertical (affects heat transfer correlations)
- Explicit Euler method for mass balance integration
- Time step
dtmust be small enough for stability (typically 0.01-1 second) - No automatic time step adjustment - user controls via
calculation.time_step
Single component fluids are significantly faster because:
- CoolProp can directly calculate properties from any pair (P-H, D-U, etc.)
- No iterative optimization needed
Multicomponent fluids require:
- Numerical optimization (scipy.optimize.minimize) to find state
- Only T-P pairs directly supported by CoolProp
- Can be very slow for large systems
HydDown supports single component two-phase systems:
- Tracks liquid and gas temperatures separately
- Different wall temperatures for wetted/unwetted regions
- Uses quality (vapor fraction) to determine phase boundaries
- Implements pool boiling and film boiling correlations
Two modes:
- Simple: Uniform wall temperature (lumped capacitance)
- Detailed: 1-D transient conduction via
thermesh.py(for Type III/IV vessels)
Detailed mode requires:
- Wall material properties (thermal conductivity, heat capacity, density)
- Mesh discretization parameters
- Significantly slower but more accurate for composite materials
HydDown has been extensively validated against:
- Published experimental data (see Manual.md)
- External codes (GeoH2, commercial software)
- API 521 relief valve sizing methods
- Literature correlations for heat transfer
Validation data can be included in input YAML files for comparison plotting:
validation:
pressure:
time: [0, 10, 20, ...]
pres: [150, 120, 90, ...]
temperature:
gas_high:
time: [...]
temp: [...]- Manual: See
Manual.mdordocs/MANUAL.pdffor rigorous explanation of methods - Citation: Andreasen, A., (2021). JOSS, 6(66), 3695, https://doi.org/10.21105/joss.03695
- Streamlit demo: https://hyddown-jltaqjxtrsflh2famtkgsj.streamlit.app/
- CoolProp documentation: http://www.coolprop.org/
- Always store figures and plots as PDF