Calsep Flash API
Calsep’s Flash API is an HTTP API that enables customers to run flash calculations consistent with PVTsim Nova through Calsep’s cloud service or in your own cloud solution.
Getting started
Calsep’s Flash API is an HTTP API that enables customers to run flash calculations consistent with PVTsim Nova through Calsep’s cloud service or in your own cloud solution.
To use the Flash API through Calsep’s Cloud Service you will need to perform the following tasks.
- Obtain a Client ID and Client Secret (license) from Calsep to access and authenticate your Flash API requests.
- Download and set up Calsep’s Software Development Kit (Python SDK or C# SDK).
- Export a characterized fluid from PVTsim Nova 5.0 or newer.
- Call the Cloud Flash API with the exported characterized fluid and the settings required for the flash calculation.
Please contact your nearest Calsep office for more information about how to get access to a Client ID, Client Secret, and download link for one of Calsep’s Flash SDKs.
Fluids from PVTsim Nova
The Flash API needs a characterized fluid serialized as a string in the .JSON format. You can export characterized fluids to this format using the Calsep Flash API interface in PVTsim Nova 5.0 or newer. The procedure is outlined here:
1. Open PVTsim Nova 5 and open the desired PVTsim Nova fluid database.
2. Select the characterized fluid you would like to export to the Cloud Flash API.
3. Click on the Interfaces tab and select ‘Calsep Flash API’.
4. The Export to Calsep Flash API menu indicates whether the fluid is legal for export to the Cloud Flash API. Click OK and save the file.
Calsep Python SDK
The Calsep Python SDK is delivered as a code package containing all the python scripts required to call the Flash API, run a flash calculation and interpret the results returned by the API. Calsep has also developed and SDK for C#, more information can be found on Calsep SDKs.
Once you have loaded the code structure in your Python environment, locate and open the ‘apiconfig.py’ script file in the ‘examples’ folder. Change the generic web address, client ID and client secret into your specific data received from Calsep.
The content of apiconfig.py is shown in the Python code below.
Python
Access to Calsep’s Flash API
BASE_API = "https://cloud.calsep.com"
CLIENT_ID = "ID"
CLIENT_SECRET = "Secret"
The Python SDK is now ready to call Calsep’s Flash API using the provided example program ‘Sample.py’. Sample.py is a simplified example provided with the Python SDK, showing how to use the SDK to call the Calsep Cloud Flash API and retrieve results from the API answer.
Simple Flash Call
To perform a flash calculation request, all you have to do is open and run the ‘Sample.py’ script located in the ‘Examples’ folder.
The flash call example illustrates how to modify the flash call e.g. by:
- Specifying flash type (Pressure-Temperature (PT), Pressure-Enthalpy (PH) or Pressure-Entropy (PS)).
- Setting input specifications (e.g. pressure and temperature).
- Selecting which outputs to receive from the Cloud API.
- Selecting viscosity model (CSP or LBC)
- Selecting water properties model.
A simple flash call from Calsep’s Python SDK is done in just a few lines of code. The Python code below shows how this is done.
Sample.py
import context from printresults import print_results from pycalsep.calsep_client import CalsepClient from pycalsep.cached_fluid import CachedFluid from pycalsep.flash_parameters import FlashParameters from pycalsep.common import FLASH_MODE from apiconfig import BASE_API, CLIENT_ID, CLIENT_SECRET with open("C:/Users/”USER”/pythonsdk/examples/fluid.json", "r") as file: fluidJson = file.read() client = CalsepClient(BASE_API, CLIENT_ID, CLIENT_SECRET) press = 101325.0 temp = 300.0 flashMode = FLASH_MODE.FlashModePt flashResponse = client.runFlashWithFluid(flashMode, press, temp, fluidJson) if flashResponse.isError: print(flashResponse.error.errorCode) print(flashResponse.error.message) else: print_results(flashMode, flashResponse)
Flash Output
In order to speed up the execution time on the Flash API side, it is possible to choose different result output modes.
The Flash API allows for five different output modes with different levels of information returned from the API.
Standard Output Mode (Default)
The Cloud API returns all the same flash results as in the PVTsim Nova flash output.
StandardPlusDerivatives Output Mode
The Flash API returns the same flash result as in the PVTsim Nova flash output, plus a number of derivative properties.
StandardMinusComp
The Cloud API returns the flash result as in the PVTsim Nova flash output ‘Properties’ tab. No phase compositions or fugacities are returned.
Reduced1
The Cloud API returns a reduced flash result, which only includes phase fractions (mol%, weight%), density, viscosity, phase type, temperature, pressure and surface tensions. No compositions are returned.
Reduced2
The Cloud API returns a further reduced flash result, which only includes phase fractions (weight% and volume%), density, phase type, temperature and pressure. No compositions are returned.
Need a Flash Engine?
Calsep’s Flash API is designed to be the engine of software applications that require multiple flash calculations every second. This could be in connection with dynamic flow simulations, monitoring of process equipment or allocation of streams from multiple sources.