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

Dev #6

Merged
merged 29 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
150a755
feat(DSP): Calculation of DSP lines
fedebenelli Nov 15, 2023
8f60a0b
cleaning of DSP mod
fedebenelli Nov 15, 2023
e205548
testing of functions with numerical diff
fedebenelli Nov 15, 2023
289efbf
No longer using this example image
fedebenelli Nov 15, 2023
935f40c
feat(linalg): Trying using MINPACK
fedebenelli Nov 15, 2023
12225dc
form
fedebenelli Nov 15, 2023
066e9a3
feat(fpm): added minpack dependency
fedebenelli Nov 15, 2023
f88e771
feat(Kinit): Kwilson for bubble points
fedebenelli Nov 15, 2023
89c3d3c
feat(F2PT): Added default cases
fedebenelli Nov 15, 2023
511f718
feat(HPLL): Generalizing method to find HPLL line
fedebenelli Nov 15, 2023
a9612fe
refactor(PT2ph): Trying different limits
fedebenelli Nov 15, 2023
2b30995
refactor(PT2ph): Detections
fedebenelli Nov 15, 2023
6c271a2
feat(PT3ph): Break on positive or negative beta
fedebenelli Nov 15, 2023
f12e5f4
feat(PT3ph): Critical points factors
fedebenelli Nov 15, 2023
c9db313
feat(PT2ph): Increasing deltaS jump
fedebenelli Nov 15, 2023
8fdbe61
prints on output after namelist reading
fedebenelli Nov 15, 2023
548ce6e
WIP(Px2ph): Initialization from PT
fedebenelli Nov 15, 2023
f650b02
feat(Px3ph): Added more details to ouput
fedebenelli Nov 15, 2023
d932deb
stepping parameters
fedebenelli Nov 15, 2023
18d4078
critical points
fedebenelli Nov 15, 2023
1633025
initializatoin from DSP
fedebenelli Nov 15, 2023
5bff29e
limiting a bit the calculation of isolated lines, tihs should be perf…
fedebenelli Nov 15, 2023
d8aced9
Don't remove lowP PT; this can give useful lines too!
fedebenelli Nov 15, 2023
c66fcaa
Kwilson initialization
fedebenelli Nov 15, 2023
5c189b1
Dew line initial temperature. This should be remove later
fedebenelli Nov 15, 2023
04e4365
Possibility of calculate PT line on a specific alpha.
fedebenelli Nov 15, 2023
dff2b5e
Calculation of DSP lines
fedebenelli Nov 15, 2023
b36fbab
calculation of self intersection on Px lines, should add bubble
fedebenelli Nov 15, 2023
b9bcf2f
tolerances for PxfromPT
fedebenelli Nov 15, 2023
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
76 changes: 53 additions & 23 deletions app/main.f90
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
program main
use envelopes, only: PTEnvel3
use dtypes, only: envelope
use inj_envelopes, only: injelope
use envelopes, only: PTEnvel3
use inj_envelopes, only: injelope, get_z
use constants, only: pr, ouput_path
use legacy_ar_models, only: nc
use legacy_ar_models, only: nc, z
use flap, only: command_line_interface
use stdlib_ansi, only: blue => fg_color_blue, red => fg_color_red, &
operator(//), operator(+), &
Expand All @@ -20,9 +20,12 @@ program main
type(PTEnvel3), allocatable :: pt_bub_3(:), pt_dew_3(:) !! Shared 3ph-PT envelopes
type(injelope) :: px_bub, px_dew, px_hpl !! Shared 2ph-Px envelopes

real(pr) :: alpha=0.0

! Setup everything
call setup

call get_z(alpha, z)
! PT Envelopes
call cpu_time(st)
call pt_envelopes
Expand Down Expand Up @@ -106,18 +109,18 @@ subroutine pt_envelopes
! ========================================================================
! Bubble envel
! ------------------------------------------------------------------------
call k_wilson_bubble(z, t, p, k)
call k_wilson_bubble(z, t_0=230.0_pr, p_end=0.5_pr, t=t, p=p, k=k)
call envelope2( &
1, nc, z, T, P, k, &
n_points, Tv, Pv, Dv, ncri, icri, Tcri, Pcri, Dcri, &
pt_bub &
)
)
! ========================================================================

! ========================================================================
! Dew/AOP envelopes
! ------------------------------------------------------------------------
t = 200
t = 300
p = p_wilson(z, t)
do while (p > 0.1)
t = t - 5
Expand All @@ -131,19 +134,6 @@ subroutine pt_envelopes
n_points, Tv, Pv, Dv, ncri, icri, Tcri, Pcri, Dcri, &
pt_dew &
)

! Remove the low pressure parts.
! n = 1
! do i = 2, size(pt_dew%t)
! n = n + 1
! if (pt_dew%t(i) - pt_dew%t(i - 1) < 0) exit
! end do

! if (n /= size(pt_dew%t)) then
! pt_dew%t = pt_dew%t(i:)
! pt_dew%p = pt_dew%p(i:)
! pt_dew%logk = pt_dew%logk(i:, :)
! end if
! ========================================================================

! ========================================================================
Expand Down Expand Up @@ -176,10 +166,17 @@ subroutine pt_envelopes

three_phase: block
use envelopes, only: pt_three_phase_from_intersection

allocate(pt_bub_3(size(intersections)), pt_dew_3(size(intersections)))
select case(pt_case)
case("2_DEW_BUB")
dsp_line: block
use dsp_lines, only: injelope, dsp_line_from_dsp
type(injelope):: dsps(2)
integer :: i
do i=1,size(intersections)
dsps = dsp_line_from_dsp(intersections(i), pt_dew, pt_bub)
end do
end block dsp_line
call pt_three_phase_from_intersection(&
pt_dew, pt_bub, intersections, &
pt_bub_3, pt_dew_3 &
Expand All @@ -193,12 +190,45 @@ subroutine pt_envelopes
pt_dew, pt_bub, [intersections(2)], &
pt_bub_3, pt_dew_3 &
)
case("2_HPL_BUB")
call pt_three_phase_from_intersection(&
pt_hpl, pt_bub, [intersections(1)], &
pt_bub_3, pt_dew_3 &
)
call pt_three_phase_from_intersection(&
pt_hpl, pt_bub, [intersections(2)], &
pt_bub_3, pt_dew_3 &
)
dsp_line_2hpl_bub: block
use dsp_lines, only: injelope, dsp_line_from_dsp
type(injelope):: dsps(2)
integer :: i
do i=1,size(intersections)
dsps = dsp_line_from_dsp(intersections(i), pt_hpl, pt_bub, alpha0=alpha)
end do
end block dsp_line_2hpl_bub
case("1_HPL_DEW")
dsp_line_hpl: block
use dsp_lines, only: injelope, dsp_line_from_dsp
type(injelope):: dsps(2)
integer :: i
do i=1,size(intersections)
dsps = dsp_line_from_dsp(intersections(i), pt_hpl, pt_dew, alpha0=alpha)
end do
end block dsp_line_hpl
call pt_three_phase_from_intersection(&
pt_hpl, pt_dew, intersections, &
pt_bub_3, pt_dew_3 &
)
case("1_HPL_BUB")
dsp_line_hpl_bub: block
use dsp_lines, only: injelope, dsp_line_from_dsp
type(injelope):: dsps(2)
integer :: i
do i=1,size(intersections)
dsps = dsp_line_from_dsp(intersections(i), pt_hpl, pt_bub)
end do
end block dsp_line_hpl_bub
call pt_three_phase_from_intersection(&
pt_hpl, pt_bub, intersections, &
pt_dew_3, pt_bub_3 &
Expand Down Expand Up @@ -238,7 +268,7 @@ subroutine px_envelopes
px_bub = px_two_phase_from_pt(t_inj, pt_bub, t_tol=5.0_pr)

print *, blue // "Running Dew" // style_reset
px_dew = px_two_phase_from_pt(t_inj, pt_dew, t_tol=15.0_pr)
px_dew = px_two_phase_from_pt(t_inj, pt_dew, t_tol=5.0_pr)

print *, blue // "Running HPLL" // style_reset
px_hpl = px_hpl_line(0.99_pr, maxval(px_bub%p))
Expand All @@ -248,7 +278,7 @@ subroutine px_envelopes
! Look for crossings
! ------------------------------------------------------------------------
inter = intersection(px_dew%alpha, px_dew%p, px_bub%alpha, px_bub%p)
self_inter = intersection(px_dew%alpha, px_dew%p)
self_inter = intersection(px_bub%alpha, px_bub%p)
print *, style_bold // "Px Intersections: " // style_reset, size(inter)
print *, style_bold // "Px Self-Intersections: " // style_reset, size(self_inter)
! ========================================================================
Expand Down Expand Up @@ -277,7 +307,7 @@ subroutine px_envelopes
!TODO: Add a check if one of the previous lines already
! in this DSP
px_branch_3 = px_three_phase_from_inter(&
self_inter(i), px_dew, px_dew &
self_inter(i), px_bub, px_bub &
)
end do
end if
Expand Down
Binary file removed figs/example.png
Binary file not shown.
3 changes: 2 additions & 1 deletion fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ maintainer = "[email protected]"
copyright = "Copyright 2023, Federico E. Benelli"

[build]
link = ["lapack", "minpack"]
link = ["lapack"]
auto-executables = true
auto-tests = true
auto-examples = true
Expand All @@ -16,6 +16,7 @@ library = false

[dependencies]
stdlib = "*"
minpack= "*"
ftools = { git = "https://github.com/fedebenelli/ftools" }
yaeos = { git = "https://github.com/fedebenelli/yaeos" }
FLAP = { git = "https://github.com/szaghi/FLAP", tag="v1.2.5" }
Expand Down
48 changes: 40 additions & 8 deletions src/linalg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function intersect_one_line(lx, ly) result(intersections)

allocate (intersections(0))
line1: do i = 2, size(lx) - 1
line2: do j = i + 15, size(lx)
line2: do j = i + 2, size(lx)
associate ( &
x1 => lx(i - 1), x2 => lx(i), &
x3 => lx(j), x4 => lx(j - 1), &
Expand Down Expand Up @@ -185,6 +185,7 @@ subroutine full_newton(fun, iters, X, ns, S, max_iters, F, dF)
!!
!! Procedure that solves a point with the Newton-Raphson method.
use constants, only: ouput_path
use minpack_module, only: dpmpar, hybrj1
interface
subroutine fun(X, ns, S, F, dF)
!! Function to solve
Expand All @@ -207,28 +208,59 @@ subroutine fun(X, ns, S, F, dF)
!&>

real(pr) :: b(size(X)), A(size(X), size(X))
real(pr) :: dX(size(X)), tol = 1e-2
integer :: funit_log_newton
real(pr) :: dX(size(X)), tol = 1e-6

integer :: n
integer :: n, ldfjac, info, lwa, funit
real(pr) :: fvec(size(x)), fjac(size(x),size(x))
real(pr), allocatable :: wa(:)

n = size(X)
! ldfjac = n
! lwa = (n*(n+13))/2
! allocate(wa(lwa))
! call hybrj1(fcn, n, x, Fvec, Fjac, Ldfjac, Tol, Info, Wa, Lwa)

! f = fvec
! df = fjac
! iters = 3
! if (info == 4) iters = max_iters+1

dX = 20

! open(newunit=funit, file="fenvelopes_output/newton")
! write(funit, *) n
b = 500

newton: do iters = 1, max_iters
if (maxval(abs(dx/x)) < tol) exit newton
if (maxval(abs(dx/x)) < tol .or. maxval(abs(b)) < tol) exit newton
call fun(X, ns, S, b, a)
b = -b

if (any(isnan(b))) dx = dx/maxval(abs(dx))
dX = solve_system(A, b)

do while (maxval(abs(dx)) > 0.5*maxval(abs(x)))
dX = dX/2
do while(maxval(abs(dx)) > 0.5)
dX = dX/10
end do

! write(funit, *) x, dx, -b

X = X + dX
end do newton

F = -b
dF = A
! close(funit)

contains
subroutine fcn(n, x, fvec, fjac, ldfjac, iflag)
integer, intent(in) :: N
real(pr), intent(in) :: x(n)
real(pr), intent(inout) :: fvec(n)
real(pr), intent(inout) :: fjac(ldfjac, n)
integer, intent(in) :: ldfjac
integer, intent(inout) :: iflag
call fun(X, ns, S, fvec, fjac)
end subroutine
end subroutine
end module linalg
end module linalg
Loading
Loading