Skip to content

Commit 8d56e6d

Browse files
authored
fixed control flow and nonlinear residual computation in presence of restrictions (#96)
1 parent 539266a commit 8d56e6d

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGES
22

3+
## v1.7.2
4+
5+
### Fixed
6+
- fixed control flow and nonlinear residual computation in presence of restrictions
7+
38
## v1.7.1
49

510
### Fixed

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ExtendableFEM"
22
uuid = "a722555e-65e0-4074-a036-ca7ce79a4aed"
3-
version = "1.7.1"
3+
version = "1.7.2"
44
authors = ["Christian Merdon <merdon@wias-berlin.de>", "Patrick Jaap <patrick.jaap@wias-berlin.de>"]
55

66
[deps]
@@ -14,7 +14,6 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1414
ExtendableFEMBase = "12fb9182-3d4c-4424-8fd1-727a0899810c"
1515
ExtendableGrids = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
1616
ExtendableSparse = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
17-
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1817
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1918
GridVisualize = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
2019
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -42,7 +41,6 @@ ExplicitImports = "1"
4241
ExtendableFEMBase = "1.3.0"
4342
ExtendableGrids = "1.10.3"
4443
ExtendableSparse = "1.5.3"
45-
FillArrays = "1.13.0"
4644
ForwardDiff = "0.10.35,1"
4745
GridVisualize = "1.8.1"
4846
IncompleteLU = "0.2.1"

src/ExtendableFEM.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ using ExtendableGrids: ExtendableGrids, AT_NODES, AbstractElementGeometry,
6464
using ExtendableSparse: ExtendableSparse, ExtendableSparseMatrix, flush!,
6565
MTExtendableSparseMatrixCSC, findindex,
6666
rawupdateindex!
67-
using FillArrays: Zeros
6867
using ForwardDiff: ForwardDiff
6968
using GridVisualize: GridVisualize, GridVisualizer, gridplot!, reveal, save,
7069
scalarplot!, vectorplot!

src/common_restrictions/coupled_dofs_restriction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function assemble!(R::CoupledDofsRestriction, sol, SC; kwargs...)
6464
end
6565

6666
R.parameters[:matrix] = B
67-
R.parameters[:rhs] = Zeros(size(B, 2))
67+
R.parameters[:rhs] = zeros(size(B, 2))
6868

6969
# fixed dofs are all active rows of B
7070
R.parameters[:fixed_dofs] = unique(findnz(B)[1])

src/solvers.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
"""
223232
function 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

Comments
 (0)