Class WaterHammerPipe

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

public class WaterHammerPipe extends Pipeline
Water hammer transient pipe model using Method of Characteristics (MOC).

This class simulates fast transient pressure waves (water hammer / hydraulic shock) in pipelines. Unlike the advection-based transient model in PipeBeggsAndBrills, this model propagates pressure waves at the speed of sound, enabling accurate simulation of:

  • Rapid valve closures (emergency shutdown)
  • Pump trips
  • Check valve slam
  • Pressure surge analysis for pipe stress design

The Method of Characteristics transforms the hyperbolic partial differential equations for one-dimensional transient pipe flow into ordinary differential equations along characteristic lines dx/dt = ±c (speed of sound).

Governing Equations:

  • Continuity: ∂H/∂t + (c²/gA) ∂Q/∂x = 0
  • Momentum: ∂Q/∂t + gA ∂H/∂x + f/(2DA) Q|Q| = 0

Example Usage:


// Create fluid
SystemInterface water = new SystemSrkEos(298.15, 10.0);
water.addComponent("water", 1.0);
water.setMixingRule("classic");

Stream feed = new Stream("feed", water);
feed.setFlowRate(100, "kg/hr");
feed.run();

// Create water hammer pipe
WaterHammerPipe pipe = new WaterHammerPipe("pipe", feed);
pipe.setLength(1000); // 1 km
pipe.setDiameter(0.2); // 200 mm
pipe.setNumberOfNodes(100); // Grid resolution
pipe.run(); // Initialize steady state

// Transient simulation with valve closure
pipe.setDownstreamBoundary(BoundaryType.VALVE);
UUID id = UUID.randomUUID();

for (int step = 0; step < 1000; step++) {
  double t = step * 0.001; // 1 ms time step

  // Close valve from t=0.1s to t=0.2s
  if (t >= 0.1 && t <= 0.2) {
    double tau = (t - 0.1) / 0.1;
    pipe.setValveOpening(1.0 - tau); // 100% -> 0%
  }

  pipe.runTransient(0.001, id);
}

// Get maximum pressure surge
double maxP = pipe.getMaxPressureEnvelope();

Version:
1.0
Author:
Even Solbraa
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • logger

      static org.apache.logging.log4j.Logger logger
    • GRAVITY

      private static final double GRAVITY
      Gravitational acceleration (m/s²).
      See Also:
    • length

      private double length
    • diameter

      private double diameter
    • wallThickness

      private double wallThickness
    • roughness

      private double roughness
    • elevationChange

      private double elevationChange
    • pipeElasticModulus

      private double pipeElasticModulus
    • pipePoissonsRatio

      private double pipePoissonsRatio
    • numberOfNodes

      private int numberOfNodes
    • waveSpeed

      private double waveSpeed
    • courantNumber

      private double courantNumber
    • currentTime

      private double currentTime
    • flow

      private double[] flow
    • headOld

      private double[] headOld
    • flowOld

      private double[] flowOld
    • pressureProfile

      private double[] pressureProfile
    • velocityProfile

      private double[] velocityProfile
    • maxPressureEnvelope

      private double[] maxPressureEnvelope
    • minPressureEnvelope

      private double[] minPressureEnvelope
    • pressureHistory

      private List<Double> pressureHistory
    • timeHistory

      private List<Double> timeHistory
    • upstreamBoundary

      private WaterHammerPipe.BoundaryType upstreamBoundary
    • downstreamBoundary

      private WaterHammerPipe.BoundaryType downstreamBoundary
    • upstreamHead

      private double upstreamHead
    • downstreamHead

      private double downstreamHead
    • valveOpening

      private double valveOpening
    • valveCv

      private double valveCv
    • fluidDensity

      private double fluidDensity
    • fluidViscosity

      private double fluidViscosity
    • fluidSoundSpeed

      private double fluidSoundSpeed
    • area

      private double area
    • segmentLength

      private double segmentLength
    • characteristicImpedance

      private double characteristicImpedance
    • frictionFactor

      private double frictionFactor
    • initialized

      private boolean initialized
  • Constructor Details

    • WaterHammerPipe

      public WaterHammerPipe(String name)
      Constructor for WaterHammerPipe.
      Parameters:
      name - Equipment name
    • WaterHammerPipe

      public WaterHammerPipe(String name, StreamInterface inStream)
      Constructor for WaterHammerPipe with inlet stream.
      Parameters:
      name - Equipment name
      inStream - Inlet stream
  • Method Details

    • setLength

      public void setLength(double length)
      Set the pipe length.
      Parameters:
      length - Length in meters
    • setLength

      public void setLength(double length, String unit)
      Set the pipe length with unit.
      Parameters:
      length - Length value
      unit - Unit ("m", "km", "ft")
    • setDiameter

      public void setDiameter(double diameter)
      Set the pipe inner diameter.
      Parameters:
      diameter - Diameter in meters
    • setDiameter

      public void setDiameter(double diameter, String unit)
      Set the pipe inner diameter with unit.
      Parameters:
      diameter - Diameter value
      unit - Unit ("m", "mm", "in")
    • setWallThickness

      public void setWallThickness(double thickness)
      Set the pipe wall thickness.
      Parameters:
      thickness - Wall thickness in meters
    • setRoughness

      public void setRoughness(double roughness)
      Set the pipe wall roughness.
      Parameters:
      roughness - Roughness in meters
    • setNumberOfNodes

      public void setNumberOfNodes(int nodes)
      Set the number of computational nodes.
      Parameters:
      nodes - Number of nodes (minimum 10)
    • setPipeElasticModulus

      public void setPipeElasticModulus(double modulus)
      Set the pipe elastic modulus.
      Parameters:
      modulus - Elastic modulus in Pa
    • setElevationChange

      public void setElevationChange(double elevation)
      Set the elevation change (outlet - inlet).
      Parameters:
      elevation - Elevation change in meters
    • setUpstreamBoundary

      public void setUpstreamBoundary(WaterHammerPipe.BoundaryType type)
      Set the upstream boundary condition type.
      Parameters:
      type - Boundary type
    • setDownstreamBoundary

      public void setDownstreamBoundary(WaterHammerPipe.BoundaryType type)
      Set the downstream boundary condition type.
      Parameters:
      type - Boundary type
    • setValveOpening

      public void setValveOpening(double opening)
      Set the valve opening fraction (0 = closed, 1 = fully open).
      Parameters:
      opening - Valve opening (0-1)
    • getValveOpening

      public double getValveOpening()
      Get the current valve opening.
      Returns:
      Valve opening (0-1)
    • setCourantNumber

      public void setCourantNumber(double cn)
      Set the Courant number for time step control.
      Parameters:
      cn - Courant number (typically 1.0 for stability)
    • setWaveSpeed

      public void setWaveSpeed(double speed)
      Override the automatically calculated wave speed.
      Parameters:
      speed - Wave speed in m/s
    • calcEffectiveWaveSpeed

      public double calcEffectiveWaveSpeed()
      Calculate the effective wave speed including pipe elasticity (Korteweg formula).
      Returns:
      Effective wave speed in m/s
    • calcJoukowskyPressureSurge

      public double calcJoukowskyPressureSurge(double velocityChange)
      Calculate Joukowsky pressure surge for instantaneous velocity change.
      Parameters:
      velocityChange - Change in velocity (m/s)
      Returns:
      Pressure surge (Pa)
    • calcJoukowskyPressureSurge

      public double calcJoukowskyPressureSurge(double velocityChange, String unit)
      Calculate Joukowsky pressure surge for instantaneous velocity change.
      Parameters:
      velocityChange - Change in velocity (m/s)
      unit - Output unit ("Pa", "bar", "psi")
      Returns:
      Pressure surge in specified unit
    • getMaxStableTimeStep

      public double getMaxStableTimeStep()
      Calculate the maximum stable time step based on Courant condition.
      Returns:
      Maximum stable time step in seconds
    • calcFrictionFactor

      private double calcFrictionFactor(double reynoldsNumber)
      Calculate friction factor using Haaland equation.
      Parameters:
      reynoldsNumber - Reynolds number
      Returns:
      Darcy friction factor
    • initialize

      private void initialize()
      Initialize the simulation arrays and calculate initial conditions.
    • run

      public void run(UUID id)

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

      Specified by:
      run in interface SimulationInterface
      Overrides:
      run in class Pipeline
      Parameters:
      id - UUID
    • 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.
      Specified by:
      runTransient in interface SimulationInterface
      Overrides:
      runTransient in class Pipeline
      Parameters:
      dt - Delta time [s]
      id - Calculation identifier
    • applyUpstreamBC

      private void applyUpstreamBC()
      Apply upstream boundary condition.
    • applyDownstreamBC

      private void applyDownstreamBC()
      Apply downstream boundary condition.
    • updateOutletStream

      private void updateOutletStream()
      Update outlet stream properties.
    • getPressureProfile

      public double[] getPressureProfile()
      Get the pressure profile along the pipe.
      Returns:
      Pressure profile in Pa
    • getPressureProfile

      public double[] getPressureProfile(String unit)
      Get the pressure profile along the pipe in specified unit.
      Parameters:
      unit - Unit ("Pa", "bar", "psi")
      Returns:
      Pressure profile
    • getVelocityProfile

      public double[] getVelocityProfile()
      Get the velocity profile along the pipe.
      Returns:
      Velocity profile in m/s
    • getHeadProfile

      public double[] getHeadProfile()
      Get the piezometric head profile.
      Returns:
      Head profile in meters
    • getFlowProfile

      public double[] getFlowProfile()
      Get the flow rate profile.
      Returns:
      Flow profile in m³/s
    • getMaxPressureEnvelope

      public double[] getMaxPressureEnvelope()
      Get the maximum pressure envelope.
      Returns:
      Maximum pressure at each node in Pa
    • getMinPressureEnvelope

      public double[] getMinPressureEnvelope()
      Get the minimum pressure envelope.
      Returns:
      Minimum pressure at each node in Pa
    • getMaxPressure

      public double getMaxPressure()
      Get the overall maximum pressure.
      Returns:
      Maximum pressure in Pa
    • getMaxPressure

      public double getMaxPressure(String unit)
      Get the overall maximum pressure in specified unit.
      Parameters:
      unit - Unit ("Pa", "bar", "psi")
      Returns:
      Maximum pressure
    • getMinPressure

      public double getMinPressure()
      Get the overall minimum pressure.
      Returns:
      Minimum pressure in Pa
    • getMinPressure

      public double getMinPressure(String unit)
      Get the overall minimum pressure in specified unit.
      Parameters:
      unit - Unit ("Pa", "bar", "psi")
      Returns:
      Minimum pressure
    • getPressureHistory

      public List<Double> getPressureHistory()
      Get the pressure history at the outlet.
      Returns:
      List of pressures in Pa
    • getTimeHistory

      public List<Double> getTimeHistory()
      Get the time history.
      Returns:
      List of times in seconds
    • getCurrentTime

      public double getCurrentTime()
      Get the current simulation time.
      Returns:
      Time in seconds
    • getWaveSpeed

      public double getWaveSpeed()
      Get the calculated wave speed.
      Returns:
      Wave speed in m/s
    • getLength

      public double getLength()
      Get the pipe length.
      Returns:
      Length in meters
    • getDiameter

      public double getDiameter()
      Get the pipe diameter.
      Returns:
      Diameter in meters
    • getNumberOfNodes

      public int getNumberOfNodes()
      Get the number of nodes.
      Returns:
      Number of computational nodes
    • getWaveRoundTripTime

      public double getWaveRoundTripTime()
      Get the wave round-trip time.
      Returns:
      Time for wave to travel L and back in seconds
    • reset

      public void reset()
      Reset the simulation to initial steady state.
    • resetEnvelopes

      public void resetEnvelopes()
      Reset the pressure envelopes.