Class Recycle
- All Implemented Interfaces:
Serializable, Runnable, MixerInterface, ProcessEquipmentInterface, SimulationInterface, NamedInterface
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 Summary
FieldsModifier and TypeFieldDescriptionprivate AccelerationMethodprivate BroydenAcceleratorBroyden accelerator instance for multi-variable acceleration.private doubleprivate doubleprivate doubleprivate doubleprivate double(package private) booleanprivate double(package private) int(package private) StreamInterface(package private) static org.apache.logging.log4j.LoggerLogger object for class.(package private) intprivate doubleprotected StreamInterfaceprotected intprivate StreamInterfaceprivate doubleprivate double[]Previous iteration input values for Wegstein slope calculation.private double[]Previous iteration output values for Wegstein slope calculation.private intprivate static final longSerialization version UID.protected ArrayList<StreamInterface> private doubleprivate intDelay iterations before applying Wegstein (allows system to stabilize).private double[]Current Wegstein q-factor values per variable.private doubleMaximum bound for Wegstein q-factor to prevent divergence.private doubleMinimum bound for Wegstein q-factor to prevent divergence.Fields inherited from class ProcessEquipmentBaseClass
conditionAnalysisMessage, energyStream, hasController, isSolved, properties, reportFields inherited from class SimulationBaseClass
calcIdentifier, calculateSteadyState, timeFields inherited from class NamedBaseClass
name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStream(StreamInterface newStream) addStream.private voidApplies Broyden's quasi-Newton acceleration to the mixed stream.private voidapplyStreamValues(double[] values) Applies accelerated values to the mixed stream.private double[]applyWegsteinAcceleration(double[] currentInput, double[] currentOutput) Applies Wegstein acceleration to calculate accelerated values.private voidApplies Wegstein acceleration to the mixed stream using previous iteration data.doublecalcMixStreamEnthalpy.doublecompositionBalanceCheck.voiddisplayResult.private double[]extractStreamValues(StreamInterface stream) Extracts the current tear stream values as an array.doublemassBalanceCheck.Gets the current acceleration method used for convergence.Gets the Broyden accelerator instance, creating one if needed.doubleGetter for the fieldcompositionTolerance.Getter for the fielddownstreamProperty.doubleGetter for the fielderrorComposition.doubleGetter for the fielderrorFlow.doubleGetter for the fielderrorPressure.doubleGetter for the fielderrorTemperature.doubleGetter for the fieldflowTolerance.intGets the current iteration count.doublegetMassBalance(String unit) getMassBalance.doubleGetter for the fieldminimumFlow, e.g., the minimum flow rate for the pump.Getter for outlet stream object.Deprecated.intGetter for the fieldpriority.getStream(int i) getStream.doubleGetter for the fieldtemperatureTolerance.getThermoSystem.intGets the number of delay iterations before Wegstein acceleration is applied.double[]Gets the current Wegstein q-factors for each variable.doubleGets the maximum bound for Wegstein q-factor.doubleGets the minimum bound for Wegstein q-factor.doubleguessTemperature.voidinitiateDownstreamProperties(StreamInterface outstream) initiateDownstreamProperties.voidmixStream.doublepressureBalanceCheck.voidremoveInputStream(int i) removeInputStream.voidreplaceStream(int i, StreamInterface newStream) replaceStream.voidResets the acceleration state for a new convergence cycle.voidresetIterations.voidIn this method all thermodynamic and unit operations will be calculated in a steady state calculation.voidSets the acceleration method for convergence.voidsetCompositionTolerance(double compositionTolerance) Setter for the fieldcompositionTolerance.voidsetDownstreamProperties.voidsetDownstreamProperty(String property) Setter for the fielddownstreamProperty.voidsetDownstreamProperty(ArrayList<String> property) Setter for the fielddownstreamProperty.voidsetErrorCompositon(double errorComposition) Setter for the fielderrorComposition.voidsetErrorFlow(double errorFlow) Setter for the fielderrorFlow.voidsetErrorPressure(double errorPressure) Setter for the fielderrorPressure.voidsetErrorTemperature(double errorTemperature) Setter for the fielderrorTemperature.voidsetFlowTolerance(double flowTolerance) Setter for the fieldflowTolerance.voidsetMinimumFlow(double minimumFlow) Setter for the fieldminimumFlow, e.g., the minimum flow rate for the pump.voidsetOutletStream(StreamInterface outletStream) Setter for the fieldoutletStream.voidsetPressure(double pres) Setter for the fieldpressure.voidsetPriority(int priority) Setter for the fieldpriority.voidsetTemperature(double temp) Setter for the fieldtemperature.voidsetTemperatureTolerance(double temperatureTolerance) Setter for the fieldtemperatureTolerance.voidsetTolerance(double tolerance) Setter for the tolerance fields.voidsetWegsteinDelayIterations(int delayIterations) Sets the number of delay iterations before Wegstein acceleration is applied.voidsetWegsteinQMax(double qMax) Sets the maximum bound for Wegstein q-factor.voidsetWegsteinQMin(double qMin) Sets the minimum bound for Wegstein q-factor.booleansolved()Returns whether or not the module has been solved.doubletemperatureBalanceCheck.toJson()Serializes the Process Equipment along with its state to a JSON string.toJson(ReportConfig cfg) Serializes the Process Equipment with configurable level of detail.Validate the process equipment before execution.Methods inherited from class ProcessEquipmentBaseClass
copy, equals, getConditionAnalysisMessage, getController, getEnergyStream, getEntropyProduction, getExergyChange, getMassBalance, getMechanicalDesign, getPressure, getPressure, getProperty, getReport_json, getResultTable, getSpecification, getTemperature, getTemperature, hashCode, initMechanicalDesign, isActive, isActive, isSetEnergyStream, reportResults, run_step, runConditionAnalysis, setController, setEnergyStream, setEnergyStream, setFlowValveController, setRegulatorOutSignal, setSpecificationMethods 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
equals, getCapacityDuty, getCapacityMax, getConditionAnalysisMessage, getController, getEntropyProduction, getExergyChange, getExergyChange, getFluid, getMassBalance, getMechanicalDesign, getPressure, getPressure, getReport_json, getRestCapacity, getResultTable, getSpecification, getTemperature, getTemperature, hashCode, initMechanicalDesign, needRecalculation, reportResults, runConditionAnalysis, setController, setRegulatorOutSignal, setSpecificationMethods inherited from interface SimulationInterface
getCalculateSteadyState, getCalculationIdentifier, getTime, increaseTime, isRunInSteps, run, run_step, run_step, runTransient, runTransient, setCalculateSteadyState, setCalculationIdentifier, setRunInSteps, setTime
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization version UID.- See Also:
-
logger
static org.apache.logging.log4j.Logger loggerLogger object for class. -
streams
-
downstreamProperty
-
numberOfInputStreams
protected int numberOfInputStreams -
mixedStream
-
lastIterationStream
StreamInterface lastIterationStream -
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
-
wegsteinQMin
private double wegsteinQMinMinimum bound for Wegstein q-factor to prevent divergence. -
wegsteinQMax
private double wegsteinQMaxMaximum bound for Wegstein q-factor to prevent divergence. -
wegsteinDelayIterations
private int wegsteinDelayIterationsDelay iterations before applying Wegstein (allows system to stabilize). -
previousInputValues
private double[] previousInputValuesPrevious iteration input values for Wegstein slope calculation. -
previousOutputValues
private double[] previousOutputValuesPrevious iteration output values for Wegstein slope calculation. -
wegsteinQFactors
private double[] wegsteinQFactorsCurrent Wegstein q-factor values per variable. -
broydenAccelerator
Broyden accelerator instance for multi-variable acceleration.
-
-
Constructor Details
-
Recycle
-
-
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
getThermoSystem.
- Specified by:
getThermoSystemin interfaceMixerInterface- Specified by:
getThermoSystemin interfaceProcessEquipmentInterface- Overrides:
getThermoSystemin classProcessEquipmentBaseClass- Returns:
- a
SystemInterfaceobject
-
setDownstreamProperty
-
setDownstreamProperty
-
replaceStream
replaceStream.
- Specified by:
replaceStreamin interfaceMixerInterface- Parameters:
i- a intnewStream- aStreamInterfaceobject
-
addStream
addStream.
- Specified by:
addStreamin interfaceMixerInterface- Parameters:
newStream- aStreamInterfaceobject
-
getStream
getStream.
- Parameters:
i- a int- Returns:
- a
StreamInterfaceobject
-
mixStream
public void mixStream()mixStream.
-
guessTemperature
public double guessTemperature()guessTemperature.
- Returns:
- a double
-
calcMixStreamEnthalpy
public double calcMixStreamEnthalpy()calcMixStreamEnthalpy.
- Returns:
- a double
-
getOutStream
Deprecated.Getter for outlet stream object.
- Specified by:
getOutStreamin interfaceMixerInterface- Returns:
- a
StreamInterfaceobject
-
initiateDownstreamProperties
initiateDownstreamProperties.
- Parameters:
outstream- aStreamInterfaceobject
-
setDownstreamProperties
public void setDownstreamProperties()setDownstreamProperties.
-
run
In this method all thermodynamic and unit operations will be calculated in a steady state calculation.
- Specified by:
runin interfaceSimulationInterface- 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:
displayResultin interfaceProcessEquipmentInterface- Overrides:
displayResultin classProcessEquipmentBaseClass
-
setPressure
public void setPressure(double pres) Setter for the field
pressure.- Specified by:
setPressurein interfaceProcessEquipmentInterface- Overrides:
setPressurein classProcessEquipmentBaseClass- Parameters:
pres- a double
-
setTemperature
public void setTemperature(double temp) Setter for the field
temperature.- Specified by:
setTemperaturein interfaceProcessEquipmentInterface- Overrides:
setTemperaturein classProcessEquipmentBaseClass- 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
Gets the current acceleration method used for convergence.- Returns:
- the acceleration method
-
setAccelerationMethod
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
Gets the Broyden accelerator instance, creating one if needed.- Returns:
- the Broyden accelerator
-
extractStreamValues
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:
solvedin interfaceSimulationInterface- Overrides:
solvedin classProcessEquipmentBaseClass- Returns:
- a boolean
-
getDownstreamProperty
-
getOutletStream
Getter for outlet stream object.
- Specified by:
getOutletStreamin interfaceMixerInterface- Returns:
- a
StreamInterfaceobject
-
setOutletStream
Setter for the field
outletStream.- Parameters:
outletStream- aStreamInterfaceobject
-
getMassBalance
getMassBalance.
- Specified by:
getMassBalancein interfaceProcessEquipmentInterface- Overrides:
getMassBalancein classProcessEquipmentBaseClass- Parameters:
unit- aStringobject- Returns:
- a double
-
removeInputStream
public void removeInputStream(int i) removeInputStream.
- Specified by:
removeInputStreamin interfaceMixerInterface- Parameters:
i- a int
-
getMinimumFlow
public double getMinimumFlow()Getter for the field
minimumFlow, e.g., the minimum flow rate for the pump.- Overrides:
getMinimumFlowin classProcessEquipmentBaseClass- Returns:
- a double
-
setMinimumFlow
public void setMinimumFlow(double minimumFlow) Setter for the field
minimumFlow, e.g., the minimum flow rate for the pump.- Overrides:
setMinimumFlowin classProcessEquipmentBaseClass- Parameters:
minimumFlow- a double
-
toJson
Serializes the Process Equipment along with its state to a JSON string.
- Specified by:
toJsonin interfaceProcessEquipmentInterface- Overrides:
toJsonin classProcessEquipmentBaseClass- Returns:
- json string.
-
toJson
Serializes the Process Equipment with configurable level of detail.- Specified by:
toJsonin interfaceProcessEquipmentInterface- Overrides:
toJsonin classProcessEquipmentBaseClass- Parameters:
cfg- report configuration- Returns:
- json string
-
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:
validateSetupin interfaceProcessEquipmentInterface- Returns:
- validation result with errors and warnings
-