Base type and derivative adapter for models defined with hyperdual numbers.
Extend ArModelAdiff, implement its hyperdual Ar function and the
inherited volume initializer, and the adapter extracts the first and
second derivatives required by the standard ArModel interface.
This is the intended user entry point for operator-overloaded AD; the
adapter routines are its implementation details.
All that is needed is a derived type extending ArModelAdiff, a
hyperdual-valued Ar function, and the inherited volume initializer.
module newmodel
use yaeos__adiff_hyperdual_ar_api, only: ArModelAdiff
use yaeos__constants, only: pr
use hyperdual_mod, only: hyperdual
implicit none
type, extends(ArModelAdiff) :: YourNewModel
real(pr) :: a = 1.0_pr
contains
procedure :: Ar => arfun
procedure :: get_v0 => v0
end type
contains
type(hyperdual) function arfun(self, n, v, t) result(arval)
class(YourNewModel) :: self
type(hyperdual), intent(in) :: n(:), v, t
arval = sum(n) * t + self%a * v
end function arfun
function v0(self, n, p, t) result(vol)
class(YourNewModel), intent(in) :: self
real(pr), intent(in) :: n(:), p, t
real(pr) :: vol
vol = self%a * sum(n)
end function v0
end module newmodel
See example/extra/adiff_pr76.f90 and the user guide’s automatic-
differentiation page for a complete implementation.
Evaluate the model’s residual Helmholtz energy [bar L] in hyperdual arithmetic.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(ArModelAdiff) | :: | self |
Concrete EOS model; passed-object dummy. |
|||
| type(hyperdual), | intent(in) | :: | n(:) |
Component mole amounts as hyperdual values. |
||
| type(hyperdual), | intent(in) | :: | v |
Total volume as a hyperdual value. |
||
| type(hyperdual), | intent(in) | :: | t |
Temperature as a hyperdual value. |
Base type for residual Helmholtz models defined with hyperdual arithmetic.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| type(Substances), | public | :: | components |
Pure-component properties for the model’s component order. |
|||
| character(len=:), | public, | allocatable | :: | name |
Name of the model |
| procedure(hyperdual_Ar), public, deferred :: Ar | |
| procedure, public :: Cp_residual_pt | |
| procedure, public :: Cp_residual_vt | |
| procedure, public :: Cv_residual_pt | |
| procedure, public :: Cv_residual_vt | |
| procedure, public :: Psat_pure | |
| procedure, public :: enthalpy_excess | |
| procedure, public :: enthalpy_residual_pt | |
| procedure, public :: enthalpy_residual_vt | |
| procedure, public :: entropy_excess | |
| procedure, public :: entropy_residual_pt | |
| procedure, public :: entropy_residual_vt | |
| procedure(abs_volume_initializer), public, deferred :: get_v0 | |
| procedure, public :: gibbs_excess | |
| procedure, public :: gibbs_residual_pt | |
| procedure, public :: gibbs_residual_vt | |
| procedure, public :: helmholtz_excess | |
| procedure, public :: helmholtz_residual_pt | |
| procedure, public :: internal_energy_excess | |
| procedure, public :: internal_energy_residual_pt | |
| procedure, public :: internal_energy_residual_vt | |
| procedure, public :: ln_activity_coefficient | |
| procedure, public :: lnfug_vt | |
| procedure, public :: lnphi_pt | |
| procedure, public :: lnphi_vt | |
| procedure, public :: pressure | |
| procedure, public :: residual_helmholtz | |
| procedure, public :: volume | |
| procedure, public :: volume_excess |
Evaluate residual Helmholtz energy and requested derivatives by AD.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(ArModelAdiff), | intent(in) | :: | self |
Model instance. |
||
| real(kind=pr), | intent(in) | :: | n(:) |
Component mole amounts [mol]. |
||
| real(kind=pr), | intent(in) | :: | v |
Total volume [L]. |
||
| real(kind=pr), | intent(in) | :: | t |
Temperature [K]. |
||
| real(kind=pr), | intent(out), | optional | :: | Ar |
Residual Helmholtz energy [bar L]. |
|
| real(kind=pr), | intent(out), | optional | :: | ArV |
[bar]. |
|
| real(kind=pr), | intent(out), | optional | :: | ArT |
[bar L/K]. |
|
| real(kind=pr), | intent(out), | optional | :: | ArTV |
[bar/K]. |
|
| real(kind=pr), | intent(out), | optional | :: | ArV2 |
[bar/L]. |
|
| real(kind=pr), | intent(out), | optional | :: | ArT2 |
[bar L/K^2]. |
|
| real(kind=pr), | intent(out), | optional, | dimension(size(n)) | :: | Arn |
[bar L/mol]. |
| real(kind=pr), | intent(out), | optional, | dimension(size(n)) | :: | ArVn |
[bar/mol]. |
| real(kind=pr), | intent(out), | optional, | dimension(size(n)) | :: | ArTn |
[bar L/(K mol)]. |
| real(kind=pr), | intent(out), | optional | :: | Arn2(size(n),size(n)) |
[bar L/mol^2]. |