Class FlashRunner

java.lang.Object
neqsim.mcp.runners.FlashRunner

public class FlashRunner extends Object
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 flash
  • PS — Pressure-Entropy flash
  • TV — Temperature-Volume flash
  • dewPointT — Dew point temperature at given pressure
  • dewPointP — Dew point pressure at given temperature
  • bubblePointT — Bubble point temperature at given pressure
  • bubblePointP — Bubble point pressure at given temperature
  • hydrateTP — 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 Details

    • GSON

      private static final com.google.gson.Gson GSON
    • SUPPORTED_FLASH_TYPES

      private static final List<String> SUPPORTED_FLASH_TYPES
    • SUPPORTED_MODELS

      private static final List<String> SUPPORTED_MODELS
  • Constructor Details

    • FlashRunner

      private FlashRunner()
      Private constructor — all methods are static.
  • Method Details

    • run

      public static String run(String json)
      Runs a flash calculation from a JSON input string.
      Parameters:
      json - the JSON flash specification
      Returns:
      a JSON string with status, fluid properties, or errors
    • getSupportedFlashTypes

      public static List<String> getSupportedFlashTypes()
      Returns the list of supported flash types.
      Returns:
      unmodifiable list of flash type names
    • getSupportedModels

      public static List<String> getSupportedModels()
      Returns the list of supported thermodynamic models.
      Returns:
      unmodifiable list of model names
    • normalizeFlashType

      private static String normalizeFlashType(String flashType)
      Normalizes legacy flash-type aliases to canonical names.
      Parameters:
      flashType - requested flash type string
      Returns:
      canonical flash type name used internally
    • 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

      static SystemInterface createFluid(String model, double temperatureK, double pressureBara)
      Creates a SystemInterface based on the model type string.
      Parameters:
      model - the model name (e.g., "SRK", "PR", "CPA")
      temperatureK - temperature in Kelvin
      pressureBara - pressure in bara
      Returns:
      the created fluid system
      Throws:
      IllegalArgumentException - if model is not recognized
    • runTyped

      public static ApiEnvelope<FlashResult> runTyped(FlashRequest request)
      Runs a flash calculation from a typed request object.

      This is the typed counterpart to run(String). It accepts a FlashRequest POJO and returns a typed ApiEnvelope with a FlashResult payload. 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

      static double convertTemperatureToKelvin(ValueWithUnit temp)
      Converts a temperature ValueWithUnit to Kelvin.
      Parameters:
      temp - the temperature with unit
      Returns:
      temperature in Kelvin, or NaN on error
    • convertPressureToBara

      static double convertPressureToBara(ValueWithUnit pres)
      Converts a pressure ValueWithUnit to bara.
      Parameters:
      pres - the pressure with unit
      Returns:
      pressure in bara, or NaN on error
    • errorJson

      private static String errorJson(String code, String message, String remediation)
      Creates a standard error JSON response.
      Parameters:
      code - the error code
      message - the error message
      remediation - the fix suggestion
      Returns:
      JSON error string