Class JsonProcessBuilder

java.lang.Object
neqsim.process.processmodel.JsonProcessBuilder

public class JsonProcessBuilder extends Object
Builds a ProcessSystem from a JSON definition string.

Supports declarative definition of fluids, streams, and equipment with automatic stream wiring by name reference. Designed for web API integration where clients submit JSON process definitions and receive simulation results.

JSON Format:

{ "fluid": { "model": "SRK", "temperature": 298.15, "pressure": 50.0, "mixingRule":
"classic", "components": { "methane": 0.85, "ethane": 0.10, "propane": 0.05 } }, "process": [ {
"type": "Stream", "name": "feed", "properties": { "flowRate": [50000.0, "kg/hr"] } }, { "type":
"Separator", "name": "HP Sep", "inlet": "feed" }, { "type": "Compressor", "name": "Comp",
"inlet": "HP Sep.gasOut", "properties": { "outletPressure": [80.0, "bara"] } } ] } 
Author:
Even Solbraa @version 1.0
  • Field Details

    • logger

      private static final org.apache.logging.log4j.Logger logger
      Logger object for class.
    • namedFluids

      private final Map<String, SystemInterface> namedFluids
      Registry of named fluids created during build.
    • namedEquipment

      private final Map<String, ProcessEquipmentInterface> namedEquipment
      Registry of named equipment created during build.
    • errors

      private final List<SimulationResult.ErrorDetail> errors
      Errors accumulated during build.
    • warnings

      private final List<String> warnings
      Warnings accumulated during build.
  • Constructor Details

    • JsonProcessBuilder

      public JsonProcessBuilder()
      Constructs a new JsonProcessBuilder.
  • Method Details

    • build

      public SimulationResult build(String json)
      Builds a ProcessSystem from a JSON string.
      Parameters:
      json - the JSON process definition
      Returns:
      a SimulationResult containing the built ProcessSystem or errors
    • buildFromJsonObject

      public SimulationResult buildFromJsonObject(com.google.gson.JsonObject root)
      Builds a ProcessSystem from a parsed JsonObject.
      Parameters:
      root - the root JSON object
      Returns:
      a SimulationResult containing the built ProcessSystem or errors
    • buildFluid

      private SystemInterface buildFluid(com.google.gson.JsonObject fluidDef)
      Builds a fluid (SystemInterface) from a JSON definition.
      Parameters:
      fluidDef - the JSON object defining the fluid
      Returns:
      the created fluid, or null if creation failed
    • createFluidByModel

      private SystemInterface createFluidByModel(String model, double temperature, double pressure)
      Creates a SystemInterface based on the model type string.
      Parameters:
      model - the model name (e.g., "SRK", "PR", "CPA")
      temperature - temperature in Kelvin
      pressure - pressure in bara
      Returns:
      the created fluid system, or null if unknown model
    • buildUnit

      private void buildUnit(ProcessSystem process, com.google.gson.JsonObject unitDef, SystemInterface defaultFluid, int index)
      Builds a single process unit from its JSON definition and adds it to the process.
      Parameters:
      process - the process system to add the unit to
      unitDef - the JSON object defining the unit
      defaultFluid - the default fluid to use for streams
      index - the unit index (for error reporting)
    • createAndWireUnit

      private ProcessEquipmentInterface createAndWireUnit(ProcessSystem process, String type, String name, com.google.gson.JsonObject unitDef, SystemInterface defaultFluid)
      Creates a unit and wires its inlet stream based on the JSON definition.
      Parameters:
      process - the process system
      type - the equipment type
      name - the equipment name
      unitDef - the JSON definition
      defaultFluid - the default fluid
      Returns:
      the created equipment, or null if creation failed
    • createStream

      private ProcessEquipmentInterface createStream(String name, com.google.gson.JsonObject unitDef, SystemInterface defaultFluid)
      Creates a Stream from its JSON definition.
      Parameters:
      name - the stream name
      unitDef - the JSON definition
      defaultFluid - the default fluid
      Returns:
      the created stream
    • resolveStreamReference

      private StreamInterface resolveStreamReference(String ref)
      Resolves a stream reference string to an actual StreamInterface.

      Supports the following reference formats:

      • "unitName" — resolves to the default outlet stream
      • "unitName.gasOut" — resolves to gas outlet of a separator
      • "unitName.liquidOut" — resolves to liquid outlet of a separator
      • "unitName.outlet" — resolves to the outlet stream
      Parameters:
      ref - the stream reference string
      Returns:
      the resolved stream, or null if not found
    • wireInletStream

      private void wireInletStream(ProcessEquipmentInterface equipment, StreamInterface stream)
      Wires an inlet stream to an equipment unit via reflection.
      Parameters:
      equipment - the equipment to wire
      stream - the inlet stream
    • applyProperties

      private void applyProperties(ProcessEquipmentInterface equipment, com.google.gson.JsonObject properties)
      Applies property settings from JSON to an equipment unit via reflection.
      Parameters:
      equipment - the equipment to configure
      properties - the properties JSON object
    • applyProperty

      private void applyProperty(ProcessEquipmentInterface equipment, String propName, com.google.gson.JsonElement value)
      Applies a single property to an equipment unit.
      Parameters:
      equipment - the equipment
      propName - the property name
      value - the property value
    • buildAndRun

      public static SimulationResult buildAndRun(String json)
      Convenience method to build and run a process from JSON.
      Parameters:
      json - the JSON process definition
      Returns:
      the simulation result with report
    • buildOnly

      public static SimulationResult buildOnly(String json)
      Convenience method to build (without running) a process from JSON.
      Parameters:
      json - the JSON process definition
      Returns:
      the simulation result with the ProcessSystem