Open longemen3000 opened 1 year ago
I encountered this error when trying your code.
{
"name": "LoadError",
"message": "LoadError: AssertionError: @variables expects a tuple of expressions or an expression of a tuple (@variables x y z(t) v[1:3] w[1:2,1:4]
or @variables x y z(t) v[1:3] w[1:2,1:4] k=1.0
)
in expression starting at c:\Users\YSY_e\Documents\TOP\BestProcessSimulation\equation\solver\jl_notebook_cell_df34fa98e69747e1a8f8a730347b8e2f_W0sZmlsZQ==.jl:3",
"stack": "LoadError: AssertionError: @variables expects a tuple of expressions or an expression of a tuple (@variables x y z(t) v[1:3] w[1:2,1:4]
or @variables x y z(t) v[1:3] w[1:2,1:4] k=1.0
)
in expression starting at c:\Users\YSY_e\Documents\TOP\BestProcessSimulation\equation\solver\jl_notebook_cell_df34fa98e69747e1a8f8a730347b8e2f_W0sZmlsZQ==.jl:3
Stacktrace: [1] _parse_vars(macroname::Symbol, type::Type, x::Tuple{Symbol, Expr}, transform::Function) @ Symbolics C:\Users\YSY_e\.julia\packages\Symbolics\2UpZj\src\variable.jl:134 [2] _parse_vars(macroname::Symbol, type::Type, x::Tuple{Symbol, Expr}) @ Symbolics C:\Users\YSY_e\.julia\packages\Symbolics\2UpZj\src\variable.jl:80 [3] var\"@variables\"(source::LineNumberNode, module::Module, xs::Vararg{Any}) @ Symbolics C:\Users\YSY_e\.julia\packages\Symbolics\2UpZj\src\variable.jl:377 [4] eval @ .\boot.jl:429 [inlined] [5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String) @ Base .\loading.jl:2571 [6] #invokelatest#2 @ .\essentials.jl:1043 [inlined] [7] invokelatest @ .\essentials.jl:1040 [inlined] [8] (::VSCodeServer.var\"#217#218\"{VSCodeServer.NotebookRunCellArguments, String})() @ VSCodeServer c:\Users\YSY_e\.vscode\extensions\julialang.language-julia-1.105.2\scripts\packages\VSCodeServer\src\serve_notebook.jl:24 [9] withpath(f::VSCodeServer.var\"#217#218\"{VSCodeServer.NotebookRunCellArguments, String}, path::String) @ VSCodeServer c:\Users\YSY_e\.vscode\extensions\julialang.language-julia-1.105.2\scripts\packages\VSCodeServer\src\repl.jl:276 [10] notebook_runcell_request(conn::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, params::VSCodeServer.NotebookRunCellArguments) @ VSCodeServer c:\Users\YSY_e\.vscode\extensions\julialang.language-julia-1.105.2\scripts\packages\VSCodeServer\src\serve_notebook.jl:13 [11] dispatch_msg(x::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::VSCodeServer.JSONRPC.MsgDispatcher, msg::Dict{String, Any}) @ VSCodeServer.JSONRPC c:\Users\YSY_e\.vscode\extensions\julialang.language-julia-1.105.2\scripts\packages\JSONRPC\src\typed.jl:67 [12] serve_notebook(pipename::String, debugger_pipename::String, outputchannel_logger::Base.CoreLogging.SimpleLogger; error_handler::var\"#5#10\"{String}) @ VSCodeServer c:\Users\YSY_e\.vscode\extensions\julialang.language-julia-1.105.2\scripts\packages\VSCodeServer\src\serve_notebook.jl:147 [13] top-level scope @ c:\Users\YSY_e\.vscode\extensions\julialang.language-julia-1.105.2\scripts\ otebook\ otebook.jl:35" }
Hello,
That seems more like a failure in the @variables
macro than in the Clapeyron code itself, can you share the notebook, or the cell that generated the error?
Hello,
That seems more like a failure in the
@variables
macro than in the Clapeyron code itself, can you share the notebook, or the cell that generated the error?
using Clapeyron, Symbolics
model = UNIFAC(["water","ethanol"])
@variables v0 T0, x1, x2
x = [x1,x2]
Ge = Clapeyron.excess_gibbs_free_energy(model,v0,T0,x)
dGe = Symbolics.gradient(Ge,x)
act = Symbolics.simplify(exp.(dGe) ./(Clapeyron.R̄ * T0))
Thank you for your replay, I also have a question about “How to obtain the derivative of the fugacity calculation ?”
namelist = ["ethane","ethylene","propylene","methane","propane"]
numcomp = length(namelist)
model = SRK(namelist;alpha=SoaveAlpha)
fugacity_coefficient(model,802384,233,[0.2,0.2,0.2,0.2,0.2,],phase=:l)
I want to get dFugdT(size=n) dFugdP(size=n) and dFugdN (size =n*n) n=5
The first error seems to be here @variables v0 T0, x1, x2
, it should be @variables v0 T0 x1 x2
For the derivatives of fugacity there is Clapeyron.∂lnϕ∂n∂P∂T(model,p,T,z)
, returns lnϕ, ∂lnϕ∂n, ∂lnϕ∂P, ∂lnϕ∂T, V
. You can see the function here:
at the moment, due to how we define functions and the fact that our models need to support ForwardDiff.jl, we have the ability, in theory, to generate fully symbolic versions of an EoS. for a proof of concept, this can be done (if we remove the NaN-safe protections):
that gives the expression for the activity coefficient in terms of T0 and x (v0 is ignored).
In practice, we need additional support to make that a seamless experience. my vision is that:
Clapeyron.activity_coefficient(model,v,T,z)
just works and returns the expression above. for that, we would need:i don't know if we can/should support higher tiers. any commentary about that it is appreciated