Class BatchRunner

java.lang.Object
neqsim.mcp.runners.BatchRunner

public class BatchRunner extends Object
Stateless batch calculation runner for MCP integration.

Runs multiple flash calculations in a single call, sharing a common fluid definition. This is designed for sensitivity studies and property sweeps where an agent needs to explore a parameter space efficiently. Each case in the batch can vary temperature, pressure, or composition.

Input JSON Format:

{ "model": "SRK", "components": {"methane": 0.85, "ethane": 0.10, "propane": 0.05},
"mixingRule": "classic", "flashType": "TP", "cases": [ {"temperature": {"value": 0.0, "unit":
"C"}, "pressure": {"value": 50.0, "unit": "bara"}}, {"temperature": {"value": 25.0, "unit": "C"},
"pressure": {"value": 50.0, "unit": "bara"}}, {"temperature": {"value": 50.0, "unit": "C"},
"pressure": {"value": 50.0, "unit": "bara"}} ] } 

Each case can also override components or flash type to explore composition sensitivity or different calculation modes within a single call.

Author:
Even Solbraa @version 1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final com.google.gson.Gson
     
    private static final int
    Maximum number of cases per batch to prevent resource exhaustion.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor — all methods are static.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static String
    errorJson(String code, String message, String remediation)
    Creates a standard error JSON response.
    private static com.google.gson.JsonObject
    mergeJsonObjects(com.google.gson.JsonObject base, com.google.gson.JsonObject overrides)
    Merges two JSON objects, with the override taking precedence.
    static String
    run(String json)
    Runs a batch of flash calculations from a JSON specification.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • GSON

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

      private static final int MAX_CASES
      Maximum number of cases per batch to prevent resource exhaustion.
      See Also:
  • Constructor Details

    • BatchRunner

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

    • run

      public static String run(String json)
      Runs a batch of flash calculations from a JSON specification.

      Each case inherits the base fluid definition (model, components, mixingRule, flashType) and can override temperature, pressure, components, or flashType per case. Results are returned as an array with per-case status so partial failures don't block the entire batch.

      Parameters:
      json - the JSON batch specification
      Returns:
      a JSON string with batch results and provenance
    • mergeJsonObjects

      private static com.google.gson.JsonObject mergeJsonObjects(com.google.gson.JsonObject base, com.google.gson.JsonObject overrides)
      Merges two JSON objects, with the override taking precedence.
      Parameters:
      base - the base object
      overrides - the overriding values
      Returns:
      a new merged JSON object
    • 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