Skip to content

Commit

Permalink
Added continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Nov 7, 2024
1 parent 54d8e04 commit 1a0e9ef
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ function _fe_operator(U,V,params)
mfs = _multi_field_style(params)
if has_transient(params)
_ode_fe_operator(mfs,U,V,params)
elseif has_continuation(params)
_continuation_fe_operator(mfs,U,V,params)
else
_fe_operator(mfs,U,V,params)
end
Expand All @@ -339,7 +341,7 @@ function _fe_operator(::BlockMultiFieldStyle,U,V,params)
return FEOperator(res,jac,U,V,assem)
end

function _ode_fe_operator(::ConsecutiveMultiFieldStyle,U,V,params)
function _ode_fe_operator(mfs,U,V,params)
k = params[:fespaces][:k]
res, jac, jac_t = weak_form(params,k)
Tm = params[:solver][:matrix_type]
Expand All @@ -348,6 +350,25 @@ function _ode_fe_operator(::ConsecutiveMultiFieldStyle,U,V,params)
return TransientFEOperator(res,(jac,jac_t),U,V,assembler=assem)
end

function _continuation_fe_operator(mfs,U,V,params)
niter = params[:continuation][:niter]
alphas = params[:continuation][:alphas]
nsteps = length(niter)

ops = map(alphas) do α
p = duplicate_params(params)
p[:fluid][] = α
_fe_operator(mfs,U,V,p)
end

op = _fe_operator(mfs,U,V,params)
for step in nsteps:-1:1
op = ContinuationFEOperator(ops[step],op,niter[step])
end

return op
end

# Sub-triangulations

const DiscreteModelTypes = Union{Gridap.DiscreteModel,GridapDistributed.DistributedDiscreteModel}
Expand Down
49 changes: 49 additions & 0 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function add_default_params(_params)
:multigrid => false,
:check_valid => false,
:transient => false,
:continuation => false,
:x0 => false,
)
_check_mandatory(_params,mandatory,"")
Expand All @@ -111,6 +112,7 @@ function add_default_params(_params)
:multigrid => nothing,
:check_valid => true,
:transient => nothing,
:continuation => nothing,
:x0 => :zero,
)
params = _add_optional(_params,mandatory,optional,_params,"")
Expand All @@ -127,12 +129,35 @@ function add_default_params(_params)
if !isnothing(params[:transient])
params[:transient] = params_transient(params)
end
if !isnothing(params[:continuation])
params[:continuation] = params_continuation(params)
end
params
end

default_ptimer(model) = PTimer(DebugArray(LinearIndices((1,))))
default_ptimer(model::GridapDistributed.DistributedDiscreteModel) = PTimer(get_parts(model))

"""
Duplicates all paramaters in `params`, such that
- isbits objects (e.g. numbers and lighweight structs) are deep-copied.
- heavier objects are copied by reference.
This is useful to create a new set of parameters where
constants can be modified without affecting the original ones.
"""
function duplicate_params(params)
new_params = Dict{Symbol,Any}()
for (key,value) in params
if isa(value,Dict)
new_params[key] = duplicate_params(value)
else
new_params[key] = value
end
end
return new_params
end

"""
Valid keys for `params[:solver]` are the following:
Expand Down Expand Up @@ -669,3 +694,27 @@ function default_solver_params(::Val{:forward})
:solver => :forward,
)
end

"""
Continuation parameters
Valid keys for the dictionaries in `params[:continuation]` are the following.
# Mandatory keys
- `:niter`: Number of nonlinear iterations per continuation step.
- `:alphas`: Array of continuation parameters.
"""
function params_continuation(params::Dict{Symbol,Any})
mandatory = Dict{Symbol,Any}(
:niter => true,
:alphas => true,
)
optional = Dict{Symbol,Any}()
continuation = _check_mandatory_and_add_optional_weak(params[:continuation],mandatory,optional,params,"[:continuation]")
@assert length(continuation[:niter]) == length(continuation[:alphas])
return continuation
end

has_continuation(params) = haskey(params,:continuation) && !isnothing(params[:continuation])

0 comments on commit 1a0e9ef

Please sign in to comment.