Class WaterHammerPipe
java.lang.Object
neqsim.util.NamedBaseClass
neqsim.process.SimulationBaseClass
neqsim.process.equipment.ProcessEquipmentBaseClass
neqsim.process.equipment.TwoPortEquipment
neqsim.process.equipment.pipeline.Pipeline
neqsim.process.equipment.pipeline.WaterHammerPipe
- All Implemented Interfaces:
Serializable, Runnable, PipeLineInterface, ProcessEquipmentInterface, TwoPortInterface, SimulationInterface, NamedInterface
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumBoundary condition types. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate doubleprivate doubleprivate doubleprivate doubleprivate doubleprivate WaterHammerPipe.BoundaryTypeprivate doubleprivate doubleprivate double[]private double[]private doubleprivate doubleprivate doubleprivate doubleprivate static final doubleGravitational acceleration (m/s²).private double[]private double[]private booleanprivate double(package private) static org.apache.logging.log4j.Loggerprivate double[]private double[]private intprivate doubleprivate doubleprivate double[]private doubleprivate doubleprivate static final longprivate WaterHammerPipe.BoundaryTypeprivate doubleprivate doubleprivate doubleprivate double[]private doubleprivate doubleFields inherited from class Pipeline
equilibriumHeatTransfer, equilibriumMassTransfer, fileName, flowPattern, legHeights, legPositions, numberOfLegs, numberOfNodesInLeg, outerHeatTransferCoeffs, outerTemperature, pipe, pipeDiameters, pipelineMechanicalDesign, pipeWallRoughness, system, times, wallHeatTransferCoeffsFields inherited from class TwoPortEquipment
inStream, outStreamFields inherited from class ProcessEquipmentBaseClass
conditionAnalysisMessage, energyStream, hasController, isSolved, properties, reportFields inherited from class SimulationBaseClass
calcIdentifier, calculateSteadyState, timeFields inherited from class NamedBaseClass
name -
Constructor Summary
ConstructorsConstructorDescriptionWaterHammerPipe(String name) Constructor for WaterHammerPipe.WaterHammerPipe(String name, StreamInterface inStream) Constructor for WaterHammerPipe with inlet stream. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidApply downstream boundary condition.private voidApply upstream boundary condition.doubleCalculate the effective wave speed including pipe elasticity (Korteweg formula).private doublecalcFrictionFactor(double reynoldsNumber) Calculate friction factor using Haaland equation.doublecalcJoukowskyPressureSurge(double velocityChange) Calculate Joukowsky pressure surge for instantaneous velocity change.doublecalcJoukowskyPressureSurge(double velocityChange, String unit) Calculate Joukowsky pressure surge for instantaneous velocity change.doubleGet the current simulation time.doubleGet the pipe diameter.double[]Get the flow rate profile.double[]Get the piezometric head profile.doubleGet the pipe length.doubleGet the overall maximum pressure.doublegetMaxPressure(String unit) Get the overall maximum pressure in specified unit.double[]Get the maximum pressure envelope.doubleCalculate the maximum stable time step based on Courant condition.doubleGet the overall minimum pressure.doublegetMinPressure(String unit) Get the overall minimum pressure in specified unit.double[]Get the minimum pressure envelope.intGet the number of nodes.Get the pressure history at the outlet.double[]Get the pressure profile along the pipe.double[]getPressureProfile(String unit) Get the pressure profile along the pipe in specified unit.Get the time history.doubleGet the current valve opening.double[]Get the velocity profile along the pipe.doubleGet the wave round-trip time.doubleGet the calculated wave speed.private voidInitialize the simulation arrays and calculate initial conditions.voidreset()Reset the simulation to initial steady state.voidReset the pressure envelopes.voidIn this method all thermodynamic and unit operations will be calculated in a steady state calculation.voidrunTransient(double dt, UUID id) runTransientvoidsetCourantNumber(double cn) Set the Courant number for time step control.voidsetDiameter(double diameter) Set the pipe inner diameter.voidsetDiameter(double diameter, String unit) Set the pipe inner diameter with unit.voidSet the downstream boundary condition type.voidsetElevationChange(double elevation) Set the elevation change (outlet - inlet).voidsetLength(double length) Set the pipe length.voidSet the pipe length with unit.voidsetNumberOfNodes(int nodes) Set the number of computational nodes.voidsetPipeElasticModulus(double modulus) Set the pipe elastic modulus.voidsetRoughness(double roughness) Set the pipe wall roughness.voidSet the upstream boundary condition type.voidsetValveOpening(double opening) Set the valve opening fraction (0 = closed, 1 = fully open).voidsetWallThickness(double thickness) Set the pipe wall thickness.voidsetWaveSpeed(double speed) Override the automatically calculated wave speed.private voidUpdate outlet stream properties.Methods inherited from class Pipeline
displayResult, getCapacityDuty, getCapacityMax, getEntropyProduction, getMechanicalDesign, getOutletPressure, getPipe, getSuperficialVelocity, getTimes, initMechanicalDesign, setEquilibriumHeatTransfer, setEquilibriumMassTransfer, setHeightProfile, setInitialFlowPattern, setLegPositions, setNumberOfLegs, setNumberOfNodesInLeg, setOuterTemperatures, setOutputFileName, setPipeDiameters, setPipeOuterHeatTransferCoefficients, setPipeWallHeatTransferCoefficients, setPipeWallRoughness, setTimeSeries, toJson, toJsonMethods inherited from class TwoPortEquipment
getInletPressure, getInletStream, getInletTemperature, getMassBalance, getOutletPressure, getOutletStream, getOutletTemperature, setInletPressure, setInletStream, setInletTemperature, setOutletPressure, setOutletStream, setOutletTemperature, validateSetupMethods inherited from class ProcessEquipmentBaseClass
copy, equals, getConditionAnalysisMessage, getController, getEnergyStream, getExergyChange, getMassBalance, getMinimumFlow, getPressure, getPressure, getProperty, getReport_json, getResultTable, getSpecification, getTemperature, getTemperature, getThermoSystem, hashCode, isActive, isActive, isSetEnergyStream, reportResults, run_step, runConditionAnalysis, setController, setEnergyStream, setEnergyStream, setFlowValveController, setMinimumFlow, setPressure, setRegulatorOutSignal, setSpecification, setTemperature, solvedMethods inherited from class SimulationBaseClass
getCalculateSteadyState, getCalculationIdentifier, getTime, increaseTime, isRunInSteps, setCalculateSteadyState, setCalculationIdentifier, setRunInSteps, setTimeMethods inherited from class NamedBaseClass
getName, getTagName, setName, setTagNameMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface NamedInterface
getName, getTagName, setName, setTagNameMethods inherited from interface ProcessEquipmentInterface
getExergyChange, getFluid, getRestCapacity, needRecalculationMethods inherited from interface SimulationInterface
getCalculateSteadyState, getCalculationIdentifier, getTime, increaseTime, isRunInSteps, run, run_step, run_step, runTransient, setCalculateSteadyState, setCalculationIdentifier, setRunInSteps, setTime, solvedMethods inherited from interface TwoPortInterface
getInletPressure, getInletStream, getInletTemperature, getInStream, getOutletPressure, getOutletStream, getOutletTemperature, getOutStream, setInletPressure, setInletStream, setInletTemperature, setOutletPressure, setOutletStream, setOutletTemperature
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
logger
static org.apache.logging.log4j.Logger logger -
GRAVITY
private static final double GRAVITYGravitational 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 -
head
private double[] head -
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
-
timeHistory
-
upstreamBoundary
-
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
Constructor for WaterHammerPipe.- Parameters:
name- Equipment name
-
WaterHammerPipe
Constructor for WaterHammerPipe with inlet stream.- Parameters:
name- Equipment nameinStream- Inlet stream
-
-
Method Details
-
setLength
public void setLength(double length) Set the pipe length.- Parameters:
length- Length in meters
-
setLength
Set the pipe length with unit.- Parameters:
length- Length valueunit- Unit ("m", "km", "ft")
-
setDiameter
public void setDiameter(double diameter) Set the pipe inner diameter.- Parameters:
diameter- Diameter in meters
-
setDiameter
Set the pipe inner diameter with unit.- Parameters:
diameter- Diameter valueunit- 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
Set the upstream boundary condition type.- Parameters:
type- Boundary type
-
setDownstreamBoundary
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
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
In this method all thermodynamic and unit operations will be calculated in a steady state calculation.
- Specified by:
runin interfaceSimulationInterface- Overrides:
runin classPipeline- Parameters:
id- UUID
-
runTransient
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:
runTransientin interfaceSimulationInterface- Overrides:
runTransientin classPipeline- 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
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
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
Get the overall minimum pressure in specified unit.- Parameters:
unit- Unit ("Pa", "bar", "psi")- Returns:
- Minimum pressure
-
getPressureHistory
-
getTimeHistory
-
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.
-