Class FlashRunner
java.lang.Object
neqsim.mcp.runners.FlashRunner
Stateless flash calculation runner for MCP integration.
Accepts a JSON string describing a fluid and flash specification, performs the flash calculation, and returns a JSON string with the results including per-phase properties, compositions, and conditions. Uses the same standard response envelope as the process simulation pipeline.
Supported Flash Types:
TP— Temperature-Pressure flash (default)PH— Pressure-Enthalpy flashPS— Pressure-Entropy flashTV— Temperature-Volume flashdewPointT— Dew point temperature at given pressuredewPointP— Dew point pressure at given temperaturebubblePointT— Bubble point temperature at given pressurebubblePointP— Bubble point pressure at given temperaturehydrateTP— Hydrate equilibrium temperature at given pressure
Input JSON Format:
{ "model": "SRK", "temperature": {"value": 25.0, "unit": "C"}, "pressure": {"value":
50.0, "unit": "bara"}, "flashType": "TP", "components": {"methane": 0.85, "ethane": 0.10,
"propane": 0.05}, "mixingRule": "classic", "enthalpy": {"value": -5000.0, "unit": "J/mol"},
"entropy": {"value": 100.0, "unit": "J/molK"}, "volume": {"value": 0.001, "unit": "m3/mol"} }
- Author:
- Even Solbraa @version 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.google.gson.Gson -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor — all methods are static. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddCompatibilityFields(com.google.gson.JsonObject fluidObj) Adds backward-compatible flattened fields used by older clients and tests.(package private) static doubleConverts a pressure ValueWithUnit to bara.(package private) static doubleConverts a temperature ValueWithUnit to Kelvin.(package private) static SystemInterfacecreateFluid(String model, double temperatureK, double pressureBara) Creates a SystemInterface based on the model type string.private static StringCreates a standard error JSON response.Returns the list of supported flash types.Returns the list of supported thermodynamic models.private static StringnormalizeFlashType(String flashType) Normalizes legacy flash-type aliases to canonical names.(package private) static doubleparsePressure(com.google.gson.JsonElement element) Parses a pressure value from JSON.(package private) static doubleparseTemperature(com.google.gson.JsonElement element) Parses a temperature value from JSON.static StringRuns a flash calculation from a JSON input string.static ApiEnvelope<FlashResult> runTyped(FlashRequest request) Runs a flash calculation from a typed request object.
-
Field Details
-
GSON
private static final com.google.gson.Gson GSON -
SUPPORTED_FLASH_TYPES
-
SUPPORTED_MODELS
-
-
Constructor Details
-
FlashRunner
private FlashRunner()Private constructor — all methods are static.
-
-
Method Details
-
run
-
getSupportedFlashTypes
-
getSupportedModels
-
normalizeFlashType
-
addCompatibilityFields
private static void addCompatibilityFields(com.google.gson.JsonObject fluidObj) Adds backward-compatible flattened fields used by older clients and tests.- Parameters:
fluidObj- fluid response JSON object
-
parseTemperature
static double parseTemperature(com.google.gson.JsonElement element) Parses a temperature value from JSON. Accepts a number (Kelvin) or an object with value and unit.- Parameters:
element- the JSON element- Returns:
- temperature in Kelvin, or NaN on error
-
parsePressure
static double parsePressure(com.google.gson.JsonElement element) Parses a pressure value from JSON. Accepts a number (bara) or an object with value and unit.- Parameters:
element- the JSON element- Returns:
- pressure in bara, or NaN on error
-
createFluid
Creates a SystemInterface based on the model type string.- Parameters:
model- the model name (e.g., "SRK", "PR", "CPA")temperatureK- temperature in KelvinpressureBara- pressure in bara- Returns:
- the created fluid system
- Throws:
IllegalArgumentException- if model is not recognized
-
runTyped
Runs a flash calculation from a typed request object.This is the typed counterpart to
run(String). It accepts aFlashRequestPOJO and returns a typedApiEnvelopewith aFlashResultpayload. For direct Java consumers this avoids JSON parsing overhead and provides compile-time type safety.- Parameters:
request- the flash request- Returns:
- an ApiEnvelope containing the FlashResult on success, or errors on failure
-
convertTemperatureToKelvin
Converts a temperature ValueWithUnit to Kelvin.- Parameters:
temp- the temperature with unit- Returns:
- temperature in Kelvin, or NaN on error
-
convertPressureToBara
Converts a pressure ValueWithUnit to bara.- Parameters:
pres- the pressure with unit- Returns:
- pressure in bara, or NaN on error
-
errorJson
-