Class ProcessGraphBuilder
java.lang.Object
neqsim.process.processmodel.graph.ProcessGraphBuilder
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.logging.log4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ProcessGraphbuildGraph(ProcessSystem system) Builds a process graph from a ProcessSystem.private static voidcollectConsumedStreamsAndCreateEdges(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer) Collects streams consumed by a unit and creates edges.private static voidcollectDistillationFeedsAndCreateEdges(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer) Creates edges from producers to a DistillationColumn for every feed stream attached to any tray (viagetTray(n).addStream(..)oraddFeedStream(..)).private static voidcollectMixerInputStreamsAndCreateEdges(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer) Collects input streams from a Mixer and creates edges.private static voidcollectPendingStreamsAndCreateEdges(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer) Creates edges from producers to a unit for any streams listed in the unit'spendingStreamsfield.private static voidcollectProducedStreams(ProcessEquipmentInterface unit, Map<Object, ProcessEquipmentInterface> streamToProducer) Collects streams produced by a unit via common getter methods.private static voidcollectSplitStreams(ProcessEquipmentInterface unit, Map<Object, ProcessEquipmentInterface> streamToProducer) Collects split streams from a Splitter via reflection.private static voidcreateEdgeFromProducer(ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer, Object stream, ProcessEquipmentInterface consumer) Creates an edge from the producer of a stream to the consumer.private static FieldFinds a field in the class hierarchy.private static Method[]getConsumerMethods(Class<?> cls) Returns the cached list of zero-argument methods onclswhose name classifies as a consumer (inlet) and that return a StreamInterface.private static Field[]getInletFields(Class<?> cls) Returns the cached list of non-static declared fields (walking the class hierarchy up toObject) onclswhose name classifies as an inlet and whose type is either aStreamInterfaceor aMixerInterface.private static Method[]getProducerMethods(Class<?> cls) Returns the cached list of zero-argument methods onclswhose name classifies as a producer (outlet) and that return a StreamInterface (or array of StreamInterface).private static ObjectinvokeMethod(ProcessEquipmentInterface unit, Method method) Safely invokes a method on a process equipment unit.private static voidscanFieldsForInletStreams(ProcessEquipmentInterface unit, ProcessGraph graph, Map<Object, ProcessEquipmentInterface> streamToProducer, Set<Object> visited) Scans fields for inlet streams.
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger logger -
PRODUCER_METHODS
-
CONSUMER_METHODS
-
INLET_FIELDS
-
-
Constructor Details
-
ProcessGraphBuilder
private ProcessGraphBuilder()
-
-
Method Details
-
buildGraph
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 fromstreamToProducer- 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 fromgraph- the process graph to add edges tostreamToProducer- map of stream to producer associations
-
findField
-
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'spendingStreamsfield. Used by multi-stream heat exchangers (e.g., LNGHeatExchanger) that defer registering input streams untilrun().- Parameters:
unit- the process equipment unit holding the pendingStreams listgraph- the process graph to add edges tostreamToProducer- 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 (viagetTray(n).addStream(..)oraddFeedStream(..)). Each tray extends Mixer and holds its feeds in astreamsArrayList; we walk the column'strayslist and read each tray'sstreamsfield via reflection.- Parameters:
unit- the DistillationColumn unitgraph- the process graph to add edges tostreamToProducer- 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 analyzestreamToProducer- map to store stream-to-producer relationships
-
getProducerMethods
Returns the cached list of zero-argument methods onclswhose 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 analyzegraph- the process graph to add edges tostreamToProducer- map of stream-to-producer relationships
-
getConsumerMethods
Returns the cached list of zero-argument methods onclswhose 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 scangraph- the process graph to add edges tostreamToProducer- map of stream-to-producer relationshipsvisited- set of already visited streams to avoid duplicates
-
getInletFields
Returns the cached list of non-static declared fields (walking the class hierarchy up toObject) onclswhose name classifies as an inlet and whose type is either aStreamInterfaceor aMixerInterface. 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 tostreamToProducer- map of stream-to-producer relationshipsstream- the stream object connecting producer to consumerconsumer- the consuming process equipment unit
-
invokeMethod
Safely invokes a method on a process equipment unit.- Parameters:
unit- the process equipment instance to invoke the method onmethod- the method to invoke- Returns:
- the result of the method invocation, or null if an exception occurs
-