Class JsonFluidReadWrite
java.lang.Object
neqsim.thermo.util.readwrite.JsonFluidReadWrite
Read and write NeqSim fluids in a JSON format that provides full EOS-level fidelity equivalent to
Eclipse E300 fluid files.
The JSON format supports all parameters needed to exactly reproduce a PVT-tuned fluid: component critical properties, acentric factors, molecular weights, volume shifts, parachors, binary interaction coefficients, viscosity model coefficients (LBC/Pedersen), and pseudo-component (TBP fraction) definitions.
Example JSON:
{
"format": "neqsim-fluid",
"version": "1.0",
"eos": "SRK",
"reservoirTemperature": { "value": 90.0, "unit": "C" },
"components": [
{
"name": "methane",
"moleFraction": 0.85,
"criticalTemperature": 190.6,
"criticalPressure": 46.0,
"acentricFactor": 0.008,
"molarMass": 16.043,
"normalBoilingPoint": 111.6,
"criticalVolume": 0.0986,
"volumeShift": -0.194,
"parachor": 77.3,
"isPseudo": false
}
],
"binaryInteractionCoefficients": [
{ "i": "methane", "j": "ethane", "kij": 0.0 }
]
}
- Version:
- 1.0
- Author:
- copilot
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classInternal data holder for a parsed component. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation — all methods are static. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidapplyBinaryInteractionCoefficients(SystemInterface fluid, List<String> componentNames, com.google.gson.JsonArray bicArray) Apply binary interaction coefficients from a JSON array to the fluid.private static voidapplyViscosityModel(SystemInterface fluid, com.google.gson.JsonObject viscObj) Apply viscosity model configuration from JSON to the fluid.private static com.google.gson.JsonObjectBuild a JSON object representing the viscosity model configuration of a fluid.static voidconvertE300ToJson(String inputE300File, String outputJsonFile) Convert a fluid from E300 format to JSON format.static voidconvertE300ToJson(String inputE300File, String outputJsonFile, double reservoirTempC) Convert a fluid from E300 format to JSON format with a specified reservoir temperature.static voidconvertJsonToE300(String inputJsonFile, String outputE300File) Convert a fluid from JSON format to E300 format.static voidconvertJsonToE300(String inputJsonFile, String outputE300File, double reservoirTempC) Convert a fluid from JSON format to E300 format with a specified reservoir temperature.private static SystemInterfacecreateFluidByEOS(String eosType, boolean prcorr) Create a SystemInterface for the given EOS type.private static intfindComponentIndex(SystemInterface fluid, List<String> componentNames, String name) Find the index of a component in the fluid by name.private static double[][]Get the binary interaction parameter matrix from the fluid.private static doublegetDoubleOrDefault(com.google.gson.JsonObject obj, String field, double defaultValue) Get a double value from a JSON object, or return a default if the field is missing.private static StringgetEOSType(SystemInterface fluid) Determine the EOS type string from the fluid class.private static StringmapToNeqSimName(String name) Map E300-style short component names to NeqSim database component names.private static JsonFluidReadWrite.ComponentDataparseComponent(com.google.gson.JsonObject comp) Parse a single component from its JSON object representation.static SystemInterfaceRead a fluid from a JSON file on disk.static SystemInterfaceRead a fluid from a JSON file and optionally add a water component.static SystemInterfaceRead a fluid from a JSON file and optionally add a water component with a custom kij value.static SystemInterfacereadString(String json) Read a fluid from a JSON string.static SystemInterfacereadString(String json, boolean addWater) Read a fluid from a JSON string and optionally add a water component.static SystemInterfacereadString(String json, boolean addWater, double waterKij) Read a fluid from a JSON string and optionally add a water component with custom kij.static StringtoJsonString(SystemInterface fluid) Convert a NeqSim fluid to a JSON string with full EOS parameters.static StringtoJsonString(SystemInterface fluid, double reservoirTempC) Convert a NeqSim fluid to a JSON string with full EOS parameters and a specified reservoir temperature.static voidwrite(SystemInterface fluid, String outputFile) Write a fluid to a JSON file.static voidwrite(SystemInterface fluid, String outputFile, double reservoirTempC) Write a fluid to a JSON file with a specified reservoir temperature.static voidwrite(SystemInterface fluid, Path outputPath) Write a fluid to a JSON file at the given path.static voidwrite(SystemInterface fluid, Path outputPath, double reservoirTempC) Write a fluid to a JSON file at the given path with a specified reservoir temperature.
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger loggerLogger object for class. -
FORMAT_ID
-
FORMAT_VERSION
-
-
Constructor Details
-
JsonFluidReadWrite
private JsonFluidReadWrite()Private constructor to prevent instantiation — all methods are static.
-
-
Method Details
-
read
Read a fluid from a JSON file on disk.- Parameters:
inputFile- path to the JSON file- Returns:
- a
SystemInterfacewith all EOS parameters set - Throws:
IllegalArgumentException- if the file does not exist, cannot be read, or has invalid content
-
read
Read a fluid from a JSON file and optionally add a water component.- Parameters:
inputFile- path to the JSON fileaddWater- if true, add a water component with default kij = 0.5- Returns:
- a
SystemInterfacewith all EOS parameters set - Throws:
IllegalArgumentException- if the file does not exist, cannot be read, or has invalid content
-
read
Read a fluid from a JSON file and optionally add a water component with a custom kij value.- Parameters:
inputFile- path to the JSON fileaddWater- if true, add a water componentwaterKij- binary interaction parameter between water and all other components- Returns:
- a
SystemInterfacewith all EOS parameters set - Throws:
IllegalArgumentException- if the file does not exist, cannot be read, or has invalid content
-
readString
Read a fluid from a JSON string.This is the primary parsing method. It supports all EOS parameters including pseudo-components, binary interaction coefficients, volume shifts, parachors, and viscosity model configuration.
- Parameters:
json- the JSON string defining the fluid- Returns:
- a
SystemInterfacewith all EOS parameters set - Throws:
IllegalArgumentException- if the JSON is invalid or missing required fields
-
readString
Read a fluid from a JSON string and optionally add a water component.- Parameters:
json- the JSON stringaddWater- if true, add a water component with kij = 0.5- Returns:
- a
SystemInterfacewith all EOS parameters set - Throws:
IllegalArgumentException- if the JSON is invalid
-
readString
Read a fluid from a JSON string and optionally add a water component with custom kij.- Parameters:
json- the JSON stringaddWater- if true, add a water componentwaterKij- binary interaction parameter between water and all other components- Returns:
- a
SystemInterfacewith all EOS parameters set - Throws:
IllegalArgumentException- if the JSON is invalid
-
write
Write a fluid to a JSON file.- Parameters:
fluid- the fluid to exportoutputFile- path to output file (e.g., "myfluid.json")- Throws:
IOException- if writing fails
-
write
public static void write(SystemInterface fluid, String outputFile, double reservoirTempC) throws IOException Write a fluid to a JSON file with a specified reservoir temperature.- Parameters:
fluid- the fluid to exportoutputFile- path to output filereservoirTempC- reservoir temperature in Celsius- Throws:
IOException- if writing fails
-
write
Write a fluid to a JSON file at the given path.- Parameters:
fluid- the fluid to exportoutputPath- output file path- Throws:
IOException- if writing fails
-
write
public static void write(SystemInterface fluid, Path outputPath, double reservoirTempC) throws IOException Write a fluid to a JSON file at the given path with a specified reservoir temperature.- Parameters:
fluid- the fluid to exportoutputPath- output file pathreservoirTempC- reservoir temperature in Celsius- Throws:
IOException- if writing fails
-
toJsonString
Convert a NeqSim fluid to a JSON string with full EOS parameters.- Parameters:
fluid- the fluid to export- Returns:
- JSON string representing the fluid
-
toJsonString
Convert a NeqSim fluid to a JSON string with full EOS parameters and a specified reservoir temperature.- Parameters:
fluid- the fluid to exportreservoirTempC- reservoir temperature in Celsius- Returns:
- JSON string representing the fluid
-
convertE300ToJson
public static void convertE300ToJson(String inputE300File, String outputJsonFile) throws IOException Convert a fluid from E300 format to JSON format.Convenience method that reads an E300 file and writes a JSON file.
- Parameters:
inputE300File- path to the E300 input fileoutputJsonFile- path to the JSON output file- Throws:
IOException- if reading or writing failsIllegalArgumentException- if the E300 file is invalid
-
convertE300ToJson
public static void convertE300ToJson(String inputE300File, String outputJsonFile, double reservoirTempC) throws IOException Convert a fluid from E300 format to JSON format with a specified reservoir temperature.- Parameters:
inputE300File- path to the E300 input fileoutputJsonFile- path to the JSON output filereservoirTempC- reservoir temperature in Celsius- Throws:
IOException- if reading or writing failsIllegalArgumentException- if the E300 file is invalid
-
convertJsonToE300
public static void convertJsonToE300(String inputJsonFile, String outputE300File) throws IOException Convert a fluid from JSON format to E300 format.Convenience method that reads a JSON file and writes an E300 file.
- Parameters:
inputJsonFile- path to the JSON input fileoutputE300File- path to the E300 output file- Throws:
IOException- if reading or writing failsIllegalArgumentException- if the JSON file is invalid
-
convertJsonToE300
public static void convertJsonToE300(String inputJsonFile, String outputE300File, double reservoirTempC) throws IOException Convert a fluid from JSON format to E300 format with a specified reservoir temperature.- Parameters:
inputJsonFile- path to the JSON input fileoutputE300File- path to the E300 output filereservoirTempC- reservoir temperature in Celsius- Throws:
IOException- if reading or writing failsIllegalArgumentException- if the JSON file is invalid
-
createFluidByEOS
Create a SystemInterface for the given EOS type.- Parameters:
eosType- the EOS type string (SRK, PR, etc.)prcorr- whether to use the 1978 PR correction- Returns:
- a new SystemInterface instance
-
parseComponent
Parse a single component from its JSON object representation.- Parameters:
comp- the JSON object for the component- Returns:
- a ComponentData record with all parsed values
- Throws:
IllegalArgumentException- if required fields are missing
-
getDoubleOrDefault
private static double getDoubleOrDefault(com.google.gson.JsonObject obj, String field, double defaultValue) Get a double value from a JSON object, or return a default if the field is missing.- Parameters:
obj- the JSON objectfield- the field namedefaultValue- the default value- Returns:
- the field value or the default
-
mapToNeqSimName
-
applyBinaryInteractionCoefficients
private static void applyBinaryInteractionCoefficients(SystemInterface fluid, List<String> componentNames, com.google.gson.JsonArray bicArray) Apply binary interaction coefficients from a JSON array to the fluid.The array contains objects with "i", "j", and "kij" fields. Components are referenced by name.
- Parameters:
fluid- the fluidcomponentNames- list of component names in orderbicArray- the JSON array of BIC entries
-
findComponentIndex
private static int findComponentIndex(SystemInterface fluid, List<String> componentNames, String name) Find the index of a component in the fluid by name. Tries exact match first, then checks the mapped names in the componentNames list.- Parameters:
fluid- the fluidcomponentNames- ordered list of component namesname- the name to find- Returns:
- the component index, or -1 if not found
-
applyViscosityModel
Apply viscosity model configuration from JSON to the fluid.- Parameters:
fluid- the fluidviscObj- the viscosity model JSON object
-
buildViscosityModelJson
Build a JSON object representing the viscosity model configuration of a fluid.- Parameters:
fluid- the fluid- Returns:
- a JsonObject, or null if no special viscosity model is configured
-
getEOSType
Determine the EOS type string from the fluid class.- Parameters:
fluid- the fluid- Returns:
- "SRK" or "PR"
-
getBinaryInteractionParameters
Get the binary interaction parameter matrix from the fluid.- Parameters:
fluid- the fluid- Returns:
- 2D array of kij values
-