Class ProcessSystem
- All Implemented Interfaces:
Serializable, Runnable, SimulationInterface, NamedInterface
- Author:
- esol
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInner class to hold mass balance results.private static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ProcessAlarmManagerprivate ProcessGraphCached process graph for topology analysis.private booleanprivate booleanFlag indicating if the cached graph needs to be rebuilt.private ProcessSystemprivate ProcessEquipmentInterface(package private) static org.apache.logging.log4j.LoggerLogger object for class.private doubleprivate doubleprivate int(package private) List<MeasurementDeviceInterface> private ProcessSystem.MeasurementHistoryprivate doubleprivate double(package private) RecycleControllerprivate booleanprivate static final longSerialization version UID.private double(package private) Threadprivate doubleprivate intprivate List<ProcessEquipmentInterface> List of unit operations in the process system.private booleanWhether to use graph-based execution order instead of insertion order.private booleanWhether to use optimized execution (parallel/hybrid) by default when run() is called.Fields inherited from class SimulationBaseClass
calcIdentifier, calculateSteadyState, timeFields inherited from class NamedBaseClass
name -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for ProcessSystem.ProcessSystem(String name) Constructor for ProcessSystem. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int position, ProcessEquipmentInterface operation) Add to specific position.voidadd(ProcessEquipmentInterface operation) Add to end.voidadd(ProcessEquipmentInterface[] operations) Add multiple process equipment to end.voidadd(MeasurementDeviceInterface measurementDevice) Add measurementdevice.<T extends ProcessEquipmentInterface>
TaddUnit.<T extends ProcessEquipmentInterface>
TaddUnit.<T extends ProcessEquipmentInterface>
TaddUnit(String name, String equipmentType, StreamInterface stream) Adds a new process equipment unit of the specified type and name, and sets its inlet stream.<T extends ProcessEquipmentInterface>
TaddUnit(String name, EquipmentEnum equipmentEnum) addUnit.addUnit(String name, ProcessEquipmentInterface equipment) addUnit.<T extends ProcessEquipmentInterface>
TaddUnit(EquipmentEnum equipmentEnum) addUnit.addUnit(ProcessEquipmentInterface equipment) addUnit.private voidapplyState(ProcessSystem source) private voidautoConnect(ProcessEquipmentInterface fromUnit, ProcessEquipmentInterface toUnit) Builds an explicit graph representation of this process system.private doublecalculateInletFlow(ProcessEquipmentInterface unitOp, String unit) private doublecalculatePercentError(double massBalanceError, double inletFlow) private doubleCalculate total system mass across all equipment and streams.private voidcaptureInitialState(boolean force) Check mass balance of all unit operations in the process system using kg/sec.checkMassBalance(String unit) Check mass balance of all unit operations in the process system.voidclear()clear.voidclearAll()clearAll.voidClears all stored transient measurement history entries and resets the time step counter.copy()Create deep copy.Creates a batch study builder for running parallel parameter studies on this process.Creates a diagram exporter for this process with full configuration options.private ProcessSystemdeepCopy()voiddisplayResult.private voidbooleanvoidexportDiagramPNG(Path path) Exports the process diagram to PNG format.voidexportDiagramSVG(Path path) Exports the process diagram to SVG format.Exports the current state of this process system for checkpointing or versioning.voidexportStateToFile(String filename) Exports the current state to a JSON file for versioning or backup.voidexportToGraphviz(String filename) exportToGraphviz.voidexportToGraphviz(String filename, ProcessSystemGraphvizExporter.GraphvizExportOptions options) Export the process to Graphviz with configurable stream annotations.generateCombinationScenarios(int maxSimultaneousFailures) Generates combination failure scenarios (multiple simultaneous failures).Generates automatic safety scenarios based on equipment failure modes.private StringgenerateUniqueName(String equipmentType) Returns the alarm manager responsible for coordinating alarm evaluation.getAllUnitNames.getBottleneck.getConditionMonitor.doublegetCoolerDuty(String unit) getCoolerDuty.Calculates current emissions from all equipment in this process system.getEmissions(double gridEmissionFactor) Calculates emissions using a custom grid emission factor.doublegetEntropyProduction(String unit) getEntropyProduction.Gets a description of how the process will be partitioned for execution.doublegetExergyChange(String unit) getExergyChange.Get unit operations that failed mass balance check using kg/sec and default threshold.getFailedMassBalance(double percentThreshold) Get unit operations that failed mass balance check using specified threshold.getFailedMassBalance(String unit, double percentThreshold) Get unit operations that failed mass balance check based on percentage error threshold.Get a formatted report of failed mass balance checks for this process system using kg/sec and default threshold.getFailedMassBalanceReport(double percentThreshold) Get a formatted report of failed mass balance checks for this process system using specified threshold.getFailedMassBalanceReport(String unit, double percentThreshold) Get a formatted report of failed mass balance checks for this process system.Gets a summary of the process graph structure.doublegetHeaterDuty(String unit) getHeaterDuty.intReturns the configured history capacity.intReturns the number of stored transient measurement entries.String[][]Returns a snapshot of the transient measurement history.doubleGet the current mass balance error percentage.doubleGet the default mass balance error threshold for this process system.Get a formatted mass balance report for this process system using kg/sec.getMassBalanceReport(String unit) Get a formatted mass balance report for this process system.intGets the maximum parallelism (max units that can run simultaneously).intGet the maximum number of iterations within each transient time step.getMeasurementDevice(String name) Get MeasureDevice by name.doubleGet the minimum flow threshold for mass balance error checking.getName()Getter for the fieldname.intGets the number of levels for parallel execution.Gets the parallel execution partition for this process.doublegetPower.intGets the number of recycle blocks (cycles) in the process.Gets a diagnostic report of recycle blocks for debugging.Gets the strongly connected components (SCCs) in the process graph.getReport_json.doubleGetter for the fieldsurroundingTemperature.doublegetTime()Getter for the fieldtime.doubleGetter for the fieldtime.doubleGetter for the fieldtimeStep.Gets the calculation order derived from process topology.doubleGets total CO2-equivalent emissions from this process in kg/hr.Get process equipmen by name.intgetUnitNumber(String name) getUnitNumber.Gets the list of unit operations.private List<List<ProcessNode>> Groups nodes by shared input streams for parallel execution safety.booleanChecks if the process contains any Adjuster units that require iterative convergence.inthashCode()booleanChecks if the process contains any multi-input equipment.booleanChecks if the process has recycle loops that require iterative solving.booleanChecks if the process contains any Recycle units.booleanhasUnitName(String name) hasUnitName.voidForces a rebuild of the process graph on next access.booleanChecks if a specific unit is part of a recycle loop.booleanChecks if parallel execution would be beneficial for this process.booleanChecks if the process system is ready to run.booleanGetter for the fieldrunStep.booleanReturns whether graph-based execution order is enabled.booleanReturns whether optimized execution is enabled.static ProcessSystemLoads a process system from a file with automatic format detection.static ProcessSystemloadFromNeqsim(String filename) Loads a process system from a compressed .neqsim file.voidloadProcessFromYaml(File yamlFile) Load a process from a YAML file.voidloadStateFromFile(String filename) Loads process state from a JSON file and applies it to this system.static ProcessSystemopen.voidprintLogFile(String filename) printLogFile.voidremoveUnit(String name) removeUnit.voidreplaceObject(String unitName, ProcessEquipmentBaseClass operation) replaceObject.booleanreplaceUnit(String name, ProcessEquipmentInterface newObject) Replace a unitoperation.voidreportMeasuredValues.String[][]reportResults.voidreset()Restores the process system to the stored initial state.voidIn this method all thermodynamic and unit operations will be calculated in a steady state calculation.voidrun_stepFuture<?> Runs this process in a separate thread using the global NeqSim thread pool.Deprecated.voidRuns the process using hybrid execution strategy.voidRuns the process using the optimal execution strategy.voidrunOptimal(UUID id) Runs the process using the optimal execution strategy with calculation ID tracking.voidRuns the process system using the optimal execution strategy based on topology analysis.voidrunOptimized(UUID id) Runs the process system using the optimal execution strategy based on topology analysis.voidRuns the process system using parallel execution for independent equipment.voidrunParallel(UUID id) Runs the process system using parallel execution for independent equipment.voidrunSequential(UUID id) Runs the process system using sequential execution.voidrunTransient.voidrunTransient(double dt, UUID id) runTransientvoidsave.booleanSaves the current state to a file with automatic format detection.booleansaveToNeqsim(String filename) Saves this process system to a compressed .neqsim file using XStream serialization.voidsetEnableMassBalanceTracking(boolean enable) Enable or disable mass balance tracking during transient simulations.voidsetFluid(SystemInterface fluid1, SystemInterface fluid2) setFluid.voidsetFluid(SystemInterface fluid1, SystemInterface fluid2, boolean addNewComponents) setFluid.voidsetHistoryCapacity(int maxEntries) Sets the maximum number of entries retained in the measurement history.voidsetMassBalanceErrorThreshold(double percentThreshold) Set the default mass balance error threshold for this process system.voidsetMaxTransientIterations(int iterations) Set the maximum number of iterations within each transient time step.voidsetMinimumFlowForMassBalanceError(double minimumFlow) Set the minimum flow threshold for mass balance error checking.voidSetter for the fieldname.voidsetRunStep(boolean runStep) Setter for the fieldrunStep.voidsetSurroundingTemperature(double surroundingTemperature) Setter for the fieldsurroundingTemperature.voidsetTimeStep(double timeStep) Setter for the fieldtimeStep.voidsetUseGraphBasedExecution(boolean useGraphBased) Sets whether to use graph-based execution order.voidsetUseOptimizedExecution(boolean useOptimized) Sets whether to use optimized execution (parallel/hybrid) by default when run() is called.intsize()size.booleansolved()Returns whether or not the module has been solved.voidStores a snapshot of the current process system state that can later be restored withreset().toDOT()Exports the process as a DOT format diagram string.toDOT(DiagramDetailLevel detailLevel) Exports the process as a DOT format diagram with specified detail level.Validates all equipment in the process system and returns individual results.Validates the process system setup before execution.Validates the process structure and returns any issues found.voidview()view.Methods inherited from class SimulationBaseClass
getCalculateSteadyState, getCalculationIdentifier, increaseTime, isRunInSteps, setCalculateSteadyState, setCalculationIdentifier, setRunInSteps, setTimeMethods inherited from class NamedBaseClass
getTagName, setTagNameMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface NamedInterface
getTagName, setTagNameMethods inherited from interface SimulationInterface
run, run_step, runTransient
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization version UID.- See Also:
-
logger
static org.apache.logging.log4j.Logger loggerLogger object for class. -
thisThread
-
measurementHistory
-
surroundingTemperature
private double surroundingTemperature -
timeStepNumber
private int timeStepNumber -
unitOperations
List of unit operations in the process system. -
measurementDevices
List<MeasurementDeviceInterface> measurementDevices -
alarmManager
-
recycleController
RecycleController recycleController -
timeStep
private double timeStep -
runStep
private boolean runStep -
equipmentCounter
-
lastAddedUnit
-
initialStateSnapshot
-
massBalanceErrorThreshold
private double massBalanceErrorThreshold -
minimumFlowForMassBalanceError
private double minimumFlowForMassBalanceError -
maxTransientIterations
private int maxTransientIterations -
enableMassBalanceTracking
private boolean enableMassBalanceTracking -
previousTotalMass
private double previousTotalMass -
massBalanceError
private double massBalanceError -
cachedGraph
Cached process graph for topology analysis. -
graphDirty
private boolean graphDirtyFlag indicating if the cached graph needs to be rebuilt. -
useGraphBasedExecution
private boolean useGraphBasedExecutionWhether to use graph-based execution order instead of insertion order. -
useOptimizedExecution
private boolean useOptimizedExecutionWhether to use optimized execution (parallel/hybrid) by default when run() is called. When true, run() delegates to runOptimized() which automatically selects the best strategy. When false, run() uses sequential execution in insertion order (legacy behavior). Default is true for optimal performance - runOptimized() automatically falls back to sequential execution for processes with multi-input equipment (mixers, heat exchangers, etc.) to preserve correct mass balance.
-
-
Constructor Details
-
ProcessSystem
public ProcessSystem()Constructor for ProcessSystem.
-
ProcessSystem
-
-
Method Details
-
add
Add to end.
- Parameters:
operation- aProcessEquipmentInterfaceobject
-
add
Add to specific position.
- Parameters:
position- 0-based positionoperation- aProcessEquipmentInterfaceobject
-
add
Add measurementdevice.
- Parameters:
measurementDevice- aMeasurementDeviceInterfaceobject
-
add
Add multiple process equipment to end.
- Parameters:
operations- an array ofProcessEquipmentInterfaceobjects
-
replaceUnit
Replace a unitoperation.
- Parameters:
name- Name of the object to replacenewObject- the object to replace it with- Returns:
- a
Booleanobject
-
getUnit
Get process equipmen by name.
- Parameters:
name- Name of- Returns:
- a
ProcessEquipmentInterfaceobject
-
hasUnitName
-
getMeasurementDevice
Get MeasureDevice by name.
- Parameters:
name- Name of measurement device- Returns:
- a
MeasurementDeviceInterfaceobject
-
getUnitNumber
-
replaceObject
replaceObject.
- Parameters:
unitName- aStringobjectoperation- aProcessEquipmentBaseClassobject
-
getAllUnitNames
-
getUnitOperations
Gets the list of unit operations.
- Returns:
- the list of unit operations
-
validateSetup
Validates the process system setup before execution.This method validates:
- The process system has at least one unit operation
- Each unit operation passes its own validateSetup() check
- Feed streams are defined
- Equipment names are unique (warning)
- Returns:
- validation result with errors and warnings for all equipment
-
validateAll
Validates all equipment in the process system and returns individual results.Unlike
validateSetup()which returns a combined result, this method returns a map of equipment names to their individual validation results, making it easier to identify specific issues.- Returns:
- map of equipment names to their validation results
-
isReadyToRun
public boolean isReadyToRun()Checks if the process system is ready to run.Convenience method that returns true if validateSetup() finds no critical errors.
- Returns:
- true if process system passes validation, false otherwise
-
removeUnit
-
clearAll
public void clearAll()clearAll.
-
clear
public void clear()clear.
-
setFluid
setFluid.
- Parameters:
fluid1- aSystemInterfaceobjectfluid2- aSystemInterfaceobjectaddNewComponents- a boolean
-
setFluid
setFluid.
- Parameters:
fluid1- aSystemInterfaceobjectfluid2- aSystemInterfaceobject
-
runAsTask
Runs this process in a separate thread using the global NeqSim thread pool.This method submits the process to the shared
NeqSimThreadPooland returns aFuturethat can be used to monitor completion, cancel the task, or retrieve any exceptions that occurred.- Returns:
- a
Futurerepresenting the pending completion of the task - See Also:
-
runOptimized
public void runOptimized()Runs the process system using the optimal execution strategy based on topology analysis.This method automatically selects the best execution mode:
- For processes WITHOUT recycles: uses parallel execution for maximum speed
- For processes WITH recycles: uses graph-based execution with optimized ordering
This is the recommended method for most use cases as it provides the best performance without requiring manual configuration.
-
runOptimized
Runs the process system using the optimal execution strategy based on topology analysis.This method automatically selects the best execution mode:
- For processes WITHOUT recycles: uses parallel execution for maximum speed
- For processes WITH recycles: uses hybrid execution - parallel for feed-forward sections, then graph-based iteration for recycle sections
- Parameters:
id- calculation identifier for tracking
-
hasAdjusters
public boolean hasAdjusters()Checks if the process contains any Adjuster units that require iterative convergence.- Returns:
- true if there are Adjuster units in the process
-
hasRecycles
public boolean hasRecycles()Checks if the process contains any Recycle units.This method directly checks for Recycle units in the process, which is more reliable than graph-based cycle detection for determining if iterative execution is needed.
- Returns:
- true if there are Recycle units in the process
-
hasMultiInputEquipment
public boolean hasMultiInputEquipment()Checks if the process contains any multi-input equipment.Multi-input equipment (Mixer, Manifold, TurboExpanderCompressor, Ejector, HeatExchanger, MultiStreamHeatExchanger) require sequential execution to ensure correct mass balance. Parallel execution can change the order in which input streams are processed, leading to incorrect results.
- Returns:
- true if there are multi-input equipment units in the process
-
runHybrid
Runs the process using hybrid execution strategy.This method partitions the process into:
- Feed-forward section: Units at the beginning with no recycle dependencies - run in parallel
- Recycle section: Units that are part of or depend on recycle loops - run with graph-based iteration
- Parameters:
id- calculation identifier for tracking- Throws:
InterruptedException- if thread is interrupted during parallel execution
-
getExecutionPartitionInfo
Gets a description of how the process will be partitioned for execution.This method analyzes the process topology and returns information about:
- Whether the process has recycle loops
- Number of parallel execution levels
- Maximum parallelism achievable
- Which units are in recycle loops
- Returns:
- description of the execution partitioning
-
runParallel
Runs the process system using parallel execution for independent equipment.This method uses the process graph to identify equipment that can run in parallel (i.e., equipment with no dependencies between them). Equipment at the same "level" in the dependency graph are executed concurrently using the NeqSim thread pool.
Note: This method does not handle recycles or adjusters - use regular
SimulationInterface.run()for processes with recycle loops. This is suitable for feed-forward processes where maximum parallelism is desired.- Throws:
InterruptedException- if the thread is interrupted while waiting for tasks
-
runParallel
Runs the process system using parallel execution for independent equipment.This method uses the process graph to identify equipment that can run in parallel (i.e., equipment with no dependencies between them). Equipment at the same "level" in the dependency graph are executed concurrently using the NeqSim thread pool.
- Parameters:
id- calculation identifier for tracking- Throws:
InterruptedException- if the thread is interrupted while waiting for tasks
-
getParallelPartition
Gets the parallel execution partition for this process.This method returns information about how the process can be parallelized, including: - The number of parallel levels - Maximum parallelism (max units that can run concurrently) - Which units are at each level
- Returns:
- parallel partition result, or null if graph cannot be built
-
isParallelExecutionBeneficial
public boolean isParallelExecutionBeneficial()Checks if parallel execution would be beneficial for this process.Parallel execution is considered beneficial when:
- There are at least 2 units that can run in parallel (maxParallelism >= 2)
- The process has no recycle loops (which require iterative sequential execution)
- There are enough units to justify thread overhead (typically > 4 units)
- Returns:
- true if parallel execution is recommended
-
runOptimal
public void runOptimal()Runs the process using the optimal execution strategy.This method automatically determines whether to use parallel or sequential execution based on the process structure. It will use parallel execution if:
- The process has independent branches that can benefit from parallelism
- There are no recycle loops or adjusters requiring iterative execution
- The process is large enough to justify the thread management overhead
For processes with recycles or adjusters, this method falls back to the standard sequential
SimulationInterface.run()method which properly handles convergence iterations. -
runOptimal
Runs the process using the optimal execution strategy with calculation ID tracking.- Parameters:
id- calculation identifier for tracking- See Also:
-
runAsThread
Deprecated.UserunAsTask()instead for better resource management. This method creates a new unmanaged thread directly.runAsThread.
- Returns:
- a
Threadobject
-
run
In this method all thermodynamic and unit operations will be calculated in a steady state calculation.
- Parameters:
id- UUID
-
runSequential
Runs the process system using sequential execution.This method executes units in insertion order (or topological order if useGraphBasedExecution is enabled). It handles recycle loops by iterating until convergence. This is the legacy execution mode preserved for backward compatibility.
- Parameters:
id- calculation identifier for tracking
-
run_step
run_step
In this method all thermodynamic and unit operations will be calculated in a steady state calculation. Sets calc identifier UUID. It does not solve recycles - only calculates one step- Parameters:
id- Calc identifier UUID to set.
-
runTransient
public void runTransient()runTransient.
-
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.- Parameters:
dt- Delta time [s]id- Calculation identifier
-
solved
public boolean solved()Returns whether or not the module has been solved.
- Returns:
- a boolean
-
getTime
public double getTime()Getter for the fieldtime.- Specified by:
getTimein interfaceSimulationInterface- Overrides:
getTimein classSimulationBaseClass- Returns:
- Value of property time.
-
getTime
-
calculateTotalSystemMass
private double calculateTotalSystemMass()Calculate total system mass across all equipment and streams.- Returns:
- Total mass in kg
-
setEnableMassBalanceTracking
public void setEnableMassBalanceTracking(boolean enable) Enable or disable mass balance tracking during transient simulations.- Parameters:
enable- true to enable tracking
-
getMassBalanceError
public double getMassBalanceError()Get the current mass balance error percentage.- Returns:
- Mass balance error in percent
-
setMaxTransientIterations
public void setMaxTransientIterations(int iterations) Set the maximum number of iterations within each transient time step.Multiple iterations help converge circular dependencies between equipment. Default is 3. Set to 1 to disable iterative convergence.
- Parameters:
iterations- Number of iterations (must be >= 1)
-
getMaxTransientIterations
public int getMaxTransientIterations()Get the maximum number of iterations within each transient time step.- Returns:
- Number of iterations
-
size
public int size()size.
- Returns:
- a int
-
view
public void view()view.
-
displayResult
public void displayResult()displayResult.
-
reportMeasuredValues
public void reportMeasuredValues()reportMeasuredValues.
-
save
-
open
open.
- Parameters:
filePath- aStringobject- Returns:
- a
ProcessSystemobject
-
reportResults
-
printLogFile
-
clearHistory
public void clearHistory()Clears all stored transient measurement history entries and resets the time step counter. -
getHistorySize
public int getHistorySize()Returns the number of stored transient measurement entries.- Returns:
- number of stored history entries
-
getAlarmManager
Returns the alarm manager responsible for coordinating alarm evaluation.- Returns:
- alarm manager
-
getHistorySnapshot
Returns a snapshot of the transient measurement history.- Returns:
- the measurement history as a two-dimensional array
-
setHistoryCapacity
public void setHistoryCapacity(int maxEntries) Sets the maximum number of entries retained in the measurement history. A value less than or equal to zero disables truncation (unbounded history).- Parameters:
maxEntries- maximum number of entries to keep, or non-positive for unlimited
-
getHistoryCapacity
public int getHistoryCapacity()Returns the configured history capacity. A value less than or equal to zero means the history grows without bounds.- Returns:
- configured maximum number of history entries or non-positive for unlimited
-
storeInitialState
public void storeInitialState()Stores a snapshot of the current process system state that can later be restored withreset(). -
reset
public void reset()Restores the process system to the stored initial state. The initial state is captured automatically the first time a transient run is executed, or manually viastoreInitialState(). -
ensureInitialStateSnapshot
private void ensureInitialStateSnapshot() -
captureInitialState
private void captureInitialState(boolean force) -
applyState
-
getTimeStep
public double getTimeStep()Getter for the field
timeStep.- Returns:
- a double
-
setTimeStep
public void setTimeStep(double timeStep) Setter for the field
timeStep.- Parameters:
timeStep- a double
-
getName
Getter for the field
name.- Specified by:
getNamein interfaceNamedInterface- Overrides:
getNamein classNamedBaseClass- Returns:
- a
Stringobject
-
setName
Setter for the field
name.- Specified by:
setNamein interfaceNamedInterface- Overrides:
setNamein classNamedBaseClass- Parameters:
name- aStringobject
-
setRunStep
public void setRunStep(boolean runStep) Setter for the fieldrunStep.- Parameters:
runStep- Abooleanvalue if run only one iteration
-
isRunStep
public boolean isRunStep()Getter for the fieldrunStep.- Returns:
- A
booleanvalue if run only one iteration
-
getEntropyProduction
-
getExergyChange
-
getPower
-
getCoolerDuty
-
getHeaterDuty
-
getSurroundingTemperature
public double getSurroundingTemperature()Getter for the field
surroundingTemperature.- Returns:
- a double
-
setSurroundingTemperature
public void setSurroundingTemperature(double surroundingTemperature) Setter for the field
surroundingTemperature.- Parameters:
surroundingTemperature- a double
-
copy
-
deepCopy
-
getConditionMonitor
getConditionMonitor.
- Returns:
- a
ConditionMonitorobject
-
checkMassBalance
Check mass balance of all unit operations in the process system.- Parameters:
unit- unit for mass flow rate (e.g., "kg/sec", "kg/hr", "mole/sec")- Returns:
- a map with unit operation name as key and mass balance result as value
-
checkMassBalance
Check mass balance of all unit operations in the process system using kg/sec.- Returns:
- a map with unit operation name as key and mass balance result as value in kg/sec
-
getFailedMassBalance
public Map<String, ProcessSystem.MassBalanceResult> getFailedMassBalance(String unit, double percentThreshold) Get unit operations that failed mass balance check based on percentage error threshold.- Parameters:
unit- unit for mass flow rate (e.g., "kg/sec", "kg/hr", "mole/sec")percentThreshold- percentage error threshold (default: 0.1%)- Returns:
- a map with failed unit operation names and their mass balance results
-
getFailedMassBalance
Get unit operations that failed mass balance check using kg/sec and default threshold.- Returns:
- a map with failed unit operation names and their mass balance results
-
getFailedMassBalance
Get unit operations that failed mass balance check using specified threshold.- Parameters:
percentThreshold- percentage error threshold- Returns:
- a map with failed unit operation names and their mass balance results in kg/sec
-
getMassBalanceReport
-
getMassBalanceReport
Get a formatted mass balance report for this process system using kg/sec.- Returns:
- a formatted string report with mass balance results
-
getFailedMassBalanceReport
Get a formatted report of failed mass balance checks for this process system.- Parameters:
unit- unit for mass flow rate (e.g., "kg/sec", "kg/hr", "mole/sec")percentThreshold- percentage error threshold- Returns:
- a formatted string report with failed unit operations
-
getFailedMassBalanceReport
Get a formatted report of failed mass balance checks for this process system using kg/sec and default threshold.- Returns:
- a formatted string report with failed unit operations
-
getFailedMassBalanceReport
Get a formatted report of failed mass balance checks for this process system using specified threshold.- Parameters:
percentThreshold- percentage error threshold- Returns:
- a formatted string report with failed unit operations in kg/sec
-
setMassBalanceErrorThreshold
public void setMassBalanceErrorThreshold(double percentThreshold) Set the default mass balance error threshold for this process system.- Parameters:
percentThreshold- percentage error threshold (e.g., 0.1 for 0.1%)
-
getMassBalanceErrorThreshold
public double getMassBalanceErrorThreshold()Get the default mass balance error threshold for this process system.- Returns:
- percentage error threshold
-
setMinimumFlowForMassBalanceError
public void setMinimumFlowForMassBalanceError(double minimumFlow) Set the minimum flow threshold for mass balance error checking. Units with inlet flow below this threshold are not considered errors.- Parameters:
minimumFlow- minimum flow in kg/sec (e.g., 1e-6)
-
getMinimumFlowForMassBalanceError
public double getMinimumFlowForMassBalanceError()Get the minimum flow threshold for mass balance error checking.- Returns:
- minimum flow in kg/sec
-
calculateInletFlow
-
calculatePercentError
private double calculatePercentError(double massBalanceError, double inletFlow) -
hashCode
-
equals
-
getReport_json
getReport_json.
Return results of simulation in json format- Returns:
- a String
-
addUnit
addUnit.
-
addUnit
addUnit.
- Type Parameters:
T- a T class- Parameters:
name- aStringobjectequipmentEnum- aEquipmentEnumobject- Returns:
- a T object
-
addUnit
addUnit.
- Type Parameters:
T- a T class- Parameters:
equipmentType- aStringobject- Returns:
- a T object
-
addUnit
addUnit.
- Type Parameters:
T- a T class- Parameters:
equipmentEnum- aEquipmentEnumobject- Returns:
- a T object
-
addUnit
public <T extends ProcessEquipmentInterface> T addUnit(String name, String equipmentType, StreamInterface stream) Adds a new process equipment unit of the specified type and name, and sets its inlet stream.- Type Parameters:
T- the type of process equipment- Parameters:
name- the name of the equipment (if null or empty, a unique name is generated)equipmentType- the type of equipment to create (as a String)stream- the inlet stream to set for the new equipment- Returns:
- the created and added process equipment unit
-
addUnit
addUnit.
- Parameters:
name- aStringobjectequipment- aProcessEquipmentInterfaceobject- Returns:
- a
ProcessEquipmentInterfaceobject
-
addUnit
addUnit.
- Parameters:
equipment- aProcessEquipmentInterfaceobject- Returns:
- a
ProcessEquipmentInterfaceobject
-
generateUniqueName
-
autoConnect
-
exportToGraphviz
-
exportToGraphviz
public void exportToGraphviz(String filename, ProcessSystemGraphvizExporter.GraphvizExportOptions options) Export the process to Graphviz with configurable stream annotations.- Parameters:
filename- the Graphviz output fileoptions- export options controlling stream annotations and table output
-
loadProcessFromYaml
Load a process from a YAML file.- Parameters:
yamlFile- the YAML file to load
-
getBottleneck
getBottleneck.
- Returns:
- a
ProcessEquipmentInterfaceobject
-
buildGraph
Builds an explicit graph representation of this process system.The graph representation enables:
- Automatic detection of calculation order (derived from topology, not insertion order)
- Partitioning for parallel execution
- AI agents to reason about flowsheet structure
- Cycle detection for recycle handling
- Graph neural network compatible representation
Example usage:
ProcessSystem system = new ProcessSystem(); // ... add units ... ProcessGraph graph = system.buildGraph(); // Get topology-based calculation order List<ProcessEquipmentInterface> order = graph.getCalculationOrder(); // Partition for parallel execution ProcessGraph.ParallelPartition partition = graph.partitionForParallelExecution();
- Returns:
- the process graph
- See Also:
-
invalidateGraph
public void invalidateGraph()Forces a rebuild of the process graph on next access.Use this method when you have made structural changes to the process that the automatic detection may have missed (e.g., modifying stream connections directly).
-
setUseGraphBasedExecution
public void setUseGraphBasedExecution(boolean useGraphBased) Sets whether to use graph-based execution order.When enabled, the run() method will execute units in topological order derived from stream connections rather than the order units were added. This can be safer when unit insertion order doesn't match the physical flow.
- Parameters:
useGraphBased- true to use topological execution order, false to use insertion order
-
isUseGraphBasedExecution
public boolean isUseGraphBasedExecution()Returns whether graph-based execution order is enabled.- Returns:
- true if using topological execution order
-
setUseOptimizedExecution
public void setUseOptimizedExecution(boolean useOptimized) Sets whether to use optimized execution (parallel/hybrid) by default when run() is called.When enabled (default), run() automatically selects the best execution strategy:
- For processes WITHOUT recycles: parallel execution for maximum speed (28-57% faster)
- For processes WITH recycles: hybrid execution - parallel for feed-forward sections, then iterative for recycle sections (28-38% faster)
When disabled, run() uses sequential execution in insertion order (legacy behavior). This may be useful for debugging or when deterministic single-threaded execution is required.
- Parameters:
useOptimized- true to use optimized execution (default), false for sequential execution
-
isUseOptimizedExecution
public boolean isUseOptimizedExecution()Returns whether optimized execution is enabled.When true (default), run() delegates to runOptimized() which automatically selects the best execution strategy based on process topology.
- Returns:
- true if optimized execution is enabled
-
getTopologicalOrder
Gets the calculation order derived from process topology.This method returns units in the order they should be calculated based on stream connections, not the order they were added to the ProcessSystem. This is safer than relying on insertion order, which can lead to wrong results if units are rearranged or recycles are added late.
- Returns:
- list of equipment in topology-derived calculation order
-
hasRecycleLoops
public boolean hasRecycleLoops()Checks if the process has recycle loops that require iterative solving.- Returns:
- true if the process contains cycles (recycles)
-
getParallelLevelCount
public int getParallelLevelCount()Gets the number of levels for parallel execution.Units at the same level have no dependencies on each other and can be executed in parallel.
- Returns:
- number of parallel execution levels
-
getMaxParallelism
public int getMaxParallelism()Gets the maximum parallelism (max units that can run simultaneously).- Returns:
- maximum number of units that can execute in parallel
-
validateStructure
-
getGraphSummary
Gets a summary of the process graph structure.- Returns:
- summary string with node/edge counts, cycles, parallelism info
-
getRecycleBlocks
Gets the strongly connected components (SCCs) in the process graph.SCCs with more than one unit represent recycle loops that require iterative convergence. This method uses Tarjan's algorithm to identify these components.
- Returns:
- list of SCCs, each containing a list of equipment in that component
-
getRecycleBlockCount
public int getRecycleBlockCount()Gets the number of recycle blocks (cycles) in the process.- Returns:
- number of strongly connected components with more than one unit
-
isInRecycleLoop
Checks if a specific unit is part of a recycle loop.- Parameters:
unit- the unit to check- Returns:
- true if the unit is in a recycle block
-
getRecycleBlockReport
Gets a diagnostic report of recycle blocks for debugging.- Returns:
- formatted string describing each recycle block
-
exportState
Exports the current state of this process system for checkpointing or versioning.This method captures all equipment states, fluid compositions, and operating conditions into a serializable format that can be saved to disk, stored in a database, or used for model versioning in digital twin applications.
Example usage:
ProcessSystem system = new ProcessSystem(); // ... configure and run ... ProcessSystemState state = system.exportState(); state.saveToFile("checkpoint_v1.json");- Returns:
- the current state as a serializable object
- See Also:
-
exportStateToFile
Exports the current state to a JSON file for versioning or backup.- Parameters:
filename- the file path to save the state
-
loadStateFromFile
Loads process state from a JSON file and applies it to this system.Note: This method updates equipment states but does not recreate equipment. The process structure must match the saved state.
- Parameters:
filename- the file path to load state from
-
saveToNeqsim
Saves this process system to a compressed .neqsim file using XStream serialization.This is the recommended format for production use, providing compact storage with full process state preservation. The file can be loaded with
loadFromNeqsim(String).Example usage:
ProcessSystem process = new ProcessSystem(); // ... configure and run ... process.saveToNeqsim("my_model.neqsim");- Parameters:
filename- the file path to save to (recommended extension: .neqsim)- Returns:
- true if save was successful, false otherwise
-
loadFromNeqsim
Loads a process system from a compressed .neqsim file.After loading, the process is automatically run to reinitialize calculations. This ensures the internal state is consistent.
Example usage:
ProcessSystem loaded = ProcessSystem.loadFromNeqsim("my_model.neqsim"); // Process is already run and ready to use Stream outlet = (Stream) loaded.getUnit("outlet");- Parameters:
filename- the file path to load from- Returns:
- the loaded ProcessSystem, or null if loading fails
-
saveAuto
Saves the current state to a file with automatic format detection.File format is determined by extension:
- .neqsim → XStream compressed XML (full serialization)
- .json → JSON state (lightweight, Git-friendly)
- other → Java binary serialization (legacy)
- Parameters:
filename- the file path to save to- Returns:
- true if save was successful
-
loadAuto
Loads a process system from a file with automatic format detection.File format is determined by extension:
- .neqsim → XStream compressed XML
- other → Java binary serialization (legacy)
- Parameters:
filename- the file path to load from- Returns:
- the loaded ProcessSystem, or null if loading fails
-
getEmissions
Calculates current emissions from all equipment in this process system.Tracks CO2-equivalent emissions from:
- Flares (combustion emissions)
- Furnaces and burners
- Compressors (electricity-based, using grid emission factor)
- Pumps (electricity-based)
- Heaters and coolers (if fuel-fired or electric)
Example usage:
ProcessSystem system = new ProcessSystem(); // ... configure and run ... EmissionsReport report = system.getEmissions(); System.out.println("Total CO2e: " + report.getTotalCO2e("kg/hr") + " kg/hr"); report.exportToCSV("emissions_report.csv");- Returns:
- emissions report with breakdown by equipment and category
- See Also:
-
getEmissions
Calculates emissions using a custom grid emission factor.Different regions have different electricity grid carbon intensities. Use this method to apply location-specific emission factors.
- Parameters:
gridEmissionFactor- kg CO2 per kWh of electricity (e.g., 0.05 for Norway, 0.4 for global average)- Returns:
- emissions report with equipment breakdown
-
getTotalCO2Emissions
public double getTotalCO2Emissions()Gets total CO2-equivalent emissions from this process in kg/hr.This is a convenience method for quick emission checks. For detailed breakdown, use
getEmissions().- Returns:
- total CO2e emissions in kg/hr
-
createBatchStudy
Creates a batch study builder for running parallel parameter studies on this process.Batch studies allow exploring the design space by running many variations of this process in parallel. Useful for concept screening, sensitivity analysis, and optimization.
Example usage:
BatchStudy study = system.createBatchStudy().addParameter("separator1", "pressure", 30.0, 50.0, 70.0) .addParameter("compressor1", "outletPressure", 80.0, 100.0, 120.0) .addObjective("totalPower", true) // minimize .withParallelism(4).build(); BatchStudyResult result = study.run();- Returns:
- a new batch study builder configured for this process
- See Also:
-
generateSafetyScenarios
Generates automatic safety scenarios based on equipment failure modes.This method analyzes the process structure and generates scenarios for common failure modes such as:
- Cooling system failure
- Valve stuck open/closed
- Compressor/pump trips
- Power failure
- Blocked outlets
Example usage:
List<ProcessSafetyScenario> scenarios = system.generateSafetyScenarios(); for (ProcessSafetyScenario scenario : scenarios) { scenario.applyTo(system.copy()); system.run(); // Check for dangerous conditions }- Returns:
- list of safety scenarios for this process
- See Also:
-
generateCombinationScenarios
Generates combination failure scenarios (multiple simultaneous failures).This is useful for analyzing cascading failures and common-cause scenarios.
- Parameters:
maxSimultaneousFailures- maximum number of failures to combine (2-3 recommended)- Returns:
- list of combination scenarios
-
toDOT
Exports the process as a DOT format diagram string.Generates a professional oil & gas style process flow diagram (PFD) following industry conventions:
- Gravity logic - Gas equipment at top, liquid at bottom
- Phase-aware styling - Streams colored by vapor/liquid fraction
- Separator semantics - Gas exits top, liquid exits bottom
- Equipment shapes matching P&ID symbols
Example usage:
String dot = process.toDOT(); Files.writeString(Path.of("process.dot"), dot); // Render with: dot -Tsvg process.dot -o process.svg- Returns:
- Graphviz DOT format string
- See Also:
-
toDOT
Exports the process as a DOT format diagram with specified detail level.- Parameters:
detailLevel- the level of detail to include (CONCEPTUAL, ENGINEERING, DEBUG)- Returns:
- Graphviz DOT format string
- See Also:
-
createDiagramExporter
Creates a diagram exporter for this process with full configuration options.Example usage:
process.createDiagramExporter().setTitle("Gas Processing Plant") .setDetailLevel(DiagramDetailLevel.ENGINEERING).setVerticalLayout(true) .exportSVG(Path.of("diagram.svg"));- Returns:
- a new ProcessDiagramExporter configured for this process
- See Also:
-
exportDiagramSVG
Exports the process diagram to SVG format.Requires Graphviz (dot) to be installed and available in PATH.
- Parameters:
path- the output file path- Throws:
IOException- if export fails
-
exportDiagramPNG
Exports the process diagram to PNG format.Requires Graphviz (dot) to be installed and available in PATH.
- Parameters:
path- the output file path- Throws:
IOException- if export fails
-
runAsTask()instead for better resource management.