Skip to content

Commit

Permalink
only and preprocess version
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebenelli committed Apr 16, 2024
1 parent 810a0b0 commit c079243
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
11 changes: 9 additions & 2 deletions fpm.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name = "forsus"
version = "0.1.0"
license = "license"
version = "0.1.1"
license = "LICENCE"
author = "Federico E. Benelli"
maintainer = "[email protected]"
copyright = "Copyright 2024, Federico E. Benelli"
categories = ["thermodynamic", "chemistry", "properties"]
keywords = ["equation of state", "thermodyanmics", "substances", "properties"]
homepage = "https://ipqa-research.github.io/forsus"

[build]
auto-executables = true
Expand All @@ -21,3 +24,7 @@ source-form = "free"

[dependencies]
json-fortran = {git = "https://github.com/jacobwilliams/json-fortran" }

[preprocess]
[preprocess.cpp]
macros=['VERSION=\"0.1.1\"']
2 changes: 1 addition & 1 deletion src/forsus.f90 → src/forsus.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module forsus
use forsus_properties
use forsus_substance

character(len=*), parameter :: version = "0.1.1"
character(len=*), parameter :: version = VERSION
end module
29 changes: 24 additions & 5 deletions src/substance.f90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module forsus_substance
!! sus = Substance("1-butanol", path="the/json/is/here/")
!! ```
!!
!! ### Extracting limited information
!! ### Extracting only specific information
!!
!! ```fortran
!! use forsus, only: Substance
Expand All @@ -57,6 +57,14 @@ module forsus_substance
!! only_these(3) = "mathiascopeman"
!! sus = Substance("1-butanol", only=only_these)
!! ```
!!
!! The available parameters to single extraction are:
!!
!! - "critical": Tc, Pc and Acentric Factor
!! - "unifac_vle": UNIFAC-VLE (Original UNIFAC) parameters
!! - "parachor": Parachor
!! - "mathiascopeman": Mathias Copeman \(\alpha\) function
!! parameters
character(len=:), allocatable :: name
!! Substance name
type(CriticalConstants) :: critical
Expand Down Expand Up @@ -87,6 +95,10 @@ type(Substance) function init_json(name, path, only)
!! Only extract this parameters, the options are:
!!
!! - "critical": Tc, Pc and Acentric Factor
!! - "unifac_vle": UNIFAC-VLE (Original UNIFAC) parameters
!! - "parachor": Parachor
!! - "mathiascopeman": Mathias Copeman \(\alpha\) function
!! parameters

character(len=:), allocatable :: file
integer :: i
Expand All @@ -95,20 +107,27 @@ type(Substance) function init_json(name, path, only)
file = init_json%name // ".json"

if (.not. present(only)) then
call init_json%critical%from_json(file, path)
call init_json%unifac_vle%from_json("UnifacVLE", file, path)
call init_json%parachor%from_json("Parachor", file, path)
call init_json%mathiascopeman(1)%from_json("MatthiasCopemanC1", file, path)
call init_json%mathiascopeman(2)%from_json("MatthiasCopemanC2", file, path)
call init_json%mathiascopeman(3)%from_json("MatthiasCopemanC3", file, path)
call init_json%unifac_vle%from_json("UnifacVLE", file, path)
call init_json%critical%from_json(file, path)
else
do i=1,size(only)
select case(only(i))
select case(trim(only(i)))
case("critical")
call init_json%critical%from_json(init_json%name//".json", path)
case("unifac_vle")
call init_json%unifac_vle%from_json("UnifacVLE", file, path)
case("mathiascopeman")
call init_json%mathiascopeman(1)%from_json("MatthiasCopemanC1", file, path)
call init_json%mathiascopeman(2)%from_json("MatthiasCopemanC2", file, path)
call init_json%mathiascopeman(3)%from_json("MatthiasCopemanC3", file, path)
case("parachor")
call init_json%parachor%from_json("Parachor", file, path)
end select
end do
end if

end function
end module
27 changes: 23 additions & 4 deletions test/test.f90
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
program main
use forsus, only: Substance, pr, forsus_dir
use forsus, only: Substance, pr, forsus_dir, version
implicit none
real(pr) :: tolerance = 1e-4
type(Substance) :: sus

print *, "ForSus version: ", version

call test_failed_read

sus = Substance("ethanol")
Expand All @@ -16,12 +18,29 @@ program main
sus = Substance("ethanol")
call test_values

sus = Substance("ethanol", only=["critical"])
call test_critical

call test_only

contains

subroutine test_only
integer :: i

sus = Substance("ethanol", only=["critical"])
call test_critical

sus = Substance("ethanol", only=["unifac_vle"])
call test_int([1, 2, 15], sus%unifac_vle%ids, "UNIFAC-VLE ids")
call test_int([1, 1, 1], sus%unifac_vle%counts, "UNIFAC-VLE counts")

sus = Substance("ethanol", only=["mathiascopeman"])
call test(1.3327_pr, sus%mathiascopeman(1)%value, "MathiasCopemanC1")
call test(0.96946_pr, sus%mathiascopeman(2)%value, "MathiasCopemanC2")
call test(-3.1879_pr, sus%mathiascopeman(3)%value, "MathiasCopemanC3")

sus = Substance("ethanol", only=["parachor"])
call test(2.2601e-2_pr, sus%parachor%value, "Parachor")
end subroutine

subroutine test_values
! =============================================================================
! Critical properties
Expand Down

0 comments on commit c079243

Please sign in to comment.