Skip to content

Thermodynamical functions

ChemistryLab.ADIM_MATH_FUNCTIONS Constant
julia
ADIM_MATH_FUNCTIONS

List of dimensionless mathematical functions to be extended for Quantity arguments.

ChemistryLab.AbstractFunc Type
julia
AbstractFunc

Abstract type for objects that can be called like functions.

ChemistryLab.NumericFunc Type
julia
NumericFunc{N, F, R, Q} <: AbstractFunc

Closure-backed thermodynamic function for models that cannot be represented as symbolic expressions (e.g. HKF, or any other numeric model). Calling convention is identical to SymbolicFunc: f(; T=..., P=..., unit=false).

Variable values are resolved in order: kwarg > refs > _NF_DEFAULT_REFS. refs stores Quantity values so that unit information is preserved.

Fields

  • compiled: closure (vars...) → value in SI units.

  • vars: names of the positional arguments (e.g. (:T, :P)).

  • refs: NamedTuple of default variable values as Quantity (e.g. (T=298.15u"K", P=1e5u"Pa")).

  • unit: output unit (DynamicQuantities Quantity).

ChemistryLab.NumericFunc Method
julia
NumericFunc(f, unit)

Backward-compatible constructor: assumes vars = (:T, :P) and empty refs.

ChemistryLab.NumericFunc Method
julia
NumericFunc(f, vars, unit)

Construct a NumericFunc with no refs (fallback to _NF_DEFAULT_REFS).

ChemistryLab.SymbolicFunc Type
julia
SymbolicFunc(expr::Expr, vars=[:T, :P, :t, :x, :y, :z]; kwargs...) -> SymbolicFunc

Create a SymbolicFunc from an expression.

ChemistryLab.SymbolicFunc Type
julia
SymbolicFunc

Thermodynamic function with symbolic expression and compiled evaluation.

ChemistryLab.SymbolicFunc Method
julia
SymbolicFunc(x::Quantity) -> SymbolicFunc

Create a constant SymbolicFunc from a quantity.

ChemistryLab.SymbolicFunc Method
julia
SymbolicFunc(x::Number) -> SymbolicFunc

Create a constant SymbolicFunc from a number (unitless).

ChemistryLab.SymbolicFunc Method
julia
SymbolicFunc(sym::Symbol; kwargs...) -> SymbolicFunc

Create a SymbolicFunc from a single symbol.

ChemistryLab.ThermoFactory Type
julia
ThermoFactory(expr, vars=[:T, :P, :t, :x, :y, :z]; units=nothing) -> ThermoFactory

Create a ThermoFactory from a symbolic expression.

Arguments

  • expr: symbolic expression (Expr or Symbol).

  • vars: list of variable symbols (default: T, P, t, x, y, z).

  • units: dictionary mapping symbols to their units.

ChemistryLab.ThermoFactory Type
julia
ThermoFactory{Q}

Factory for creating SymbolicFunc instances from expressions. Units for each variable/parameter and the output unit are stored explicitly, removing the need for symbolic unit propagation (previously done via ModelingToolkitBase).

ChemistryLab.ThermoFactory Method
julia
(factory::ThermoFactory)(; kwargs...)

Create a SymbolicFunc with caching for optimal performance.

Base.show Method
julia
Base.show(io::IO, ::MIME"text/plain", sf::SymbolicFunc)

Detailed string representation of a SymbolicFunc.

Base.show Method
julia
Base.show(io::IO, ::MIME"text/plain", factory::ThermoFactory)

Detailed string representation of a ThermoFactory.

Base.show Method
julia
Base.show(io::IO, sf::SymbolicFunc)

Compact string representation of a SymbolicFunc.

Base.show Method
julia
Base.show(io::IO, factory::ThermoFactory)

Compact string representation of a ThermoFactory.

ChemistryLab.apply_symbolic Method
julia
apply_symbolic(op, sf::SymbolicFunc)

Apply unary operation.

ChemistryLab.combine_symbolic Method
julia
combine_symbolic(op, x::Number, sf::SymbolicFunc)

Combine scalar with SymbolicFunc.

ChemistryLab.combine_symbolic Method
julia
combine_symbolic(op, sf::SymbolicFunc, x::Number)

Combine SymbolicFunc with scalar.

ChemistryLab.combine_symbolic Method
julia
combine_symbolic(op, sf1::SymbolicFunc, sf2::SymbolicFunc)

Combine two SymbolicFuncs.

ChemistryLab.compile_symbolic Method
julia
compile_symbolic(symbolic_expr, var_symbols)

Compile a symbolic expression to RuntimeGeneratedFunction.

ChemistryLab.derivative Method
julia
derivative(sf::SymbolicFunc, var::Symbol) -> SymbolicFunc

Compute the analytical derivative of sf with respect to variable var using Symbolics.jl and return a new SymbolicFunc for the result.

The output unit is inferred as sf.unit / unit_of_var, where unit_of_var is read from sf.refs (defaulting to dimensionless if var has no ref entry).

Examples

julia
Cp = SymbolicFunc(:(a + b*T + c/T^2); a=25.0, b=8e-3, c=-1.5e5)
dCp_dT = derivative(Cp, :T)   # ∂Cp/∂T
dCp_dT(T = 500.0)
ChemistryLab.extract_vars_params Method
julia
extract_vars_params(expr, vars) -> (Vector{Symbol}, Vector{Symbol})

Identify variables and parameters in an expression.

Arguments

  • expr: symbolic expression to analyze.

  • vars: list of symbols considered as variables (others are parameters).

Returns

  • Tuple of (variables, parameters) found in the expression.
ChemistryLab.get_unit Method
julia
get_unit(factory::ThermoFactory, sym::Symbol) -> Quantity

Get the unit of a specific variable or parameter in the factory.

ChemistryLab.get_unit Method
julia
get_unit(factory::ThermoFactory) -> Quantity

Get the output unit of the expression managed by the factory.