How to properly add a fluid in CoolProp library?

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 :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Unable to validate cubics library against schema with error: {
"enum": {
"instanceRef": "#/0/pc_units",
"schemaRef": "#/items/properties/pc_units"
}
}
</code>
<code>Unable to validate cubics library against schema with error: { "enum": { "instanceRef": "#/0/pc_units", "schemaRef": "#/items/properties/pc_units" } } </code>
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 :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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()
</code>
<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() </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()
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
[
[
{
"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"
}
]
]
</code>
<code> [ [ { "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" } ] ] </code>

[
    [
        {
            "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 :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Unable to validate cubics library against schema with error: {
"enum": {
"instanceRef": "#/0/pc_units",
"schemaRef": "#/items/properties/pc_units"
}
}
</code>
<code>Unable to validate cubics library against schema with error: { "enum": { "instanceRef": "#/0/pc_units", "schemaRef": "#/items/properties/pc_units" } } </code>
Unable to validate cubics library against schema with error: {
    "enum": {
        "instanceRef": "#/0/pc_units",
        "schemaRef": "#/items/properties/pc_units"
    }
}

New contributor

as0d is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật