Class JsonProcessExporter

java.lang.Object
neqsim.process.processmodel.JsonProcessExporter

public class JsonProcessExporter extends Object
Exports a ProcessSystem to the JSON schema consumed by JsonProcessBuilder.

The exported JSON is round-trippable: ProcessSystem -> toJson() -> JsonProcessBuilder -> ProcessSystem. Streams are serialized first, followed by equipment in topological order. Each equipment unit references its inlet stream(s) by name using dot-notation for specific outlet ports (e.g. "HP Sep.gasOut").

Version:
1.0
Author:
Even Solbraa
  • Field Details

  • Constructor Details

    • JsonProcessExporter

      public JsonProcessExporter()
  • Method Details

    • toJson

      public String toJson(ProcessSystem process)
      Exports a ProcessSystem to a JSON string that can be consumed by JsonProcessBuilder.build(String).
      Parameters:
      process - the process system to export
      Returns:
      JSON string in the JsonProcessBuilder schema
    • toJson

      public String toJson(ProcessSystem process, boolean prettyPrint)
      Exports a ProcessSystem to a JSON string.
      Parameters:
      process - the process system to export
      prettyPrint - whether to format the JSON with indentation
      Returns:
      JSON string in the JsonProcessBuilder schema
    • toJsonObject

      public com.google.gson.JsonObject toJsonObject(ProcessSystem process)
      Exports a ProcessSystem to a JsonObject.
      Parameters:
      process - the process system to export
      Returns:
      JsonObject in the JsonProcessBuilder schema
    • buildStreamRefMap

      private void buildStreamRefMap(List<ProcessEquipmentInterface> units)
      Builds a mapping from stream object identity to string reference. Feed streams (top-level Stream objects) map to their name. Outlet streams from equipment map to "equipmentName.portName".
      Parameters:
      units - the ordered list of unit operations
    • mapOutletStreams

      private void mapOutletStreams(ProcessEquipmentInterface unit)
      Maps outlet streams of an equipment unit to their reference strings.
      Parameters:
      unit - the equipment unit
    • findFeedFluid

      private SystemInterface findFeedFluid(List<ProcessEquipmentInterface> units)
      Finds the first feed stream's fluid for the fluid section.
      Parameters:
      units - the ordered list of unit operations
      Returns:
      the fluid from the first Stream, or null
    • exportFluid

      private com.google.gson.JsonObject exportFluid(SystemInterface fluid)
      Exports a fluid (SystemInterface) to a JSON object matching the JsonProcessBuilder schema.

      For characterized (TBP/plus) fractions, exports critical properties (Tc, Pc, acentric factor, molar mass, density) so the fluid can be reconstructed without the original E300/PVT source file. Binary interaction parameters (BICs) are exported when any non-zero value is present.

      Parameters:
      fluid - the fluid to export
      Returns:
      JsonObject with model, temperature, pressure, mixingRule, components, and optionally characterizedComponents and binaryInteractionParameters
    • exportBinaryInteractionParameters

      private void exportBinaryInteractionParameters(com.google.gson.JsonObject fluidJson, SystemInterface fluid)
      Exports binary interaction parameters (kij) from the fluid's mixing rule. Only exports non-zero BICs to keep the JSON compact. The builder uses these to override the default database BICs when reconstructing the fluid.
      Parameters:
      fluidJson - the fluid JSON object to add BICs to
      fluid - the fluid system
    • mapModelName

      private String mapModelName(String modelName)
      Maps internal NeqSim model names to the short identifiers used by JsonProcessBuilder.
      Parameters:
      modelName - the internal model name (e.g. "SRK-EOS")
      Returns:
      short identifier (e.g. "SRK")
    • exportUnit

      private com.google.gson.JsonObject exportUnit(ProcessEquipmentInterface unit)
      Exports a single equipment unit to a JSON object.
      Parameters:
      unit - the equipment to export
      Returns:
      JsonObject describing the unit, or null if the unit should be skipped
    • getTypeName

      private String getTypeName(ProcessEquipmentInterface unit)
      Gets the type name string for an equipment unit matching the JsonProcessBuilder type names.
      Parameters:
      unit - the equipment
      Returns:
      the type name string
    • exportStreamProperties

      private void exportStreamProperties(com.google.gson.JsonObject json, StreamInterface stream)
      Exports Stream-specific properties: flowRate, temperature, pressure.
      Parameters:
      json - the unit JSON object to populate
      stream - the stream to export
    • exportMixerInlets

      private void exportMixerInlets(com.google.gson.JsonObject json, Mixer mixer)
      Exports Mixer inlets as an "inlets" array.
      Parameters:
      json - the unit JSON object
      mixer - the mixer
    • exportHeatExchangerInlets

      private void exportHeatExchangerInlets(com.google.gson.JsonObject json, HeatExchanger hx)
      Exports HeatExchanger inlets as an "inlets" array (shell-side + tube-side).
      Parameters:
      json - the unit JSON object
      hx - the heat exchanger
    • exportProperties

      private com.google.gson.JsonObject exportProperties(ProcessEquipmentInterface unit)
      Exports equipment-specific design properties (outlet pressure, efficiency, split factors etc.).
      Parameters:
      unit - the equipment
      Returns:
      JsonObject with properties, or null if no properties to export