-
Notifications
You must be signed in to change notification settings - Fork 68
Open
Description
Dear Developers,
Can we use the package instead of the following code for the finite element:
Thanks in advance. I'm wondering if can we can also add LineSearch in this case like the usual cases.
# Pre-allocation of vectors for the solution and Newton increments
_ndofs = ndofs(dh)
un = zeros(_ndofs) # previous solution vector
u = zeros(_ndofs)
Δu = zeros(_ndofs)
ΔΔu = zeros(_ndofs)
apply!(un, dbcs)
# Create sparse matrix and residual vector
K = allocate_matrix(dh)
g = zeros(_ndofs)
# Perform Newton iterations
newton_itr = -1
NEWTON_TOL = 1.0e-8
NEWTON_MAXITER = 30
prog = ProgressMeter.ProgressThresh(NEWTON_TOL; desc = "Solving:")
while true
newton_itr += 1
# Construct the current guess
u .= un .+ Δu
# Compute residual and tangent for current guess
assemble_global!(K, g, dh, cv, fv, mp, u, ΓN)
# Apply boundary conditions
apply_zero!(K, g, dbcs)
# Compute the residual norm and compare with tolerance
normg = norm(g)
ProgressMeter.update!(prog, normg; showvalues = [(:iter, newton_itr)])
if normg < NEWTON_TOL
break
elseif newton_itr > NEWTON_MAXITER
error("Reached maximum Newton iterations, aborting")
end
# Compute increment using conjugate gradients
@timeit "linear solve" IterativeSolvers.cg!(ΔΔu, K, g; maxiter = 1000)
apply_zero!(ΔΔu, dbcs)
Δu .-= ΔΔu
end
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels