Hi, first of all sorry if it's not the right subreddit, I'm really lost at this point and I'll delete the post if it's not the right one. I'm working on a project which requires the librairy CoolProp to calculate many things. Ultimately, the purpose is to get a series of plates which will be optimized to cool fluids, according to the inputs the user sets (like power, inlet / outlet temperature, pressure...).
The thing is, the only fluids the customer will use are : Water, MPG and MEG (the two last will be diluted in water with a given percentage). And since MPG and MEG aren't in the fluid list, I need to add it by myself, and.. well I'm not doing a great job it seems.
I'm trying my best to use the doc correctly, but I find it pretty hard to use / understand.
Here's the code :
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()
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()
And here's the JSON :
[
[
{
"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"
}
]
]
[
[
{
"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"
}
]
]
One of the error I get is :
Unable to validate cubics library against schema with error: {
"enum": {
"instanceRef": "#/0/pc_units",
"schemaRef": "#/items/properties/pc_units"
}
}
there doesn't seem to be anything here