Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial hydrate support #182

Merged
merged 35 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ef1c873
Added code to calculate phase diagrams with a free water phase in add…
morteham May 28, 2023
9adc69e
Added hydrate model
morteham May 28, 2023
da2298b
Ran test scripts and debugged code
morteham May 29, 2023
69e5102
Corrected unittestes
morteham May 29, 2023
a6cb6ec
Tested pytests
morteham May 29, 2023
fb39c13
Added method to get volume shift of mixture to correct bounds in satu…
Jun 22, 2023
8f13664
Avoid negative pressures when evaluating hydrate model
Jun 25, 2023
e5977e6
Make sure initial beta is between 0 and 1
Jun 25, 2023
451cb6c
Use log(f) in envelope crossing function
Jun 25, 2023
8f8fbb2
Adapt initial step length based on dpdv
Jun 26, 2023
6bcd327
Merging with main
morteham Oct 5, 2023
451895e
Fix duplicated name for hydrate wrapper
ailoa Oct 6, 2023
a4eeb30
Merging with main
morteham Nov 17, 2023
c789abb
Merging with main
morteham Jan 23, 2024
37c8a19
Commented code in saturation TV
morteham Jan 23, 2024
6ceb81a
Merging with main
morteham Feb 14, 2024
093fd77
Added print of speed of sound from TV method
morteham Jul 2, 2024
e041602
Added SaturationCurve utility class
morteham Jul 2, 2024
9aae006
Merging with main
morteham Jul 2, 2024
f9645f3
Initial support for multiphase hydrate tracking
morteham Jul 4, 2024
0522152
Introduced betaL as variable when tracing three fluid phases in equil…
morteham Jul 4, 2024
e6956d9
Merging with main
morteham Dec 1, 2024
5b29ac1
Allow reaching Pmin when stepping multiphase curves
morteham Jul 7, 2024
ef02e4c
Correct b for volume trnaskaltions
morteham Jul 7, 2024
566d2c3
Initial support for mapping three-fluid + hydrate curves
morteham Jul 7, 2024
e7d579a
Updated hydrate memo
morteham Dec 5, 2024
d359c1c
Moved hydrate doc
morteham Dec 5, 2024
9b5fde3
Updated hydrate example
morteham Dec 5, 2024
2fa5020
Only print hydrate info when verbose is active
morteham Dec 5, 2024
818e840
Tveaked some hydrate numerics
morteham Dec 5, 2024
3c5c99d
Updated hydrate.py curve
morteham Dec 5, 2024
f97d84e
Restructured python code for hydrate
morteham Dec 6, 2024
8059188
Fix export list.
vegardjervell Dec 9, 2024
5f43cba
GitHub actions runner for macOS 12 has reached EOL. Removing jobs usi…
vegardjervell Dec 9, 2024
9e679b7
Bump version number to 2.2.5b0.
vegardjervell Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions MSVStudio/thermopack.def
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; File generated by thermopack/addon/pyUtils/exports/export_list.py
; Time stamp: 2024-10-04T15:56:57.529901
; Time stamp: 2024-12-01T11:39:41.420875
; @[email protected] : Declares the module parameters.

LIBRARY
Expand Down Expand Up @@ -98,6 +98,10 @@ EXPORTS
eostv_mp_enthalpy_tvp_
fundamental_measure_theory_mp_fmt_energy_density_
hardsphere_bmcsl_mp_calc_bmcsl_gij_fmt_
init_hydrate_model_mp_hydrate_
fugacity_water_in_hydrate_tpx_mp_hydrate_
fugacity_water_in_hydrate_tvn_mp_hydrate_
map_hydrate_appearance_curve_mp_hydrate_curves_
ideal_mp_set_standard_entropy_
ideal_mp_get_standard_entropy_
ideal_mp_set_enthalpy_of_formation_
Expand All @@ -117,6 +121,7 @@ EXPORTS
lj_splined_mp_ljs_wca_model_control_
lj_splined_mp_ljs_wca_set_pure_params_
lj_splined_mp_ljs_wca_get_pure_params_
multi_phase_envelope_tv_mp_multi_phase_envelope_plot_tv_
mut_solver_mp_solve_mu_t_
mut_solver_mp_solve_lnf_t_
mut_solver_mp_map_meta_isotherm_
Expand Down Expand Up @@ -196,6 +201,7 @@ EXPORTS
saturation_curve_mp_envelopeplot_
saturation_curve_mp_envelope_isentrope_cross_
saturation_curve_mp_pure_fluid_saturation_wrapper_
saturation_tv_mp_envelope_plot_tv_
saturation_point_locators_mp_locate_saturation_property_
saturation_point_locators_mp_property_index_from_string_
saturation_point_locators_mp_sat_points_based_on_prop_
Expand Down Expand Up @@ -229,4 +235,4 @@ EXPORTS
thermopack_var_mp_get_eos_identification_
tp_solver_mp_twophasetpflash_
sv_solver_mp_twophasesvflash_
uv_solver_mp_twophaseuvflash_
uv_solver_mp_twophaseuvflash_
50 changes: 46 additions & 4 deletions Makefile.code
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,16 @@ OBJE = \
$(ODIR)/puresaturation.o \
$(ODIR)/thermo_utils.o \
$(ODIR)/critical.o \
$(ODIR)/stability.o \
$(ODIR)/saturation.o \
$(ODIR)/solideos.o \
$(ODIR)/vls.o \
$(ODIR)/stability.o \
$(ODIR)/tuning.o \
$(ODIR)/tp_solver.o \
$(ODIR)/state_functions.o \
$(ODIR)/saturation_curve.o \
$(ODIR)/saturation_tv.o \
$(ODIR)/multi_phase_envelope_tv.o \
$(ODIR)/solid_saturation.o \
$(ODIR)/saturation_point_locators.o \
$(ODIR)/joule_thompson_inversion.o \
Expand All @@ -183,6 +185,8 @@ OBJE = \
$(ODIR)/binaryplot.o \
$(ODIR)/speed_of_sound.o \
$(ODIR)/saftvrmie_testing.o \
$(ODIR)/hydrate.o \
$(ODIR)/hydrate_curves.o \
$(ODIR)/consistency.o \
$(ODIR)/eoslibinit.o \
$(ODIR)/complexmodelinit.o \
Expand Down Expand Up @@ -503,6 +507,23 @@ $(ODIR)/hardsphere_wca.o: $(SRC)/hardsphere_wca.f90 \
$(SRC)/thermopack_constants.f90 $(SRC)/hardsphere_wca.f90 \
$(SRC)/saftvrmie_options.f90
@$(call make_object, $(SRC)/hardsphere_wca.f90)
$(ODIR)/hydrate.o: $(SRC)/hydrate.f90 \
$(SRC)/thermopack_constants.f90 $(SRC)/thermopack_var.f90 \
$(SRC)/eostv.f90 $(SRC)/saturation.f90 \
$(SRC)/stringmod.f90 $(SRC)/solideos.f90 \
$(SRC)/nonlinear_solvers.f90 $(SRC)/numconstants.f90 \
$(SRC)/quadratures.f90 $(SRC)/eos.f90
@$(call make_object, $(SRC)/hydrate.f90)
$(ODIR)/hydrate_curves.o: $(SRC)/hydrate_curves.f90 \
$(SRC)/hydrate.f90 $(SRC)/thermopack_constants.f90 \
$(SRC)/thermopack_var.f90 $(SRC)/eostv.f90 \
$(SRC)/saturation.f90 $(SRC)/multi_phase_envelope_tv.f90 \
$(SRC)/saturation_tv.f90 $(SRC)/nonlinear_solvers.f90 \
$(SRC)/stability.f90 $(SRC)/numconstants.f90 \
$(SRC)/eosdata.f90 $(SRC)/cubic_eos.f90 \
$(SRC)/utilities.f90 $(SRC)/eos.f90 \
$(SRC)/thermo_utils.f90
@$(call make_object, $(SRC)/hydrate_curves.f90)
$(ODIR)/hyperdual_mod.o: $(SRC)/hyperdual_mod.f90
@$(call make_object, $(SRC)/hyperdual_mod.f90)
$(ODIR)/hyperdual_utility.o: $(SRC)/hyperdual_utility.f90 \
Expand Down Expand Up @@ -562,6 +583,16 @@ $(ODIR)/mbwrdata.o: $(SRC)/mbwrdata.f90 \
$(ODIR)/mixdatadb.o: $(SRC)/mixdatadb.f90 \
$(SRC)/cubic_eos.f90 $(SRC)/assocschemeutils.f90
@$(call make_object, $(SRC)/mixdatadb.f90)
$(ODIR)/multi_phase_envelope_tv.o: $(SRC)/multi_phase_envelope_tv.f90 \
$(SRC)/eos.f90 $(SRC)/eostv.f90 \
$(SRC)/thermopack_constants.f90 $(SRC)/nonlinear_solvers.f90 \
$(SRC)/thermopack_var.f90 $(SRC)/numconstants.f90 \
$(SRC)/thermo_utils.f90 $(SRC)/saturation.f90 \
$(SRC)/saturation_tv.f90 $(SRC)/saturation_curve.f90 \
$(SRC)/cubic_eos.f90 $(SRC)/utilities.f90 \
$(SRC)/eosdata.f90 $(SRC)/stability.f90 \
$(SRC)/critical.f90
@$(call make_object, $(SRC)/multi_phase_envelope_tv.f90)
$(ODIR)/multiparameter_base.o: $(SRC)/multiparameter_base.f90 \
$(SRC)/numconstants.f90 $(SRC)/thermopack_constants.f90 \
$(SRC)/hyperdual_mod.f90
Expand Down Expand Up @@ -765,16 +796,17 @@ $(ODIR)/saturation.o: $(SRC)/saturation.f90 \
$(SRC)/eos.f90 $(SRC)/thermopack_constants.f90 \
$(SRC)/thermopack_var.f90 $(SRC)/nonlinear_solvers.f90 \
$(SRC)/numconstants.f90 $(SRC)/puresaturation.f90 \
$(SRC)/thermo_utils.f90 $(SRC)/eostv.f90
$(SRC)/thermo_utils.f90 $(SRC)/eostv.f90 \
$(SRC)/stability.f90
@$(call make_object, $(SRC)/saturation.f90)
$(ODIR)/saturation_curve.o: $(SRC)/saturation_curve.f90 \
$(SRC)/eos.f90 $(SRC)/thermopack_constants.f90 \
$(SRC)/thermopack_var.f90 $(SRC)/numconstants.f90 \
$(SRC)/puresaturation.f90 $(SRC)/saturation.f90 \
$(SRC)/nonlinear_solvers.f90 $(SRC)/critical.f90 \
$(SRC)/thermo_utils.f90 $(SRC)/eostv.f90 \
$(SRC)/eosdata.f90 $(SRC)/utilities.f90 \
$(SRC)/solideos.f90
$(SRC)/eosdata.f90 $(SRC)/solideos.f90 \
$(SRC)/stability.f90 $(SRC)/utilities.f90
@$(call make_object, $(SRC)/saturation_curve.f90)
$(ODIR)/saturation_point_locators.o: $(SRC)/saturation_point_locators.f90 \
$(SRC)/saturation.f90 $(SRC)/saturation_curve.f90 \
Expand All @@ -786,6 +818,16 @@ $(ODIR)/saturation_point_locators.o: $(SRC)/saturation_point_locators.f90 \
$(SRC)/thermo_utils.f90 $(SRC)/critical.f90 \
$(SRC)/solideos.f90 $(SRC)/vls.f90
@$(call make_object, $(SRC)/saturation_point_locators.f90)
$(ODIR)/saturation_tv.o: $(SRC)/saturation_tv.f90 \
$(SRC)/eostv.f90 $(SRC)/thermopack_constants.f90 \
$(SRC)/thermopack_var.f90 $(SRC)/nonlinear_solvers.f90 \
$(SRC)/numconstants.f90 $(SRC)/saturation.f90 \
$(SRC)/saturation_curve.f90 $(SRC)/puresaturation.f90 \
$(SRC)/cubic_eos.f90 $(SRC)/utilities.f90 \
$(SRC)/thermo_utils.f90 $(SRC)/eos.f90 \
$(SRC)/eosdata.f90 $(SRC)/critical.f90 \
$(SRC)/stability.f90
@$(call make_object, $(SRC)/saturation_tv.f90)
$(ODIR)/single_component.o: $(SRC)/single_component.f90 \
$(SRC)/eos_parameters.f90 $(SRC)/eosdata.f90 \
$(SRC)/mbwr_additional.f90 $(SRC)/compdata.f90 \
Expand Down
90 changes: 90 additions & 0 deletions addon/pyExamples/hydrate_curves.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/python
#Modify system path
import sys
sys.path.insert(0,'../pycThermopack/')
from thermopack.cubic import cubic
import numpy as np
import matplotlib.pyplot as plt
import itertools as it
import csv

cb = cubic("CO2,H2O","SRK")
cb.init_hydrate()

Z_H2O = np.array([30.0, 100.0, 250.0])*1e-6
initial_pressure = 1.0e3
minimum_temperature = 100.0
maximum_pressure = 150.0e5
p_scaling = 1.0e-6
colors = [ "black", "blue", "red", "green", "m"]
linestyles = [ "-", "--", ":", "-.", "."]

z = np.zeros((2))
for i in range(len(Z_H2O)):
z[0] = (1-Z_H2O[i])
z[1] = Z_H2O[i]
fluid, water = cb.get_multi_phase_envelope_tv(initial_pressure, z,
minimum_temperature,
maximum_pressure)
t_vals, p_vals = (fluid.t, fluid.p)
tw_vals, pw_vals = (water.t, water.p)
t_hyd_vals, p_hyd_vals = cb.get_hydrate_apperance_curve(initial_pressure, z,
minimum_temperature,
maximum_pressure)
plt.plot(t_vals, p_vals*p_scaling, linestyle="-", color=colors[i])
#plt.plot(tw_vals, pw_vals*p_scaling, linestyle=":", color=colors[i],
# label="H2O: {} ppm".format(round(z[-1]*1e6)))
plt.plot(t_hyd_vals, p_hyd_vals*p_scaling, linestyle="--", color=colors[i],
label="Hyd. H2O: {} ppm".format(round(z[-1]*1e6)))

# z = np.ones((2))*0.5
# t_hyd_vals, p_hyd_vals = cb.get_hydrate_apperance_curve(initial_pressure, z,
# minimum_temperature,
# maximum_pressure)
# plt.plot(t_hyd_vals, p_hyd_vals*p_scaling, linestyle="--", color="orange",
# label="Hyd. excess H2O")

plt.title("SRK: CO2 and variable H2O")
leg = plt.legend(loc="best", numpoints=1)
leg.get_frame().set_linewidth(0.0)
plt.ylabel(r"$P$ (MPa)")
plt.xlabel(r"$T$ (K)")
plt.tight_layout()
plt.savefig("hydrate_co2.pdf")

plt.figure()
cb.init("CO2,N2,H2O","SRK","Classic","Classic")
cb.init_hydrate()
Z_CO2 = np.array([0.85,0.15])
Z_H2O = np.array([30.0, 100.0, 250.0])*1e-6
initial_pressure = 5.0e3

z = np.zeros((3))
for i in range(len(Z_H2O)):
z[0:2] = (1-Z_H2O[i])*Z_CO2
z[2] = Z_H2O[i]
fluid, water = cb.get_multi_phase_envelope_tv(initial_pressure, z,
minimum_temperature,
maximum_pressure)
t_vals, p_vals = (fluid.t, fluid.p)
tw_vals, pw_vals = (water.t, water.p)
t_hyd_vals, p_hyd_vals = cb.get_hydrate_apperance_curve(initial_pressure, z,
minimum_temperature,
maximum_pressure)

plt.plot(t_vals, p_vals*p_scaling, linestyle="-", color=colors[i])
# plt.plot(tw_vals, pw_vals*p_scaling, linestyle=":", color=colors[i],
# label="H2O: {} ppm".format(round(z[-1]*1e6)))
plt.plot(t_hyd_vals, p_hyd_vals*p_scaling, linestyle="--", color=colors[i],
label="Hyd. H2O: {} ppm".format(round(z[-1]*1e6)))


plt.title("SRK: CO2 (0.85), N2 (0.15) and variable H2O")
leg = plt.legend(loc="best", numpoints=1)
leg.get_frame().set_linewidth(0.0)
plt.ylabel(r"$P$ (MPa)")
plt.xlabel(r"$T$ (K)")
plt.tight_layout()
plt.savefig("hydrate_co2_n2.pdf")
plt.show()
plt.clf()
88 changes: 88 additions & 0 deletions addon/pyExamples/multi_phase_curves.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/python
#Modify system path
import sys
sys.path.insert(0,'../pycThermopack/')
from thermopack.cubic import cubic
import numpy as np
import matplotlib.pyplot as plt
import itertools as it
import csv

cb = cubic("CO2,N2,H2O","SRK")
Z_CO2 = np.array([0.85,0.15])
Z_H2O = np.array([0.05,1e-2,1e-3,1e-4])
Z_H2O = np.array([5.0, 30.0, 100.0, 1000.0])*1e-6
initial_pressure = 5.0e3
minimum_temperature = 140.0
maximum_pressure = 150.0e5
p_scaling = 1.0e-6
colors = [ "black", "blue", "red", "green"]
linestyles = [ "-", "--", ":", "-."]

z = np.zeros((3))
for i in range(len(Z_H2O)):
z[0:2] = (1-Z_H2O[i])*Z_CO2
z[2] = Z_H2O[i]
fluid, water = cb.get_multi_phase_envelope_tv(initial_pressure, z,
minimum_temperature,
maximum_pressure)
t_vals, p_vals = (fluid.t, fluid.p)
tw_vals, pw_vals = (water.t, water.p)
plt.plot(t_vals, p_vals*p_scaling, linestyle="-", color=colors[i])
plt.plot(tw_vals, pw_vals*p_scaling, linestyle="--", color=colors[i],
label="H2O: {} ppm".format(round(z[-1]*1e6)))

cb.init("CO2,N2","SRK","Classic","Classic")
Z_CO2 = np.array([0.85,0.15])
T, P, v = cb.get_envelope_twophase_tv(initial_pressure, Z_CO2,
maximum_pressure=maximum_pressure,
minimum_temperature=minimum_temperature)
plt.plot(T, P*p_scaling, linestyle="-", color="cyan", label="No water")

plt.title("SRK: CO2 (0.85), N2 (0.15) and variable H2O")
leg = plt.legend(loc="best", numpoints=1)
leg.get_frame().set_linewidth(0.0)
plt.ylabel(r"$P$ (MPa)")
plt.xlabel(r"$T$ (K)")

plt.figure()
cb.init("CO2,H2O","SRK","Classic","Classic")
initial_pressure = 1.0e3
minimum_temperature = 100.0
maximum_pressure = 150.0e5
p_scaling = 1.0e-6
colors = [ "black", "blue", "red", "green"]
linestyles = [ "-", "--", ":", "-."]

arrays = []
z = np.zeros((2))
for i in range(len(Z_H2O)):
z[0] = (1-Z_H2O[i])
z[1] = Z_H2O[i]
fluid, water = cb.get_multi_phase_envelope_tv(initial_pressure, z,
minimum_temperature,
maximum_pressure)
t_vals, p_vals = (fluid.t, fluid.p)
tw_vals, pw_vals = (water.t, water.p)
arrays += [t_vals, p_vals, tw_vals, pw_vals]
plt.plot(t_vals, p_vals*p_scaling, linestyle="-", color=colors[i])
plt.plot(tw_vals, pw_vals*p_scaling, linestyle="--", color=colors[i],
label="H2O: {} ppm".format(round(z[-1]*1e6)))

# with open('co2_h2o.csv', 'w') as f:
# csv.writer(f, delimiter='\t').writerows(it.zip_longest(*arrays, fillvalue =np.NaN))

cb.init("CO2","SRK","Classic","Classic")
Z_CO2 = np.array([1.0])
T, P, v = cb.get_envelope_twophase_tv(initial_pressure, Z_CO2,
maximum_pressure=maximum_pressure,
minimum_temperature=minimum_temperature)
plt.plot(T, P*p_scaling, linestyle="-", color="cyan", label="No water")

plt.title("SRK: CO2 and variable H2O")
leg = plt.legend(loc="best", numpoints=1)
leg.get_frame().set_linewidth(0.0)
plt.ylabel(r"$P$ (MPa)")
plt.xlabel(r"$T$ (K)")

plt.show()
4 changes: 4 additions & 0 deletions addon/pyExamples/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
print("Compressibility factor: {}".format(zFac))

sos = srk.speed_of_sound(T, P, x=z, y=z, z=z, betaV=0.0, betaL=1.0, phase=srk.LIQPH)
sos_z = srk.speed_of_sound_tv(T, v, n=z)
sos_n = srk.speed_of_sound_tv(T, v*2, n=z*2)
print("Saturated liquid speed of sound: {} (m/s)".format(sos))
print("Saturated liquid speed of sound: {} (m/s)".format(sos_z))
print("Saturated liquid speed of sound: {} (m/s)".format(sos_n))

# Properties evaluated in temperature volume and mol numbers
p, dp = srk.pressure_tv(T, v, z, dpdv=True)
Expand Down
9 changes: 9 additions & 0 deletions addon/pyUtils/exports/export_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ def append_export(method, module=None, isBindC=False):

append_export("calc_bmcsl_gij_fmt", "hardsphere_bmcsl")

append_export("hydrate", "init_hydrate_model")
append_export("hydrate", "fugacity_water_in_hydrate_tpx")
append_export("hydrate", "fugacity_water_in_hydrate_tvn")
append_export("hydrate_curves", "map_hydrate_appearance_curve")

append_export("set_standard_entropy", "ideal")
append_export("get_standard_entropy", "ideal")
append_export("set_enthalpy_of_formation", "ideal")
Expand All @@ -211,6 +216,8 @@ def append_export(method, module=None, isBindC=False):
append_export("ljs_wca_set_pure_params", "lj_splined")
append_export("ljs_wca_get_pure_params", "lj_splined")

append_export("multi_phase_envelope_plot_tv", "multi_phase_envelope_tv")

append_export("solve_mu_t", "mut_solver")
append_export("solve_lnf_t", "mut_solver")
append_export("map_meta_isotherm", "mut_solver")
Expand Down Expand Up @@ -302,6 +309,8 @@ def append_export(method, module=None, isBindC=False):
append_export("envelope_isentrope_cross", "saturation_curve")
append_export("pure_fluid_saturation_wrapper", "saturation_curve")

append_export("envelope_plot_tv", "saturation_tv")

append_export("locate_saturation_property", "saturation_point_locators")
append_export("property_index_from_string", "saturation_point_locators")
append_export("sat_points_based_on_prop", "saturation_point_locators")
Expand Down
7 changes: 0 additions & 7 deletions addon/pycThermopack/thermopack/cpa.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# Support for python2
from __future__ import print_function
# Import ctypes
from ctypes import *
# Importing Numpy (math, arrays, etc...)
import numpy as np
# Import platform to detect OS
from sys import platform, exit
# Import os utils
from os import path
# Import thermo
from .thermo import c_len_type
from .cubic import cubic

Expand Down
2 changes: 1 addition & 1 deletion addon/pycThermopack/thermopack/cubic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import numpy as np
import warnings
from os import path
from .volume_translation import volume_translation
from .thermo import c_len_type
from .volume_translation import volume_translation


class cubic(volume_translation):
Expand Down
Loading
Loading