Skip to content

Commit

Permalink
Merge pull request #39 from tmigot/up-constructor
Browse files Browse the repository at this point in the history
Up constructor
  • Loading branch information
tmigot authored Aug 29, 2022
2 parents 2c311b7 + 64d070f commit 4097e84
Show file tree
Hide file tree
Showing 27 changed files with 31 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PDENLPModels = "80da258d-c172-4540-9646-64f172512520"
ChainRulesCore = "=1.3.0"
DataFrames = "1"
Gridap = "0.15.5"
PDENLPModels = "0.2, 0.3"
PDENLPModels = "^0.3.2"
julia = "^1.3.0"

[extras]
Expand Down
3 changes: 1 addition & 2 deletions src/apinene.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function apinene(args...; n = 400, kwargs...)
trian = Triangulation(model)
degree = 1
= Measure(trian, degree)
op_sis = FEOperator(res, Y, X)

zmes = [
88.35 7.3 2.3 0.4 1.75
Expand All @@ -51,7 +50,7 @@ function apinene(args...; n = 400, kwargs...)

ndofs = Gridap.FESpaces.num_free_dofs(Y)
xin = zeros(ndofs + 5)
return GridapPDENLPModel(xin, f, trian, Y, X, op_sis, name = "Isometrization of α-pinene n=$n")
return GridapPDENLPModel(xin, f, trian, Y, X, res, name = "Isometrization of α-pinene n=$n")
end

apinene_meta = Dict(
Expand Down
3 changes: 1 addition & 2 deletions src/burger1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ function burger1d(args...; n::Int = 512, kwargs...)
function res(y, u, v)
(-nu * ((v) (y)) + c(y, v) - v * u - v * h)dΩ
end
op = FEOperator(res, Ypde, Xpde)

nvar_pde = Gridap.FESpaces.num_free_dofs(Ypde)
nvar_con = Gridap.FESpaces.num_free_dofs(Ycon)
x0 = zeros(nvar_pde + nvar_con)
nlp = GridapPDENLPModel(x0, f, trian, Ypde, Ycon, Xpde, Xcon, op, name = "burger1d n=$n")
nlp = GridapPDENLPModel(x0, f, trian, Ypde, Ycon, Xpde, Xcon, res, name = "burger1d n=$n")

#=
#The solution is just y = yd and u=0.
Expand Down
3 changes: 1 addition & 2 deletions src/burger1d_param.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ function burger1d_param(args...; n = 512, kwargs...)
k1(x) = -k[1]
(nu * ((v) (y)) + k1 + c(y, v) - v * u - v * h)dΩ
end
op = FEOperator(res, U, V)

Xcon = TestFESpace(model, reffe; conformity = :H1)
Ycon = TrialFESpace(Xcon)
Ycon = TrialFESpace(Xcon)

Y = MultiFieldFESpace([U, Ycon])
xin = zeros(Gridap.FESpaces.num_free_dofs(Y) + 1)
return GridapPDENLPModel(xin, f, trian, U, Ycon, V, Xcon, op, name = "burger1d_param n=$n")
return GridapPDENLPModel(xin, f, trian, U, Ycon, V, Xcon, res, name = "burger1d_param n=$n")
end

burger1d_param_meta = Dict(
Expand Down
3 changes: 1 addition & 2 deletions src/catmix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function catmix(args...; n::Int = 100, kwargs...)
dt(Y2, V2) )dΩ +
( (Y1 - y1) * V1 )dΓ + ( (Y2 - y2) * V2 )dΓ
end
op = FEOperator(res, Ypde, Xpde)

nvar_con = Gridap.FESpaces.num_free_dofs(Ycon)
# u = 0, y1 = 1, y2 = 0
Expand All @@ -71,7 +70,7 @@ function catmix(args...; n::Int = 100, kwargs...)
Ycon,
Xpde,
Xcon,
op,
res,
lvaru = zeros(nvar_con),
uvaru = ones(nvar_con),
name = "Catalyst Mixing n=$n",
Expand Down
4 changes: 1 addition & 3 deletions src/cellincrease.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ function cellincrease(args...; x0 = [0.6, 0.1], n = 10, T = 7, kwargs...)
end

Y = MultiFieldFESpace([UI, US, Ucon])
op_sir = FEOperator(res, Ypde, Xpde)

xin = zeros(Gridap.FESpaces.num_free_dofs(Y))
return GridapPDENLPModel(xin, f, trian, Ypde, Ycon, Xpde, Xcon, op_sir, name = "cellincrease n=$n")
return GridapPDENLPModel(xin, f, trian, Ypde, Ycon, Xpde, Xcon, res, name = "cellincrease n=$n")
end

cellincrease_meta = Dict(
Expand Down
4 changes: 1 addition & 3 deletions src/cellincrease_MichaelisMenten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ function cellincrease_MichaelisMenten(args...; x0 = [0.6, 0.1], n = 10, T = 7, k
end

Y = MultiFieldFESpace([UI, US, Ucon])
op_sir = FEOperator(res, Ypde, Xpde)

xin = zeros(Gridap.FESpaces.num_free_dofs(Y))
return GridapPDENLPModel(xin, f, trian, Ypde, Ycon, Xpde, Xcon, op_sir, name = "cellincrease_MichaelisMenten n=$n")
return GridapPDENLPModel(xin, f, trian, Ypde, Ycon, Xpde, Xcon, res, name = "cellincrease_MichaelisMenten n=$n")
end

cellincrease_MichaelisMenten_meta = Dict(
Expand Down
3 changes: 1 addition & 2 deletions src/channel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ function channel(args...; n = 400, kwargs...)
p4 * R * (y2 * y3 - y1 * y4),
)dΩ
end
op = FEOperator(res, Y, X)

ndofs = Gridap.FESpaces.num_free_dofs(Y)
xin = zeros(ndofs)
return GridapPDENLPModel(xin, NoFETerm(), Y, X, op, name = "Flow in a Channel n=$n")
return GridapPDENLPModel(xin, NoFETerm(), Y, X, res, name = "Flow in a Channel n=$n")
end

channel_meta = Dict(
Expand Down
3 changes: 1 addition & 2 deletions src/controlsir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function controlsir(args...; x0 = [1, 2], n = 10, a = 0.2, b = 0.1, μ = 0.1, T
trian = Triangulation(model)
degree = 1
= Measure(trian, degree)
op_sis = FEOperator(res, Y, X)

function f(u) #:: Union{Gridap.MultiField.MultiFieldFEFunction, Gridap.CellData.GenericCellField}
I, S = u
Expand All @@ -36,7 +35,7 @@ function controlsir(args...; x0 = [1, 2], n = 10, a = 0.2, b = 0.1, μ = 0.1, T

ndofs = Gridap.FESpaces.num_free_dofs(Y)
xin = zeros(ndofs)
return GridapPDENLPModel(xin, f, trian, Y, X, op_sis, name = "control-SIR n=$n")
return GridapPDENLPModel(xin, f, trian, Y, X, res, name = "control-SIR n=$n")
end

controlsir_meta = Dict(
Expand Down
3 changes: 1 addition & 2 deletions src/dynamicsir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function dynamicsir(args...; x0 = [1, 2], n = 10, T = 1, kwargs...)
= Measure(trian, degree)
#t_Ω_nl = FETerm(res_pde_nl, trian, dΩ)
#t_Ω = FETerm(res_pde, trian, dΩ)
op_sir = FEOperator(res, Ypde, Xpde)

Xbcon = TestFESpace(model, reffe; conformity = :H1)
Ybcon = TrialFESpace(Xbcon)
Expand All @@ -62,7 +61,7 @@ function dynamicsir(args...; x0 = [1, 2], n = 10, T = 1, kwargs...)

ndofs = Gridap.FESpaces.num_free_dofs(Ypde) + Gridap.FESpaces.num_free_dofs(Ycon)
xin = zeros(ndofs)
return GridapPDENLPModel(xin, f, trian, Ypde, Ycon, Xpde, Xcon, op_sir, name = "dynamic-SIR n=$n")
return GridapPDENLPModel(xin, f, trian, Ypde, Ycon, Xpde, Xcon, res, name = "dynamic-SIR n=$n")
end

dynamicsir_meta = Dict(
Expand Down
3 changes: 1 addition & 2 deletions src/gasoil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function gasoil(args...; n = 100, kwargs...)
(dt(y1, v1) + v1 * (θ[1] + θ[3]) * y1 * y1) + (dt(y2, v2) - θ[1] * y1 * y1 - θ[2] * y2),
)dΩ
end
op = FEOperator(res, Ypde, Xpde)

z = [
1.0000 0
Expand Down Expand Up @@ -98,7 +97,7 @@ function gasoil(args...; n = 100, kwargs...)
trian,
Ypde,
Xpde,
op,
res,
lvar = lvar,
uvar = uvar,
name = "Catalytic Cracking of Gas Oil n=$n",
Expand Down
3 changes: 1 addition & 2 deletions src/glider.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function glider(args...; n = 100, kwargs...)
(dt(yp, pyp) + pyp * g - pyp * (L(x, xp, yp, cL) * xp - D(x, xp, yp, cL) * w(x, yp))) +
dt(Y, pY) )dΩ + ( (Y - y) * pY )dΓ
end
op = FEOperator(res, Ypde, Xpde)

function f(xy, u)
x, xp, y, Y, yp = xy
Expand Down Expand Up @@ -96,7 +95,7 @@ function glider(args...; n = 100, kwargs...)
Ycon,
Xpde,
Xcon,
op,
res,
lvaru = zeros(ndofs_con),
uvaru = cmax * ones(ndofs_con),
lvary = vcat(
Expand Down
6 changes: 3 additions & 3 deletions src/incompressibleNavierStokes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ function incompressiblenavierstokes(args...; n = 3, kwargs...)

# t_Ω = FETerm(res, Ωₕ, dΩ)
# op = FEOperator(Y, X, t_Ω)
op = FEOperator(res, Y, X)
# op = FEOperator(res, Y, X)
# t_with_jac_Ω = FETerm(res, ja, Ωₕ, dΩ)
op_with_jac = FEOperator(res, jac, Y, X)
# op_with_jac = FEOperator(res, jac, Y, X)

ndofs = Gridap.FESpaces.num_free_dofs(Y)
xin = zeros(ndofs)
# Ycon, Xcon = nothing, nothing
# @time nlp = GridapPDENLPModel(xin, x->0.0, Ωₕ, dΩ, Y, Ycon, X, Xcon, op)
return GridapPDENLPModel(xin, x -> (0.0)dΩ, Ωₕ, Y, X, op, name = "incompressible Navier-Stokes n=$n")
return GridapPDENLPModel(xin, x -> (0.0)dΩ, Ωₕ, Y, X, res, name = "incompressible Navier-Stokes n=$n")
end

incompressiblenavierstokes_meta = Dict(
Expand Down
4 changes: 2 additions & 2 deletions src/inversepoissonproblem2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function inversepoissonproblem2d(; n::Int = 100)
function res(y, u, v)
(-u * ((v) (y)) - v * h) *
end
op = FEOperator(res, Y, Xpde)

npde = Gridap.FESpaces.num_free_dofs(Ypde)
ncon = Gridap.FESpaces.num_free_dofs(Ycon)

Expand All @@ -82,7 +82,7 @@ function inversepoissonproblem2d(; n::Int = 100)
Ycon,
Xpde,
Xcon,
op,
res,
lvaru = zeros(ncon),
name = "inversePoissonproblem2d n=$n",
)
Expand Down
3 changes: 1 addition & 2 deletions src/methanol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function methanol(args...; n = 100, kwargs...)
(dt(y3, v3) - v3 * (θ[1] * y1 * (θ[5] * y1 + y2) / ((θ[2] + θ[5]) * y1 + y2) + θ[4] * y1)),
)dΩ
end
op = FEOperator(res, Ypde, Xpde)

z = [
1.0000 0 0
Expand Down Expand Up @@ -96,7 +95,7 @@ function methanol(args...; n = 100, kwargs...)
trian,
Ypde,
Xpde,
op,
res,
lvar = lvar,
uvar = uvar,
name = "Methanol to Hydrocarbons n=$n",
Expand Down
3 changes: 1 addition & 2 deletions src/minsurf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function minsurf(args...; n = 50, kwargs...)
function res(y, s, v)
return (v * (s - y + vL)) *
end
op = FEOperator(res, U, V)

nU = Gridap.FESpaces.num_free_dofs(U)
nUs = Gridap.FESpaces.num_free_dofs(Us)
Expand All @@ -59,7 +58,7 @@ function minsurf(args...; n = 50, kwargs...)
Us,
V,
Vs,
op,
res,
lvaru = zeros(nUs),
uvaru = Inf * ones(nUs),
name = "Minimal Surface with Obstacle n=$n",
Expand Down
4 changes: 1 addition & 3 deletions src/poisson_with_Neumann_and_Dirichlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ function poisson_with_Neumann_and_Dirichlet(args...; n::Int = 10, kwargs...)
end

xin = zeros(Gridap.FESpaces.num_free_dofs(Y))
op = FEOperator(res, Ypde, Xpde)

return GridapPDENLPModel(
xin,
f,
Expand All @@ -49,7 +47,7 @@ function poisson_with_Neumann_and_Dirichlet(args...; n::Int = 10, kwargs...)
Ycon,
Xpde,
Xcon,
op,
res,
name = "poisson with Neumann and Dirichlet n=$n",
)
end
Expand Down
3 changes: 1 addition & 2 deletions src/poissonboltzman2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ function poissonboltzman2d(; n::Int = 100)
((v) (y) + (sinh y) * v - u * v - v * h) *
#operate(tanh,ph)
end
op = FEOperator(res, Y, Xpde)

xin = zeros(Gridap.FESpaces.num_free_dofs(Y))
return GridapPDENLPModel(xin, f, trian, Ypde, Ycon, Xpde, Xcon, op, name = "2D-Poisson Boltzman n=$n")
return GridapPDENLPModel(xin, f, trian, Ypde, Ycon, Xpde, Xcon, res, name = "2D-Poisson Boltzman n=$n")
end

poissonboltzman2d_meta = Dict(
Expand Down
3 changes: 1 addition & 2 deletions src/poissonmixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function poissonmixed(args...; n = 3, kwargs...)
function res(k, y, v)
(k[1] * (v) (y) - v * f * k[2])dΩ
end
op = FEOperator(res, Ug, V0)

function fk(k, y)
(
Expand All @@ -49,7 +48,7 @@ function poissonmixed(args...; n = 3, kwargs...)

nUg = num_free_dofs(Ug)
x0 = zeros(nUg + 2)
return GridapPDENLPModel(x0, nrj, Ug, V0, op, name = "poissonmixed n=$n")
return GridapPDENLPModel(x0, nrj, Ug, V0, res, name = "poissonmixed n=$n")
end

poissonmixed_meta = Dict(
Expand Down
3 changes: 1 addition & 2 deletions src/poissonmixed2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function poissonmixed2(args...; n = 3, kwargs...)
function res(k, y, v)
(k[1] * (v) (y) - v * f * k[2])dΩ
end
op = FEOperator(res, Ug, V0)

function fk(k, y)
k1(x) = k[1]
Expand All @@ -49,7 +48,7 @@ function poissonmixed2(args...; n = 3, kwargs...)

nUg = num_free_dofs(Ug)
x0 = zeros(nUg + 2) #zeros(nUg + 2)
return GridapPDENLPModel(x0, nrj, Ug, V0, op, name = "poissonmixed2 n=$n")
return GridapPDENLPModel(x0, nrj, Ug, V0, res, name = "poissonmixed2 n=$n")
end

poissonmixed2_meta = Dict(
Expand Down
4 changes: 1 addition & 3 deletions src/poissonparam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ function poissonparam(args...; n = 3, kwargs...)
k1(x) = k[1]
(k1 * (v) (y) - v * f)dΩ
end
# t_Ω = FETerm(res, trian, dΩ)
op = FEOperator(res, Ug, V0)

fk(k) = 0.5 * dot(k .- 1.0, k .- 1.0)
nrj = NoFETerm(fk) #length(k)=1

nUg = num_free_dofs(Ug)
xs = rand(nUg + 1)
return GridapPDENLPModel(xs, nrj, Ug, V0, op, name = "poissonparam n=$n")
return GridapPDENLPModel(xs, nrj, Ug, V0, res, name = "poissonparam n=$n")
end

poissonparam_meta = Dict(
Expand Down
3 changes: 1 addition & 2 deletions src/robot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function robot(args...; n = 400, kwargs...)
((ρ) * ((r) (φ)) -* p)
)dΩ # + ∫(p * 0 + q * 0 + r * 0) * dΓ
end
op = FEOperator(res, Ypde, Xpde)

ndofs_pde = Gridap.FESpaces.num_free_dofs(Ypde)
ndofs_con = Gridap.FESpaces.num_free_dofs(Ycon)
Expand All @@ -84,7 +83,7 @@ function robot(args...; n = 400, kwargs...)
Ycon,
Xpde,
Xcon,
op,
res,
lvaru = -ones(ndofs_con),
uvaru = ones(ndofs_con),
lvary = lvar,
Expand Down
3 changes: 1 addition & 2 deletions src/rocket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function rocket(args...; n = 400, T = 1, kwargs...)
dt(H, pH)
)dΩ + ( (H - h) * pH )dΓ
end
op = FEOperator(res, Ypde, Xpde)

function f(y, u)
h, H, v, m = y
Expand Down Expand Up @@ -89,7 +88,7 @@ function rocket(args...; n = 400, T = 1, kwargs...)
Ycon,
Xpde,
Xcon,
op,
res,
lvaru = zeros(ndofs_con),
uvaru = Tmax * ones(ndofs_con),
lvary = vcat(
Expand Down
4 changes: 1 addition & 3 deletions src/sis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ function sis(args...; x0 = [1, 2], n = 10, a = 0.2, b = 0.7, T = 1, kwargs...)
(dt(I, p) + dt(S, q) - p * (_a * S * I - _b * I) - q * (_b * I - _a * S * I))dΩ
end

op_sis = FEOperator(res, Y, X)

ndofs = Gridap.FESpaces.num_free_dofs(Y)
xin = zeros(ndofs)
return GridapPDENLPModel(xin, NoFETerm(), Y, X, op_sis, name = "SIS n=$n")
return GridapPDENLPModel(xin, NoFETerm(), Y, X, res, name = "SIS n=$n")
end

sis_meta = Dict(
Expand Down
4 changes: 2 additions & 2 deletions src/smallestlaplacianeigenvalue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ function smallestlaplacianeigenvalue(; n::Int = 10, args...)
function res(y, v)
((y * y - 1) * v) *
end
op = FEOperator(res, Ypde, Xpde)

xin = zeros(Gridap.FESpaces.num_free_dofs(Ypde))
return GridapPDENLPModel(xin, f, trian, Ypde, Xpde, op, name = "smallestLaplacianeigenvalue n=$n")
return GridapPDENLPModel(xin, f, trian, Ypde, Xpde, res, name = "smallestLaplacianeigenvalue n=$n")
end

smallestlaplacianeigenvalue_meta = Dict(
Expand Down
Loading

0 comments on commit 4097e84

Please sign in to comment.