@@ -223,7 +223,7 @@ setup_internal_cache(material_model::Union{<:ElastodynamicsModel{<:ActiveStressM
223223
224224# TODO this actually belongs to the multi-level newton file :)
225225# Dual (global cache and element-level cache) use for now to make it non-allocating.
226- struct GenericFirstOrderRateIndependentCondensationMaterialStateCache{LocalModelType, LocalModelCacheType, QType, QType2, T, LVH} <: RateIndependentCondensationMaterialStateCache
226+ struct GenericFirstOrderRateIndependentCondensationMaterialStateCache{LocalModelType, LocalModelCacheType, LocalSolverType, QType, QType2, T, LVH} <: RateIndependentCondensationMaterialStateCache
227227 # The actual model
228228 model:: LocalModelType
229229 model_cache:: LocalModelCacheType
@@ -233,7 +233,7 @@ struct GenericFirstOrderRateIndependentCondensationMaterialStateCache{LocalModel
233233 Qprev:: QType
234234 # t - tprev
235235 Δt:: T
236- # local_solver::...?
236+ local_solver_cache :: LocalSolverType
237237 lvh:: LVH
238238 # These are used locally
239239 localQ:: QType2
@@ -274,24 +274,23 @@ function solve_local_constraint(F::Tensor{2,dim}, coefficients, material_model::
274274 function local_residual! (R, Q, λ, dλdt)
275275 dQ = zeros (eltype (Q), length (Q)) # TODO preallocate during setup
276276 sarcomere_rhs! (dQ, Q, λ, dλdt, Ca, time, material_model. contraction_model)
277- R . = (Q . - Qprev) . / state_cache. Δt . - dQ
277+ @. . R = (Q - Qprev) / state_cache. Δt - dQ
278278 return nothing
279279 end
280280
281281 function local_residual_jac_wrap! (R, Q)
282282 return local_residual! (R, Q, λ, dλdt)
283283 end
284284
285- # TODO preallocate during setup
286- R = zeros (length (Q))
287- J = zeros (length (Q),length (Q))
288- for newton_iter in 1 : 10
285+ R = state_cache. local_solver_cache. residual
286+ J = state_cache. local_solver_cache. J
287+ for newton_iter in 1 : state_cache. local_solver_cache. params. max_iters
289288 ForwardDiff. jacobian! (J, local_residual_jac_wrap!, R, Q)
290289 local_residual! (R, Q, λ, dλdt)
291290 ΔQ = J \ R
292291 Q .- = ΔQ
293292 # @info qp.i, norm(R), norm(ΔQ)
294- if norm (R) < 1e-16
293+ if norm (R) < state_cache . local_solver_cache . params . tol
295294 break
296295 elseif newton_iter == 10
297296 error (" Local Newton did not converge" )
@@ -307,23 +306,16 @@ function solve_local_constraint(F::Tensor{2,dim}, coefficients, material_model::
307306 _store_local_state! (state_cache, geometry_cache, qp)
308307
309308 # Solve corrector problem
310- # function local_residual_rhs_wrap!(R, λ)
311- # dQ = zeros(eltype(λ), 20) # TODO preallocate during setup
312- # sarcomere_rhs!(dQ, Q, λ, dλdt, Ca, time, material_model.contraction_model)
313- # # R .= (Q .- Qprev) .- dQ
314- # R .= (Q .- Qprevflat) .- dQ
315- # return nothing
316- # end
317- function local_residual_rhs_wrap (λ)
309+ function local_residual_rhs_wrap! (R, λ)
318310 dQ = zeros (eltype (λ), length (Q)) # TODO preallocate during setup
319311 sarcomere_rhs! (dQ, Q, λ, dλdt, Ca, time, material_model. contraction_model)
320- # R .= (Q .- Qprev) .- dQ
321- return (Q .- Qprevflat) ./ state_cache. Δt .- dQ
312+ @. . R = (Q - Qprevflat) / state_cache. Δt - dQ
322313 return nothing
323314 end
324- ∂fₗ∂λ = zeros (length (Q))
325- ForwardDiff. derivative! (∂fₗ∂λ, local_residual_rhs_wrap, λ)
326- dQdλ = - J \ ∂fₗ∂λ
315+ R = state_cache. local_solver_cache. residual
316+ ∂fₗ∂λ = state_cache. local_solver_cache. rhs_corrector
317+ ForwardDiff. derivative! (∂fₗ∂λ, local_residual_rhs_wrap!, R, λ)
318+ dQdλ = J \ - ∂fₗ∂λ
327319
328320 return Q, _solve_local_sarcomere_dQdF (dQdλ, dλdF, λ, F, coefficients, material_model. active_stress_model, material_model. contraction_model)
329321end
0 commit comments