Class ProcessGraphBuilder

java.lang.Object
neqsim.process.processmodel.graph.ProcessGraphBuilder

public final class ProcessGraphBuilder extends Object
Builder class for constructing a ProcessGraph from a ProcessSystem.

This class discovers stream connections between equipment units and produces an explicit graph structure that enables topology-based calculation order derivation.

Usage:

ProcessSystem system = ...;
ProcessGraph graph = ProcessGraphBuilder.buildGraph(system);

// Get calculation order derived from topology
List<ProcessEquipmentInterface> order = graph.getCalculationOrder();

// Partition for parallel execution
ProcessGraph.ParallelPartition partition = graph.partitionForParallelExecution();
Version:
1.0
Author:
NeqSim
  • Field Details

    • logger

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

      private static final Map<Class<?>,Method[]> PRODUCER_METHODS
    • CONSUMER_METHODS

      private static final Map<Class<?>,Method[]> CONSUMER_METHODS
    • INLET_FIELDS

      private static final Map<Class<?>,Field[]> INLET_FIELDS
  • Constructor Details

    • ProcessGraphBuilder

      private ProcessGraphBuilder()
  • Method Details

    • buildGraph

      public static ProcessGraph buildGraph(ProcessSystem system)
      Builds a process graph from a ProcessSystem.
      Parameters:
      system - the process system
      Returns:
      the constructed graph
    • collectSplitStreams

      private static void collectSplitStreams(ProcessEquipmentInterface unit, Map<Object, ProcessEquipmentInterface> streamToProducer)
      Collects split streams from a Splitter via reflection. Uses the splitStream field or getSplitStream(int) method.
      Parameters:
      unit - the splitter unit to collect streams from
      streamToProducer - map to store stream to producer associations
    • collectMixerInputStreamsAndCreateEdges

      private static void collectMixerInputStreamsAndCreateEdges(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer)
      Collects input streams from a Mixer and creates edges. Uses reflection since getStream(int) is not in MixerInterface.
      Parameters:
      unit - the mixer unit to collect streams from
      graph - the process graph to add edges to
      streamToProducer - map of stream to producer associations
    • findField

      private static Field findField(Class<?> clazz, String fieldName)
      Finds a field in the class hierarchy.
      Parameters:
      clazz - the class to search in (including superclasses)
      fieldName - the name of the field to find
      Returns:
      the Field object, or null if not found
    • collectPendingStreamsAndCreateEdges

      private static void collectPendingStreamsAndCreateEdges(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer)
      Creates edges from producers to a unit for any streams listed in the unit's pendingStreams field. Used by multi-stream heat exchangers (e.g., LNGHeatExchanger) that defer registering input streams until run().
      Parameters:
      unit - the process equipment unit holding the pendingStreams list
      graph - the process graph to add edges to
      streamToProducer - map of stream-to-producer relationships
    • collectDistillationFeedsAndCreateEdges

      private static void collectDistillationFeedsAndCreateEdges(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer)
      Creates edges from producers to a DistillationColumn for every feed stream attached to any tray (via getTray(n).addStream(..) or addFeedStream(..)). Each tray extends Mixer and holds its feeds in a streams ArrayList; we walk the column's trays list and read each tray's streams field via reflection.
      Parameters:
      unit - the DistillationColumn unit
      graph - the process graph to add edges to
      streamToProducer - map of stream-to-producer relationships
    • collectProducedStreams

      private static void collectProducedStreams(ProcessEquipmentInterface unit, Map<Object, ProcessEquipmentInterface> streamToProducer)
      Collects streams produced by a unit via common getter methods.
      Parameters:
      unit - the process equipment unit to analyze
      streamToProducer - map to store stream-to-producer relationships
    • getProducerMethods

      private static Method[] getProducerMethods(Class<?> cls)
      Returns the cached list of zero-argument methods on cls whose name classifies as a producer (outlet) and that return a StreamInterface (or array of StreamInterface). Computed once per Class.
      Parameters:
      cls - equipment class to inspect
      Returns:
      filtered producer methods for cls
    • collectConsumedStreamsAndCreateEdges

      private static void collectConsumedStreamsAndCreateEdges(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer)
      Collects streams consumed by a unit and creates edges.
      Parameters:
      unit - the process equipment unit to analyze
      graph - the process graph to add edges to
      streamToProducer - map of stream-to-producer relationships
    • getConsumerMethods

      private static Method[] getConsumerMethods(Class<?> cls)
      Returns the cached list of zero-argument methods on cls whose name classifies as a consumer (inlet) and that return a StreamInterface. Computed once per Class.
      Parameters:
      cls - equipment class to inspect
      Returns:
      filtered consumer methods for cls
    • scanFieldsForInletStreams

      private static void scanFieldsForInletStreams(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer, Set<Object> visited)
      Scans fields for inlet streams.
      Parameters:
      unit - the process equipment unit to scan
      graph - the process graph to add edges to
      streamToProducer - map of stream-to-producer relationships
      visited - set of already visited streams to avoid duplicates
    • getInletFields

      private static Field[] getInletFields(Class<?> cls)
      Returns the cached list of non-static declared fields (walking the class hierarchy up to Object) on cls whose name classifies as an inlet and whose type is either a StreamInterface or a MixerInterface. Fields are returned already made accessible. Computed once per Class.
      Parameters:
      cls - equipment class to inspect
      Returns:
      filtered inlet fields for cls
    • createEdgeFromProducer

      private static void createEdgeFromProducer(ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer, Object stream, ProcessEquipmentInterface consumer)
      Creates an edge from the producer of a stream to the consumer.
      Parameters:
      graph - the process graph to add the edge to
      streamToProducer - map of stream-to-producer relationships
      stream - the stream object connecting producer to consumer
      consumer - the consuming process equipment unit
    • invokeMethod

      private static Object invokeMethod(ProcessEquipmentInterface unit, Method method)
      Safely invokes a method on a process equipment unit.
      Parameters:
      unit - the process equipment instance to invoke the method on
      method - the method to invoke
      Returns:
      the result of the method invocation, or null if an exception occurs