ThermoState.jl icon indicating copy to clipboard operation
ThermoState.jl copied to clipboard

Mixture total vs. single component properties, accessing nonstandard state parameters

Open doomphoenix-qxz opened this issue 3 years ago • 2 comments

Overall, I like the ideas I'm seeing here and am considering adopting the interface for my implementation of the Modified Quasichemical model. I'd like to request an easy way to get any of these properties for individual components as well as the entire mixture. I think this should be doable by a final argument or similar:

function mol_gibbs(mt::MultiPT, model::MyFancyModel, st::ThermodynamicState, unit=u"J/mol", component="Total")
    p = pressure(FromState(), st, u"Pa")
    t = temperature(FromState(), st, u"K")
    x = molefracs(FromState(), st) # didn't see this in the Readme, so not quite sure what the name is?
    val = gibbs_impl(mt, model, p, t, x, component) # or dispatch to different implementations of gibbs_impl depending on the component?
    return ThermoState.convert_unit(u"J/mol",unit,val)
end

But since you already have a bunch of types for dispatch, you could do something similar here:

function gibbs_impl(mt::MultiPT, model::MyFancyModel, p, t, x, ::ComponentChoice{TOTAL})
    # implement total Gibbs of liquid here
end

function gibbs_impl(mt::MultiPT, model::MyFancyModel, p, t, x, ::ComponentChoice{FIRST})
    myfunc(x1) = gibbs_impl(mt, model, p, t, [x1, x[2:end]...], ComponentChoice{TOTAL})
    return ForwardDiff.derivative(myfunc, x[1]) # Or implement the derivative by hand
end 

Either of those would be helpful to me.

Also, and I don't know if this is a separate issue or not, but the Modified Quasichemical Model has a special state parameter called coordination fractions which basically measure which species in the liquid phase coordinate better with each other. The computationally-expensive piece of the model is a nonlinear solve for the optimal coordination fractions given the mole fractions and temperature. I don't know if the ThermodynamicState struct is the best place to encode this information; actually I rather think it would be the MyFancyModel (in this case the QuasichemicalModel) struct, but it would be nice to have some kind of standard interface for getting special information like this from a WhateverModel struct to make it available for the ThermodynamicState struct. Or maybe I should just access in the gibbs_impl functions and other functions I'm writing to implement the model. What do you think?

(Edit: missed a ')' in some code)

doomphoenix-qxz avatar Oct 15 '20 21:10 doomphoenix-qxz