Class ProcessModule

All Implemented Interfaces:
Serializable, Runnable, SimulationInterface, NamedInterface

public class ProcessModule extends SimulationBaseClass
A class representing a process module class that can contain unit operations and other modules. Module will be runnning until all recycles in this module are solved. If no recycle in the module then run only once.
Version:
1.0
Author:
[seros]
See Also:
  • Field Details

    • serialVersionUID

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

      private static final org.apache.logging.log4j.Logger logger
    • unitIndex

      private int unitIndex
    • recycleModules

      private final List<ProcessEquipmentInterface> recycleModules
    • addedUnitOperations

      private List<ProcessSystem> addedUnitOperations
    • operationsIndex

      private List<Integer> operationsIndex
    • addedModules

      private List<ProcessModule> addedModules
    • modulesIndex

      private List<Integer> modulesIndex
    • solved

      private boolean solved
    • progressListener

      private transient ProcessSystem.SimulationProgressListener progressListener
      Transient listener for simulation progress callbacks. Propagated to all child ProcessSystems.
  • Constructor Details

    • ProcessModule

      public ProcessModule(String name)
      Constructor that takes a name as a parameter.
      Parameters:
      name - the name of the process module
  • Method Details

    • add

      public void add(ProcessSystem processSystem)
      Add an unit operation to the process module.
      Parameters:
      processSystem - the process system that contains the unit operations to be added.
    • add

      public void add(ProcessModule module)
      Add a process module to the process module.
      Parameters:
      module - the process module to be added
    • getAddedUnitOperations

      public List<ProcessSystem> getAddedUnitOperations()
      Get the list of added unit operations.
      Returns:
      the list of added unit operations
    • getOperationsIndex

      public List<Integer> getOperationsIndex()
      Get the list of operations index. The operations index is used to follow the correct order of calculations.
      Returns:
      the list of operations index
    • getAddedModules

      public List<ProcessModule> getAddedModules()
      Get the list of added process modules.
      Returns:
      the list of added process modules
    • getAllProcessSystems

      public List<ProcessSystem> getAllProcessSystems()
      Get all ProcessSystem instances from this module and all nested modules recursively.
      Returns:
      list of all ProcessSystem instances in the module hierarchy
    • getModulesIndex

      public List<Integer> getModulesIndex()
      Get the list of module index. The module index is used to follow the correct order of calculations.
      Returns:
      the list of module index
    • setProgressListener

      public void setProgressListener(ProcessSystem.SimulationProgressListener listener)
      Set a listener to receive progress updates during simulation. The listener is propagated to all contained ProcessSystem instances.
      Parameters:
      listener - the progress listener, or null to disable callbacks
    • getProgressListener

      public ProcessSystem.SimulationProgressListener getProgressListener()
      Get the current progress listener.
      Returns:
      the current listener, or null if none is set
    • runWithCallback

      public void runWithCallback(Consumer<ProcessEquipmentInterface> callback)
      Run module with a simple callback for each completed unit operation. This is a convenience method for Python/Jupyter integration.
      Parameters:
      callback - Consumer function called with each completed unit operation
    • run

      public void run(UUID id)

      In this method all thermodynamic and unit operations will be calculated in a steady state calculation.

      Parameters:
      id - UUID
    • checkModulesRecycles

      public void checkModulesRecycles()
      Adds all recycle operations from addedUnitOperations to recycleModules list.
    • recyclesSolved

      public boolean recyclesSolved()
      Checks if all recycle operations in recycleModules are solved.
      Returns:
      true if all recycle operations are solved, false otherwise
    • solved

      public boolean solved()

      Returns whether or not the module has been solved.

      Returns:
      a boolean
    • runAsTask

      public Future<?> runAsTask()
      Runs this module in a separate thread using the global NeqSim thread pool.

      This method submits the module to the shared NeqSimThreadPool and returns a Future that can be used to monitor completion, cancel the task, or retrieve any exceptions that occurred.

      Returns:
      a Future representing the pending completion of the task
      See Also:
    • runAsThread

      @Deprecated public Thread runAsThread()
      Deprecated.
      Use runAsTask() instead for better resource management. This method creates a new unmanaged thread directly.

      runAsThread.

      Returns:
      a Thread object
    • getUnit

      public Object getUnit(String name)
      Returns the unit with the given name from the list of added unit operations and list of added modules.
      Parameters:
      name - the name of the unit to retrieve
      Returns:
      the unit with the given name, or null if no such unit is found
    • getMeasurementDevice

      public Object getMeasurementDevice(String name)
      Returns the unit with the given name from the list of added unit operations and list of added modules.
      Parameters:
      name - the name of the unit to retrieve
      Returns:
      the unit with the given name, or null if no such unit is found
    • copy

      public ProcessModule copy()

      Create deep copy.

      Returns:
      a ProcessModule object
    • getReport

      public ArrayList<String[]> getReport()

      getReport.

      Returns:
      a ArrayList object
    • checkMassBalance

      public Map<String, ProcessSystem.MassBalanceResult> checkMassBalance(String unit)
      Check mass balance of all unit operations in all process systems within this module.
      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

      public Map<String, ProcessSystem.MassBalanceResult> checkMassBalance()
      Check mass balance of all unit operations in all process systems 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

      public Map<String, ProcessSystem.MassBalanceResult> getFailedMassBalance()
      Get unit operations that failed mass balance check using kg/sec and 0.1% threshold.
      Returns:
      a map with failed unit operation names and their mass balance results
    • getFailedMassBalance

      public Map<String, ProcessSystem.MassBalanceResult> getFailedMassBalance(double percentThreshold)
      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
    • getReport_json

      public String getReport_json()

      getReport_json.

      Return results of simulation in json format
      Returns:
      a String
    • run_step

      public void run_step(UUID id)

      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.
    • buildModelGraph

      public ProcessModelGraph buildModelGraph()
      Builds a graph representation of this module and all its sub-systems.

      The returned ProcessModelGraph contains:

      • Individual graphs for each ProcessSystem
      • A unified flattened graph for the entire module
      • Information about inter-system connections
      Returns:
      the graph representation of this module
    • getCalculationOrder

      public List<ProcessEquipmentInterface> getCalculationOrder()
      Gets the topologically-sorted calculation order for all equipment in this module.

      This order respects stream dependencies across all sub-systems.

      Returns:
      list of equipment in calculation order, or null if cycles prevent ordering
    • hasRecycleLoops

      public boolean hasRecycleLoops()
      Checks if this module (or any sub-system) contains recycle loops.
      Returns:
      true if cycles exist
    • getSubSystemCount

      public int getSubSystemCount()
      Gets the number of sub-systems in this module.
      Returns:
      number of ProcessSystems and nested ProcessModules
    • getGraphSummary

      public String getGraphSummary()
      Gets a summary of the module's graph structure.
      Returns:
      human-readable summary string
    • validateStructure

      public List<String> validateStructure()
      Validates the structural integrity of this module.
      Returns:
      list of validation issues, empty if valid
    • getConstrainedEquipment

      public List<CapacityConstrainedEquipment> getConstrainedEquipment()
      Gets all capacity-constrained equipment in this module and all nested modules/systems.

      Returns equipment that implements the CapacityConstrainedEquipment interface, such as separators, compressors, pumps, pipelines, manifolds, etc.

      Returns:
      list of capacity-constrained equipment from all systems in this module
    • findBottleneck

      public BottleneckResult findBottleneck()
      Finds the process bottleneck with detailed constraint information across all systems.

      This method searches all ProcessSystems and nested ProcessModules to find the equipment with the highest capacity utilization.

      Returns:
      BottleneckResult containing the bottleneck equipment, limiting constraint, and utilization; returns empty result if no constrained equipment found
    • isAnyEquipmentOverloaded

      public boolean isAnyEquipmentOverloaded()
      Checks if any equipment in this module is overloaded (exceeds design capacity).
      Returns:
      true if any equipment has capacity utilization above 100%
    • isAnyHardLimitExceeded

      public boolean isAnyHardLimitExceeded()
      Checks if any equipment exceeds a HARD capacity limit.

      HARD limits represent absolute equipment limits that cannot be exceeded without trip or damage, such as maximum compressor speed or surge limits.

      Returns:
      true if any HARD constraint is exceeded
    • getCapacityUtilizationSummary

      public Map<String,Double> getCapacityUtilizationSummary()
      Gets a summary of capacity utilization for all constrained equipment in this module.

      Returns a map of equipment names to their maximum constraint utilization. Useful for displaying overall module capacity status.

      Returns:
      map of equipment name to utilization percentage
    • getEquipmentNearCapacityLimit

      public List<String> getEquipmentNearCapacityLimit()
      Gets equipment that is near its capacity limit (above warning threshold).

      Returns equipment where at least one constraint is above its warning threshold (typically 90% of design). Useful for identifying potential future bottlenecks.

      Returns:
      list of equipment names that are near capacity limits