Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing COPS instances #325

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions src/PureJuMP/catmix.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Catalyst Mixing Problem
# Collocation formulation
# COPS 3.0 - November 2002
# COPS 3.1 - March 2004

function catmix(args...; n::Int = default_nvar, kwargs...)
ne = 2
nc = 3

tf = 1
h = tf / n # Final time
fact = [factorial(k) for k in 0:nc]

rho = [
0.11270166537926,
0.50000000000000,
0.88729833462074,
]
bc = [1.0, 0.0] # Boundary conditions for x
alpha = 0.0 # Smoothing parameter

model = Model()

@variable(model, 0.0 <= u[i=1:n, j=1:nc] <= 1.0, start=0.0)
@variable(model, v[i=1:n, s=1:ne], start=mod(s, ne))
@variable(model, w[i=1:n, j=1:nc, s=1:ne], start=0.0)
@variable(model, pp[i=1:n, j=1:nc, s=1:ne], start=mod(s, ne))
@variable(model, Dpp[i=1:n, j=1:nc, s=1:ne], start=0.0)
@variable(model, ppf[s=1:ne], start=mod(s, ne))

@objective(
model,
Min,
-1.0 + ppf[1] + ppf[2] +
alpha/h*sum((u[i+1, j] - u[i, j])^2 for i in 1:n-1, j in 1:nc)
)

# Collocation model
@constraint(
model,
[i=1:n, k=1:nc, s=1:ne],
pp[i, k, s] == v[i, s] + h*sum(w[i, j, s]*(rho[k]^j/fact[j+1]) for j in 1:nc)
)
@constraint(
model,
[i=1:n, k=1:nc, s=1:ne],
Dpp[i, k, s] == sum(w[i, j, s]*(rho[k]^(j-1)/fact[j]) for j in 1:nc)
)
@constraint(
model,
[s=1:ne],
ppf[s] == v[n, s] + h * sum(w[n, j, s] / fact[j+1] for j in 1:nc)
)
# Continuity
@constraint(
model,
continuity[i=1:n-1, s=1:ne],
v[i, s] + sum(w[i, j, s] * h / fact[j+1] for j in 1:nc) == v[i+1, s]
)
# Dynamics
@NLconstraint(
model,
de1[i=1:n, j=1:nc],
Dpp[i,j,1] == u[i,j] * (10.0*pp[i,j,2] - pp[i,j,1]),
)
@NLconstraint(
model,
de2[i=1:n, j=1:nc],
Dpp[i,j,2] == u[i,j] * (pp[i,j,1] - 10.0*pp[i,j,2]) - (1 - u[i,j])*pp[i,j,2]
)
@constraint(model, b_eqn[s=1:ne], v[1, s] == bc[s])

return model
end


117 changes: 117 additions & 0 deletions src/PureJuMP/gasoil.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Catalytic Cracking of Gas Oil Problem
# Collocation formulation
# Michael Merritt - Summer 2000
# COPS 2.0 - September 2000
# COPS 3.0 - November 2002
# COPS 3.1 - March 2004

function gasoil(; n::Int = default_nvar, kwargs...)
nc = 4 # number of collocation points
ne = 2 # number of differential equations
np = 3 # number of ODE parameters
nm = 21 # number of measurements

# roots of k-th degree Legendre polynomial
rho = [0.06943184420297, 0.33000947820757, 0.66999052179243, 0.93056815579703]
# ODE initial conditions
bc = [1, 1, 2, 0]
# times at which observations made
tau = [0.0, 0.025, 0.05, 0.075, 0.10, 0.125, 0.150, 0.175, 0.20, 0.225, 0.250, 0.30, 0.35, 0.40, 0.45, 0.50, 0.55, 0.65, 0.75, 0.85, 0.95]
# ODEs defined in [0,tf]
tf = tau[nm]
# uniform interval length
h = tf / n
t = [(i-1)*h for i in 1:n+1]
fact = [factorial(k) for k in 0:nc]

itau = Int[min(n, floor(tau[i]/h)+1) for i in 1:nm]

# Concentrations
z = [
1.0000 0;
0.8105 0.2000;
0.6208 0.2886;
0.5258 0.3010;
0.4345 0.3215;
0.3903 0.3123;
0.3342 0.2716;
0.3034 0.2551;
0.2735 0.2258;
0.2405 0.1959;
0.2283 0.1789;
0.2071 0.1457;
0.1669 0.1198;
0.1530 0.0909;
0.1339 0.0719;
0.1265 0.0561;
0.1200 0.0460;
0.0990 0.0280;
0.0870 0.0190;
0.0770 0.0140;
0.0690 0.0100;
]

v0 = zeros(n, ne)
# Starting-value
for i in 1:itau[1], s in 1:ne
v0[i, s] = bc[s]
end
for j in 2:nm, i =itau[j-1]+1:itau[j], s in 1:ne
v0[i, s] = z[j, s]
end
for i in itau[nm]+1:n, s in 1:ne
v0[i, s] = z[nm, s]
end

model = Model()

# ODE parameters
@variable(model, theta[1:np] >= 0.0, start=0.0)
# The collocation approximation u is defined by the parameters v and w.
# uc and Duc are, respectively, u and u' evaluated at the collocation points.
@variable(model, v[i=1:n, s=1:ne], start=v0[i, s])
@variable(model, w[1:n, 1:nc, 1:ne], start=0.0)
@variable(model, uc[i=1:n, j=1:nc, s=1:ne], start=v0[i,s])
@variable(model, Duc[i=1:n, j=1:nc, s=1:ne], start=0.0)

@NLexpression(
model,
error[j=1:nm, s=1:ne],
v[itau[j],s] + sum(w[itau[j],k,s]*(tau[j]-t[itau[j]])^k/(fact[k+1]*h^(k-1)) for k in 1:nc) - z[j,s],
)
# L2 error
@NLobjective(model, Min, sum(error[j, s]^2 for s in 1:ne, j in 1:nm))

# Collocation model
@constraint(
model,
[i=1:n, j=1:nc, s=1:ne],
uc[i, j, s] == v[i,s] + h*sum(w[i,k,s]*(rho[j]^k/fact[k+1]) for k in 1:nc),
)
@constraint(
model,
[i=1:n, j=1:nc, s=1:ne],
Duc[i, j, s] == sum(w[i,k,s]*(rho[j]^(k-1)/fact[k]) for k in 1:nc),
)

# Boundary
@constraint(model, [s=1:ne], v[1, s] == z[1, s]) #TODO
# Continuity
@constraint(
model,
[i=1:n-1, s=1:ne],
v[i, s] + sum(w[i, j, s]*h/fact[j+1] for j in 1:nc) == v[i+1, s],
)
@NLconstraint(
model,
[i=1:n, j=1:nc],
Duc[i, j, 1] == -(theta[1]+theta[3])*uc[i, j, 1]^2,
)
@NLconstraint(
model,
[i=1:n, j=1:nc],
Duc[i, j, 2] == theta[1]*uc[i,j,1]^2 - theta[2]*uc[i,j,2],
)
return model
end

74 changes: 74 additions & 0 deletions src/PureJuMP/glider.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Hang Glider Problem
# Trapezoidal formulation
# David Bortz - Summer 1998
# COPS 2.0 - September 2000
# COPS 3.0 - November 2002
# COPS 3.1 - March 2004

function glider(; n::Int = default_nvar, kwargs...)
# Design parameters
x_0 = 0.0
y_0 = 1000.0
y_f = 900.0
vx_0 = 13.23
vx_f = 13.23
vy_0 = -1.288
vy_f = -1.288
u_c = 2.5
r_0 = 100.0
m = 100.0
g = 9.81
c0 = 0.034
c1 = 0.069662
S = 14.0
rho = 1.13
cL_min = 0.0
cL_max = 1.4

model = Model()

@variables(model, begin
0 <= t_f, (start=1.0)
0.0 <= x[k=0:n], (start=x_0 + vx_0*(k/n))
y[k=0:n], (start=y_0 + (k/n)*(y_f - y_0))
0.0 <= vx[k=0:n], (start=vx_0)
vy[k=0:n], (start=vy_0)
cL_min <= cL[k=0:n] <= cL_max, (start=cL_max/2.0)
end)

@objective(model, Max, x[n])

@NLexpressions(model, begin
step, t_f / n
r[i=0:n], (x[i]/r_0 - 2.5)^2
u[i=0:n], u_c*(1 - r[i])*exp(-r[i])
w[i=0:n], vy[i] - u[i]
v[i=0:n], sqrt(vx[i]^2 + w[i]^2)
D[i=0:n], 0.5*(c0+c1*cL[i]^2)*rho*S*v[i]^2
L[i=0:n], 0.5*cL[i]*rho*S*v[i]^2
vx_dot[i=0:n], (-L[i]*(w[i]/v[i]) - D[i]*(vx[i]/v[i]))/m
vy_dot[i=0:n], (L[i]*(vx[i]/v[i]) - D[i]*(w[i]/v[i]))/m - g
end)

# Dynamics
@NLconstraints(model, begin
x_eqn[j=1:n], x[j] == x[j-1] + 0.5 * step * (vx[j] + vx[j-1])
y_eqn[j=1:n], y[j] == y[j-1] + 0.5 * step * (vy[j] + vy[j-1])
vx_eqn[j=1:n], vx[j] == vx[j-1] + 0.5 * step * (vx_dot[j] + vx_dot[j-1])
vy_eqn[j=1:n], vy[j] == vy[j-1] + 0.5 * step * (vy_dot[j] + vy_dot[j-1])
end)
# Boundary constraints
@constraints(model, begin
x[0] == x_0
y[0] == y_0
y[n] == y_f
vx[0] == vx_0
vx[n] == vx_f
vy[0] == vy_0
vy[n] == vy_f
end)

return model
end


Loading