Class DexpiSimulationBuilder

java.lang.Object
neqsim.process.processmodel.dexpi.DexpiSimulationBuilder

public class DexpiSimulationBuilder extends Object
High-level builder that converts a DEXPI P&ID XML file into a runnable NeqSim ProcessSystem.

Usage:

SystemInterface fluid = new SystemSrkEos(298.15, 50.0);
fluid.addComponent("methane", 0.9);
fluid.addComponent("ethane", 0.1);
fluid.setMixingRule("classic");

ProcessSystem process = new DexpiSimulationBuilder(new File("plant.xml")).setFluidTemplate(fluid)
    .setFeedPressure(50.0, "bara").setFeedTemperature(30.0, "C").setFeedFlowRate(1.0, "MSm3/day")
    .build();

process.run();

The builder performs these steps:

  1. Parse the DEXPI XML document securely (XXE protection)
  2. Resolve topology (nozzle/connection graph)
  3. Identify equipment and piping components with their sizing attributes
  4. Create a feed stream from the fluid template
  5. Walk the topology in upstream-to-downstream order, instantiating real NeqSim equipment via DexpiEquipmentFactory
  6. Wire outlet streams of upstream equipment to inlet of downstream equipment
  7. Optionally auto-instrument the process with transmitters and PID controllers
Version:
1.0
Author:
NeqSim
  • Field Details

    • logger

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

      private final File dexpiFile
    • fluidTemplate

      private SystemInterface fluidTemplate
    • feedPressure

      private double feedPressure
    • feedPressureUnit

      private String feedPressureUnit
    • feedTemperature

      private double feedTemperature
    • feedTemperatureUnit

      private String feedTemperatureUnit
    • feedFlowRate

      private double feedFlowRate
    • feedFlowRateUnit

      private String feedFlowRateUnit
    • autoInstrument

      private boolean autoInstrument
    • namespaceAware

      private boolean namespaceAware
  • Constructor Details

    • DexpiSimulationBuilder

      public DexpiSimulationBuilder(File dexpiFile)
      Creates a new simulation builder for the given DEXPI XML file.
      Parameters:
      dexpiFile - the DEXPI XML file to process
  • Method Details

    • setFluidTemplate

      public DexpiSimulationBuilder setFluidTemplate(SystemInterface fluidTemplate)
      Sets the thermodynamic fluid template to use for all streams. If not set, a default methane/ethane system with SRK EOS is used.
      Parameters:
      fluidTemplate - the fluid system to clone for each stream
      Returns:
      this builder for chaining
    • setFeedPressure

      public DexpiSimulationBuilder setFeedPressure(double pressure, String unit)
      Sets the feed stream pressure.
      Parameters:
      pressure - the pressure value
      unit - the pressure unit (e.g. "bara", "barg", "psia")
      Returns:
      this builder for chaining
    • setFeedTemperature

      public DexpiSimulationBuilder setFeedTemperature(double temperature, String unit)
      Sets the feed stream temperature.
      Parameters:
      temperature - the temperature value
      unit - the temperature unit (e.g. "C", "K", "F")
      Returns:
      this builder for chaining
    • setFeedFlowRate

      public DexpiSimulationBuilder setFeedFlowRate(double flowRate, String unit)
      Sets the feed stream flow rate.
      Parameters:
      flowRate - the flow rate value
      unit - the flow rate unit (e.g. "MSm3/day", "kg/hr")
      Returns:
      this builder for chaining
    • setAutoInstrument

      public DexpiSimulationBuilder setAutoInstrument(boolean autoInstrument)
      Enables automatic instrumentation (transmitters and PID controllers) on separators, compressors, and heat exchangers.
      Parameters:
      autoInstrument - true to enable auto-instrumentation
      Returns:
      this builder for chaining
    • setNamespaceAware

      public DexpiSimulationBuilder setNamespaceAware(boolean namespaceAware)
      Enables namespace-aware XML parsing. When enabled, the parser will respect namespace prefixes in element names. By default, namespace awareness is disabled for compatibility with DEXPI files that may use local names without namespace declarations.
      Parameters:
      namespaceAware - true to enable namespace-aware parsing
      Returns:
      this builder for chaining
    • build

      Builds the NeqSim ProcessSystem from the DEXPI XML file.
      Returns:
      a fully wired ProcessSystem ready for process.run()
      Throws:
      IOException - if the file cannot be read
      DexpiXmlReaderException - if the XML cannot be parsed
    • buildUnitMap

      private Map<String, DexpiProcessUnit> buildUnitMap(Document document, DexpiTopologyResolver.ResolvedTopology topology)
      Builds a map of equipment ID to DexpiProcessUnit with sizing attributes populated.
      Parameters:
      document - the parsed XML document
      topology - the resolved topology
      Returns:
      map of equipment ID to DexpiProcessUnit
    • getOutletStream

      private StreamInterface getOutletStream(ProcessEquipmentInterface equipment)
      Gets the outlet stream from a process equipment instance.
      Parameters:
      equipment - the equipment
      Returns:
      the outlet stream, or null if not available
    • applyAutoInstrumentation

      private void applyAutoInstrumentation(ProcessSystem processSystem, List<DexpiInstrumentInfo> dexpiInstruments)
      Applies auto-instrumentation using the DynamicProcessHelper, then logs associations between DEXPI instrument tags and auto-generated transmitters/controllers.
      Parameters:
      processSystem - the process system to instrument
      dexpiInstruments - the DEXPI instrument info list (may be empty)
    • parseDexpiInstruments

      private List<DexpiInstrumentInfo> parseDexpiInstruments(Document document)
      Parses DEXPI instrument info from the XML document.
      Parameters:
      document - the parsed XML document
      Returns:
      list of DEXPI instrument info records (may be empty)
    • getOrCreateFluidTemplate

      private SystemInterface getOrCreateFluidTemplate()
      Returns the fluid template, creating a default if none was set.
      Returns:
      the fluid template
    • parseDocument

      private static Document parseDocument(InputStream inputStream, boolean nsAware) throws DexpiXmlReaderException
      Parses a DEXPI XML document with security hardening.
      Parameters:
      inputStream - the input stream
      nsAware - whether to enable namespace-aware parsing
      Returns:
      the parsed Document
      Throws:
      DexpiXmlReaderException - if parsing fails
    • getGenericAttribute

      private static String getGenericAttribute(Element element, String attributeName)
      Reads a GenericAttribute value from the given element.
      Parameters:
      element - the XML element
      attributeName - the attribute name to search for
      Returns:
      the attribute value, or null if not found