Class JsonProcessBuilder
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final List<SimulationResult.ErrorDetail> Errors accumulated during build.private static final org.apache.logging.log4j.LoggerLogger object for class.private final Map<String, ProcessEquipmentInterface> Registry of named equipment created during build.private final Map<String, SystemInterface> Registry of named fluids created during build.Warnings accumulated during build. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidapplyEntrainment(Separator separator, com.google.gson.JsonElement entrainmentElement) Applies entrainment specifications to a separator from a JSON array.private voidapplyMechanicalDesignProperties(ProcessEquipmentInterface equipment, com.google.gson.JsonObject mdProps) private voidapplyProperties(ProcessEquipmentInterface equipment, com.google.gson.JsonObject properties) Applies property settings from JSON to an equipment unit via reflection.private voidapplyProperty(ProcessEquipmentInterface equipment, String propName, com.google.gson.JsonElement value) Applies a single property to an equipment unit.private voidapplyPropertyObject(Object target, String targetName, String propName, com.google.gson.JsonElement value) Builds a ProcessSystem from a JSON string.static SimulationResultbuildAndRun(String json) Convenience method to build and run a process from JSON.static SimulationResultbuildAndRun(String json, SystemInterface fluid) Convenience method to build and run a process from JSON with a pre-built fluid.private SystemInterfacebuildFluid(com.google.gson.JsonObject fluidDef) Builds a fluid (SystemInterface) from a JSON definition.buildFromJsonObject(com.google.gson.JsonObject root) Builds a ProcessSystem from a parsed JsonObject.buildFromJsonObject(com.google.gson.JsonObject root, SystemInterface preBuiltFluid) Builds a ProcessSystem from a parsed JsonObject, optionally with a pre-built fluid.static SimulationResultConvenience method to build (without running) a process from JSON.private voidbuildUnit(ProcessSystem process, com.google.gson.JsonObject unitDef, SystemInterface defaultFluid, int index) Deprecated.Use createUnit + wireUnit two-pass approach insteadprivate ProcessEquipmentInterfacecreateAndWireUnit(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.private ProcessEquipmentInterfacecreateDistillationColumn(String name, com.google.gson.JsonObject unitDef) Creates a DistillationColumn from its JSON definition, extracting tray count and condenser/reboiler flags from properties.private SystemInterfacecreateFluidByModel(String model, double temperature, double pressure) Creates a SystemInterface based on the model type string.private ProcessEquipmentInterfacecreateStream(String name, com.google.gson.JsonObject unitDef, SystemInterface defaultFluid) Creates a Stream from its JSON definition.private voidcreateUnit(ProcessSystem process, com.google.gson.JsonObject unitDef, SystemInterface defaultFluid, int index) Pass 1: Creates a unit (no wiring) and registers it.private voidinvokeNoArg(Object target, String targetName, String methodName) private booleanneedsWiring(com.google.gson.JsonObject unitDef) Checks whether a unit definition needs inlet wiring.private voidreportUnwiredUnit(String name, com.google.gson.JsonObject unitDef) Reports an unwired unit as a warning (not a hard error).private StreamInterfaceResolves a stream reference string to an actual StreamInterface.private booleantryWireUnit(String name, com.google.gson.JsonObject unitDef) Attempts to wire all inlet references for a unit.private voidwireAdjuster(Adjuster adjuster, com.google.gson.JsonObject props) Wires an Adjuster's adjusted and target variables from JSON properties.private voidwireInletStream(ProcessEquipmentInterface equipment, StreamInterface stream) Wires an inlet stream to an equipment unit via reflection.private voidPass 2: Wires inlet connections for a unit (all units now exist).
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger loggerLogger object for class. -
namedFluids
Registry of named fluids created during build. -
namedEquipment
Registry of named equipment created during build. -
errors
Errors accumulated during build. -
warnings
-
-
Constructor Details
-
JsonProcessBuilder
public JsonProcessBuilder()Constructs a new JsonProcessBuilder.
-
-
Method Details
-
build
Builds a ProcessSystem from a JSON string.- Parameters:
json- the JSON process definition- Returns:
- a SimulationResult containing the built ProcessSystem or errors
-
buildFromJsonObject
Builds a ProcessSystem from a parsed JsonObject.- Parameters:
root- the root JSON object- Returns:
- a SimulationResult containing the built ProcessSystem or errors
-
buildFromJsonObject
public SimulationResult buildFromJsonObject(com.google.gson.JsonObject root, SystemInterface preBuiltFluid) Builds a ProcessSystem from a parsed JsonObject, optionally with a pre-built fluid.When
preBuiltFluidis non-null, it is used as the default fluid for all streams instead of parsing the 'fluid' section from JSON. This is the recommended path when importing fluids from external sources (e.g., Eclipse E300 files) that preserve all component critical properties and BIPs.- Parameters:
root- the root JSON objectpreBuiltFluid- optional pre-built fluid system (null to use JSON fluid section)- Returns:
- a SimulationResult containing the built ProcessSystem or errors
-
buildFluid
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
Creates a SystemInterface based on the model type string.- Parameters:
model- the model name (e.g., "SRK", "PR", "CPA")temperature- temperature in Kelvinpressure- pressure in bara- Returns:
- the created fluid system, or null if unknown model
-
createUnit
private void createUnit(ProcessSystem process, com.google.gson.JsonObject unitDef, SystemInterface defaultFluid, int index) Pass 1: Creates a unit (no wiring) and registers it.- Parameters:
process- the process systemunitDef- the JSON definitiondefaultFluid- the default fluidindex- the unit index
-
createDistillationColumn
private ProcessEquipmentInterface createDistillationColumn(String name, com.google.gson.JsonObject unitDef) Creates a DistillationColumn from its JSON definition, extracting tray count and condenser/reboiler flags from properties.- Parameters:
name- the column nameunitDef- the JSON definition- Returns:
- the created DistillationColumn
-
reportUnwiredUnit
Reports an unwired unit as a warning (not a hard error). Extracts reference details so the user knows which connections could not be resolved.- Parameters:
name- the unit nameunitDef- the JSON definition
-
wireUnit
Pass 2: Wires inlet connections for a unit (all units now exist).- Parameters:
name- the unit nameunitDef- the JSON definition
-
needsWiring
private boolean needsWiring(com.google.gson.JsonObject unitDef) Checks whether a unit definition needs inlet wiring.- Parameters:
unitDef- the JSON definition- Returns:
- true if the unit has inlet references that need to be resolved
-
tryWireUnit
Attempts to wire all inlet references for a unit. Returns true only if ALL references resolve successfully, allowing downstream units to use this unit's outlets. Does not add error details on failure (those are added by the fallback wireUnit call).- Parameters:
name- the unit nameunitDef- the JSON definition- Returns:
- true if all inlet references resolved and were wired
-
buildUnit
@Deprecated private void buildUnit(ProcessSystem process, com.google.gson.JsonObject unitDef, SystemInterface defaultFluid, int index) Deprecated.Use createUnit + wireUnit two-pass approach insteadBuilds a single process unit from its JSON definition and adds it to the process.- Parameters:
process- the process system to add the unit tounitDef- the JSON object defining the unitdefaultFluid- the default fluid to use for streamsindex- 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 systemtype- the equipment typename- the equipment nameunitDef- the JSON definitiondefaultFluid- 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 nameunitDef- the JSON definitiondefaultFluid- the default fluid- Returns:
- the created stream
-
resolveStreamReference
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
Wires an inlet stream to an equipment unit via reflection.- Parameters:
equipment- the equipment to wirestream- 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 configureproperties- the properties JSON object
-
applyMechanicalDesignProperties
private void applyMechanicalDesignProperties(ProcessEquipmentInterface equipment, com.google.gson.JsonObject mdProps) -
wireAdjuster
Wires an Adjuster's adjusted and target variables from JSON properties.The Adjuster modifies one equipment property (adjusted variable) to achieve a target value on another equipment property (target variable). JSON format:
"properties": { "adjustedEquipment": "Valve-1", "adjustedVariable": "pressure", "targetEquipment": "Stream-Out", "targetVariable": "temperature", "targetValue": 298.15, "tolerance": 0.01, "stepSize": 0.5 }- Parameters:
adjuster- the adjuster to configureprops- the properties JSON object
-
applyEntrainment
Applies entrainment specifications to a separator from a JSON array.Each array element is an object with keys: value, specType, specifiedStream, phaseFrom, phaseTo. These map directly to
Separator.setEntrainment(double, String, String, String, String).- Parameters:
separator- the separator to configureentrainmentElement- the JSON element (expected to be a JsonArray)
-
applyProperty
private void applyProperty(ProcessEquipmentInterface equipment, String propName, com.google.gson.JsonElement value) Applies a single property to an equipment unit.- Parameters:
equipment- the equipmentpropName- the property namevalue- the property value
-
applyPropertyObject
-
invokeNoArg
-
buildAndRun
Convenience method to build and run a process from JSON.- Parameters:
json- the JSON process definition- Returns:
- the simulation result with report
-
buildAndRun
Convenience method to build and run a process from JSON with a pre-built fluid.This overload is used when the fluid has been loaded from an external source (e.g., an Eclipse E300 file via
EclipseFluidReadWrite) and should be used instead of the fluid definition in the JSON. The pre-built fluid preserves all critical properties (Tc, Pc, acentric factor, MW, BIPs) for both standard and hypothetical/pseudo components.- Parameters:
json- the JSON process definition (the 'fluid' section is ignored)fluid- the pre-built thermodynamic system to use- Returns:
- the simulation result with report
-
buildOnly
Convenience method to build (without running) a process from JSON.- Parameters:
json- the JSON process definition- Returns:
- the simulation result with the ProcessSystem
-