Contents

Index

Model Macros

Clapeyron.@newmodelgcMacro
@newmodelgc modelname parent paramstype [sitemodel = true, use_struct_param = false]

This is a data type that contains all the information needed to use an EoS model. It also functions as an identifier to ensure that the right functions are called.

You can pass an optional 4th Bool argument indicating if you want to use sites with this model or not. defaults to true

You can also pass another optional 5th Bool argument indicating if a second order GroupParam (StructGroupParam) is used or not. defaults to false

= Fields = The Struct consists of the following fields:

  • components: a string lists of components
  • groups: a GroupParam
  • sites: a SiteParam (optional)
  • params: the Struct paramstype that contains all parameters in the model
  • idealmodel: the IdealModel struct that determines which ideal model to use
  • assoc_options: struct containing options for the association solver. see AssocOptions
  • references: reference for this EoS

See the tutorial or browse the implementations to see how this is used.

Clapeyron.@newmodelMacro
@newmodel name parent paramstype [sitemodel = true]

This is exactly the same as the above but for non-GC models. All group parameters are absent in this struct. The sites are associated to the main component rather than the groups, and the respective fieldnames are named correspondingly.

You can pass an optional bool indicating if you want to use sites with this model or not. defaults to true

Example

struct MySAFTParam
    a::SingleParam{Float64}
    b::SingleParam{Float64}
    epsilon_assoc::AssocParam{Float64}
    bondvol::AssocParam{Float64}
end

@newmodel MySAFT SAFTModel MySAFTParam #defines a model, with association sites

struct MyModelParam
    a::SingleParam{Float64}
    b::SingleParam{Float64}
end

@newmodel MyModel EoSModel MyModelParam false #defines a model without sites
Clapeyron.@newmodelsimpleMacro
@newmodelsimple name parent paramstype

Even simpler model, primarily for the ideal models. Contains neither sites nor ideal models.

Clapeyron.@newmodelsingletonMacro
@newmodelsingleton name parent

A macro that defines an EoSModel without any fields ("singleton" struct.). useful for defining EoS that don't use any parameters, while being composable with other EoSModels.

Clapeyron.@registermodelMacro
@registermodel(model)

given an existing model, composed of Clapeyron EoS models, ClapeyronParams or EoSParams, it will generate the necessary traits to make the model compatible with Clapeyron routines.

Info

This macro is a no-op from Clapeyron 0.5 onwards.

Functions used by the Model Macros

Clapeyron.default_referencesFunction
default_references(::Type{<:EoSModel})::Vector{String}

Return the default references of a model. If you are using the @newmodel, @newmodelsimple or @newmodelgc macros, define this function to set the references for the defined EoS.

Clapeyron.default_locationsFunction
default_locations(::Type{T}) where T <: EoSModel

Used for models defined via the @newmodel, @newmodelsimple or @newmodelgc macros.

Defines the default locations used for parsing the parameters for the input EoSModel type, relative to the database location.

Clapeyron.default_gclocationsFunction
default_gclocations(::Type{T}) where T <: EoSModel

Used for models defined via the @newmodel, @newmodelsimple or @newmodelgc macros.

Defines the default locations used for parsing groups for the input EoSModel type, relative to the database location.

Clapeyron.default_getparams_argumentsFunction
default_getparams_arguments(::Type{T},userlocations,verbose) where T <: EoSModel

Used for models defined via the @newmodel, @newmodelsimple or @newmodelgc macros.

Defines the ParamsOptions object that is passed as arguments to getparams, when building the input EoSModel.

Clapeyron.transform_paramsFunction
transform_params(::Type{T},params) where T <: EoSModel
transform_params(::Type{T},params,components_or_groups) where T <: EoSModel
transform_params(::Type{T},params,components_or_groups,verbose) where T <: EoSModel

Used for models defined via the @newmodel, @newmodelsimple or @newmodelgc macros.

Given a collection of params, with (keytype(params)) isa String, returns a modified collection with all the parameters necessary to build the params field contained in the EoSModel.

You can overload the 2, 3 or 4-argument version, depending on the need of a components vector (or GroupParam in a GC model), or if you want to customize the verbose message.

Example

For the PC-SAFT equation of state, we perform Lorentz-Berthelot mixing of epsilon and sigma, and we scale the sigma parameters:

function transform_params(::Type{PCSAFT},params)
    segment = params["segment"]
        k = get(params,"k",nothing)
        params["sigma"].values .*= 1E-10
        sigma = sigma_LorentzBerthelot(params["sigma"])
        epsilon = epsilon_LorentzBerthelot(params["epsilon"], k)
        params["sigma"] = sigma
        params["epsilon"] = epsilon
        return params
    end

Utility Macros

Clapeyron.@compsMacro
@comps

This macro is an alias to 1:length(model) The caveat is that model has to exist in the local namespace. model is expected to any struct that has length defined in terms of the amount of components.

Clapeyron.@groupsMacro
@groups

This macro is an alias to

1:length(model.groups.flattenedgroups)
@groups(component)

This macro is an alias to

model.groups.i_groups[component]

i_groups[component] is an iterator that goes through all groups in relevent to a given component.

Clapeyron.@sitesMacro
@sites(component)

This macro is an alias to

model.sites.i_sites[component]

i_sites[component] is an iterator that goes through all sites relevant to each group in a GC model, and to each main component in a non-GC model.

Clapeyron.@fMacro
@f(func,a,b,c,...)

This macro is an alias to

func(model, V, T, z, a, b, c, ...)

where func is the name of the function, model is the model struct, V is the volume, T is the absolute temperature, z is an array of number of moles of each component, and a, b, c, ... are arbitrary parameters that get passed to func.

It is very common for functions that are involved in the models to contain the model, V, T and z parameters, so this macro helps reduce code repetition as long as the first four parameters in the function are written exactly as above.

Clapeyron.@nanMacro
@nan(function_call,default=NaN)

Wraps the function in a try-catch block, and if a DomainError or DivideError is raised, then returns default. for better results, its best to generate the default result beforehand