-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from ipqa-research/dev
Set of examples
- Loading branch information
Showing
22 changed files
with
275 additions
and
1,554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# yaeos examples | ||
Here are located a set of examples of how the library could be used. | ||
|
||
We show them in three different categories: | ||
|
||
- basics: The basics of what can be done with the library | ||
1. Thermodynamic properties | ||
2. Saturation points | ||
3. Phase split (FlashPT and FlashVT) | ||
4. Phase envelopes tracing | ||
5. Implementation of a simple algorithm to calculate pure component | ||
saturation pressure. | ||
- Advanced: How a more advanced user can take benefit of the library. | ||
- extra: Other set of examples with no particular structure. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
program basics | ||
use yaeos ! First the module is imported (used). This will bring all the | ||
! types and functions defined in the module to this program. | ||
implicit none | ||
! =========================================================================== | ||
|
||
! In yaeos, all residual Helmholtz models are based on the structure | ||
! `ArModel` and are derivatives from it. | ||
! Defining the model variable as an allocatable ArModel means that this | ||
! variable can be redefined as any other kind of variable that derives from | ||
! `ArModel`, for example `CubicEoS`. | ||
class(ArModel), allocatable :: model | ||
|
||
integer, parameter :: nc=2 !! In this case we define a constant number of | ||
!! components. | ||
|
||
! Used input variables | ||
real(pr) :: n(nc), Tc(nc), Pc(nc), w(nc) | ||
|
||
! Output variables | ||
real(pr) :: P, dPdV | ||
! --------------------------------------------------------------------------- | ||
|
||
! Here the executed code starts | ||
|
||
! A classic Cubic model can be defined with each component critial constants | ||
tc = [190._pr, 310._pr] | ||
pc = [14._pr, 30._pr ] | ||
w = [0.001_pr, 0.03_pr] | ||
|
||
! Here we chose to model with the PengRobinson EoS | ||
model = PengRobinson78(tc, pc, w) | ||
|
||
! Number of moles vector | ||
n = [0.3, 0.7] | ||
|
||
! Pressure calculation | ||
call model%pressure(n, V=2.5_pr, T=150._pr, P=P) | ||
print *, "P: ", P | ||
|
||
! Derivatives can also be calculated when included as optional arguments! | ||
call model%pressure(n, V=2.5_pr, T=150._pr, P=P, dPdV=dPdV) | ||
print *, "dPdV: ", dPdV | ||
|
||
thermoproperties: block | ||
!! Al the bulk thermodynamic properties currently available | ||
real(pr) :: Cpr, Cvr | ||
real(pr) :: Gr, GrT, GrV, Grn(nc) | ||
real(pr) :: Hr, HrT, HrV, Hrn(nc) | ||
real(pr) :: lnPhi(nc), dlnPhidT(nc), dlnPhidP(nc), dlnPhidn(nc, nc) | ||
|
||
real(pr) :: n(nc), P, V, T | ||
|
||
n = [0.3_pr, 0.7_pr] | ||
V = 3.5_pr | ||
P = 5.0_pr | ||
call model%Cp_residual_vt(n, V=2.5_pr, T=150._pr, Cp=Cpr) | ||
call model%Cv_residual_vt(n, V=2.5_pr, T=150._pr, Cv=Cvr) | ||
call model%gibbs_residual_vt(n, V=2.5_pr, T=150._pr, Gr=Gr, GrT=GrT, GrV=GrV, Grn=Grn) | ||
call model%enthalpy_residual_vt(n, V=2.5_pr, T=150._pr, Hr=Hr, HrT=HrT, HrV=HrV, Hrn=Hrn) | ||
call model%lnphi_pt(& | ||
n, P=P, T=T, root_type="stable", & | ||
lnPhi=lnPhi, dlnPhidT=dlnphidT, dlnPhidP=dlnPhidP, dlnPhidn=dlnPhidn & | ||
) | ||
call model%lnphi_vt(& | ||
n, V=V, T=T, & | ||
lnPhi=lnPhi, dlnPhidT=dlnphidT, dlnPhidP=dlnPhidP, dlnPhidn=dlnPhidn & | ||
) | ||
call model%volume(n, P=P, T=T, root_type="vapor", V=V) | ||
end block thermoproperties | ||
end program basics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
program flasher | ||
!! Example program to make flash calculations with a PengRobinson76 | ||
!! EoS model. | ||
|
||
! Import the relevant | ||
use yaeos, only: pr, EquilibriumState, flash, PengRobinson76, ArModel, k_wilson | ||
implicit none | ||
|
||
! Variables definition: | ||
class(ArModel), allocatable :: model !! Model to use | ||
type(EquilibriumState) :: flash_result !! Result of Flash calculation | ||
|
||
real(pr) :: tc(2), pc(2), w(2) | ||
real(pr) :: n(2), t, p, k0(2) | ||
integer :: iter | ||
|
||
! Code starts here: | ||
print *, "FLASH EXAMPLE:" | ||
print *, "Methane/Butane mixture" | ||
|
||
! Methane/ Butane mixture | ||
n = [0.4, 0.6] ! Composition | ||
tc = [190.564, 425.12] ! Critical temperatures | ||
pc = [45.99, 37.96] ! Critical pressures | ||
w = [0.0115478, 0.200164] ! Acentric factors | ||
|
||
! Use the PengRobinson76 model | ||
model = PengRobinson76(tc, pc, w) | ||
|
||
! Set pressure and temperatures | ||
P = 60 | ||
T = 294 | ||
|
||
! Calculate flashes | ||
flash_result = flash(model, n, t=t, p_spec=p, iters=iter) | ||
write(*, *) flash_result | ||
|
||
! K-wilson factors for initialization | ||
k0 = k_wilson(model, T=T, P=P) | ||
flash_result = flash(model, n, t=t, p_spec=p, k0=k0, iters=iter) | ||
write(*, *) flash_result | ||
|
||
! Specify volume | ||
flash_result = flash(model, n, t=t, V_spec=1.0_pr, iters=iter) | ||
write(*, *) flash_result | ||
end program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
program phase_envelope | ||
use yaeos | ||
implicit none | ||
|
||
class(ArModel), allocatable :: model ! Model | ||
type(EquilibriumState) :: bubble ! Saturation point | ||
type(PTEnvel2) :: envelope | ||
|
||
integer, parameter :: nc=2 | ||
real(pr) :: z(nc), tc(nc), pc(nc), w(nc) | ||
|
||
tc = [190.564, 425.12] ! Critical temperatures | ||
pc = [45.99, 37.96] ! Critical pressures | ||
w = [0.0115478, 0.200164] ! Acentric factors | ||
|
||
! Get the example PR76 binary model | ||
model = PengRobinson76(tc, pc, w) | ||
|
||
! Composition | ||
z = [0.1_pr, 0.9_pr] | ||
|
||
! Calculate a bubble point at 100K to initialize the rest of the phase | ||
! envelope calculation | ||
bubble = saturation_pressure(model, z, T=150._pr, kind="bubble") | ||
|
||
! Calculate the whole phase envelope using the information from the converged | ||
! dew point | ||
envelope = pt_envelope_2ph(model, z, bubble) | ||
|
||
! Write the resulting phase envelope to the screen | ||
write(*, *) envelope | ||
|
||
! Write the resulting phase envelope to a file | ||
open(1, file="phase_envelope.dat") | ||
write(1, *) envelope | ||
close(1) | ||
|
||
! It is also possible to initialize the phase_envelope with a manually | ||
! defined point | ||
manual: block | ||
real(pr) :: k(nc), T, P | ||
T = 150 | ||
P = 1 | ||
k = k_wilson(model, T=T, P=P) | ||
|
||
! Define manually an initial point | ||
bubble%kind = "bubble" | ||
bubble%x = z | ||
bubble%y = k*z | ||
bubble%beta = 0 | ||
|
||
envelope = pt_envelope_2ph(model, z, bubble) | ||
end block manual | ||
end program phase_envelope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
program examples | ||
use bench, only: benchmarks => main | ||
! use bench, only: benchmarks => main | ||
use hyperdual_pr76, only: run_hyperdual_pr76 => main | ||
use flashing, only: run_flashes => main | ||
use TapeRobinson, only: run_tape_pr76 => main | ||
use tape_nrtl, only: run_tape_nrtl => main | ||
|
||
! print *, "Running Tapenade generated NRTL model" | ||
! call run_tape_nrtl | ||
! print *, "Running Tapenade generated PR76" | ||
! call run_tape_pr76 | ||
! print *, "Running Hyperdual generated PR76" | ||
! call run_hyperdual_pr76 | ||
print *, "Running bencharks O(f(N))" | ||
call benchmarks | ||
! print *, "Flash example" | ||
! call run_flashes | ||
print *, "=========================================" | ||
print *, "YAEOS DEMO" | ||
print *, "Running Tapenade generated NRTL model" | ||
call run_tape_nrtl | ||
print *, "Running Hyperdual generated PR76" | ||
call run_hyperdual_pr76 | ||
! print *, "Running bencharks O(f(N))" | ||
! call benchmarks | ||
print *, "Flash example" | ||
call run_flashes | ||
print *, "=========================================" | ||
end program |
Oops, something went wrong.