Skip to content

Commit 7deb3cb

Browse files
🤖 Format .jl files (#387)
Co-authored-by: tmigot <[email protected]>
1 parent 3a68db0 commit 7deb3cb

File tree

12 files changed

+317
-237
lines changed

12 files changed

+317
-237
lines changed

src/Meta/minsurf.jl

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,50 @@ minsurf_meta = Dict(
1717
:defined_everywhere => missing,
1818
:origin => :unknown,
1919
)
20-
get_minsurf_nvar(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = (nx + 2)*(ny + 2)
21-
get_minsurf_ncon(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = (nx + 2)*(ny + 2) + 2*(nx + ny + 4) + ((2*divrem(nx + 1, 4)[1] + divrem(nx + 1, 4)[2] + 1) * (2*divrem(ny + 1, 4)[1] + divrem(ny + 1, 4)[2] + 1))
22-
get_minsurf_nlin(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = (nx + 2)*(ny + 2) + 2*(nx + ny + 4) + ((2*divrem(nx + 1, 4)[1] + divrem(nx + 1, 4)[2] + 1) * (2*divrem(ny + 1, 4)[1] + divrem(ny + 1, 4)[2] + 1))
20+
get_minsurf_nvar(;
21+
n::Integer = default_nvar,
22+
nx = Int(round(sqrt(max(1, n - 2)))),
23+
ny = Int(round(sqrt(max(1, n - 2)))),
24+
kwargs...,
25+
) = (nx + 2)*(ny + 2)
26+
get_minsurf_ncon(;
27+
n::Integer = default_nvar,
28+
nx = Int(round(sqrt(max(1, n - 2)))),
29+
ny = Int(round(sqrt(max(1, n - 2)))),
30+
kwargs...,
31+
) =
32+
(nx + 2)*(ny + 2) +
33+
2*(nx + ny + 4) +
34+
(
35+
(2*divrem(nx + 1, 4)[1] + divrem(nx + 1, 4)[2] + 1) *
36+
(2*divrem(ny + 1, 4)[1] + divrem(ny + 1, 4)[2] + 1)
37+
)
38+
get_minsurf_nlin(;
39+
n::Integer = default_nvar,
40+
nx = Int(round(sqrt(max(1, n - 2)))),
41+
ny = Int(round(sqrt(max(1, n - 2)))),
42+
kwargs...,
43+
) =
44+
(nx + 2)*(ny + 2) +
45+
2*(nx + ny + 4) +
46+
(
47+
(2*divrem(nx + 1, 4)[1] + divrem(nx + 1, 4)[2] + 1) *
48+
(2*divrem(ny + 1, 4)[1] + divrem(ny + 1, 4)[2] + 1)
49+
)
2350
get_minsurf_nnln(; n::Integer = default_nvar, kwargs...) = 0
24-
get_minsurf_nequ(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = 2*(nx + ny + 4)
25-
get_minsurf_nineq(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = (nx + 2) * (ny + 2) + ((2*divrem(nx + 1, 4)[1] + divrem(nx + 1, 4)[2] + 1) * (2*divrem(ny + 1, 4)[1] + divrem(ny + 1, 4)[2] + 1))
51+
get_minsurf_nequ(;
52+
n::Integer = default_nvar,
53+
nx = Int(round(sqrt(max(1, n - 2)))),
54+
ny = Int(round(sqrt(max(1, n - 2)))),
55+
kwargs...,
56+
) = 2*(nx + ny + 4)
57+
get_minsurf_nineq(;
58+
n::Integer = default_nvar,
59+
nx = Int(round(sqrt(max(1, n - 2)))),
60+
ny = Int(round(sqrt(max(1, n - 2)))),
61+
kwargs...,
62+
) =
63+
(nx + 2) * (ny + 2) + (
64+
(2*divrem(nx + 1, 4)[1] + divrem(nx + 1, 4)[2] + 1) *
65+
(2*divrem(ny + 1, 4)[1] + divrem(ny + 1, 4)[2] + 1)
66+
)

src/Meta/torsion.jl

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,39 @@ torsion_meta = Dict(
1717
:defined_everywhere => missing,
1818
:origin => :unknown,
1919
)
20-
get_torsion_nvar(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = (nx + 2) * (ny + 2)
21-
get_torsion_ncon(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = (nx + 2) * (ny + 2)
22-
get_torsion_nlin(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = (nx + 2) * (ny + 2)
23-
get_torsion_nnln(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = 0
24-
get_torsion_nequ(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = 0
25-
get_torsion_nineq(; n::Integer = default_nvar, nx = Int(round(sqrt(max(1, n - 2)))), ny = Int(round(sqrt(max(1, n - 2)))), kwargs...) = (nx + 2) * (ny + 2)
20+
get_torsion_nvar(;
21+
n::Integer = default_nvar,
22+
nx = Int(round(sqrt(max(1, n - 2)))),
23+
ny = Int(round(sqrt(max(1, n - 2)))),
24+
kwargs...,
25+
) = (nx + 2) * (ny + 2)
26+
get_torsion_ncon(;
27+
n::Integer = default_nvar,
28+
nx = Int(round(sqrt(max(1, n - 2)))),
29+
ny = Int(round(sqrt(max(1, n - 2)))),
30+
kwargs...,
31+
) = (nx + 2) * (ny + 2)
32+
get_torsion_nlin(;
33+
n::Integer = default_nvar,
34+
nx = Int(round(sqrt(max(1, n - 2)))),
35+
ny = Int(round(sqrt(max(1, n - 2)))),
36+
kwargs...,
37+
) = (nx + 2) * (ny + 2)
38+
get_torsion_nnln(;
39+
n::Integer = default_nvar,
40+
nx = Int(round(sqrt(max(1, n - 2)))),
41+
ny = Int(round(sqrt(max(1, n - 2)))),
42+
kwargs...,
43+
) = 0
44+
get_torsion_nequ(;
45+
n::Integer = default_nvar,
46+
nx = Int(round(sqrt(max(1, n - 2)))),
47+
ny = Int(round(sqrt(max(1, n - 2)))),
48+
kwargs...,
49+
) = 0
50+
get_torsion_nineq(;
51+
n::Integer = default_nvar,
52+
nx = Int(round(sqrt(max(1, n - 2)))),
53+
ny = Int(round(sqrt(max(1, n - 2)))),
54+
kwargs...,
55+
) = (nx + 2) * (ny + 2)

src/PureJuMP/catmix.jl

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,57 @@ function catmix(args...; n::Int = default_nvar, kwargs...)
1111

1212
tf = 1
1313
h = tf / n # Final time
14-
fact = [factorial(k) for k in 0:nc]
14+
fact = [factorial(k) for k = 0:nc]
1515

16-
rho = [
17-
0.11270166537926,
18-
0.50000000000000,
19-
0.88729833462074,
20-
]
16+
rho = [0.11270166537926, 0.50000000000000, 0.88729833462074]
2117
bc = [1.0, 0.0] # Boundary conditions for x
2218
alpha = 0.0 # Smoothing parameter
2319

2420
model = Model()
2521

26-
@variable(model, 0.0 <= u[i=1:n, j=1:nc] <= 1.0, start=0.0)
27-
@variable(model, v[i=1:n, s=1:ne], start=mod(s, ne))
28-
@variable(model, w[i=1:n, j=1:nc, s=1:ne], start=0.0)
29-
@variable(model, pp[i=1:n, j=1:nc, s=1:ne], start=mod(s, ne))
30-
@variable(model, Dpp[i=1:n, j=1:nc, s=1:ne], start=0.0)
31-
@variable(model, ppf[s=1:ne], start=mod(s, ne))
22+
@variable(model, 0.0 <= u[i = 1:n, j = 1:nc] <= 1.0, start=0.0)
23+
@variable(model, v[i = 1:n, s = 1:ne], start=mod(s, ne))
24+
@variable(model, w[i = 1:n, j = 1:nc, s = 1:ne], start=0.0)
25+
@variable(model, pp[i = 1:n, j = 1:nc, s = 1:ne], start=mod(s, ne))
26+
@variable(model, Dpp[i = 1:n, j = 1:nc, s = 1:ne], start=0.0)
27+
@variable(model, ppf[s = 1:ne], start=mod(s, ne))
3228

3329
@objective(
3430
model,
3531
Min,
36-
-1.0 + ppf[1] + ppf[2] +
37-
alpha/h*sum((u[i+1, j] - u[i, j])^2 for i in 1:n-1, j in 1:nc)
32+
-1.0 + ppf[1] + ppf[2] + alpha/h*sum((u[i + 1, j] - u[i, j])^2 for i = 1:(n - 1), j = 1:nc)
3833
)
3934

4035
# Collocation model
4136
@constraint(
4237
model,
4338
[i=1:n, k=1:nc, s=1:ne],
44-
pp[i, k, s] == v[i, s] + h*sum(w[i, j, s]*(rho[k]^j/fact[j+1]) for j in 1:nc)
39+
pp[i, k, s] == v[i, s] + h*sum(w[i, j, s]*(rho[k]^j/fact[j + 1]) for j = 1:nc)
4540
)
4641
@constraint(
4742
model,
4843
[i=1:n, k=1:nc, s=1:ne],
49-
Dpp[i, k, s] == sum(w[i, j, s]*(rho[k]^(j-1)/fact[j]) for j in 1:nc)
50-
)
51-
@constraint(
52-
model,
53-
[s=1:ne],
54-
ppf[s] == v[n, s] + h * sum(w[n, j, s] / fact[j+1] for j in 1:nc)
44+
Dpp[i, k, s] == sum(w[i, j, s]*(rho[k]^(j-1)/fact[j]) for j = 1:nc)
5545
)
46+
@constraint(model, [s=1:ne], ppf[s] == v[n, s] + h * sum(w[n, j, s] / fact[j + 1] for j = 1:nc))
5647
# Continuity
5748
@constraint(
5849
model,
59-
continuity[i=1:n-1, s=1:ne],
60-
v[i, s] + sum(w[i, j, s] * h / fact[j+1] for j in 1:nc) == v[i+1, s]
50+
continuity[i = 1:(n - 1), s = 1:ne],
51+
v[i, s] + sum(w[i, j, s] * h / fact[j + 1] for j = 1:nc) == v[i + 1, s]
6152
)
6253
# Dynamics
6354
@constraint(
6455
model,
65-
de1[i=1:n, j=1:nc],
66-
Dpp[i,j,1] == u[i,j] * (10.0*pp[i,j,2] - pp[i,j,1]),
56+
de1[i = 1:n, j = 1:nc],
57+
Dpp[i, j, 1] == u[i, j] * (10.0*pp[i, j, 2] - pp[i, j, 1]),
6758
)
6859
@constraint(
6960
model,
70-
de2[i=1:n, j=1:nc],
71-
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]
61+
de2[i = 1:n, j = 1:nc],
62+
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]
7263
)
73-
@constraint(model, b_eqn[s=1:ne], v[1, s] == bc[s])
64+
@constraint(model, b_eqn[s = 1:ne], v[1, s] == bc[s])
7465

7566
return model
7667
end
77-
78-

src/PureJuMP/gasoil.jl

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,72 @@ function gasoil(; n::Int = default_nvar, kwargs...)
1818
# ODE initial conditions
1919
bc = [1, 1, 2, 0]
2020
# times at which observations made
21-
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]
21+
tau = [
22+
0.0,
23+
0.025,
24+
0.05,
25+
0.075,
26+
0.10,
27+
0.125,
28+
0.150,
29+
0.175,
30+
0.20,
31+
0.225,
32+
0.250,
33+
0.30,
34+
0.35,
35+
0.40,
36+
0.45,
37+
0.50,
38+
0.55,
39+
0.65,
40+
0.75,
41+
0.85,
42+
0.95,
43+
]
2244
# ODEs defined in [0,tf]
2345
tf = tau[nm]
2446
# uniform interval length
2547
h = tf / n
26-
t = [(i-1)*h for i in 1:n+1]
27-
fact = [factorial(k) for k in 0:nc]
48+
t = [(i-1)*h for i = 1:(n + 1)]
49+
fact = [factorial(k) for k = 0:nc]
2850

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

3153
# Concentrations
3254
z = [
33-
1.0000 0;
34-
0.8105 0.2000;
35-
0.6208 0.2886;
36-
0.5258 0.3010;
37-
0.4345 0.3215;
38-
0.3903 0.3123;
39-
0.3342 0.2716;
40-
0.3034 0.2551;
41-
0.2735 0.2258;
42-
0.2405 0.1959;
43-
0.2283 0.1789;
44-
0.2071 0.1457;
45-
0.1669 0.1198;
46-
0.1530 0.0909;
47-
0.1339 0.0719;
48-
0.1265 0.0561;
49-
0.1200 0.0460;
50-
0.0990 0.0280;
51-
0.0870 0.0190;
52-
0.0770 0.0140;
53-
0.0690 0.0100;
54-
]
55+
1.0000 0;
56+
0.8105 0.2000;
57+
0.6208 0.2886;
58+
0.5258 0.3010;
59+
0.4345 0.3215;
60+
0.3903 0.3123;
61+
0.3342 0.2716;
62+
0.3034 0.2551;
63+
0.2735 0.2258;
64+
0.2405 0.1959;
65+
0.2283 0.1789;
66+
0.2071 0.1457;
67+
0.1669 0.1198;
68+
0.1530 0.0909;
69+
0.1339 0.0719;
70+
0.1265 0.0561;
71+
0.1200 0.0460;
72+
0.0990 0.0280;
73+
0.0870 0.0190;
74+
0.0770 0.0140;
75+
0.0690 0.0100;
76+
]
5577

5678
v0 = zeros(n, ne)
5779
# Starting-value
58-
for i in 1:itau[1], s in 1:ne
80+
for i = 1:itau[1], s = 1:ne
5981
v0[i, s] = bc[s]
6082
end
61-
for j in 2:nm, i =itau[j-1]+1:itau[j], s in 1:ne
83+
for j = 2:nm, i = (itau[j - 1] + 1):itau[j], s = 1:ne
6284
v0[i, s] = z[j, s]
6385
end
64-
for i in itau[nm]+1:n, s in 1:ne
86+
for i = (itau[nm] + 1):n, s = 1:ne
6587
v0[i, s] = z[nm, s]
6688
end
6789

@@ -71,49 +93,45 @@ function gasoil(; n::Int = default_nvar, kwargs...)
7193
@variable(model, theta[1:np] >= 0.0, start=0.0)
7294
# The collocation approximation u is defined by the parameters v and w.
7395
# uc and Duc are, respectively, u and u' evaluated at the collocation points.
74-
@variable(model, v[i=1:n, s=1:ne], start=v0[i, s])
96+
@variable(model, v[i = 1:n, s = 1:ne], start=v0[i, s])
7597
@variable(model, w[1:n, 1:nc, 1:ne], start=0.0)
76-
@variable(model, uc[i=1:n, j=1:nc, s=1:ne], start=v0[i,s])
77-
@variable(model, Duc[i=1:n, j=1:nc, s=1:ne], start=0.0)
98+
@variable(model, uc[i = 1:n, j = 1:nc, s = 1:ne], start=v0[i, s])
99+
@variable(model, Duc[i = 1:n, j = 1:nc, s = 1:ne], start=0.0)
78100

79101
@expression(
80102
model,
81-
error[j=1:nm, s=1:ne],
82-
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],
103+
error[j = 1:nm, s = 1:ne],
104+
v[itau[j], s] + sum(w[itau[j], k, s]*(tau[j]-t[itau[j]])^k/(fact[k + 1]*h^(k-1)) for k = 1:nc) -
105+
z[j, s],
83106
)
84107
# L2 error
85-
@objective(model, Min, sum(error[j, s]^2 for s in 1:ne, j in 1:nm))
108+
@objective(model, Min, sum(error[j, s]^2 for s = 1:ne, j = 1:nm))
86109

87110
# Collocation model
88111
@constraint(
89112
model,
90113
[i=1:n, j=1:nc, s=1:ne],
91-
uc[i, j, s] == v[i,s] + h*sum(w[i,k,s]*(rho[j]^k/fact[k+1]) for k in 1:nc),
114+
uc[i, j, s] == v[i, s] + h*sum(w[i, k, s]*(rho[j]^k/fact[k + 1]) for k = 1:nc),
92115
)
93116
@constraint(
94117
model,
95118
[i=1:n, j=1:nc, s=1:ne],
96-
Duc[i, j, s] == sum(w[i,k,s]*(rho[j]^(k-1)/fact[k]) for k in 1:nc),
119+
Duc[i, j, s] == sum(w[i, k, s]*(rho[j]^(k-1)/fact[k]) for k = 1:nc),
97120
)
98121

99122
# Boundary
100123
@constraint(model, [s=1:ne], v[1, s] == z[1, s]) #TODO
101124
# Continuity
102125
@constraint(
103126
model,
104-
[i=1:n-1, s=1:ne],
105-
v[i, s] + sum(w[i, j, s]*h/fact[j+1] for j in 1:nc) == v[i+1, s],
127+
[i=1:(n - 1), s=1:ne],
128+
v[i, s] + sum(w[i, j, s]*h/fact[j + 1] for j = 1:nc) == v[i + 1, s],
106129
)
130+
@constraint(model, [i=1:n, j=1:nc], Duc[i, j, 1] == -(theta[1]+theta[3])*uc[i, j, 1]^2,)
107131
@constraint(
108132
model,
109133
[i=1:n, j=1:nc],
110-
Duc[i, j, 1] == -(theta[1]+theta[3])*uc[i, j, 1]^2,
111-
)
112-
@constraint(
113-
model,
114-
[i=1:n, j=1:nc],
115-
Duc[i, j, 2] == theta[1]*uc[i,j,1]^2 - theta[2]*uc[i,j,2],
134+
Duc[i, j, 2] == theta[1]*uc[i, j, 1]^2 - theta[2]*uc[i, j, 2],
116135
)
117136
return model
118137
end
119-

0 commit comments

Comments
 (0)