Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 25 additions & 24 deletions fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,58 @@ source-form = "free"

[dependencies]
stdlib = "*"
forbear = {git="https://github.com/szaghi/forbear"}
json-fortran = {git="https://github.com/jacobwilliams/json-fortran"}
nlopt-f = {git="https://github.com/grimme-lab/nlopt-f"}
forsus = {git="https://github.com/ipqa-research/forsus"}
forbear = { git = "https://github.com/szaghi/forbear" }
json-fortran = { git = "https://github.com/jacobwilliams/json-fortran" }
nlopt-f = { git = "https://github.com/grimme-lab/nlopt-f" }
forsus = { git = "https://github.com/ipqa-research/forsus" }
fortime = { git = "https://github.com/gha3mi/fortime.git" }
ftools = { git = "https://github.com/fedebenelli/ftools" }


[dev-dependencies]
test-drive = {git = "https://github.com/fortran-lang/test-drive"}
test-drive = { git = "https://github.com/fortran-lang/test-drive" }

[[example]]
name = "demo"
name = "demo"
source-dir = "example/extra"
main = "demo.f90"
main = "demo.f90"

[[example]]
name = "basics"
name = "basics"
source-dir = "example/basics"
main = "1_basics.f90"
main = "1_basics.f90"

[[example]]
name = "saturation_points"
name = "saturation_points"
source-dir = "example/basics"
main = "2_saturation_points.f90"
main = "2_saturation_points.f90"

[[example]]
name = "phase_split"
name = "phase_split"
source-dir = "example/basics"
main = "3_phase_split.f90"
main = "3_phase_split.f90"

[[example]]
name = "phase_envelope"
name = "phase_envelope"
source-dir = "example/basics"
main = "4_phase_envelope.f90"
main = "4_phase_envelope.f90"

[[example]]
name = "new_alpha_function"
name = "new_alpha_function"
source-dir = "example/advanced"
main = "new_alpha_function.f90"
main = "new_alpha_function.f90"

[[example]]
name = "pure_psat"
name = "pure_psat"
source-dir = "example/basics"
main = "5_pure_psat.f90"
main = "5_pure_psat.f90"

[[example]]
name = "huron_vidal"
name = "huron_vidal"
source-dir = "example/basics"
main = "7_huron_vidal.f90"
main = "7_huron_vidal.f90"

[[example]]
name = "cubic_eos"
name = "cubic_eos"
source-dir = "example/advanced"
main = "cubic_eos.f90"

main = "cubic_eos.f90"
3 changes: 3 additions & 0 deletions src/io/io.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module yaeos__io
use yaeos__io_namelist, only: model_from_namelist
end module
119 changes: 119 additions & 0 deletions src/io/namelist.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
module yaeos__io_namelist
!! File IO to set up models from namelist files.
use yaeos__models_ar_genericcubic, only: CubicMixRule
use yaeos, only: &
pr, &
ArModel, &
CubicEoS , PengRobinson76, PengRobinson78, SoaveRedlichKwong, RKPR, &
QMR, MHV
implicit none

contains

function model_from_namelist(filepath) result(model)
character(len=*), intent(in) :: filepath
class(ArModel), allocatable :: model

integer :: nc
character(len=50) :: model_name

call read_setup(filepath, nc, model_name)

select case(model_name)
case("SoaveRedlichKwong", "PengRobinson76", "PengRobinson78", "RKPR")
model = read_cubic_eos(filepath, nc, model_name)
end select
end function model_from_namelist

type(CubicEoS) function read_cubic_eos(filepath, nc, model_name) result(model)
character(len=*), intent(in) :: filepath
integer, intent(in) :: nc
character(len=*), intent(in) :: model_name
character(len=50) :: mixrule
class(CubicMixRule), allocatable :: mix

real(pr) :: Tc(nc), Pc(nc), w(nc), Zc(nc)

integer :: fu

namelist /yaeos_cubic/ mixrule

call read_critical(filepath, Tc, Pc, w, Zc)

select case (model_name)
case("SoaveRedlichKwong")
model = SoaveRedlichKwong(Tc, Pc, w)
case("PengRobinson76")
model = PengRobinson76(Tc, Pc, w)
case("PengRobinson78")
model = PengRobinson78(Tc, Pc, w)
case("RKPR")
model = RKPR(Tc, Pc, w, Zc)
case default
error stop 1
end select

open(newunit=fu, file=filepath)
read(fu, nml=yaeos_cubic)
close(fu)

select case (mixrule)
case("QMR")
mix = QMR_from_namelist(filepath, nc)
deallocate(model%mixrule)
model%mixrule = mix
case default
error stop 1
end select
end function read_cubic_eos

type(QMR) function QMR_from_namelist(filepath, nc)
character(len=*), intent(in) :: filepath
integer, intent(in) :: nc

integer :: fu

real(pr) :: kij(nc, nc), lij(nc, nc)

namelist /yaeos_qmr/ kij, lij

kij = 0
lij = 0
open(newunit=fu, file=filepath)
read(fu, nml=yaeos_qmr)
close(fu)

QMR_from_namelist = QMR(kij, lij)
end function QMR_from_namelist

subroutine read_setup(filepath, nc, model)
character(len=*), intent(in) :: filepath
integer, intent(out) :: nc
character(len=50), intent(out) :: model

namelist /yaeos_setup/ nc, model

integer :: fu

open(newunit=fu, file=filepath)
read(fu, nml=yaeos_setup)
close(fu)
end subroutine read_setup

subroutine read_critical(filepath, Tc, Pc, w, Zc)
character(len=*), intent(in) :: filepath
real(pr), intent(out) :: Tc(:), Pc(:), w(:), Zc(:)
integer :: fu

namelist /yaeos_critical/ Tc, Pc, w, Zc

Tc = 0
Pc = 0
w = 0
Zc = 0

open(newunit=fu, file=filepath)
read(fu, nml=yaeos_critical)
close(fu)
end subroutine read_critical
end module yaeos__io_namelist
21 changes: 21 additions & 0 deletions test/data/model.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
&yaeos_setup
nc = 3
model = "PengRobinson76"
/

&yaeos_cubic
mixrule = "QMR"
/

&yaeos_critical
Tc = 190 200 300
Pc = 10 30 40
w = 0.1 0.2 0.3
Zc = 0.15 0.2 0.25
/

&yaeos_qmr
kij(1, :) = 0 2 3
kij(2, :) = 2 0 4
kij(3, :) = 3 4 0
/
25 changes: 25 additions & 0 deletions test/test_io.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
program test_io
use yaeos, only: ArModel, CubicEoS, QMR
use yaeos__io, only: model_from_namelist
implicit none

class(ArModel), allocatable :: model
model = model_from_namelist("test/data/model.nml")

select type(model)
type is (CubicEoS)
print *, model%components%Tc
print *, model%components%Pc
print *, model%components%w

associate (mr => model%mixrule)
select type(mr)
type is (QMR)
print *, mr%k(1, :)
print *, mr%k(2, :)
print *, mr%k(3, :)
end select
end associate

end select
end program