Class CrossValidationRunner

java.lang.Object
neqsim.mcp.runners.CrossValidationRunner

public class CrossValidationRunner extends Object
Cross-validation runner that compares the same process model under different thermodynamic models (equations of state) to quantify model-selection risk.

This is a key enabler for UniSim–NeqSim cooperation: an engineer can export a UniSim model (typically Peng-Robinson), convert it to NeqSim JSON, then run cross-validation against CPA, GERG-2008, or other EoS that UniSim does not offer — all in a single MCP tool call.

Input JSON Format:

{ "baseProcess": { ... standard process JSON ... }, "models": ["SRK", "PR", "CPA",
"GERG2008"], "compareVariables": [ {"address": "HP Sep.gasOutStream.temperature", "unit": "C"},
{"address": "Compressor.power", "unit": "kW"}, {"address": "HP Sep.gasOutStream.density", "unit":
"kg/m3"} ], "tolerances": { "temperature": 2.0, "pressure": 0.5, "density": 5.0, "default": 10.0
} } 
Author:
Even Solbraa @version 1.0
  • Field Details

    • GSON

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

      private static final int MAX_MODELS
      Maximum number of EoS models per comparison to prevent resource exhaustion.
      See Also:
  • Constructor Details

    • CrossValidationRunner

      private CrossValidationRunner()
  • Method Details

    • crossValidate

      public static String crossValidate(String json)
      Runs the same process definition under multiple thermodynamic models and compares key output variables across all models.
      Parameters:
      json - JSON specification with baseProcess, models, and compareVariables
      Returns:
      JSON string with per-model results, deviations, and risk flags
    • runWithModel

      private static CrossValidationRunner.ModelRun runWithModel(com.google.gson.JsonObject baseProcess, String modelName, List<CrossValidationRunner.CompareSpec> compareSpecs)
      Runs the process with a specific EoS model, extracting the requested variables.
      Parameters:
      baseProcess - the base process JSON definition
      modelName - the EoS model name to use
      compareSpecs - list of variables to extract after simulation
      Returns:
      a ModelRun containing extracted values and convergence status
    • buildComparisons

      private static com.google.gson.JsonArray buildComparisons(List<CrossValidationRunner.CompareSpec> specs, List<CrossValidationRunner.ModelRun> runs, Map<String,Double> tolerances, double defaultTol)
      Builds per-variable cross-model comparisons with deviation analysis.
      Parameters:
      specs - list of variables to compare
      runs - list of model run results
      tolerances - per-variable tolerance overrides
      defaultTol - default tolerance percentage
      Returns:
      a JSON array of comparison objects
    • buildRiskAssessment

      private static com.google.gson.JsonObject buildRiskAssessment(List<CrossValidationRunner.CompareSpec> specs, List<CrossValidationRunner.ModelRun> runs, Map<String,Double> tolerances, double defaultTol)
      Builds an overall risk assessment summary.
      Parameters:
      specs - list of variables to assess
      runs - list of model run results
      tolerances - per-variable tolerance overrides
      defaultTol - default tolerance percentage
      Returns:
      a JSON object with the risk assessment summary
    • errorJson

      private static String errorJson(String code, String message, String remediation)