Class JsonProcessBuilder
java.lang.Object
neqsim.process.processmodel.JsonProcessBuilder
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 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 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.Builds a ProcessSystem from a JSON string.static SimulationResultbuildAndRun(String json) Convenience method to build and run a process from JSON.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.static SimulationResultConvenience method to build (without running) a process from JSON.private voidbuildUnit(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.private 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 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 StreamInterfaceResolves a stream reference string to an actual StreamInterface.private voidwireInletStream(ProcessEquipmentInterface equipment, StreamInterface stream) Wires an inlet stream to an equipment unit via reflection.
-
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
-
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
-
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 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
-
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
-
buildAndRun
Convenience method to build and run a process from JSON.- Parameters:
json- the JSON process definition- 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
-