Skip to main content

Tools for launching EES calculation and retrieving results from python

Project description

EES connector

EES connector is a tools developed by the SERG research group of the University of Florence for launching EES calculation and retrieving results from python.

Installing EES Connector 💾

The beta version can be downloaded using PIP:

pip install EES_connector

EES Connector + ✨🎉

From version 1.0.0 a major improvement has been made to the code. For compatibility the previous class (EESConnector) is still usable (you can find the old documentation here) but it will not be maintained

Launching a calculation 💻

Once the installation has been completed the user can import the tool and initialize the connector itself.

from EESConnect import EESConnectorPlus

with EESConnectorPlus() as ees:

    # insert your code here

Two important aspects to keep in mind for the initialization:

  • Please use the with statement during the initialization as shown above

  • A file-dialog will appear the first time that the connector is imported asking the user to select the EES executable path (usually it's "C:\EES32\ees.exe"). Once the executable path has been selected, the program keep it in memory in order to avoid new appearance of the file-dialog. The stored executable can be modified calling the following function:

from EESConnect import EESConnectorPlus

EESConnectorPlus.modify_ees_executable_path()

Finally, you can ask the program to launch EES calculation using the following command:
from EESConnect import EESConnectorPlus
from tkinter import filedialog
import tkinter as tk

#select the ees file path
root = tk.Tk()
root.withdraw()
ees_file_path = filedialog.askopenfilename()

with EESConnectorPlus() as ees:
    
    ees.ees_file_path = ees_file_path
    params = ees.calculate({
        
        "input": {"fluid$": "air_ha", "T": 300, "P": 1013.25}, 
        "output": {"h": None, "s": None}
    
    })
    print(params)

Calls with multiple parameters are possible as follows:

from EESConnect import EESConnectorPlus
from tkinter import filedialog
import tkinter as tk

#select the ees file path
root = tk.Tk()
root.withdraw()
ees_file_path = filedialog.askopenfilename()

params = {
    
    "input": {
        
        "fluid$": ["air_ha", "R22", "R236fa", "R134a"], 
        "T": [300, 300, 300, 300], 
        "P": [1013.25, 1013.25, 1013.25, 1013.25]
    
    }, 
    "output": {"h": None, "s": None}

}

with EESConnectorPlus() as ees:
    
    ees.ees_file_path = ees_file_path
    params = ees.calculate(params)
    print(params)

EES file configuration 📑

Please notice that the EES file has to be configured properly in order to work.
Here's an example, that works with the python code described above:

$UnitSystem SI K kPa kJ 
h=enthalpy(fluid$; T=T; P=P)
s=entropy(fluid$; T=T; P=P)

An explanation on how to set EES properly can be found here. In addition here's some important things had to be noted:

  • The keys of the "input" and "output" dictionaries must share the same name, in the EES code, with the variable that they refer in
  • The values identified in the "input" dictionary must not be defined in the code (e.g. do not write "T=300" in the code above)
  • The code must work if the variable identified in the "input" dictionary are manually set in the code

Calculation Options ⚙

Multiple options could be set in initializing the calculator:

from EESConnect import EESConnectorPlus

with EESConnectorPlus(ees_decimal_separator=".", display_progress_bar=True, timeout=10) as ees:

    # insert your code here
  • "ees_decimal_separator" allows you to set the decimal separator in order to match the one required by your EES file. The default is a comma (",")
  • "display_progress_bar" shows a bar describing the progress of the calculation
  • "timeout" set a timeout limit for the calculation (value to be set in seconds)

Excel Exporter 💾📊

You export the results of your calculation to excel using Pandas with the following code:

with EESConnectorPlus(timeout=10, display_progress_bar=True) as ees:

    # Calculate
    params = ees.calculate(params)
    
    # Export results
    ees.export_to_excel(params=params, excel_path=os.path.join(base_folder, "results.xlsx"))

EES Optimization and other Execution Personalization 🛠🔧

EESConnectorPlus works by executing EES Macros. The behaviour of the macro can be modified by the user to perform more complex operation (the most typical usage is to perform optimization in EES). This can be done by modifying the attribute "ees.calculation_instruction". For example, for performing the optimization, you can use the Minimize Macro instruction as shown below:

from EESConnect import EESConnectorPlus

with EESConnectorPlus() as ees:

    ees.ees_file_path = os.path.join(base_folder, "optimization_trial.EES")
    
    # This code can be used to minimize y_max by changing x_max
    ees.calculation_instruction = "Minimize y_max  x_max  /Method=Conjugate  /RelTol=1e-6  /MaxIt=500"

    params = ees.calculate(params)

by default ees.calculation_instruction = "Solve".
In general the MACRO that will be run by EES will be the following:

ONERROR GOTO 10
DIR$=GetDirectory$
Open 'ees_program.ees'
Import 'ees_input.dat' f$ {{ Input Parameters }}

{{ calculation_instruction }}

Export f$ {{ Output Parameters }}
10:quit

Example Code 🔎

You can find some example code in this folder

-------------------------- !!! THIS IS A BETA VERSION !!! --------------------------

please report any bug or problems in the installation to pietro.ungar@unifi.it
for further information visit: https://tinyurl.com/SERG-3ETool

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

EES_connector-1.0.0.tar.gz (22.5 kB view details)

Uploaded Source

File details

Details for the file EES_connector-1.0.0.tar.gz.

File metadata

  • Download URL: EES_connector-1.0.0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for EES_connector-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fba6f779bcc1588c827cdca8e153c9ee904119a0b0f8e71990d4217c0c8f3894
MD5 4803fa9e37fd208653f45cdc0f98a5cd
BLAKE2b-256 dd8d2a6a1a50dcf975ed60bee82587d2316e9bc02b195a5e169dfc3fe1294968

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page