Class Recycle

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

public class Recycle extends ProcessEquipmentBaseClass implements MixerInterface
Recycle class for handling tear streams in process simulations.

This class implements convergence acceleration methods for recycle calculations, including direct substitution, Wegstein acceleration, and Broyden's method.

Version:
$Id: $Id
Author:
Even Solbraa
See Also:
  • Field Details

    • serialVersionUID

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

      static org.apache.logging.log4j.Logger logger
      Logger object for class.
    • streams

      protected ArrayList<StreamInterface> streams
    • downstreamProperty

      private ArrayList<String> downstreamProperty
    • numberOfInputStreams

      protected int numberOfInputStreams
    • mixedStream

      protected StreamInterface mixedStream
    • lastIterationStream

      StreamInterface lastIterationStream
    • outletStream

      private StreamInterface outletStream
    • priority

      private int priority
    • firstTime

      boolean firstTime
    • iterations

      int iterations
    • maxIterations

      int maxIterations
    • errorComposition

      private double errorComposition
    • errorFlow

      private double errorFlow
    • errorTemperature

      private double errorTemperature
    • errorPressure

      private double errorPressure
    • flowTolerance

      private double flowTolerance
    • compositionTolerance

      private double compositionTolerance
    • temperatureTolerance

      private double temperatureTolerance
    • pressureTolerance

      private double pressureTolerance
    • minimumFlow

      private double minimumFlow
    • accelerationMethod

      private AccelerationMethod accelerationMethod
    • wegsteinQMin

      private double wegsteinQMin
      Minimum bound for Wegstein q-factor to prevent divergence.
    • wegsteinQMax

      private double wegsteinQMax
      Maximum bound for Wegstein q-factor to prevent divergence.
    • wegsteinDelayIterations

      private int wegsteinDelayIterations
      Delay iterations before applying Wegstein (allows system to stabilize).
    • previousInputValues

      private double[] previousInputValues
      Previous iteration input values for Wegstein slope calculation.
    • previousOutputValues

      private double[] previousOutputValues
      Previous iteration output values for Wegstein slope calculation.
    • wegsteinQFactors

      private double[] wegsteinQFactors
      Current Wegstein q-factor values per variable.
    • broydenAccelerator

      private transient BroydenAccelerator broydenAccelerator
      Broyden accelerator instance for multi-variable acceleration.
  • Constructor Details

    • Recycle

      public Recycle(String name)

      Constructor for Recycle.

      Parameters:
      name - a String object
  • Method Details

    • setCompositionTolerance

      public void setCompositionTolerance(double compositionTolerance)

      Setter for the field compositionTolerance.

      Parameters:
      compositionTolerance - a double
    • getCompositionTolerance

      public double getCompositionTolerance()

      Getter for the field compositionTolerance.

      Returns:
      a double
    • setTemperatureTolerance

      public void setTemperatureTolerance(double temperatureTolerance)

      Setter for the field temperatureTolerance.

      Parameters:
      temperatureTolerance - a double in % error
    • getTemperatureTolerance

      public double getTemperatureTolerance()

      Getter for the field temperatureTolerance.

      Returns:
      a double
    • setFlowTolerance

      public void setFlowTolerance(double flowTolerance)

      Setter for the field flowTolerance.

      Parameters:
      flowTolerance - a double
    • getFlowTolerance

      public double getFlowTolerance()

      Getter for the field flowTolerance.

      Returns:
      a double
    • resetIterations

      public void resetIterations()

      resetIterations.

    • getIterations

      public int getIterations()
      Gets the current iteration count.
      Returns:
      number of iterations performed since last reset
    • getThermoSystem

      public SystemInterface getThermoSystem()

      getThermoSystem.

      Specified by:
      getThermoSystem in interface MixerInterface
      Specified by:
      getThermoSystem in interface ProcessEquipmentInterface
      Overrides:
      getThermoSystem in class ProcessEquipmentBaseClass
      Returns:
      a SystemInterface object
    • setDownstreamProperty

      public void setDownstreamProperty(ArrayList<String> property)

      Setter for the field downstreamProperty.

      Parameters:
      property - a ArrayList object
    • setDownstreamProperty

      public void setDownstreamProperty(String property)

      Setter for the field downstreamProperty.

      Parameters:
      property - a String object
    • replaceStream

      public void replaceStream(int i, StreamInterface newStream)

      replaceStream.

      Specified by:
      replaceStream in interface MixerInterface
      Parameters:
      i - a int
      newStream - a StreamInterface object
    • addStream

      public void addStream(StreamInterface newStream)

      addStream.

      Specified by:
      addStream in interface MixerInterface
      Parameters:
      newStream - a StreamInterface object
    • getStream

      public StreamInterface getStream(int i)

      getStream.

      Parameters:
      i - a int
      Returns:
      a StreamInterface object
    • mixStream

      public void mixStream()

      mixStream.

    • guessTemperature

      public double guessTemperature()

      guessTemperature.

      Returns:
      a double
    • calcMixStreamEnthalpy

      public double calcMixStreamEnthalpy()

      calcMixStreamEnthalpy.

      Returns:
      a double
    • getOutStream

      @Deprecated public StreamInterface getOutStream()
      Deprecated.

      Getter for outlet stream object.

      Specified by:
      getOutStream in interface MixerInterface
      Returns:
      a StreamInterface object
    • initiateDownstreamProperties

      public void initiateDownstreamProperties(StreamInterface outstream)

      initiateDownstreamProperties.

      Parameters:
      outstream - a StreamInterface object
    • setDownstreamProperties

      public void setDownstreamProperties()

      setDownstreamProperties.

    • 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
      Parameters:
      id - UUID
    • flowBalanceCheck

      public double flowBalanceCheck()

      massBalanceCheck.

      Returns:
      a double
    • compositionBalanceCheck

      public double compositionBalanceCheck()

      compositionBalanceCheck.

      Returns:
      a double
    • temperatureBalanceCheck

      public double temperatureBalanceCheck()

      temperatureBalanceCheck.

      Returns:
      a double
    • pressureBalanceCheck

      public double pressureBalanceCheck()

      pressureBalanceCheck.

      Returns:
      a double
    • displayResult

      public void displayResult()

      displayResult.

      Specified by:
      displayResult in interface ProcessEquipmentInterface
      Overrides:
      displayResult in class ProcessEquipmentBaseClass
    • setPressure

      public void setPressure(double pres)

      Setter for the field pressure.

      Specified by:
      setPressure in interface ProcessEquipmentInterface
      Overrides:
      setPressure in class ProcessEquipmentBaseClass
      Parameters:
      pres - a double
    • setTemperature

      public void setTemperature(double temp)

      Setter for the field temperature.

      Specified by:
      setTemperature in interface ProcessEquipmentInterface
      Overrides:
      setTemperature in class ProcessEquipmentBaseClass
      Parameters:
      temp - Temperature in Kelvin
    • setTolerance

      public void setTolerance(double tolerance)

      Setter for the tolerance fields.

      Set tolerances to tolerance input.
      Parameters:
      tolerance - the tolerance to set
    • getAccelerationMethod

      public AccelerationMethod getAccelerationMethod()
      Gets the current acceleration method used for convergence.
      Returns:
      the acceleration method
    • setAccelerationMethod

      public void setAccelerationMethod(AccelerationMethod method)
      Sets the acceleration method for convergence.
      Parameters:
      method - the acceleration method to use
    • getWegsteinQMin

      public double getWegsteinQMin()
      Gets the minimum bound for Wegstein q-factor.
      Returns:
      the minimum q-factor
    • setWegsteinQMin

      public void setWegsteinQMin(double qMin)
      Sets the minimum bound for Wegstein q-factor. Default is -5.0. More negative values allow stronger acceleration but risk instability.
      Parameters:
      qMin - the minimum q-factor
    • getWegsteinQMax

      public double getWegsteinQMax()
      Gets the maximum bound for Wegstein q-factor.
      Returns:
      the maximum q-factor
    • setWegsteinQMax

      public void setWegsteinQMax(double qMax)
      Sets the maximum bound for Wegstein q-factor. Default is 0.0 (no acceleration beyond direct substitution). Positive values can help with oscillating systems.
      Parameters:
      qMax - the maximum q-factor
    • getWegsteinDelayIterations

      public int getWegsteinDelayIterations()
      Gets the number of delay iterations before Wegstein acceleration is applied.
      Returns:
      the delay iterations
    • setWegsteinDelayIterations

      public void setWegsteinDelayIterations(int delayIterations)
      Sets the number of delay iterations before Wegstein acceleration is applied. This allows the system to stabilize before acceleration. Default is 2.
      Parameters:
      delayIterations - number of iterations to delay
    • getWegsteinQFactors

      public double[] getWegsteinQFactors()
      Gets the current Wegstein q-factors for each variable.
      Returns:
      array of q-factors, or null if not yet calculated
    • resetAccelerationState

      public void resetAccelerationState()
      Resets the acceleration state for a new convergence cycle.
    • getBroydenAccelerator

      public BroydenAccelerator getBroydenAccelerator()
      Gets the Broyden accelerator instance, creating one if needed.
      Returns:
      the Broyden accelerator
    • extractStreamValues

      private double[] extractStreamValues(StreamInterface stream)
      Extracts the current tear stream values as an array. The array contains: [temperature, pressure, total_flow, mole_fractions...]
      Parameters:
      stream - the stream to extract values from
      Returns:
      array of stream property values
    • applyWegsteinAcceleration

      private double[] applyWegsteinAcceleration(double[] currentInput, double[] currentOutput)
      Applies Wegstein acceleration to calculate accelerated values.

      The Wegstein method uses the formula: x_{n+1} = q * g(x_n) + (1-q) * x_n where q = s / (s - 1) and s is the slope estimate.

      The q-factor is bounded to prevent divergence: - q between qMin and qMax (typically -5 to 0) - q = 0 corresponds to direct substitution - Negative q provides acceleration for monotonic convergence

      Parameters:
      currentInput - the input values for current iteration (x_n)
      currentOutput - the output values from current iteration (g(x_n))
      Returns:
      accelerated values for next iteration input
    • applyStreamValues

      private void applyStreamValues(double[] values)
      Applies accelerated values to the mixed stream.
      Parameters:
      values - array containing [temperature, pressure, flow, mole_fractions...]
    • applyWegsteinToStream

      private void applyWegsteinToStream()
      Applies Wegstein acceleration to the mixed stream using previous iteration data. This method is called during run() when Wegstein acceleration is enabled.
    • applyBroydenToStream

      private void applyBroydenToStream()
      Applies Broyden's quasi-Newton acceleration to the mixed stream. This method is called during run() when Broyden acceleration is enabled.
    • setErrorTemperature

      public void setErrorTemperature(double errorTemperature)

      Setter for the field errorTemperature.

      Parameters:
      errorTemperature - the errorTemperature to set
    • setErrorPressure

      public void setErrorPressure(double errorPressure)

      Setter for the field errorPressure.

      Parameters:
      errorPressure - the errorPressure to set
    • setErrorFlow

      public void setErrorFlow(double errorFlow)

      Setter for the field errorFlow.

      Parameters:
      errorFlow - the error to set
    • getErrorFlow

      public double getErrorFlow()

      Getter for the field errorFlow.

      Returns:
      a double
    • getErrorTemperature

      public double getErrorTemperature()

      Getter for the field errorTemperature.

      Returns:
      a double
    • getErrorPressure

      public double getErrorPressure()

      Getter for the field errorPressure.

      Returns:
      a double
    • setErrorCompositon

      public void setErrorCompositon(double errorComposition)

      Setter for the field errorComposition.

      Parameters:
      errorComposition - the error to set
    • getErrorComposition

      public double getErrorComposition()

      Getter for the field errorComposition.

      Returns:
      a double
    • getPriority

      public int getPriority()

      Getter for the field priority.

      Returns:
      a int
    • setPriority

      public void setPriority(int priority)

      Setter for the field priority.

      Parameters:
      priority - a int
    • solved

      public boolean solved()

      Returns whether or not the module has been solved.

      Specified by:
      solved in interface SimulationInterface
      Overrides:
      solved in class ProcessEquipmentBaseClass
      Returns:
      a boolean
    • getDownstreamProperty

      public ArrayList<String> getDownstreamProperty()

      Getter for the field downstreamProperty.

      Returns:
      a ArrayList object
    • getOutletStream

      public StreamInterface getOutletStream()

      Getter for outlet stream object.

      Specified by:
      getOutletStream in interface MixerInterface
      Returns:
      a StreamInterface object
    • setOutletStream

      public void setOutletStream(StreamInterface outletStream)

      Setter for the field outletStream.

      Parameters:
      outletStream - a StreamInterface object
    • getMassBalance

      public double getMassBalance(String unit)

      getMassBalance.

      Specified by:
      getMassBalance in interface ProcessEquipmentInterface
      Overrides:
      getMassBalance in class ProcessEquipmentBaseClass
      Parameters:
      unit - a String object
      Returns:
      a double
    • removeInputStream

      public void removeInputStream(int i)

      removeInputStream.

      Specified by:
      removeInputStream in interface MixerInterface
      Parameters:
      i - a int
    • getMinimumFlow

      public double getMinimumFlow()

      Getter for the field minimumFlow, e.g., the minimum flow rate for the pump.

      Overrides:
      getMinimumFlow in class ProcessEquipmentBaseClass
      Returns:
      a double
    • setMinimumFlow

      public void setMinimumFlow(double minimumFlow)

      Setter for the field minimumFlow, e.g., the minimum flow rate for the pump.

      Overrides:
      setMinimumFlow in class ProcessEquipmentBaseClass
      Parameters:
      minimumFlow - a double
    • toJson

      public String toJson()

      Serializes the Process Equipment along with its state to a JSON string.

      Specified by:
      toJson in interface ProcessEquipmentInterface
      Overrides:
      toJson in class ProcessEquipmentBaseClass
      Returns:
      json string.
    • toJson

      public String toJson(ReportConfig cfg)
      Serializes the Process Equipment with configurable level of detail.
      Specified by:
      toJson in interface ProcessEquipmentInterface
      Overrides:
      toJson in class ProcessEquipmentBaseClass
      Parameters:
      cfg - report configuration
      Returns:
      json string
    • validateSetup

      public ValidationResult validateSetup()
      Validate the process equipment before execution.

      Checks for common setup errors:

      • Equipment has a valid name
      • Input streams connected
      • Operating parameters in valid ranges

      Validates the recycle setup before execution. Checks that:

      • Equipment has a valid name
      • At least one input stream is connected
      • Outlet stream is set
      • Tolerance values are positive
      Specified by:
      validateSetup in interface ProcessEquipmentInterface
      Returns:
      validation result with errors and warnings