Skip to content

Commit a335aed

Browse files
committed
Extended assembly of matrices to skeleton terms
1 parent 14f8917 commit a335aed

File tree

5 files changed

+46
-27
lines changed

5 files changed

+46
-27
lines changed

src/FESpaces/Assemblers.jl

+23-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Assembly of a matrix allocating output
3131
"""
3232
function assemble(
3333
::Assembler{M,V},
34-
::Vararg{Tuple{<:CellMatrix,<:CellNumber}})::M where {M,V}
34+
::Vararg{Tuple{<:CellMatrix,<:CellNumber,<:CellNumber}})::M where {M,V}
3535
@abstractmethod
3636
end
3737

@@ -51,22 +51,34 @@ In-place assembly of a matrix (allows a LOT of optimizations)
5151
function assemble!(
5252
::M,
5353
::Assembler{M,V},
54-
::Vararg{Tuple{<:CellMatrix,<:CellNumber}})::M where {M,V}
54+
::Vararg{Tuple{<:CellMatrix,<:CellNumber,<:CellNumber}})::M where {M,V}
5555
@abstractmethod
5656
end
5757

58-
function assemble(a::Assembler,cv::CellArray)
58+
function assemble(a::Assembler,cv::CellVector)
5959
l = length(cv)
6060
ide = IdentityCellNumber(Int,l)
6161
assemble(a,(cv,ide))
6262
end
6363

64-
function assemble!(r,a::Assembler,cv::CellArray)
64+
function assemble(a::Assembler,cv::CellMatrix)
65+
l = length(cv)
66+
ide = IdentityCellNumber(Int,l)
67+
assemble(a,(cv,ide,ide))
68+
end
69+
70+
function assemble!(r,a::Assembler,cv::CellVector)
6571
l = length(cv)
6672
ide = IdentityCellNumber(Int,l)
6773
assemble!(r,a,(cv,ide))
6874
end
6975

76+
function assemble!(r,a::Assembler,cv::CellMatrix)
77+
l = length(cv)
78+
ide = IdentityCellNumber(Int,l)
79+
assemble!(r,a,(cv,ide,ide))
80+
end
81+
7082
"""
7183
Assembler that produces SparseMatrices from the SparseArrays package
7284
"""
@@ -116,19 +128,19 @@ end
116128

117129
function assemble(
118130
this::SparseMatrixAssembler{E},
119-
allvals::Vararg{Tuple{<:CellMatrix,<:CellNumber}}) where E
131+
allvals::Vararg{Tuple{<:CellMatrix,<:CellNumber,<:CellNumber}}) where E
120132

121133
I = Int
122134
aux_row = I[]; aux_col = I[]; aux_val = E[]
123135

124136
_rows_m = celldofids(this.testfesp)
125137
_cols_m = celldofids(this.trialfesp)
126138

127-
for (vals,cellids) in allvals
128-
_vals = apply_constraints_rows(this.testfesp, vals, cellids)
129-
rows_m = reindex(_rows_m, cellids)
130-
vals_m = apply_constraints_cols(this.trialfesp, _vals, cellids)
131-
cols_m = reindex(_cols_m, cellids)
139+
for (vals, cellids_row, cellids_col) in allvals
140+
_vals = apply_constraints_rows(this.testfesp, vals, cellids_row)
141+
rows_m = reindex(_rows_m, cellids_row)
142+
vals_m = apply_constraints_cols(this.trialfesp, _vals, cellids_col)
143+
cols_m = reindex(_cols_m, cellids_col)
132144
_assemble_sparse_matrix_values!(
133145
aux_row,aux_col,aux_val,vals_m,rows_m,cols_m)
134146
end
@@ -154,7 +166,7 @@ end
154166
function assemble!(
155167
mat::SparseMatrixCSC{E},
156168
this::SparseMatrixAssembler{E},
157-
vals::Vararg{Tuple{<:CellMatrix,<:CellNumber}}) where E
169+
vals::Vararg{Tuple{<:CellMatrix,<:CellNumber,<:CellNumber}}) where E
158170
# This routine can be optimized a lot taking into a count the sparsity graph of mat
159171
# For the moment we create an intermediate matrix and then transfer the nz values
160172
m = assemble(this,vals...)

src/FESpaces/FETerms.jl

+11-9
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,21 @@ function _append_vector_contribution!(m,r,c)
222222
push!(m,(r,c))
223223
end
224224

225-
#function _append_vector_contribution!(m,r::SkeletonCellVector,c)
226-
# push!(m,(r.cellvector1,c[1]))
227-
# push!(m,(r.cellvector2,c[2]))
228-
#end
225+
function _append_vector_contribution!(m,r::SkeletonCellVector,c)
226+
push!(m,(r.cellvector1,c[1]))
227+
push!(m,(r.cellvector2,c[2]))
228+
end
229229

230230
function _append_matrix_contribution!(m,r,c)
231-
push!(m,(r,c))
231+
push!(m,(r,c,c))
232232
end
233233

234-
#function _append_matrix_contribution!(m,r::SkeletonCellMatrix,c)
235-
# push!(m,(r.cellmatrix11,c[1]))
236-
# push!(m,(r.cellmatrix12,c[2]))
237-
#end
234+
function _append_matrix_contribution!(m,r::SkeletonCellMatrix,c)
235+
push!(m,(r.cellmatrix11,c[1],c[1]))
236+
push!(m,(r.cellmatrix12,c[1],c[2]))
237+
push!(m,(r.cellmatrix21,c[2],c[1]))
238+
push!(m,(r.cellmatrix22,c[2],c[2]))
239+
end
238240

239241
const _jac = setup_cell_jacobian
240242

src/Integration/SkeletonCellFields.jl

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ module SkeletonCellFields
22

33
using Gridap
44

5+
export SkeletonPair
6+
export SkeletonCellBasis
7+
export SkeletonCellVector
8+
export SkeletonCellMatrix
9+
510
export jump
611
import Gridap: restrict
712
import Gridap: gradient

test/FESpacesTests/AssemblersTests.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ vec3 = assemble(assem, (bvec,cellids), (bvec,cellids))
6464
assemble!(vec3, assem, (bvec,cellids), (bvec,cellids))
6565
@test vec3 2*vec
6666

67-
mat2 = assemble(assem, (mmat,cellids) )
67+
mat2 = assemble(assem, (mmat,cellids,cellids) )
6868

6969
@test mat2 == mat
7070

71-
mat3 = assemble(assem, (mmat,cellids), (mmat,cellids))
71+
mat3 = assemble(assem, (mmat,cellids,cellids), (mmat,cellids,cellids))
7272
@test mat3 2*mat
7373

74-
assemble!(mat3, assem, (mmat,cellids), (mmat,cellids))
74+
assemble!(mat3, assem, (mmat,cellids,cellids), (mmat,cellids,cellids))
7575
@test mat3 2*mat
7676

7777
end # module AssemblersTests

test/FESpacesTests/FETermsTests.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,19 @@ assem = SparseMatrixAssembler(V,U)
152152

153153
cms = setup_cell_jacobian(uh,v,du,t1)
154154

155-
cms = setup_cell_jacobian(uh,v,du,t1,t2)
155+
cms = setup_cell_jacobian(uh,v,du,t1,t2,t6)
156156

157157
mat = assemble(assem,cms...)
158158

159-
cvs = setup_cell_residual(uh,v,t1,t2)
159+
cvs = setup_cell_residual(uh,v,t1,t2,t6)
160160

161161
vec = assemble(assem,cvs...)
162162

163-
cvs = setup_cell_vector(v,uhd,t1,t2)
163+
cvs = setup_cell_vector(v,uhd,t1,t2,t6)
164164

165165
vec = assemble(assem,cvs...)
166166

167-
cms = setup_cell_matrix(v,du,t1,t2)
167+
cms = setup_cell_matrix(v,du,t1,t2,t6)
168168

169169
mat = assemble(assem,cms...)
170170

0 commit comments

Comments
 (0)