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
Show file tree
Hide file tree
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
Chasing some very stupid error.
  • Loading branch information
termi-official committed Aug 30, 2024
commit 1fd1e19ca6ae460cca002262e3782a677981d5ab
12 changes: 7 additions & 5 deletions examples/local-global-1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct LinearViscoelasticity1D{T,TV,FT}
end

# Ferrite-specific
struct MaterialCache{M, DH, CV, FV}
struct ElementCache{M, DH, CV, FV}
material::M
dh::DH
cv::CV
Expand Down Expand Up @@ -71,7 +71,7 @@ function assemble_cell!(ke, fe, u, q, cell, cellvalues, material::LinearViscoela
end

# Standard assembly loop for global problem
function stress!(du, u, q, cache::MaterialCache, t)
function stress!(du, u, q, cache::ElementCache, t)
K = allocate_matrix(cache.dh)
f = zeros(ndofs(cache.dh))
# Allocate the element stiffness matrix
Expand Down Expand Up @@ -116,7 +116,7 @@ function stress!(du, u, q, cache::MaterialCache, t)
du .= K*u .- f
end

function stress_Ju!(K, u, q, cache::MaterialCache, t)
function stress_Ju!(K, u, q, cache::ElementCache, t)
# Allocate the element stiffness matrix
n_basefuncs = getnbasefunctions(cache.cv)
ke = zeros(n_basefuncs, n_basefuncs)
Expand All @@ -135,7 +135,7 @@ function stress_Ju!(K, u, q, cache::MaterialCache, t)
end
end

function stress_Jq!(K, u, q, cache::MaterialCache, t)
function stress_Jq!(K, u, q, cache::ElementCache, t)
# Allocate the element stiffness matrix
n_basefuncs = getnbasefunctions(cache.cv)
ke = zeros(n_basefuncs, n_basefuncs)
Expand Down Expand Up @@ -224,7 +224,7 @@ function generate_linear_elasticity_problem()
end

dh,ch,cv,fv = generate_linear_elasticity_problem()
cache = MaterialCache(
cache = ElementCache(
material,
dh,
cv,
Expand Down Expand Up @@ -320,8 +320,10 @@ for t ∈ 0.0:dt:T
assemble!(assembler, celldofs(cell), ke)
end
# 2. Residual and Jacobian of global function G(qₙ₊₁, uₙ₊₁) w.r.t. to global vector uₙ₊₁ with qₙ₊₁ frozen
@show J
global_f(global_residual, u, qmat, cache, t+dt)
global_jacobian_u(J, u, qmat, cache, t+dt)
@show J
# 3. Apply boundary conditions
apply_zero!(J, global_residual, ch)
# 4. Solve linear system
Expand Down
19 changes: 8 additions & 11 deletions examples/local-global.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function stress_Ju!(K, u, q, cache::MaterialCache, t)
n_basefuncs = getnbasefunctions(cache.cv)
ke = zeros(n_basefuncs, n_basefuncs)
# Create an assembler
assembler = start_assemble(K)
assembler = start_assemble(K; fillzero=false)
# Loop over all cells
for cell in CellIterator(dh)
# Update the shape function gradients based on the cell coordinates
Expand Down Expand Up @@ -259,7 +259,6 @@ function viscosity_evolution_Ju(u, q, p::OverstressedViscosity, t, local_chunk_i

return Ju
end

# function solve_local()
# # for each local chunk # Element loop
# # for each element in chunk # Quadrature loop
Expand Down Expand Up @@ -356,14 +355,11 @@ for t ∈ 0.0:dt:T
global_f(global_residual, u, qmat, cache, t+dt)

#Setup Jacobian
# 1. Jacobian of global function G w.r.t. to global vector u
global_jacobian_u(J, u, qmat, cache, t+dt)
# 2. Local solves and Jacobian corrections (normally these are done IN global_jacobian_u for efficiency reasons)
# 1. Local solves and Jacobian corrections (normally these are done IN global_jacobian_u for efficiency reasons)
# for each local chunk # Element loop
∂G∂Qₑ = zeros(SymmetricTensor{2,3}, (getnbasefunctions(cache.cv), getnquadpoints(cache.cv))) # TODO flatten to second order tensor
dQdUₑ = zeros(SymmetricTensor{2,3}, (getnquadpoints(cache.cv), getnbasefunctions(cache.cv)))

assembler = start_assemble(J; fillzero=false)
assembler = start_assemble(J; fillzero=true)
ke = zeros(getnbasefunctions(cache.cv), getnbasefunctions(cache.cv))
for cell in CellIterator(dh)
# prepare iteration
Expand Down Expand Up @@ -406,15 +402,17 @@ for t ∈ 0.0:dt:T
# Contribution to corrector part ,,∂G∂Qₑ``
chunk_jacobian_q(∂G∂Qₑ, ue, qmat, cell, cache.cv, cache.material)
# Correction of global Jacobian
for i in getnbasefunctions(cache.cv)
for j in getnbasefunctions(cache.cv)
for k in getnquadpoints(cache.cv)
for i in 1:getnbasefunctions(cache.cv)
for j in 1:getnbasefunctions(cache.cv)
for k in 1:getnquadpoints(cache.cv)
ke[i,j] += ∂G∂Qₑ[i,k] ⊡ dQdUₑ[k,j]
end
end
end
assemble!(assembler, celldofs(cell), ke)
end
# 2. Jacobian of global function G w.r.t. to global vector u
global_jacobian_u(J, u, qmat, cache, t+dt)
# 3. Apply boundary conditions
apply_zero!(J, global_residual, ch)
# 4. Solve linear system
Expand All @@ -432,7 +430,6 @@ for t ∈ 0.0:dt:T
end
outer_iter == max_iter && error("max iter")
end
@show qmat[1,1]
qprev .= q

VTKGridFile("linear-viscoelasticity-$t.vtu", dh) do vtk
Expand Down