Skip to content

Commit

Permalink
parallel flash grid, Python API pending
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebenelli committed Sep 10, 2024
1 parent b081bb0 commit b5232a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
39 changes: 38 additions & 1 deletion c_interface/yaeos_c.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module yaeos_c
public :: lnphi_vt, lnphi_pt, pressure, volume

! Phase equilibria
public :: flash
public :: flash, flash_grid
public :: saturation_pressure
public :: pt2_phase_envelope

Expand Down Expand Up @@ -434,4 +434,41 @@ subroutine pt2_phase_envelope(id, z, kind, max_points, Ts, Ps, tcs, pcs, T0, P0)
Tcs(:i) = env%cps%T
Pcs(:i) = env%cps%P
end subroutine pt2_phase_envelope

subroutine flash_grid(id, z, Ts, Ps, xs, ys, Vxs, Vys, betas)
use yaeos, only: EquilibriumState, flash
integer(c_int), intent(in) :: id
real(c_double), intent(in) :: z(:)
real(c_double), intent(in) :: Ts(:)
real(c_double), intent(in) :: Ps(:)
real(c_double), dimension(size(Ps), size(Ts), size(z)), intent(out) :: xs, ys
real(c_double), dimension(size(Ps), size(Ts)), intent(out) :: Vxs, Vys, betas

class(ArModel), allocatable :: model
type(EquilibriumState) :: flash_result

real(8) :: T, P

integer :: i, j, nt, np, iter

model = ar_models(id)%model
np = size(Ps)
nt = size(Ts)

!$OMP PARALLEL DO PRIVATE(i, j, t, p, flash_result) shared(model, z, ts, ps, betas, Vxs, Vys, xs, ys)
do i=1,np
do j=1,nt
T = Ts(j)
P = Ps(i)
flash_result = flash(model, z, T=T, P_spec=P, iters=iter)
betas(i, j) = flash_result%beta

Vxs(i, j) = flash_result%Vx
Vys(i, j) = flash_result%Vy
xs(i, j, :) = flash_result%x
ys(i, j, :) = flash_result%y
end do
end do
!$OMP END PARALLEL DO
end subroutine
end module yaeos_c
4 changes: 2 additions & 2 deletions python/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ py.extension_module(module_name,
[c_wrapper, f2py_gen_source],
incdir_f2py / 'fortranobject.c',
include_directories: [inc_np],
dependencies : py_dep,
link_args: ['-L' + 'fpm_build' / 'lib', '-l' + 'yaeos', '-llapack'],
dependencies : [py_dep, omp],
link_args: ['-L' + 'fpm_build' / 'lib', '-l' + 'yaeos', '-llapack', '-fopenmp'],
subdir: python_lib / 'lib',
install : true,
)

0 comments on commit b5232a3

Please sign in to comment.