I’m making a website to calculate heat exchanger solutions. In order to do so, I must calculate complex data, which is why I use the CoolProp library. While the website is handled in PHP, the librairy is in Python, so I just send my PHP form datas to Python, and it returns me the result. This works well.
But ! The customer needs me to use some fluids which are not in the librairy : MPG and MEG (on this website it shows a way to use it, but I get an error saying the fluid doesn’t exist). Those fluids will even be mixed with water at different percentae (10, 20, 30, 40, and 50%). I’ve been reading the documentation, mainly this part, but I get some other errors, like :
Unable to validate cubics library against schema with error: {
"enum": {
"instanceRef": "#/0/pc_units",
"schemaRef": "#/items/properties/pc_units"
}
}
Here are my Python code, and the JSON I’m trying to add :
import sys
import json
import os
import CoolProp.CoolProp as CP
def add_custom_fluids(json_filename):
with open(json_filename, 'r') as f:
fluids_json = f.read()
fluids_data = json.loads(fluids_json)
# Add each fluid to CoolProp
for fluid in fluids_data:
CP.add_fluids_as_JSON('PR', json.dumps(fluid))
# Verify by printing the fluid list
fluid_list = CP.get_global_param_string('FluidsList')
print(fluid_list)
def main():
try:
# Ajout des fluides "customs" (MEG-10%, MPG-40%, etc.)
script_dir = os.path.dirname(__file__)
json_file_path = os.path.join(script_dir, 'custom_fluids.json')
add_custom_fluids(json_file_path)
# Récupérer les arguments de la ligne de commande
output = sys.argv[1]
input1 = sys.argv[2]
value1 = float(sys.argv[3])
input2 = sys.argv[4]
value2 = float(sys.argv[5])
fluid = sys.argv[6]
# Calculate the property using CoolProp
result = CP.PropsSI(output, input1, value1, input2, value2, fluid)
# Print the result
print(result)
except Exception as e:
# Print the error message
print(f"Error: {e}", file=sys.stderr)
print(0) # Return 0 in case of error
if __name__ == "__main__":
main()
[
[
{
"name": "MPG",
"description": "Pure Mono Propylene Glycol",
"incompressible": true,
"T_min": 183.15,
"T_max": 590.15,
"isothermal_compressibility": 4.4e-10,
"rhoT": [
1036,
-0.58,
0.0,
0.0,
0.0
],
"specific_heat": [
2480,
0.0,
0.0,
0.0,
0.0
],
"conductivity": [
0.23,
0.0,
0.0,
0.0,
0.0
],
"viscosity": [
0.041,
0.0,
0.0,
0.0,
0.0
],
"CAS": "57-55-6",
"Tc": 592.0,
"pc": 4.69,
"acentric": 0.615,
"molemass": 0.07609,
"molemass_units": "kg/mol",
"pc_units": "mPa",
"Tc_units": "K"
}
],
[
{
"name": "MEG",
"description": "Pure Mono Ethylene Glycol",
"incompressible": true,
"T_min": 213.15,
"T_max": 653.15,
"isothermal_compressibility": 4.4e-10,
"rhoT": [
1112,
-0.61,
0.0,
0.0,
0.0
],
"specific_heat": [
2400,
0.0,
0.0,
0.0,
0.0
],
"conductivity": [
0.25,
0.0,
0.0,
0.0,
0.0
],
"viscosity": [
0.016,
0.0,
0.0,
0.0,
0.0
],
"CAS": "107-21-1",
"Tc": 653.0,
"pc": 8.06,
"acentric": 0.433,
"molemass": 0.06207,
"molemass_units": "kg/mol",
"pc_units": "mPa",
"Tc_units": "K"
}
]
]
After that, I should be able to make a mixture of Water and the new fluids for the different percentages I need.
I tried using the add_fluids_as_JSON()
function by looping inside my JSON array, expecting each fluids to be added to the librairy. I also tried to insert them differently, one entry for each percentage. All of these resulted in the same error :
Unable to validate cubics library against schema with error: {
"enum": {
"instanceRef": "#/0/pc_units",
"schemaRef": "#/items/properties/pc_units"
}
}
as0d is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.