-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphase_diagram_sample.py
More file actions
59 lines (49 loc) · 2.84 KB
/
Copy pathphase_diagram_sample.py
File metadata and controls
59 lines (49 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import asyncio
import matplotlib.pyplot as plt
from equia.models import CalculationComposition, ProblemDetails
from equia.equia_client import EquiaClient
from equia.demofluids.demofluid1_nHexane_Ethylene_HDPE7 import demofluid1_nHexane_Ethylene_HDPE7
from helpers import print_exception_info, print_problem_details
from shared_settings import sharedsettings
def create_client():
return EquiaClient(sharedsettings.url, sharedsettings.access_key)
async def call_phase_diagram():
client = create_client()
argument = client.get_phasediagram_standard_input()
argument.fluid = demofluid1_nHexane_Ethylene_HDPE7() #1 Use predefined demo fluid
argument.fluidid = None #No needed since we supply fluid in line above
argument.sle = True #Ask to include the SLE part of the phasediagram
argument.slve = True #Ask to include the SLVE part of the phasediagram
argument.vlle = True #Ask to include the VLLE part of the phasediagram
argument.components = [
CalculationComposition(amount=0.78),
CalculationComposition(amount=0.02),
CalculationComposition(amount=0.2)]
argument.units = "C(In,Massfraction);C(Out,Massfraction);T(In,Kelvin);T(Out,Kelvin);P(In,Bar);P(Out,Bar);H(In,kJ/Kg);H(Out,kJ/Kg);S(In,kJ/(Kg Kelvin));S(Out,kJ/(Kg Kelvin));Cp(In,kJ/(Kg Kelvin));Cp(Out,kJ/(Kg Kelvin));Viscosity(In,centiPoise);Viscosity(Out,centiPoise);Surfacetension(In,N/m);Surfacetension(Out,N/m)"
result = await client.call_phasediagram_standard_async(argument)
# Always do the cleanup
await client.cleanup()
if (isinstance(result, ProblemDetails)):
print_problem_details(result)
elif (result.success == True):
plt.title("Phase diagram")
plt.xlabel(f"Temperature [{result.curve.temperature_units}]")
plt.ylabel(f"Pressure [{result.curve.pressure_units}]")
if (len(result.curve.phaseenvelope) > 0):
plt.plot(list(map(lambda point: point.temperature, result.curve.phaseenvelope)), list(
map(lambda point: point.pressure, result.curve.phaseenvelope)), label="Phase Envelope")
if (len(result.curve.vlle) > 0):
plt.plot(list(map(lambda point: point.temperature, result.curve.vlle)), list(
map(lambda point: point.pressure, result.curve.vlle)), label="VLLE")
if (len(result.curve.sle) > 0):
plt.plot(list(map(lambda point: point.temperature, result.curve.sle)), list(
map(lambda point: point.pressure, result.curve.sle)), label="SLE")
if (len(result.curve.slve) > 0):
plt.plot(list(map(lambda point: point.temperature, result.curve.slve)), list(
map(lambda point: point.pressure, result.curve.slve)), label="SLVE")
plt.legend()
plt.show()
else:
print_exception_info(result.exception_info)
if __name__ == "__main__":
asyncio.run(call_phase_diagram())