Class VesselDepressurization

All Implemented Interfaces:
Serializable, Runnable, ProcessEquipmentInterface, SimulationInterface, NamedInterface

public class VesselDepressurization extends ProcessEquipmentBaseClass
VesselDepressurization models dynamic filling and depressurization of pressure vessels.

This class provides a comprehensive model for vessel dynamics including:

  • Isothermal process (constant temperature)
  • Isenthalpic/Adiabatic process (constant enthalpy)
  • Isentropic process (constant entropy, with PV work)
  • Isenergetic process (constant internal energy)
  • Energy balance (full heat transfer modeling)

The implementation follows the approach of HydDown for hydrogen vessel calculations but extends it to support multi-component mixtures using NeqSim's thermodynamic backend.

Reference: Andreasen, A. (2021). HydDown: A Python package for calculation of hydrogen (or other gas) pressure vessel filling and discharge. Journal of Open Source Software, 6(66), 3695.

Author:
ESOL
See Also:
  • HydDown - JOSS Paper

    Usage example:

         SystemInterface gas = new SystemSrkEos(298.0, 100.0);
         gas.addComponent("hydrogen", 1.0);
         gas.setMixingRule("classic");
    
         Stream feed = new Stream("feed", gas);
         feed.setFlowRate(0.0, "kg/hr"); // Closed vessel
         feed.run();
    
         VesselDepressurization vessel = new VesselDepressurization("HP Vessel", feed);
         vessel.setVolume(0.1); // 100 liters
         vessel.setCalculationType(CalculationType.ENERGY_BALANCE);
         vessel.setVesselProperties(0.01, 7800.0, 500.0, 45.0); // Steel vessel
         vessel.setOrificeDiameter(0.005); // 5mm orifice
         vessel.setBackPressure(1.0); // 1 bara
         vessel.run();
    
         // Transient simulation
         for (double t = 0; t <= 100; t += 0.5) {
           vessel.runTransient(0.5, UUID.randomUUID());
           System.out.println(vessel.getPressure() + " " + vessel.getTemperature());
         }
         
  • HydDown
  • Serialized Form
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization version UID.
      See Also:
    • logger

      private static final org.apache.logging.log4j.Logger logger
      Logger object for class.
    • volume

      private double volume
    • vesselLength

      private double vesselLength
    • vesselDiameter

      private double vesselDiameter
    • orientation

    • wallThickness

      private double wallThickness
    • wallDensity

      private double wallDensity
    • wallHeatCapacity

      private double wallHeatCapacity
    • wallThermalConductivity

      private double wallThermalConductivity
    • hasLiner

      private boolean hasLiner
    • linerThickness

      private double linerThickness
    • linerDensity

      private double linerDensity
    • linerHeatCapacity

      private double linerHeatCapacity
    • linerThermalConductivity

      private double linerThermalConductivity
    • backPressure

      private double backPressure
    • ambientTemperature

      private double ambientTemperature
    • externalHeatTransferCoeff

      private double externalHeatTransferCoeff
    • fireCase

      private boolean fireCase
    • fireHeatFlux

      private double fireHeatFlux
    • wetSurfaceFraction

      private double wetSurfaceFraction
    • orificeDiameter

      private double orificeDiameter
    • dischargeCoefficient

      private double dischargeCoefficient
    • valveOpeningTime

      private double valveOpeningTime
    • valveOpeningFraction

      private double valveOpeningFraction
    • calculationType

      private VesselDepressurization.CalculationType calculationType
    • heatTransferType

      private VesselDepressurization.HeatTransferType heatTransferType
    • flowDirection

      private VesselDepressurization.FlowDirection flowDirection
    • fixedU

      private double fixedU
    • fixedQ

      private double fixedQ
    • thermoSystem

      private SystemInterface thermoSystem
    • outletStream

      private StreamInterface outletStream
    • wallTemperature

      private double wallTemperature
    • wallModel

      private TransientWallHeatTransfer wallModel
    • currentTime

      private double currentTime
    • twoPhaseHeatTransfer

      private boolean twoPhaseHeatTransfer
    • initialLiquidLevel

      private double initialLiquidLevel
    • initialBeta

      private double initialBeta
    • gasWallTemperature

      private double gasWallTemperature
    • liquidWallTemperature

      private double liquidWallTemperature
    • gasWallModel

      private TransientWallHeatTransfer gasWallModel
    • liquidWallModel

      private TransientWallHeatTransfer liquidWallModel
    • liquidVolumeFraction

      private double liquidVolumeFraction
    • timeHistory

      private List<Double> timeHistory
    • pressureHistory

      private List<Double> pressureHistory
    • temperatureHistory

      private List<Double> temperatureHistory
    • massHistory

      private List<Double> massHistory
    • wallTemperatureHistory

      private List<Double> wallTemperatureHistory
    • massFlowHistory

      private List<Double> massFlowHistory
    • heatRateHistory

      private List<Double> heatRateHistory
    • gasWallTemperatureHistory

      private List<Double> gasWallTemperatureHistory
    • liquidWallTemperatureHistory

      private List<Double> liquidWallTemperatureHistory
    • liquidLevelHistory

      private List<Double> liquidLevelHistory
  • Constructor Details

    • VesselDepressurization

      public VesselDepressurization(String name)
      Constructor for VesselDepressurization.
      Parameters:
      name - Name of the vessel
    • VesselDepressurization

      public VesselDepressurization(String name, StreamInterface inletStream)
      Constructor for VesselDepressurization with inlet stream.
      Parameters:
      name - Name of the vessel
      inletStream - Initial fluid stream
  • Method Details

    • setInletStream

      public void setInletStream(StreamInterface inletStream)
      Sets the inlet stream and initializes the vessel.
      Parameters:
      inletStream - Inlet stream
    • initializeWallModel

      private void initializeWallModel()
      Initializes the transient wall heat transfer model.
    • setTwoPhaseHeatTransfer

      public void setTwoPhaseHeatTransfer(boolean enabled)
      Enables two-phase heat transfer modeling with separate gas and liquid wall zones.

      When enabled, the model tracks separate wall temperatures for the gas-wetted and liquid-wetted portions of the vessel. Heat transfer to the gas phase uses natural convection, while heat transfer to the liquid phase uses natural convection or nucleate boiling correlations.

      Parameters:
      enabled - true to enable two-phase heat transfer modeling
    • setInitialLiquidLevel

      public void setInitialLiquidLevel(double level)
      Sets the initial liquid level as a fraction of vessel height.

      For a vertical vessel, this is the fraction of the height filled with liquid. For a horizontal vessel, this is the fraction of the diameter filled with liquid (from bottom).

      Parameters:
      level - Liquid level fraction (0.0 = empty, 1.0 = full)
    • getLiquidLevel

      public double getLiquidLevel()
      Gets the current liquid level as a fraction of vessel height.
      Returns:
      Liquid level fraction (0-1)
    • getGasWallTemperature

      public double getGasWallTemperature()
      Gets the gas-wetted wall temperature.
      Returns:
      Gas wall temperature [K]
    • getLiquidWallTemperature

      public double getLiquidWallTemperature()
      Gets the liquid-wetted wall temperature.
      Returns:
      Liquid wall temperature [K]
    • getGasWallTemperatureHistory

      public List<Double> getGasWallTemperatureHistory()
      Gets the gas wall temperature history.
      Returns:
      List of gas wall temperatures [K]
    • getLiquidWallTemperatureHistory

      public List<Double> getLiquidWallTemperatureHistory()
      Gets the liquid wall temperature history.
      Returns:
      List of liquid wall temperatures [K]
    • getLiquidLevelHistory

      public List<Double> getLiquidLevelHistory()
      Gets the liquid level history.
      Returns:
      List of liquid level fractions (0-1)
    • calculateLiquidLevel

      private double calculateLiquidLevel()
      Calculates the current liquid level based on phase volumes.
      Returns:
      Liquid level fraction (0-1)
    • calculateHorizontalLiquidLevel

      private double calculateHorizontalLiquidLevel(double volumeFraction)
      Calculates liquid level for horizontal cylinder given volume fraction.
      Parameters:
      volumeFraction - Liquid volume fraction (0-1)
      Returns:
      Liquid level fraction (0-1) based on height
    • getWettedWallArea

      private double getWettedWallArea()
      Calculates the wetted (liquid contact) wall area.
      Returns:
      Wetted wall area [m²]
    • getUnwettedWallArea

      private double getUnwettedWallArea()
      Calculates the unwetted (gas contact) wall area.
      Returns:
      Unwetted wall area [m²]
    • setVolume

      public void setVolume(double volume)
      Sets the vessel volume.
      Parameters:
      volume - Volume [m³]
    • getVolume

      public double getVolume()
      Gets the vessel volume.
      Returns:
      Volume [m³]
    • setVesselGeometry

      public void setVesselGeometry(double length, double diameter, VesselDepressurization.VesselOrientation orientation)
      Sets the vessel geometry.
      Parameters:
      length - Vessel length [m]
      diameter - Vessel diameter [m]
      orientation - Vessel orientation
    • setVesselProperties

      public void setVesselProperties(double thickness, double density, double heatCapacity, double thermalConductivity)
      Sets the vessel wall properties.
      Parameters:
      thickness - Wall thickness [m]
      density - Wall material density [kg/m³]
      heatCapacity - Wall material heat capacity [J/(kg*K)]
      thermalConductivity - Wall thermal conductivity [W/(m*K)]
    • setVesselMaterial

      public void setVesselMaterial(double thickness, VesselDepressurization.VesselMaterial material)
      Sets the vessel wall properties using a preset material.

      Example:

      vessel.setVesselMaterial(0.015, VesselMaterial.CARBON_STEEL);
      
      Parameters:
      thickness - Wall thickness [m]
      material - Preset material from VesselDepressurization.VesselMaterial
    • setLinerProperties

      public void setLinerProperties(double thickness, double density, double heatCapacity, double thermalConductivity)
      Sets the liner properties for Type III/IV vessels.
      Parameters:
      thickness - Liner thickness [m]
      density - Liner density [kg/m³]
      heatCapacity - Liner heat capacity [J/(kg*K)]
      thermalConductivity - Liner thermal conductivity [W/(m*K)]
    • setLinerMaterial

      public void setLinerMaterial(double thickness, VesselDepressurization.LinerMaterial material)
      Sets the liner properties using a preset material.

      Example for Type IV vessel (CFRP shell with HDPE liner):

      vessel.setVesselMaterial(0.017, VesselMaterial.CFRP);
      vessel.setLinerMaterial(0.007, LinerMaterial.HDPE);
      
      Parameters:
      thickness - Liner thickness [m]
      material - Preset liner material from VesselDepressurization.LinerMaterial
    • setOrificeDiameter

      public void setOrificeDiameter(double diameter)
      Sets the orifice diameter for flow calculations.
      Parameters:
      diameter - Orifice diameter [m]
    • setDischargeCoefficient

      public void setDischargeCoefficient(double cd)
      Sets the discharge coefficient.
      Parameters:
      cd - Discharge coefficient (typically 0.6-0.65 for sharp-edge orifice)
    • setBackPressure

      public void setBackPressure(double pressure)
      Sets the back pressure for discharge calculations.
      Parameters:
      pressure - Back pressure [bara]
    • setAmbientTemperature

      public void setAmbientTemperature(double temperature)
      Sets the ambient temperature.
      Parameters:
      temperature - Ambient temperature [K]
    • setExternalHeatTransferCoefficient

      public void setExternalHeatTransferCoefficient(double h)
      Sets the external heat transfer coefficient.
      Parameters:
      h - External film coefficient [W/(m²*K)]
    • setFireCase

      public void setFireCase(boolean enable)
      Enables fire case simulation per API 521.

      In fire case, external heat flux is applied to the vessel surface, representing pool fire or jet fire scenarios. The heat input is calculated as: Q = fireHeatFlux * wetSurfaceFraction * wallArea

      Parameters:
      enable - True to enable fire case
    • setFireHeatFlux

      public void setFireHeatFlux(double heatFlux)
      Sets the fire heat flux per API 521.

      Typical values per API 521:

      • Pool fire (adequate drainage): 25,000 W/m² (25 kW/m²)
      • Pool fire (inadequate drainage): 43,200 W/m² (43.2 kW/m²)
      • Jet fire: 100,000+ W/m² (100+ kW/m²)
      Parameters:
      heatFlux - Heat flux [W/m²]
    • setFireHeatFlux

      public void setFireHeatFlux(double heatFlux, String unit)
      Sets the fire heat flux with unit.
      Parameters:
      heatFlux - Heat flux value
      unit - Unit ("W/m2", "kW/m2", "BTU/hr/ft2")
    • setWettedSurfaceFraction

      public void setWettedSurfaceFraction(double fraction)
      Sets the wetted surface fraction for fire relief calculations.

      This is the fraction of vessel surface that is wetted by liquid and can absorb fire heat. Per API 521, only wetted surface should be considered for relief valve sizing.

      Parameters:
      fraction - Wetted fraction (0-1), typically 0.25-0.5 for horizontal vessels
    • isFireCase

      public boolean isFireCase()
      Checks if fire case is enabled.
      Returns:
      True if fire case simulation is active
    • getFireHeatInput

      public double getFireHeatInput(String unit)
      Gets the current fire heat input rate.
      Parameters:
      unit - Unit ("W", "kW", "MW")
      Returns:
      Fire heat input rate
    • setValveOpeningTime

      public void setValveOpeningTime(double time)
      Sets the valve opening time for ESD valve dynamics.

      Models gradual valve opening at start of blowdown. The effective orifice area ramps from 0 to full over this time period.

      Parameters:
      time - Opening time [s], 0 for instant opening
    • setCalculationType

      public void setCalculationType(VesselDepressurization.CalculationType type)
      Sets the calculation type.
      Parameters:
      type - Calculation type
    • setHeatTransferType

      public void setHeatTransferType(VesselDepressurization.HeatTransferType type)
      Sets the heat transfer type.
      Parameters:
      type - Heat transfer type
    • setFlowDirection

      public void setFlowDirection(VesselDepressurization.FlowDirection direction)
      Sets the flow direction.
      Parameters:
      direction - Flow direction
    • setFixedU

      public void setFixedU(double u)
      Sets a fixed overall heat transfer coefficient.
      Parameters:
      u - U-value [W/(m²*K)]
    • setFixedQ

      public void setFixedQ(double q)
      Sets a fixed heat rate.
      Parameters:
      q - Heat rate [W] (positive = heat into vessel)
    • getPressure

      public double getPressure()
      Gets the current vessel pressure.
      Specified by:
      getPressure in interface ProcessEquipmentInterface
      Overrides:
      getPressure in class ProcessEquipmentBaseClass
      Returns:
      Pressure [Pa]
    • getPressure

      public double getPressure(String unit)
      Gets the current vessel pressure in specified unit.
      Specified by:
      getPressure in interface ProcessEquipmentInterface
      Overrides:
      getPressure in class ProcessEquipmentBaseClass
      Parameters:
      unit - Pressure unit ("Pa", "bar", "bara", "barg", "psi")
      Returns:
      Pressure in specified unit
    • getTemperature

      public double getTemperature()
      Gets the current fluid temperature.
      Specified by:
      getTemperature in interface ProcessEquipmentInterface
      Overrides:
      getTemperature in class ProcessEquipmentBaseClass
      Returns:
      Temperature [K]
    • getTemperature

      public double getTemperature(String unit)
      Gets the current fluid temperature in specified unit.
      Specified by:
      getTemperature in interface ProcessEquipmentInterface
      Overrides:
      getTemperature in class ProcessEquipmentBaseClass
      Parameters:
      unit - Temperature unit ("K", "C", "F")
      Returns:
      Temperature in specified unit
    • getWallTemperature

      public double getWallTemperature()
      Gets the current wall temperature.
      Returns:
      Wall temperature [K]
    • getMass

      public double getMass()
      Gets the current mass in the vessel.
      Returns:
      Mass [kg]
    • getDensity

      public double getDensity()
      Gets the current density.
      Returns:
      Density [kg/m³]
    • getOutletStream

      public StreamInterface getOutletStream()
      Gets the outlet stream.

      The outlet stream represents the gas leaving the vessel through the orifice. It can be connected to downstream equipment like a Flare or Mixer (flare header).

      Example integration with flare system:

      VesselDepressurization vessel = new VesselDepressurization("Tank", feed);
      vessel.run();
      
      // Connect to flare
      Flare flare = new Flare("Emergency Flare", vessel.getOutletStream());
      flare.setFlameHeight(50.0);
      
      // Or connect via flare header
      Mixer flareHeader = new Mixer("Flare Header");
      flareHeader.addStream(vessel.getOutletStream());
      Flare flare = new Flare("Flare", flareHeader.getOutletStream());
      
      Returns:
      Outlet stream with current discharge conditions
    • getDischargeRate

      public double getDischargeRate(String unit)
      Gets the current mass discharge rate.

      This is the instantaneous mass flow rate through the orifice, useful for flare capacity checks and header sizing.

      Parameters:
      unit - Flow rate unit ("kg/s", "kg/hr", "kg/min")
      Returns:
      Mass discharge rate in specified unit
    • getPeakDischargeRate

      public double getPeakDischargeRate(String unit)
      Gets the peak mass discharge rate from simulation history.

      This is critical for flare header sizing - the maximum flow rate determines the required capacity.

      Parameters:
      unit - Flow rate unit ("kg/s", "kg/hr", "kg/min")
      Returns:
      Peak mass discharge rate in specified unit
    • getTotalMassDischarged

      public double getTotalMassDischarged(String unit)
      Gets the total mass discharged from simulation history.
      Parameters:
      unit - Mass unit ("kg", "tonnes")
      Returns:
      Total mass discharged
    • getTimeToReachPressure

      public double getTimeToReachPressure(double targetPressure)
      Gets the time to reach a target pressure.

      Useful for blowdown time calculations per API 521.

      Parameters:
      targetPressure - Target pressure [bar]
      Returns:
      Time to reach target pressure [s], or -1 if not reached
    • getMinimumTemperatureReached

      public double getMinimumTemperatureReached(String unit)
      Gets the minimum temperature reached during blowdown.

      Critical for MDMT (Minimum Design Metal Temperature) assessment.

      Parameters:
      unit - Temperature unit ("K", "C")
      Returns:
      Minimum temperature reached
    • getMinimumWallTemperatureReached

      public double getMinimumWallTemperatureReached(String unit)
      Gets the minimum wall temperature reached during blowdown.

      Critical for MDMT assessment - wall temperature may be limiting for brittle fracture.

      Parameters:
      unit - Temperature unit ("K", "C")
      Returns:
      Minimum wall temperature reached
    • getTimeHistory

      public List<Double> getTimeHistory()
      Gets the time history.
      Returns:
      List of time values [s]
    • getPressureHistory

      public List<Double> getPressureHistory()
      Gets the pressure history.
      Returns:
      List of pressure values [Pa]
    • getTemperatureHistory

      public List<Double> getTemperatureHistory()
      Gets the temperature history.
      Returns:
      List of temperature values [K]
    • getMassHistory

      public List<Double> getMassHistory()
      Gets the mass history.
      Returns:
      List of mass values [kg]
    • clearHistory

      public void clearHistory()
      Clears the history arrays.
    • calculateMassFlowRate

      private double calculateMassFlowRate()
      Calculates the mass flow rate through the orifice.
      Returns:
      Mass flow rate [kg/s] (positive for discharge)
    • calculateInternalHeatTransferCoeff

      private double calculateInternalHeatTransferCoeff()
      Calculates the internal heat transfer coefficient.
      Returns:
      Internal film coefficient [W/(m²*K)]
    • calculateGasHeatTransferCoeff

      private double calculateGasHeatTransferCoeff()
      Calculates the gas phase heat transfer coefficient.
      Returns:
      Gas phase film coefficient [W/(m²*K)]
    • calculateLiquidHeatTransferCoeff

      private double calculateLiquidHeatTransferCoeff()
      Calculates the liquid phase heat transfer coefficient.

      Uses natural convection or nucleate boiling correlation depending on wall superheat.

      Returns:
      Liquid phase film coefficient [W/(m²*K)]
    • calculateHeatRate

      private double calculateHeatRate()
      Calculates the heat transfer rate to the fluid.
      Returns:
      Heat rate [W] (positive = heat into fluid)
    • calculateTwoPhaseHeatRate

      private double calculateTwoPhaseHeatRate()
      Calculates heat transfer rate for two-phase conditions.

      Computes separate heat transfer rates for the gas-wetted and liquid-wetted wall areas, using appropriate correlations for each phase.

      Returns:
      Total heat rate [W] (positive = heat into fluid)
    • getWallArea

      private double getWallArea()
      Gets the total inner wall surface area.
      Returns:
      Wall area [m²]
    • run

      public void run(UUID id)

      In this method all thermodynamic and unit operations will be calculated in a steady state calculation.

      Parameters:
      id - UUID
    • initializeWithLiquidLevel

      private void initializeWithLiquidLevel()
      Initializes the vessel with the specified initial liquid level.

      This method adjusts the moles in each phase to match the target liquid and gas volumes based on the specified initial liquid level fraction. Similar to the approach used in Separator.

    • calculateLiquidVolumeFromLevel

      private double calculateLiquidVolumeFromLevel(double levelFraction)
      Calculates the liquid volume corresponding to a given liquid level fraction.
      Parameters:
      levelFraction - Liquid level fraction (0-1)
      Returns:
      Liquid volume [m³]
    • runTransient

      public void runTransient(double dt, UUID id)

      runTransient

      This method calculates thermodynamic and unit operations using difference equations if available and calculateSteadyState is true. Use setCalculateSteadyState to set the parameter. Sets calc identifier UUID.
      Parameters:
      dt - Delta time [s]
      id - Calculation identifier
    • recordState

      private void recordState(double massFlowRate, double heatRate)
      Records the current state to history arrays.
      Parameters:
      massFlowRate - Current mass flow rate [kg/s]
      heatRate - Current heat rate [W]
    • updateOutletStream

      private void updateOutletStream()
      Updates the outlet stream with current conditions.
    • getVentTemperature

      public double getVentTemperature()
      Gets the vent temperature (temperature after expansion through orifice).
      Returns:
      Vent temperature [K]
    • getVaporFraction

      public double getVaporFraction()
      Gets the current vapor fraction.
      Returns:
      Vapor mole fraction (0-1)
    • getInternalEnergy

      public double getInternalEnergy()
      Gets the current internal energy.
      Returns:
      Internal energy [J]
    • getEnthalpy

      public double getEnthalpy()
      Gets the current enthalpy.
      Returns:
      Enthalpy [J]
    • getEntropy

      public double getEntropy()
      Gets the current entropy.
      Returns:
      Entropy [J/K]
    • getThermoSystem

      public SystemInterface getThermoSystem()
      Gets the thermoSystem.
      Specified by:
      getThermoSystem in interface ProcessEquipmentInterface
      Overrides:
      getThermoSystem in class ProcessEquipmentBaseClass
      Returns:
      The thermodynamic system
    • runSimulation

      public VesselDepressurization.SimulationResult runSimulation(double endTime, double dt)
      Runs a complete simulation and returns structured results.

      This is a convenience method that handles the time loop and data collection internally. It provides a cleaner API compared to manually calling runTransient(double, UUID) in a loop.

      Example:

      vessel.run();
      SimulationResult result = vessel.runSimulation(300.0, 0.5); // 5 min, 0.5s steps
      System.out.println("Min temp: " + result.getMinTemperature());
      System.out.println("Mass discharged: " + result.getMassDischarged() + " kg");
      
      Parameters:
      endTime - Total simulation time [s]
      dt - Time step [s]
      Returns:
      SimulationResult containing all history data
    • runSimulation

      public VesselDepressurization.SimulationResult runSimulation(double endTime, double dt, int recordInterval)
      Runs a complete simulation with configurable output interval.
      Parameters:
      endTime - Total simulation time [s]
      dt - Time step [s]
      recordInterval - Record data every N steps (1 = every step)
      Returns:
      SimulationResult containing history data
    • validate

      public void validate()
      Validates the vessel configuration and throws exceptions for invalid setups.

      Call this method before running a simulation to catch common configuration errors:

      • Back pressure higher than initial pressure
      • Unreasonably large orifice compared to vessel
      • Invalid liquid level settings
      • Missing heat transfer configuration for ENERGY_BALANCE mode
      Throws:
      IllegalStateException - if configuration is invalid
    • validateWithWarnings

      public List<String> validateWithWarnings()
      Validates configuration and returns warnings without throwing exceptions.
      Returns:
      List of warning messages (empty if no issues)
    • createTwoPhaseFluid

      public static SystemInterface createTwoPhaseFluid(String componentName, double temperature, double vaporFraction)
      Creates a two-phase pure component system at its saturation conditions.

      This is a convenience method that handles the bubble point calculation and phase setup automatically. For pure components, a simple TPflash won't produce two phases - you need to be exactly at saturation and explicitly set the phase fraction.

      Example:

      // Create CO2 at 250K with 60% vapor, 40% liquid
      SystemInterface co2 = VesselDepressurization.createTwoPhaseFluid("CO2", 250.0, 0.6);
      Stream feed = new Stream("feed", co2);
      
      Parameters:
      componentName - Component name (e.g., "CO2", "propane", "methane")
      temperature - Temperature [K]
      vaporFraction - Desired vapor mole fraction (0 = all liquid, 1 = all vapor)
      Returns:
      Configured two-phase thermodynamic system
    • createTwoPhaseFluidAtPressure

      public static SystemInterface createTwoPhaseFluidAtPressure(String componentName, double pressure, double vaporFraction)
      Creates a two-phase pure component system at specified pressure.

      If the specified pressure corresponds to saturation conditions, two phases will form. The temperature will be the saturation temperature at the given pressure.

      Parameters:
      componentName - Component name
      pressure - Pressure [bar]
      vaporFraction - Desired vapor mole fraction (0 = all liquid, 1 = all vapor)
      Returns:
      Configured two-phase thermodynamic system
    • exportToCSV

      public String exportToCSV()
      Exports transient simulation results to CSV format.

      The CSV includes time, pressure, temperature, mass, wall temperature, mass flow rate, and heat rate. This can be used for post-processing in Excel, Python pandas, or other tools.

      Returns:
      CSV formatted string with header row
    • exportToJSON

      public String exportToJSON()
      Exports transient results to JSON format.
      Returns:
      JSON formatted string
    • calculateRequiredOrificeDiameter

      public double calculateRequiredOrificeDiameter(double targetTime, double pressureReduction)
      Calculates required orifice diameter to meet API 521 blowdown time requirement.

      API 521 requires depressurization to 50% of initial pressure (or 6.9 barg, whichever is lower) within 15 minutes for fire case.

      Parameters:
      targetTime - Target blowdown time [s], typically 900s (15 min)
      pressureReduction - Fraction of pressure to reduce (0.5 = 50%)
      Returns:
      Required orifice diameter [m]
    • runOrificeSensitivity

      public double[] runOrificeSensitivity(double[] orificeSizes, double targetPressure)
      Runs sensitivity analysis on orifice size.

      Calculates blowdown time for a range of orifice diameters. Useful for selecting optimal orifice size considering multiple constraints.

      Parameters:
      orificeSizes - Array of orifice diameters to test [m]
      targetPressure - Target pressure [bar]
      Returns:
      Array of blowdown times [s] for each orifice size
    • hasLiquidRainout

      public boolean hasLiquidRainout()
      Checks for liquid rainout conditions in the outlet stream.

      Liquid rainout can occur when two-phase flow exits the vessel during depressurization. This can cause problems in flare headers (liquid accumulation) and at the flare tip (unstable burning).

      Returns:
      True if outlet stream contains liquid phase
    • getOutletLiquidFraction

      public double getOutletLiquidFraction()
      Gets the liquid mass fraction in the outlet stream.
      Returns:
      Liquid mass fraction (0-1), 0 if all vapor
    • getPeakOutletLiquidFraction

      public double getPeakOutletLiquidFraction()
      Gets the peak liquid fraction observed during blowdown.

      This indicates the worst-case liquid loading on the flare header. Values above 0.1 (10%) may require liquid knockout facilities.

      Returns:
      Peak liquid mass fraction in outlet
    • getFlareHeaderVelocity

      public double getFlareHeaderVelocity(double headerDiameter, String unit)
      Estimates flare header velocity.

      Typical design limits:

      • Flare headers: 0.3-0.6 Mach (approximately 100-200 m/s)
      • Relief valve outlets: 0.5 Mach max
      Parameters:
      headerDiameter - Flare header internal diameter [m]
      unit - Velocity unit ("m/s", "ft/s")
      Returns:
      Gas velocity in header at current flow rate
    • getFlareHeaderMach

      public double getFlareHeaderMach(double headerDiameter)
      Estimates Mach number in flare header.
      Parameters:
      headerDiameter - Flare header internal diameter [m]
      Returns:
      Mach number
    • getHydrateFormationTemperature

      public double getHydrateFormationTemperature()
      Calculates hydrate formation temperature at current vessel conditions.

      Hydrate formation during depressurization can occur when temperature drops below the hydrate equilibrium temperature. This can cause flow restrictions in blowdown lines and safety hazards.

      Returns:
      Hydrate formation temperature [K], or -1 if calculation fails or no hydrate formers
    • getHydrateFormationTemperature

      public double getHydrateFormationTemperature(String unit)
      Calculates hydrate formation temperature at current conditions with unit conversion.
      Parameters:
      unit - Temperature unit ("K", "C")
      Returns:
      Hydrate formation temperature in specified unit
    • hasHydrateRisk

      public boolean hasHydrateRisk()
      Checks if current vessel temperature is below hydrate formation temperature.
      Returns:
      True if hydrate formation risk exists (T_vessel < T_hydrate)
    • getHydrateSubcooling

      public double getHydrateSubcooling(String unit)
      Gets the hydrate subcooling (margin below hydrate temperature).

      Positive values indicate hydrate risk. Negative values indicate safety margin.

      Parameters:
      unit - Temperature unit ("K", "C")
      Returns:
      Subcooling = T_hydrate - T_vessel
    • getMaxHydrateSubcoolingDuringBlowdown

      public double getMaxHydrateSubcoolingDuringBlowdown()
      Gets the minimum hydrate subcooling (maximum risk) observed during blowdown history.

      Tracks the point where temperature was furthest below hydrate curve during the entire depressurization.

      Returns:
      Maximum subcooling observed [K or C]
    • getCO2FreezingTemperature

      public double getCO2FreezingTemperature()
      Gets the CO2 freezing (dry ice) temperature at current pressure.

      CO2 triple point is at 5.18 bar, -56.6°C (216.55 K). Below this pressure, CO2 sublimates directly from solid to vapor. At higher pressures, the solid-liquid melting line applies.

      Key points on CO2 phase diagram:

      • Sublimation at 1 bar: -78.5°C (194.7 K)
      • Triple point: 5.18 bar, -56.6°C (216.55 K)
      • Melting at 100 bar: approx -55°C (218 K)
      • Melting at 500 bar: approx -45°C (228 K)
      The CO2 melting curve has a very small slope (~0.02 K/bar).
      Returns:
      CO2 freezing temperature [K], or -1 if no CO2 in system
    • getCO2FreezingTemperature

      public double getCO2FreezingTemperature(String unit)
      Gets the CO2 freezing temperature with unit conversion.
      Parameters:
      unit - Temperature unit ("K", "C")
      Returns:
      CO2 freezing temperature
    • hasCO2FreezingRisk

      public boolean hasCO2FreezingRisk()
      Checks if current temperature is below CO2 freezing point.
      Returns:
      True if CO2 freezing (dry ice) risk exists
    • getCO2FreezingSubcooling

      public double getCO2FreezingSubcooling()
      Gets the CO2 freezing subcooling (margin below freezing point).
      Returns:
      Subcooling [K] = T_freeze - T_vessel (positive = freezing risk)
    • assessFlowAssuranceRisks

      public Map<String,String> assessFlowAssuranceRisks()
      Comprehensive flow assurance risk assessment during blowdown.

      Returns a summary of all flow assurance risks including:

      • Hydrate formation risk
      • CO2 freezing (dry ice) risk
      • MDMT (minimum design metal temperature) concerns
      • Liquid rainout in flare header
      Returns:
      Map of risk assessments with descriptions