Skip to content

Commit

Permalink
Added continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Oct 31, 2024
1 parent 8d3a181 commit b9a9a14
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
26 changes: 19 additions & 7 deletions src/Main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function main(_params::Dict;output::Dict=Dict{Symbol,Any}())

mfs = _multi_field_style(params)
V = MultiFieldFESpace([V_u,V_p,V_j,V_φ];style=mfs)
if !params[:transient]
if !has_transient(params)
U = MultiFieldFESpace([U_u,U_p,U_j,U_φ];style=mfs)
else
U = TransientMultiFieldFESpace([U_u,U_p,U_j,U_φ];style=mfs)
Expand Down Expand Up @@ -183,7 +183,7 @@ end

function _solver(op,params)
solver = _solver(Val(params[:solver][:solver]),op,params)
if !isnothing(params[:transient])
if has_transient(params)
solver = _ode_solver(solver,params)
end
return solver
Expand Down Expand Up @@ -315,7 +315,7 @@ end

function _fe_operator(U,V,params)
mfs = _multi_field_style(params)
if isnothing(params[:transient])
if !has_transient(params)
_fe_operator(mfs,U,V,params)
else
_ode_fe_operator(mfs,U,V,params)
Expand Down Expand Up @@ -417,6 +417,8 @@ function _solve(xh,solver,op::TransientFEOperator,params)
solve(solver,op,t0,tf,xh), cache
end

# Initial guess for the solver

function initial_guess(op::FEOperator,params)
U = get_trial(op)
initial_guess(params[:x0],U,op,params)
Expand All @@ -428,15 +430,25 @@ function initial_guess(op::TransientFEOperator,params)
initial_guess(params[:x0],U0,op,params)
end

initial_guess(x0::Symbol,trial,op,params) = initial_guess(Val(x0),trial,op,params)
initial_guess(::Val{:zero},trial,op,params) = zero(trial)
initial_guess(::Val{:solve},trial,op,params) = @notimplemented

function initial_guess(x0::Dict,trial,op,params)
vals = [x0[:u],x0[:p],x0[:j],x0[]]
interpolate(vals,trial)
end

initial_guess(x0::Symbol,trial,op,params) = initial_guess(Val(x0),trial,op,params)
initial_guess(::Val{:zero},trial,op,params) = zero(trial)

function initial_guess(::Val{:solve},trial,op,params)
@notimplementedif isa(op,TransientFEOperator)
@assert params[:fluid][:convection] "Convection must be enabled to use initial guess :solve"
params[:fluid][:convection] = false
xh = initial_guess(:zero,trial,op,params)
solver = _solver(op,params)
xh, cache = _solve(xh,solver,op,params)
params[:fluid][:convection] = true
return xh
end

# Mesh sizes

get_cell_size(t::TriangulationTypes) = CellField(_get_cell_size(t),t)
Expand Down
18 changes: 18 additions & 0 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,22 @@ function params_bcs_stabilization(params::Dict{Symbol,Any})
_check_mandatory_and_add_optional_weak(params[:bcs][:stabilization],mandatory,optional,params,"[:bcs][:stabilization]")
end

"""
Transient parameters
Valid keys for the dictionaries in `params[:transient]` are the following.
# Mandatory keys
- `:t0`: Initial time
- `:tf`: Final time
- `:Δt`: Time step
# Optional keys
- `:solver`: Solver name and parameters for the transient solver. Possible options
are `[:theta, :forward]`. Defaults to `:theta`.
"""
function params_transient(params::Dict{Symbol,Any})
mandatory = Dict(
:t0 => true,
Expand All @@ -624,6 +640,8 @@ function params_transient(params::Dict{Symbol,Any})
return transient
end

has_transient(params) = haskey(params,:transient) && !isnothing(params[:transient])

function default_solver_params(::Val{:theta})
return Dict(
:solver => :theta,
Expand Down
2 changes: 1 addition & 1 deletion src/weakforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function weak_form(params)
end

function weak_form(params,k)
if !params[:transient]
if !has_transient(params)
_weak_form(params,k)
else
_ode_weak_form(params,k)
Expand Down

0 comments on commit b9a9a14

Please sign in to comment.