To do this, I need an activity coeff., which is dependent on the composition xp1. The way this work is, you keep looking for two phase compositions xp1 and xp2, until xp1actcoeff1-xp2actcoeff2 = 0.
The activity coeff. is a function of the composition xp1 or xp2. Instead using Unifac/Uniquac/etc… to calculate the act. coeff., I am using a quantum chemical software, which can be triggered by command line with GAMMAP1().
The Problem is that this software needs a .inp file with the concentrations xp1 and xp2. When I ran my JuMP Model, the .inp file that was created had { xp1[1] xp1[2] } as concentration, instead of the values that the solver is currently using for this iteration step.
My question is: How do I get to the value that is currently being used by the solver on the current iteration step?
using JuMP
using Ipopt
m = Model(solver=IpoptSolver(print_level=0))
@variable(m, xp1[1:n_komp])
@variable(m, xp2[1:n_komp])
@variable(m, x[1:n_komp])
@variable(m, y[1:n_komp])
@variable(m, F)
@variable(m, V)
@variable(m, g1[1:n_komp], start = GAMMAP1(t, n_komp, getvalue(xp1)))
@variable(m, g2[1:n_komp], start = GAMMAP2(t, n_komp, getvalue(xp2)))
@NLobjective(m, Min, V+F-1)
@constraint(m, sum(x) == 1)
@constraint(m, sum(y) == 1)
@constraint(m, sum(xp1) == 1)
@constraint(m, sum(xp2) == 1)
@constraint(m, K.*x.-y .== 0)
@constraint(m, F.*x+V*y.-z .== 0)
@constraint(m, xp1.*g1 .== xp2.*g2 )
solve(m)
global x = getvalue(x)
global y = getvalue(y)
global V = getvalue(V)
global F = getvalue(F)
println("x = ", x)
println("y = ", y)
println("F = ", F)
println("V = ", V)
I need the solver to get the g1 and g2 values from the function. This function gets the value from an outside software (CosmoTherm). It need the concentration vector xp1 and xp2 as input to calculate g1 and g2.
It looks unlikely that you can get derivatives out of GAMMAP1? You might want to consider using https://github.com/JuliaOpt/NLopt.jl. It has some derivative-free methods.
Thanks. I just updates to 0.19 earlier. I was using JuliaPro 1.0.3 and it automatically installed v0.18.
I am not sure if I need derivatives. I guess g1 should be given as a constraint and not a variable.
What I need is to use the current value for the variables xp1 and xp2 to calculate g1 and g2 (activity coefficients) with CosmoTherm. The GAMMAP1 and GAMMAP2 are used to run CosmoTherm (quantum chemical software) from the command line.