Class PipingRouteBuilder

java.lang.Object
neqsim.process.equipment.pipeline.routing.PipingRouteBuilder
All Implemented Interfaces:
Serializable

public class PipingRouteBuilder extends Object implements Serializable
Builds a serial route-level piping hydraulics model from structured line-list data.

The builder stores route segments with from/to nodes, hydraulic diameter, straight length, optional wall thickness, roughness, elevation change, and K-value minor losses. Calling build(StreamInterface) creates a ProcessSystem containing the inlet stream and one PipeBeggsAndBrills unit per segment, wired in the same order as the line-list rows.

Minor losses are converted from resistance coefficient K to equivalent length ratio L/D using a configurable Darcy friction factor assumption. The default assumption is 0.02, a typical turbulent screening value.

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

    • serialVersionUID

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

      private static final double DEFAULT_MINOR_LOSS_FRICTION_FACTOR
      Default Darcy friction factor used for converting K values to L/D values.
      See Also:
    • segments

      private final List<PipingRouteBuilder.RouteSegment> segments
    • defaultPipeWallRoughnessMeters

      private double defaultPipeWallRoughnessMeters
    • defaultNumberOfIncrements

      private int defaultNumberOfIncrements
    • minorLossFrictionFactor

      private double minorLossFrictionFactor
    • defaultHeatTransferMode

      private PipeBeggsAndBrills.HeatTransferMode defaultHeatTransferMode
  • Constructor Details

    • PipingRouteBuilder

      public PipingRouteBuilder()
      Creates an empty piping route builder.
  • Method Details

    • addSegment

      public PipingRouteBuilder addSegment(String fromNode, String toNode, double length, String lengthUnit, double nominalDiameter, String diameterUnit)
      Adds one route segment and assigns a generated segment id such as S1.
      Parameters:
      fromNode - upstream node name from the line list
      toNode - downstream node name from the line list
      length - straight pipe length, must be positive
      lengthUnit - unit for length, for example m, km, ft
      nominalDiameter - hydraulic diameter used by the pipe model, must be positive
      diameterUnit - unit for nominalDiameter, for example m, mm, inch
      Returns:
      this builder for chaining
      Throws:
      IllegalArgumentException - if inputs are blank, non-positive, duplicated, or unsupported
    • addSegment

      public PipingRouteBuilder addSegment(String segmentId, String fromNode, String toNode, double length, String lengthUnit, double nominalDiameter, String diameterUnit)
      Adds one route segment with an explicit segment id.
      Parameters:
      segmentId - unique segment id, for example a line number or S1
      fromNode - upstream node name from the line list
      toNode - downstream node name from the line list
      length - straight pipe length, must be positive
      lengthUnit - unit for length, for example m, km, ft
      nominalDiameter - hydraulic diameter used by the pipe model, must be positive
      diameterUnit - unit for nominalDiameter, for example m, mm, inch
      Returns:
      this builder for chaining
      Throws:
      IllegalArgumentException - if inputs are blank, non-positive, duplicated, or unsupported
    • setSegmentWallThickness

      public PipingRouteBuilder setSegmentWallThickness(String segmentId, double wallThickness, String unit)
      Sets segment wall thickness metadata and pipe wall thickness on the generated pipe.
      Parameters:
      segmentId - segment id or fromNode->toNode route reference
      wallThickness - wall thickness, must be non-negative
      unit - unit for wallThickness, for example m, mm, inch
      Returns:
      this builder for chaining
      Throws:
      IllegalArgumentException - if the segment cannot be found or the value/unit is invalid
    • setSegmentElevationChange

      public PipingRouteBuilder setSegmentElevationChange(String segmentId, double elevationChange, String unit)
      Sets segment elevation change from inlet to outlet.
      Parameters:
      segmentId - segment id or fromNode->toNode route reference
      elevationChange - elevation change, positive for uphill and negative for downhill
      unit - unit for elevationChange, for example m, ft
      Returns:
      this builder for chaining
      Throws:
      IllegalArgumentException - if the segment cannot be found or the unit is invalid
    • setSegmentPipeWallRoughness

      public PipingRouteBuilder setSegmentPipeWallRoughness(String segmentId, double roughness, String unit)
      Sets segment pipe wall roughness.
      Parameters:
      segmentId - segment id or fromNode->toNode route reference
      roughness - roughness, must be non-negative
      unit - unit for roughness, for example m, mm, micrometer
      Returns:
      this builder for chaining
      Throws:
      IllegalArgumentException - if the segment cannot be found or the value/unit is invalid
    • addMinorLoss

      public PipingRouteBuilder addMinorLoss(String segmentId, String fittingType, double kValue)
      Adds one K-value minor loss to a segment.
      Parameters:
      segmentId - segment id or fromNode->toNode route reference
      fittingType - fitting, valve, strainer, bend, or equipment-loss description
      kValue - resistance coefficient K, must be non-negative
      Returns:
      this builder for chaining
      Throws:
      IllegalArgumentException - if the segment cannot be found or the K value is invalid
    • setDefaultPipeWallRoughness

      public PipingRouteBuilder setDefaultPipeWallRoughness(double roughness, String unit)
      Sets the default wall roughness used for segments without explicit roughness.
      Parameters:
      roughness - roughness, must be non-negative
      unit - unit for roughness, for example m, mm, micrometer
      Returns:
      this builder for chaining
      Throws:
      IllegalArgumentException - if the roughness or unit is invalid
    • setMinorLossFrictionFactor

      public PipingRouteBuilder setMinorLossFrictionFactor(double frictionFactor)
      Sets the Darcy friction factor assumption used to convert K values to equivalent L/D values.
      Parameters:
      frictionFactor - Darcy friction factor, must be positive
      Returns:
      this builder for chaining
      Throws:
      IllegalArgumentException - if the friction factor is not positive
    • setDefaultNumberOfIncrements

      public PipingRouteBuilder setDefaultNumberOfIncrements(int numberOfIncrements)
      Sets the number of increments used for each generated Beggs-and-Brill pipe.
      Parameters:
      numberOfIncrements - number of increments, must be positive
      Returns:
      this builder for chaining
      Throws:
      IllegalArgumentException - if numberOfIncrements is not positive
    • setDefaultHeatTransferMode

      public PipingRouteBuilder setDefaultHeatTransferMode(PipeBeggsAndBrills.HeatTransferMode heatTransferMode)
      Sets the heat transfer mode applied to each generated Beggs-and-Brill pipe.
      Parameters:
      heatTransferMode - heat transfer mode, must not be null
      Returns:
      this builder for chaining
      Throws:
      NullPointerException - if heatTransferMode is null
    • build

      public ProcessSystem build(StreamInterface inletStream)
      Builds a serial ProcessSystem route model from the stored route segments.
      Parameters:
      inletStream - inlet stream for the first pipe segment, must not be null
      Returns:
      process system containing the inlet stream and route pipe units
      Throws:
      IllegalArgumentException - if no route segments have been added
      NullPointerException - if inletStream is null
    • addToProcessSystem

      public StreamInterface addToProcessSystem(ProcessSystem process, StreamInterface inletStream)
      Adds the route pipe units to an existing ProcessSystem and returns the outlet stream of the final generated pipe.

      Use this method when a line-list route is only one section of a larger flowsheet. The caller is responsible for adding the upstream feed stream or upstream equipment to the process system. The returned stream can be passed directly to downstream equipment constructors.

      Parameters:
      process - process system that will receive the generated pipe units, must not be null
      inletStream - stream connected to the first generated pipe, must not be null
      Returns:
      outlet stream from the last generated pipe
      Throws:
      IllegalArgumentException - if no route segments have been added
      NullPointerException - if process or inletStream is null
    • addToProcessSystem

      public StreamInterface addToProcessSystem(ProcessSystem process, StreamInterface inletStream, String sourceEquipmentName, String sourcePortName)
      Adds the route pipe units to an existing ProcessSystem with explicit source-equipment metadata for the first route connection.

      This overload is useful when inletStream is the outlet stream of an upstream equipment item. The stream object performs the actual process wiring, while sourceEquipmentName and sourcePortName preserve the topology metadata in ProcessConnection records.

      Parameters:
      process - process system that will receive the generated pipe units, must not be null
      inletStream - stream connected to the first generated pipe, must not be null
      sourceEquipmentName - upstream equipment name for the first material connection
      sourcePortName - upstream port name for the first material connection
      Returns:
      outlet stream from the last generated pipe
      Throws:
      IllegalArgumentException - if no route segments have been added or source metadata is blank
      NullPointerException - if process or inletStream is null
    • getSegments

      public List<PipingRouteBuilder.RouteSegment> getSegments()
      Returns route segments in build order.
      Returns:
      unmodifiable list of route segments
    • getSegment

      public PipingRouteBuilder.RouteSegment getSegment(String segmentId)
      Gets a route segment by id or by fromNode->toNode reference.
      Parameters:
      segmentId - segment id or route reference
      Returns:
      matching route segment, or null if no segment matches
    • toJson

      public String toJson()
      Exports route geometry, assumptions, and minor losses as JSON.
      Returns:
      pretty-printed JSON route definition
    • createPipe

      private PipeBeggsAndBrills createPipe(PipingRouteBuilder.RouteSegment segment, StreamInterface inletStream)
      Creates and configures one Beggs-and-Brill pipe for a route segment.
      Parameters:
      segment - route segment definition
      inletStream - inlet stream connected to the pipe
      Returns:
      configured pipe unit
    • recalculateMinorLossEquivalentLengths

      private void recalculateMinorLossEquivalentLengths()
      Recalculates stored equivalent length ratios after the friction factor assumption changes.
    • findSegmentOrThrow

      private PipingRouteBuilder.RouteSegment findSegmentOrThrow(String segmentId)
      Finds a segment or throws an exception.
      Parameters:
      segmentId - segment id or route reference
      Returns:
      matching route segment
      Throws:
      IllegalArgumentException - if no segment matches
    • findSegment

      private PipingRouteBuilder.RouteSegment findSegment(String segmentId)
      Finds a segment by id or by route reference.
      Parameters:
      segmentId - segment id or route reference
      Returns:
      matching route segment, or null if none matches
    • toMap

      private Map<String,Object> toMap()
      Converts the builder state to a JSON-friendly map.
      Returns:
      map representation of the route
    • requireText

      private static String requireText(String value, String fieldName)
      Requires a non-empty text value.
      Parameters:
      value - text value to validate
      fieldName - field name used in error messages
      Returns:
      trimmed text value
      Throws:
      IllegalArgumentException - if the value is null or blank
    • requirePositive

      private static double requirePositive(double value, String fieldName)
      Requires a finite positive value.
      Parameters:
      value - numeric value to validate
      fieldName - field name used in error messages
      Returns:
      validated value
      Throws:
      IllegalArgumentException - if the value is not finite and positive
    • requireNonNegative

      private static double requireNonNegative(double value, String fieldName)
      Requires a finite non-negative value.
      Parameters:
      value - numeric value to validate
      fieldName - field name used in error messages
      Returns:
      validated value
      Throws:
      IllegalArgumentException - if the value is not finite or is negative
    • requireFinite

      private static double requireFinite(double value, String fieldName)
      Requires a finite value.
      Parameters:
      value - numeric value to validate
      fieldName - field name used in error messages
      Returns:
      validated value
      Throws:
      IllegalArgumentException - if the value is NaN or infinite
    • convertLengthToMeters

      private static double convertLengthToMeters(double value, String unit)
      Converts a length-like value to meters.
      Parameters:
      value - value to convert
      unit - source unit, for example m, km, mm, inch, ft, or micrometer
      Returns:
      value converted to meters
      Throws:
      IllegalArgumentException - if the unit is blank or unsupported