@@ -45,14 +45,19 @@ function compute_nonlinear_residual!(residual, A, b, sol, unknowns, PD, SC, free
4545 residual. entries[fixed_dofs (op)] .= 0
4646 end
4747
48+ mask_nonrestricted = ones (Bool, length (residual. entries))
49+ for rs in PD. restrictions
50+ mask_nonrestricted[fixed_dofs (rs)] .= false
51+ end
52+
4853 for u_off in SC. parameters[:inactive ]
4954 j = get_unknown_id (SC, u_off)
5055 if j > 0
5156 fill! (residual[j], 0 )
5257 end
5358 end
5459
55- nlres = length (freedofs) > 0 ? norm (residual. entries[freedofs]) : norm (residual. entries)
60+ nlres = length (freedofs) > 0 ? norm (residual. entries[freedofs]) : norm (residual. entries[mask_nonrestricted] )
5661
5762 if SC. parameters[:verbosity ] > 0 && length (residual) > 1
5863 @info " sub-residuals = $(norms (residual)) "
@@ -112,7 +117,7 @@ function assemble_system!(A, b, sol, PD, SC, timer; kwargs...)
112117 fill! (A. entries. cscmatrix. nzval, 0 )
113118 end
114119
115- # Assemble operators
120+ # Assemble operators and restrictions
116121 if SC. parameters[:initialized ]
117122 for op in PD. operators
118123 @timeit timer " $(op. parameters[:name ]) " begin
@@ -139,6 +144,10 @@ function assemble_system!(A, b, sol, PD, SC, timer; kwargs...)
139144 time_assembly += stats. time
140145 allocs_assembly += stats. bytes
141146 end
147+ # # assemble restrictions
148+ for restriction in PD. restrictions
149+ @timeit timer " $(restriction. parameters[:name ]) " assemble! (restriction, sol, SC; kwargs... )
150+ end
142151 end
143152 flush! (A. entries)
144153
@@ -222,17 +231,9 @@ Solves the linear system and updates the solution vector. This includes:
222231"""
223232function solve_linear_system! (A, b, sol, soltemp, residual, linsolve, unknowns, freedofs, damping, PD, SC, stats, is_linear, timer, kwargs... )
224233
225- @timeit timer " assembly" begin
226- # # assemble restrctions
227- if ! SC. parameters[:initialized ]
228- for restriction in PD. restrictions
229- @timeit timer " $(restriction. parameters[:name ]) " assemble! (restriction, sol, SC; kwargs... )
230- end
231- end
232- end
233-
234234 @timeit timer " linear solver" begin
235235
236+
236237 # does the linsolve object need a (new) matrix?
237238 linsolve_needs_matrix = ! SC. parameters[:constant_matrix ] || ! SC. parameters[:initialized ]
238239
@@ -243,6 +244,8 @@ function solve_linear_system!(A, b, sol, soltemp, residual, linsolve, unknowns,
243244 else
244245 A_unrestricted = A. entries. cscmatrix
245246 end
247+ # else
248+ # A_unrestricted = A.entries.cscmatrix
246249 end
247250
248251 # we solve for A Δx = r
@@ -264,10 +267,10 @@ function solve_linear_system!(A, b, sol, soltemp, residual, linsolve, unknowns,
264267 else
265268 # add possible Lagrange restrictions
266269 restriction_matrices = [length (freedofs) > 0 ? view (restriction_matrix (re), freedofs, :) : restriction_matrix (re) for re in PD. restrictions ]
267- restriction_rhss = deepcopy ( [length (freedofs) > 0 ? view (restriction_rhs (re), freedofs) : restriction_rhs (re) for re in PD. restrictions ])
270+ restriction_rhss = [length (freedofs) > 0 ? view (restriction_rhs (re), freedofs) : restriction_rhs (re) for re in PD. restrictions ]
268271
269272 # block sizes for the block matrix
270- block_sizes = [size (A_unrestricted, 2 ), [ size (B, 2 ) for B in restriction_matrices ]. .. ]
273+ block_sizes = [length (b_unrestricted ), [ length (b ) for b in restriction_rhss ]. .. ]
271274
272275 # total number of additional LM dofs
273276 nLMs = @views sum (block_sizes[2 : end ])
@@ -280,7 +283,7 @@ function solve_linear_system!(A, b, sol, soltemp, residual, linsolve, unknowns,
280283 end
281284
282285 total_size = sum (block_sizes)
283- Tv = eltype (A_unrestricted )
286+ Tv = eltype (b_unrestricted )
284287
285288 # # create block matrix
286289 if linsolve_needs_matrix
@@ -506,6 +509,8 @@ function check_problem_linearity!(PDs, SCs, unknowns)
506509 end
507510 if SCs[j]. parameters[:is_linear ] == " auto"
508511 is_linear[j] = ! nonlinear[j]
512+ elseif SCs[j]. parameters[:is_linear ] == true
513+ is_linear[j] = true
509514 end
510515 if is_linear[j] && nonlinear[j]
511516 @warn " problem $(PD. name) seems nonlinear, but user set is_linear = true (results may be wrong)!!"
0 commit comments