Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local-Global Solver API #144

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c95cc7c
Prototyping.
termi-official Aug 26, 2024
9a537e0
Inconsistent version for multilevel newton works.
termi-official Aug 28, 2024
5d4d5b2
Rename and stricter convergence criterion.
termi-official Aug 28, 2024
2e4a246
Inconsistent tangent.
termi-official Aug 28, 2024
a39e31b
Local solver derp.
termi-official Aug 28, 2024
4f17a3b
Dunno how that happened. Now it at least converges linearly.
termi-official Aug 28, 2024
7b3178f
Can reproduce issue in 1D
termi-official Aug 28, 2024
a049963
Fixed some issues
termi-official Aug 29, 2024
e7c072f
Cleanup.
termi-official Aug 29, 2024
1fd1e19
Chasing some very stupid error.
termi-official Aug 30, 2024
487c58f
Works finally.
termi-official Aug 30, 2024
a8dc58b
Alternative version
termi-official Aug 30, 2024
f9c950e
Refactor backward Euler for affine right hand side
termi-official Sep 3, 2024
9f9724d
Generalize the affine function API.
termi-official Sep 3, 2024
3f53053
Stash current state
termi-official Sep 4, 2024
735e937
Merge main
termi-official Sep 4, 2024
ca9ce8e
Fix precompilation
termi-official Sep 4, 2024
80db657
Some temporary changes
termi-official Sep 14, 2024
f2271d9
More changes
termi-official Sep 17, 2024
2ea9641
Recover 1D-v2
termi-official Sep 17, 2024
2efda1a
Trying to generalize
termi-official Sep 18, 2024
794fae3
Generalize example with local solve
termi-official Sep 18, 2024
3cedb0d
Docs
termi-official Sep 19, 2024
110b573
More comments for v2
termi-official Sep 19, 2024
f7f038b
First step to strip down the nonlinear operator and add de-/compressi…
termi-official Nov 5, 2024
0228b37
Update example manifest and typos
termi-official Nov 6, 2024
08d254c
Merge main.
termi-official Jan 18, 2025
d35ccc7
Merge oopsies.
termi-official Jan 18, 2025
29a1320
Operators TLDR
termi-official Jan 18, 2025
b8cf9cf
[skip ci] intermediate state
termi-official Jan 18, 2025
711a66d
Big interface refactor as basis for stiff DAEs
termi-official Jan 19, 2025
9cbef41
Remaining interface.
termi-official Jan 19, 2025
b6497b6
Derp
termi-official Jan 19, 2025
6c9c094
Add local variable manager and allow users to pass custom quadrature …
termi-official Jan 20, 2025
e1e3d79
Pass integration rule via integrator object into bilinear operators.
termi-official Jan 20, 2025
7a9f700
Factor qvector utils into ferrite addon
termi-official Jan 20, 2025
f3e506c
Rename StructuralModel to QuasiStaticModel with all implications
termi-official Jan 20, 2025
96603f7
Hoist elastodynamic problem
termi-official Jan 20, 2025
2d7991d
Baseline for communicating local solver for multilevel newton
termi-official Jan 22, 2025
686b889
Working prototype for outer Newton solve on a generalized Maxwell mat…
termi-official Jan 24, 2025
e90be9f
Viscoelasticity prototype done with correct convergence and monotonicity
termi-official Jan 24, 2025
354233b
Rename and function size query.
termi-official Jan 24, 2025
232c2bc
Try to fix dispatch ambiguity
termi-official Jan 24, 2025
902a1b0
Derp
termi-official Jan 24, 2025
bac153c
Fix CI
termi-official Jan 24, 2025
29c8248
[skip ci] Intermediate state
termi-official Jan 29, 2025
792cd6e
Merge branch 'do/local-global-solver' of github.com:termi-official/Th…
termi-official Jan 29, 2025
3fcb35d
Add annotation types
termi-official Feb 18, 2025
add571f
Typo
termi-official Feb 18, 2025
573dd4a
Fix more typos and params
termi-official Feb 18, 2025
c0a9d25
Merge main
termi-official Feb 19, 2025
8ff9b4f
Speed up local solve
termi-official Feb 19, 2025
8c68644
Fix RDS20MF model and revive test coverage.
termi-official Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More changes
  • Loading branch information
termi-official committed Sep 17, 2024
commit f2271d9f4d91ad8a371aeb12cd072a7facaabc5a
47 changes: 26 additions & 21 deletions examples/local-global-1d-v2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ end

abstract type AbstractStageCache end

struct QuasiStaticSolutionState
struct QuasiStaticSolutionState{UT, QT}
u::UT
q::QT
end

struct DynamicSolutionState
struct DynamicSolutionState{UT, VT, QT}
u::UT
v::VT
q::QT
Expand All @@ -50,17 +50,22 @@ struct QuadraturePointStageInfo{CID, QID}
qpi::QID
end

function solve_local_problem(cache::LocalBackwardEulerCache, model::LocalODEModel)
@unpack t, dt, tol = cache
@unpack u, uprev, q, qprev = cache
function local_problem_residual(cache::LocalBackwardEulerCache, model::LocalODEModel)
dq = f(u, q, model, t+dt)
residual = (q .- qprev) .- dt .* dq # = L(u,q)
return residual
end

function solve_local_problem(solver_cache::LocalBackwardEulerCache, model::LocalODEModel)
@unpack t, dt, tol = solver_cache
@unpack u, uprev, q, qprev = solver_cache
# du = (u - uprev)/dt
# solve local problem
for inner_iter in 1:max_iter
# setup system for local backward Euler solve L(qₙ₊₁, uₙ₊₁) = (qₙ₊₁ - qₙ) - Δt*rhs(qₙ₊₁, uₙ₊₁) = 0 w.r.t. qₙ₊₁ with uₙ₊₁ frozen
J = jacobian_q(u, q, model, t+dt)
dq = f(u, q, model, t+dt)
residual = (q .- qprev) .- dt .* dq # = L(u,q)
dq = local_problem_residual(solver_cache, model) # = L(u,q)
# solve linear sytem and update local solution
J = jacobian_q(u, q, model, t+dt)
∂L∂q = one(J) - (dt .* J)
Δq = ∂L∂q \ residual
q -= Δq
Expand All @@ -70,29 +75,30 @@ function solve_local_problem(cache::LocalBackwardEulerCache, model::LocalODEMode
# inner_iter == max_iter && error("Newton diverged for cell=$(cellid(cell))|qp=$qp at t=$t resnorm=$resnorm")
inner_iter == max_iter && error("t=$t resnorm=$resnorm")
end
return nothing
return q
end

function solve_corrector_problem(E, Eᵥ, model, solver_cache::LocalBackwardEulerCache)
function solve_corrector_problem(solver_cache::LocalBackwardEulerCache, model::LocalODEModel)
@unpack t, dt = solver_cache
J = jacobian_q(E, Eᵥ, model, t+dt)
@unpack u, q = solver_cache
J = jacobian_q(u, q, model, t+dt)
∂L∂Q = (one(J) - (dt .* J))
∂L∂U = -dt * jacobian_u(E, Eᵥ, model, t+dt)
dQdU = zeros(length(∂L∂U))
return dQdU = ∂L∂Q \ -∂L∂U
∂L∂U = -dt * jacobian_u(u, q, model, t+dt)
return ∂L∂Q \ -∂L∂U # = dQdU
end

function assemble_cell!(ke, fe, u, q, cell, cellvalues, material::LinearViscoelasticity1D, solver_cache::AbstractStageCache)
function assemble_cell!(ke, fe, sol::QuasiStaticSolutionState, cell, cellvalues, material::LinearViscoelasticity1D, solver_cache::AbstractStageCache)
@unpack u, q = sol
q_offset = getnquadpoints(cellvalues)*(cellid(cell)-1)
@unpack E₁ = material.viscosity
@unpack E₀ = material
ke2 = zeros(2,2)
for q_point in 1:getnquadpoints(cellvalues)
# 1. Solve for Qₙ₊₁
E = function_gradient(cellvalues, q_point, u)[1]
Eᵥ = q[q_offset+q_point] # Current guess
Eᵥ = solve_local_problem(E, Eᵥ, material.viscosity, solver_cache, LocalInfoCache(q_offset+q_point))
q[q_offset+q_point] = Eᵥ # Update guess
E = function_gradient(cellvalues, q_point, u)[1] # Frozen u for inner function
Eᵥ = q[q_offset+q_point] # Current initial guess q
#
Eᵥ = solve_local_problem(E, Eᵥ, material.viscosity, solver_cache) # Updated q
q[q_offset+q_point] = Eᵥ # Current guess
# 2. Contribution to corrector part ,,dQdU`` by solving the linear system
dQdU = solve_corrector_problem(E, Eᵥ, material.viscosity, solver_cache)
# 3. ∂G∂Q
Expand All @@ -110,7 +116,6 @@ function assemble_cell!(ke, fe, u, q, cell, cellvalues, material::LinearViscoela
ke[i, j] += (∇ˢʸᵐNⱼ * T) * dΩ
# Corrector part
ke[i, j] += ∇ˢʸᵐNⱼ * ∂G∂Q * dQdU * ∇Nᵢ * dΩ
ke2[i, j] += ∇ˢʸᵐNⱼ * ∂G∂Q * dQdU * ∇Nᵢ * dΩ
end
end
end
Expand Down
Loading