diff --git a/src/FESpaces/AffineFEOperators.jl b/src/FESpaces/AffineFEOperators.jl index e6ca9f6e9..1a2163484 100644 --- a/src/FESpaces/AffineFEOperators.jl +++ b/src/FESpaces/AffineFEOperators.jl @@ -28,13 +28,13 @@ function AffineFEOperator(trial::FESpace,test::FESpace,assem::Assembler,terms::A uhd = zero(trial) - matvecdata, matdata, vecdata = collect_cell_matrix_and_vector(uhd,u,v,terms) - A,b = assemble_matrix_and_vector(assem,matvecdata,matdata,vecdata) + data = collect_cell_matrix_and_vector(uhd,u,v,terms) + A,b = assemble_matrix_and_vector(assem,data) #matdata = collect_cell_matrix(u,v,terms) #vecdata = collect_cell_vector(uhd,v,terms) - #A = assemble_matrix(assem,matdata...) - #b = assemble_vector(assem,vecdata...) + #A = assemble_matrix(assem,matdata) + #b = assemble_vector(assem,vecdata) AffineFEOperator(trial,test,A,b) end diff --git a/src/FESpaces/Assemblers.jl b/src/FESpaces/Assemblers.jl index 149337094..854917d4f 100644 --- a/src/FESpaces/Assemblers.jl +++ b/src/FESpaces/Assemblers.jl @@ -61,149 +61,106 @@ end """ """ -function allocate_matrix(a::Assembler,cellidsrows,cellidscols) +function allocate_matrix(a::Assembler,matdata) @abstractmethod end -function allocate_matrix(a::Assembler,cellmat,cellidsrows,cellidscols) - allocate_matrix(a,cellidsrows,cellidscols) -end - """ """ -function allocate_vector(a::Assembler,cellidsrows) +function allocate_vector(a::Assembler,vecdata) @abstractmethod end -function allocate_vector(a::Assembler,cellvec,cellidsrows) - allocate_vector(a,cellidsrows) -end - """ """ -function allocate_matrix_and_vector(a::Assembler,matvecdata,matdata,vecdata) - matrows, matcols, vecrows = _rearange_cell_ids(matvecdata,matdata,vecdata) - A = allocate_matrix(a,matrows,matcols) - b = allocate_vector(a,vecrows) - (A,b) -end - -function allocate_matrix_and_vector(a::Assembler,matvecdata) - matdata = ([],[],[]) - vecdata = ([],[]) - allocate_matrix_and_vector(a,matvecdata,matdata,vecdata) +function allocate_matrix_and_vector(a::Assembler,data) + @abstractmethod end """ """ -function assemble_matrix!(A,a::Assembler,cellmat,cellidsrows,cellidscols) +function assemble_matrix!(A,a::Assembler,matdata) @abstractmethod end """ """ -function assemble_matrix_add!( - mat,a::Assembler, term_to_cellmat, term_to_cellidsrows, term_to_cellidscols) +function assemble_matrix_add!(mat,a::Assembler, matdata) @abstractmethod end """ """ -function assemble_vector!(b,a::Assembler,cellvec,cellids) +function assemble_vector!(b,a::Assembler,vecdata) @abstractmethod end """ """ -function assemble_vector_add!(b,a::Assembler,term_to_cellvec,term_to_cellidsrows) +function assemble_vector_add!(b,a::Assembler,vecdata) @abstractmethod end """ """ -function assemble_matrix_and_vector!(A,b,a::Assembler,matvecdata,matdata,vecdata) +function assemble_matrix_and_vector!(A,b,a::Assembler, data) @abstractmethod end -function assemble_matrix_and_vector_add!(A,b,a::Assembler, matvecdata, matdata, vecdata) +function assemble_matrix_and_vector_add!(A,b,a::Assembler, data) @abstractmethod end -function assemble_matrix_and_vector!(A,b,a::Assembler,matvecdata) - matdata = ([],[],[]) - vecdata = ([],[]) - assemble_matrix_and_vector!(A,b,a,matvecdata,matdata,vecdata) -end - """ """ -function assemble_matrix(a::Assembler,cellmat,cellidsrows,cellidscols) - A = allocate_matrix(a,cellidsrows,cellidscols) - assemble_matrix!(A,a,cellmat,cellidsrows,cellidscols) +function assemble_matrix(a::Assembler,matdata) + A = allocate_matrix(a,matdata) + assemble_matrix!(A,a,matdata) A end """ """ -function assemble_vector(a::Assembler,cellvec,cellids) - b = allocate_vector(a,cellids) - assemble_vector!(b,a,cellvec,cellids) +function assemble_vector(a::Assembler,vecdata) + b = allocate_vector(a,vecdata) + assemble_vector!(b,a,vecdata) b end """ """ -function assemble_matrix_and_vector(a::Assembler,matvecdata,matdata,vecdata) - A, b = allocate_matrix_and_vector(a,matvecdata,matdata,vecdata) - assemble_matrix_and_vector!(A,b,a,matvecdata,matdata,vecdata) +function assemble_matrix_and_vector(a::Assembler,data) + A, b = allocate_matrix_and_vector(a,data) + assemble_matrix_and_vector!(A,b,a,data) (A, b) end -function assemble_matrix_and_vector(a::Assembler,matvecdata) - matdata = ([],[],[]) - vecdata = ([],[]) - assemble_matrix_and_vector(a,matvecdata,matdata,vecdata) -end - -function _rearange_cell_ids(matvecdata,matdata,vecdata) - - matvec1, rows1, cols1 = matvecdata - mat2, rows2, cols2 = matdata - vec3, rows3 = vecdata - - matrows = vcat(rows1,rows2) - matcols = vcat(cols1,cols2) - vecrows = vcat(rows1,rows3) - - (matrows, matcols, vecrows) -end - """ """ -function test_assembler(a::Assembler,matvecdata,matdata,vecdata) +function test_assembler(a::Assembler,matdata,vecdata,data) trial_fesp = get_trial(a) test_fesp = get_test(a) - A = allocate_matrix(a,matdata...) + A = allocate_matrix(a,matdata) @test num_free_dofs(trial_fesp) == size(A,2) @test num_free_dofs(test_fesp) == size(A,1) - assemble_matrix!(A,a,matdata...) - assemble_matrix_add!(A,a,matdata...) - A = assemble_matrix(a,matdata...) + assemble_matrix!(A,a,matdata) + assemble_matrix_add!(A,a,matdata) + A = assemble_matrix(a,matdata) @test num_free_dofs(trial_fesp) == size(A,2) @test num_free_dofs(test_fesp) == size(A,1) - b = allocate_vector(a,vecdata...) + b = allocate_vector(a,vecdata) @test num_free_dofs(test_fesp) == length(b) - assemble_vector!(b,a,vecdata...) - assemble_vector_add!(b,a,vecdata...) - b = assemble_vector(a,vecdata...) + assemble_vector!(b,a,vecdata) + assemble_vector_add!(b,a,vecdata) + b = assemble_vector(a,vecdata) @test num_free_dofs(test_fesp) == length(b) - A, b = allocate_matrix_and_vector(a,matvecdata,matdata,vecdata) - assemble_matrix_and_vector!(A,b,a,matvecdata,matdata,vecdata) - assemble_matrix_and_vector_add!(A,b,a,matvecdata,matdata,vecdata) + A, b = allocate_matrix_and_vector(a,data) + assemble_matrix_and_vector!(A,b,a,data) + assemble_matrix_and_vector_add!(A,b,a,data) @test num_free_dofs(trial_fesp) == size(A,2) @test num_free_dofs(test_fesp) == size(A,1) @test num_free_dofs(test_fesp) == length(b) - A, b = assemble_matrix_and_vector(a,matvecdata,matdata,vecdata) + A, b = assemble_matrix_and_vector(a,data) @test num_free_dofs(trial_fesp) == size(A,2) @test num_free_dofs(test_fesp) == size(A,1) @test num_free_dofs(test_fesp) == length(b) @@ -211,8 +168,8 @@ function test_assembler(a::Assembler,matvecdata,matdata,vecdata) @test isa(strategy,AssemblyStrategy) end -# This is an extended interface that only make sense for assemblers that build sparse matrices -# (e.g. not for matrix free assemblers) +# This is an extended interface that only make sense for assemblers that build (sequential) sparse matrices +# (e.g. not for matrix free assemblers or for distributed assemblers) """ """ @@ -230,112 +187,122 @@ function get_vector_type(a::SparseMatrixAssembler) @abstractmethod end -function allocate_vector(a::SparseMatrixAssembler,term_to_cellidsrows) - n = num_free_dofs(a.test) +function allocate_vector(a::SparseMatrixAssembler,vecdata) + n = num_free_dofs(get_test(a)) allocate_vector(get_vector_type(a),n) end -function assemble_vector!(b,a::SparseMatrixAssembler,term_to_cellvec,term_to_cellidsrows) +function assemble_vector!(b,a::SparseMatrixAssembler,vecdata) fill_entries!(b,zero(eltype(b))) - assemble_vector_add!(b,a,term_to_cellvec,term_to_cellidsrows) + assemble_vector_add!(b,a,vecdata) end """ """ -function count_matrix_nnz_coo(a::SparseMatrixAssembler,term_to_cellidsrows, term_to_cellidscols) +function count_matrix_nnz_coo(a::SparseMatrixAssembler,vecdata) @abstractmethod end -function count_matrix_nnz_coo(a::SparseMatrixAssembler,term_to_cellmat,term_to_cellidsrows, term_to_cellidscols) - count_matrix_nnz_coo(a,term_to_cellidsrows, term_to_cellidscols) +""" +""" +function count_matrix_and_vector_nnz_coo(a::SparseMatrixAssembler,data) + @abstractmethod end """ """ -function fill_matrix_coo_symbolic!(I,J,a::SparseMatrixAssembler,term_to_cellidsrows, term_to_cellidscols) +function fill_matrix_coo_symbolic!(I,J,a::SparseMatrixAssembler,matdata,n=0) @abstractmethod end -function fill_matrix_coo_symbolic!(I,J,a::SparseMatrixAssembler,term_to_cellmat,term_to_cellidsrows, term_to_cellidscols) - fill_matrix_coo_symbolic!(I,J,a,term_to_cellidsrows, term_to_cellidscols) +function fill_matrix_and_vector_coo_symbolic!(I,J,a::SparseMatrixAssembler,data,n=0) + @abstractmethod end -function allocate_matrix(a::SparseMatrixAssembler, term_to_cellidsrows, term_to_cellidscols) - n = count_matrix_nnz_coo(a,term_to_cellidsrows,term_to_cellidscols) +function allocate_matrix(a::SparseMatrixAssembler,matdata) + n = count_matrix_nnz_coo(a,matdata) I,J,V = allocate_coo_vectors(get_matrix_type(a),n) - fill_matrix_coo_symbolic!(I,J,a,term_to_cellidsrows,term_to_cellidscols) - m = num_free_dofs(a.test) - n = num_free_dofs(a.trial) + fill_matrix_coo_symbolic!(I,J,a,matdata) + m = num_free_dofs(get_test(a)) + n = num_free_dofs(get_trial(a)) finalize_coo!(get_matrix_type(a),I,J,V,m,n) sparse_from_coo(get_matrix_type(a),I,J,V,m,n) end -function assemble_matrix!( - mat,a::SparseMatrixAssembler, term_to_cellmat, term_to_cellidsrows, term_to_cellidscols) +function assemble_matrix!(mat,a::SparseMatrixAssembler,matdata) z = zero(eltype(mat)) fill_entries!(mat,z) - assemble_matrix_add!(mat,a,term_to_cellmat,term_to_cellidsrows,term_to_cellidscols) + assemble_matrix_add!(mat,a,matdata) end """ """ -function fill_matrix_coo_numeric!( - I,J,V,a::SparseMatrixAssembler,term_to_cellmat,term_to_cellidsrows, term_to_cellidscols,n=0) +function fill_matrix_coo_numeric!(I,J,V,a::SparseMatrixAssembler,matdata,n=0) @abstractmethod end -function assemble_matrix( - a::SparseMatrixAssembler, term_to_cellmat, term_to_cellidsrows, term_to_cellidscols) +function assemble_matrix(a::SparseMatrixAssembler,matdata) - n = count_matrix_nnz_coo(a,term_to_cellidsrows,term_to_cellidscols) + n = count_matrix_nnz_coo(a,matdata) I,J,V = allocate_coo_vectors(get_matrix_type(a),n) - nmax = fill_matrix_coo_numeric!(I,J,V,a,term_to_cellmat,term_to_cellidsrows,term_to_cellidscols) - resize!(I,nmax) - resize!(J,nmax) - resize!(V,nmax) + fill_matrix_coo_numeric!(I,J,V,a,matdata) - m = num_free_dofs(a.test) - n = num_free_dofs(a.trial) + m = num_free_dofs(get_test(a)) + n = num_free_dofs(get_trial(a)) finalize_coo!(get_matrix_type(a),I,J,V,m,n) sparse_from_coo(get_matrix_type(a),I,J,V,m,n) end -function assemble_matrix_and_vector!(A,b,a::SparseMatrixAssembler, matvecdata, matdata, vecdata) + +function allocate_matrix_and_vector(a::SparseMatrixAssembler,data) + + n = count_matrix_and_vector_nnz_coo(a,data) + + I,J,V = allocate_coo_vectors(get_matrix_type(a),n) + fill_matrix_and_vector_coo_symbolic!(I,J,a,data) + m = num_free_dofs(get_test(a)) + n = num_free_dofs(get_trial(a)) + finalize_coo!(get_matrix_type(a),I,J,V,m,n) + A = sparse_from_coo(get_matrix_type(a),I,J,V,m,n) + + b = allocate_vector(get_vector_type(a),m) + + A,b +end + +function assemble_matrix_and_vector!(A,b,a::SparseMatrixAssembler, data) fill_entries!(A,zero(eltype(A))) fill_entries!(b,zero(eltype(b))) - assemble_matrix_and_vector_add!(A,b,a,matvecdata, matdata, vecdata) + assemble_matrix_and_vector_add!(A,b,a,data) A, b end """ """ -function fill_matrix_and_vector_coo_numeric!(I,J,V,b,a::SparseMatrixAssembler,matvecdata, matdata, vecdata,n=0) +function fill_matrix_and_vector_coo_numeric!(I,J,V,b,a::SparseMatrixAssembler,data,n=0) @abstractmethod end -function assemble_matrix_and_vector(a::SparseMatrixAssembler, matvecdata, matdata, vecdata) +function assemble_matrix_and_vector(a::SparseMatrixAssembler, data) - term_to_cellidsrows, term_to_cellidscols, = _rearange_cell_ids(matvecdata,matdata,vecdata) - n = count_matrix_nnz_coo(a,term_to_cellidsrows,term_to_cellidscols) + n = count_matrix_and_vector_nnz_coo(a,data) I,J,V = allocate_coo_vectors(get_matrix_type(a),n) - b = allocate_vector(a,vecdata...) + n = num_free_dofs(get_test(a)) + b = allocate_vector(get_vector_type(a),n) - nmax = fill_matrix_and_vector_coo_numeric!(I,J,V,b,a, matvecdata, matdata, vecdata) - resize!(I,nmax) - resize!(J,nmax) - resize!(V,nmax) + fill_matrix_and_vector_coo_numeric!(I,J,V,b,a,data) - m = num_free_dofs(a.test) - n = num_free_dofs(a.trial) + m = num_free_dofs(get_test(a)) + n = num_free_dofs(get_trial(a)) finalize_coo!(get_matrix_type(a),I,J,V,m,n) A = sparse_from_coo(get_matrix_type(a),I,J,V,m,n) A, b end -function test_sparse_matrix_assembler(a::SparseMatrixAssembler,matvecdata,matdata,vecdata) - test_assembler(a,matvecdata,matdata,vecdata) +function test_sparse_matrix_assembler(a::SparseMatrixAssembler,matdata,vecdata,data) + test_assembler(a,matdata,vecdata,data) _ = get_matrix_type(a) _ = get_vector_type(a) end diff --git a/src/FESpaces/FEOperatorsFromTerms.jl b/src/FESpaces/FEOperatorsFromTerms.jl index 436909d92..b69e1e25d 100644 --- a/src/FESpaces/FEOperatorsFromTerms.jl +++ b/src/FESpaces/FEOperatorsFromTerms.jl @@ -43,15 +43,15 @@ end function allocate_residual(op::FEOperatorFromTerms,uh) @assert is_a_fe_function(uh) v = get_cell_basis(op.test) - _, cellids = collect_cell_residual(uh,v,op.terms) - allocate_vector(op.assem, cellids) + vecdata = collect_cell_residual(uh,v,op.terms) + allocate_vector(op.assem, vecdata) end function residual!(b::AbstractVector,op::FEOperatorFromTerms,uh) @assert is_a_fe_function(uh) v = get_cell_basis(op.test) - cellvecs, cellids = collect_cell_residual(uh,v,op.terms) - assemble_vector!(b,op.assem, cellvecs, cellids) + vecdata = collect_cell_residual(uh,v,op.terms) + assemble_vector!(b,op.assem, vecdata) b end @@ -59,16 +59,16 @@ function allocate_jacobian(op::FEOperatorFromTerms,uh) @assert is_a_fe_function(uh) du = get_cell_basis(op.trial) v = get_cell_basis(op.test) - _, cellidsrows, cellidscols = collect_cell_jacobian(uh,du,v,op.terms) - allocate_matrix(op.assem, cellidsrows, cellidscols) + matdata = collect_cell_jacobian(uh,du,v,op.terms) + allocate_matrix(op.assem, matdata) end function jacobian!(A::AbstractMatrix,op::FEOperatorFromTerms,uh) @assert is_a_fe_function(uh) du = get_cell_basis(op.trial) v = get_cell_basis(op.test) - cellmats, cellidsrows, cellidscols = collect_cell_jacobian(uh,du,v,op.terms) - assemble_matrix!(A,op.assem, cellmats, cellidsrows, cellidscols) + matdata = collect_cell_jacobian(uh,du,v,op.terms) + assemble_matrix!(A,op.assem,matdata) A end @@ -77,7 +77,7 @@ function residual_and_jacobian!(b::AbstractVector,A::AbstractMatrix,op::FEOperat du = get_cell_basis(op.trial) v = get_cell_basis(op.test) data = collect_cell_jacobian_and_residual(uh,du,v,op.terms) - assemble_matrix_and_vector!(A, b, op.assem,data...) + assemble_matrix_and_vector!(A, b, op.assem, data) (b,A) end @@ -86,6 +86,6 @@ function residual_and_jacobian(op::FEOperatorFromTerms,uh) du = get_cell_basis(op.trial) v = get_cell_basis(op.test) data = collect_cell_jacobian_and_residual(uh,du,v,op.terms) - A, b = assemble_matrix_and_vector(op.assem,data...) + A, b = assemble_matrix_and_vector(op.assem, data) (b, A) end diff --git a/src/FESpaces/SparseMatrixAssemblers.jl b/src/FESpaces/SparseMatrixAssemblers.jl index 777335c10..283aa50da 100644 --- a/src/FESpaces/SparseMatrixAssemblers.jl +++ b/src/FESpaces/SparseMatrixAssemblers.jl @@ -41,9 +41,9 @@ get_vector_type(a::SingleFieldSparseMatrixAssembler) = a.vector_type get_assembly_strategy(a::SingleFieldSparseMatrixAssembler) = a.strategy -function assemble_vector_add!(b,a::SingleFieldSparseMatrixAssembler,term_to_cellvec,term_to_cellidsrows) +function assemble_vector_add!(b,a::SingleFieldSparseMatrixAssembler,vecdata) celldofs = get_cell_dofs(a.test) - for (cellvec, cellids) in zip(term_to_cellvec,term_to_cellidsrows) + for (cellvec, cellids) in zip(vecdata...) rows = reindex(celldofs,cellids) vals = apply_constraints_vector(a.test,cellvec,cellids) rows_cache = array_cache(rows) @@ -67,7 +67,8 @@ function _assemble_vector!(vec,vals_cache,rows_cache,cell_vals,cell_rows,strateg end end -function count_matrix_nnz_coo(a::SingleFieldSparseMatrixAssembler,term_to_cellidsrows, term_to_cellidscols) +function count_matrix_nnz_coo(a::SingleFieldSparseMatrixAssembler,matdata) + _,term_to_cellidsrows, term_to_cellidscols = matdata celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) n = 0 @@ -105,10 +106,18 @@ end n end -function fill_matrix_coo_symbolic!(I,J,a::SingleFieldSparseMatrixAssembler,term_to_cellidsrows, term_to_cellidscols) +function count_matrix_and_vector_nnz_coo(a::SingleFieldSparseMatrixAssembler,data) + matvecdata, matdata, vecdata = data + n = count_matrix_nnz_coo(a,matvecdata) + n += count_matrix_nnz_coo(a,matdata) + n +end + +function fill_matrix_coo_symbolic!(I,J,a::SingleFieldSparseMatrixAssembler,matdata,n=0) + _,term_to_cellidsrows, term_to_cellidscols = matdata celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) - nini = 0 + nini = n for (cellidsrows,cellidscols) in zip(term_to_cellidsrows,term_to_cellidscols) cell_rows = reindex(celldofs_rows,cellidsrows) cell_cols = reindex(celldofs_cols,cellidscols) @@ -116,6 +125,7 @@ function fill_matrix_coo_symbolic!(I,J,a::SingleFieldSparseMatrixAssembler,term_ cols_cache = array_cache(cell_cols) nini = _allocate_matrix!(a.matrix_type,nini,I,J,rows_cache,cols_cache,cell_rows,cell_cols,a.strategy) end + nini end @noinline function _allocate_matrix!(a::Type{M},nini,I,J,rows_cache,cols_cache,cell_rows,cell_cols,strategy) where M @@ -142,12 +152,18 @@ end n end -function assemble_matrix_add!( - mat,a::SingleFieldSparseMatrixAssembler, term_to_cellmat, term_to_cellidsrows, term_to_cellidscols) +function fill_matrix_and_vector_coo_symbolic!(I,J,a::SingleFieldSparseMatrixAssembler,data,n=0) + matvecdata, matdata, vecdata = data + nini = fill_matrix_coo_symbolic!(I,J,a,matvecdata,n) + nini = fill_matrix_coo_symbolic!(I,J,a,matdata,nini) + nini +end + +function assemble_matrix_add!(mat,a::SingleFieldSparseMatrixAssembler,matdata) celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) - for (cellmat_rc,cellidsrows,cellidscols) in zip(term_to_cellmat,term_to_cellidsrows,term_to_cellidscols) + for (cellmat_rc,cellidsrows,cellidscols) in zip(matdata...) cell_rows = reindex(celldofs_rows,cellidsrows) cell_cols = reindex(celldofs_cols,cellidscols) cellmat_r = apply_constraints_matrix_cols(a.trial,cellmat_rc,cellidscols) @@ -182,13 +198,12 @@ function _assemble_matrix!(mat,vals_cache,rows_cache,cols_cache,cell_vals,cell_r end end -function fill_matrix_coo_numeric!( - I,J,V,a::SingleFieldSparseMatrixAssembler,term_to_cellmat,term_to_cellidsrows, term_to_cellidscols,n=0) +function fill_matrix_coo_numeric!(I,J,V,a::SingleFieldSparseMatrixAssembler,matdata,n=0) nini = n celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) - for (cellmat_rc,cellidsrows,cellidscols) in zip(term_to_cellmat,term_to_cellidsrows,term_to_cellidscols) + for (cellmat_rc,cellidsrows,cellidscols) in zip(matdata...) cell_rows = reindex(celldofs_rows,cellidsrows) cell_cols = reindex(celldofs_cols,cellidscols) cellmat_r = apply_constraints_matrix_cols(a.trial,cellmat_rc,cellidscols) @@ -231,9 +246,9 @@ end n end -function assemble_matrix_and_vector_add!( - A,b,a::SingleFieldSparseMatrixAssembler, matvecdata, matdata, vecdata) +function assemble_matrix_and_vector_add!(A,b,a::SingleFieldSparseMatrixAssembler, data) + matvecdata, matdata, vecdata = data celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) @@ -247,8 +262,8 @@ function assemble_matrix_and_vector_add!( vals_cache = array_cache(cellmatvec) _assemble_matrix_and_vector!(A,b,vals_cache,rows_cache,cols_cache,cellmatvec,cell_rows,cell_cols,a.strategy) end - assemble_matrix_add!(A,a,matdata...) - assemble_vector_add!(b,a,vecdata...) + assemble_matrix_add!(A,a,matdata) + assemble_vector_add!(b,a,vecdata) A, b end @@ -282,8 +297,9 @@ function _assemble_matrix_and_vector!(A,b,vals_cache,rows_cache,cols_cache,cell_ end end -function fill_matrix_and_vector_coo_numeric!(I,J,V,b,a::SingleFieldSparseMatrixAssembler,matvecdata, matdata, vecdata,n=0) - +function fill_matrix_and_vector_coo_numeric!(I,J,V,b,a::SingleFieldSparseMatrixAssembler,data,n=0) + + matvecdata, matdata, vecdata = data nini = n celldofs_rows = get_cell_dofs(a.test) @@ -303,8 +319,8 @@ function fill_matrix_and_vector_coo_numeric!(I,J,V,b,a::SingleFieldSparseMatrixA a.matrix_type,nini,I,J,V,b,vals_cache,rows_cache,cols_cache,cellmatvec,cell_rows,cell_cols,a.strategy) end - nini = fill_matrix_coo_numeric!(I,J,V,a,matdata...,nini) - assemble_vector_add!(b,a,vecdata...) + nini = fill_matrix_coo_numeric!(I,J,V,a,matdata,nini) + assemble_vector_add!(b,a,vecdata) nini end diff --git a/src/FESpaces/ZeroMeanFESpaces.jl b/src/FESpaces/ZeroMeanFESpaces.jl index fc12ce1d2..dbd02abd8 100644 --- a/src/FESpaces/ZeroMeanFESpaces.jl +++ b/src/FESpaces/ZeroMeanFESpaces.jl @@ -32,7 +32,8 @@ function _setup_vols(V,trian,quad) bh_trian = restrict(bh,trian) cellvec = integrate(bh_trian,trian,quad) cellids = get_cell_id(trian) - vol_i = assemble_vector(assem,[cellvec],[cellids]) + vecdata = ([cellvec],[cellids]) + vol_i = assemble_vector(assem,vecdata) vol = sum(vol_i) (vol_i, vol) end diff --git a/src/MultiField/MultiField.jl b/src/MultiField/MultiField.jl index 821fbd6ce..27577d11a 100644 --- a/src/MultiField/MultiField.jl +++ b/src/MultiField/MultiField.jl @@ -81,6 +81,8 @@ import Gridap.FESpaces: count_matrix_nnz_coo import Gridap.FESpaces: fill_matrix_coo_symbolic! import Gridap.FESpaces: fill_matrix_coo_numeric! import Gridap.FESpaces: fill_matrix_and_vector_coo_numeric! +import Gridap.FESpaces: count_matrix_and_vector_nnz_coo +import Gridap.FESpaces: fill_matrix_and_vector_coo_symbolic! import Base: +, - diff --git a/src/MultiField/MultiFieldSparseMatrixAssemblers.jl b/src/MultiField/MultiFieldSparseMatrixAssemblers.jl index a8a745a38..c26b24210 100644 --- a/src/MultiField/MultiFieldSparseMatrixAssemblers.jl +++ b/src/MultiField/MultiFieldSparseMatrixAssemblers.jl @@ -64,9 +64,9 @@ get_vector_type(a::MultiFieldSparseMatrixAssembler) = a.vector_type get_assembly_strategy(a::MultiFieldSparseMatrixAssembler) = a.strategy -function assemble_vector_add!(b,a::MultiFieldSparseMatrixAssembler,term_to_cellvec,term_to_cellidsrows) +function assemble_vector_add!(b,a::MultiFieldSparseMatrixAssembler,vecdata) celldofs = get_cell_dofs(a.test) - for (cellvec, cellids) in zip(term_to_cellvec,term_to_cellidsrows) + for (cellvec, cellids) in zip(vecdata...) rows = reindex(celldofs,cellids) vals = apply_constraints_vector(a.test,cellvec,cellids) rows_cache = array_cache(rows) @@ -96,42 +96,63 @@ function _assemble_vector!(vec,vals_cache,rows_cache,cell_vals,cell_rows,strateg end end -function count_matrix_nnz_coo(a::MultiFieldSparseMatrixAssembler,term_to_cellidsrows, term_to_cellidscols) +function count_matrix_nnz_coo(a::MultiFieldSparseMatrixAssembler,matdata) celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) n = 0 - for (cellidsrows,cellidscols) in zip(term_to_cellidsrows,term_to_cellidscols) + for (cellmat_rc,cellidsrows,cellidscols) in zip(matdata...) cell_rows = reindex(celldofs_rows,cellidsrows) cell_cols = reindex(celldofs_cols,cellidscols) + cellmat_r = apply_constraints_matrix_cols(a.trial,cellmat_rc,cellidscols) + cellmat = apply_constraints_matrix_rows(a.test,cellmat_r,cellidsrows) rows_cache = array_cache(cell_rows) cols_cache = array_cache(cell_cols) @assert length(cell_cols) == length(cell_rows) - n += _count_matrix_entries(a.matrix_type,rows_cache,cols_cache,cell_rows,cell_cols,a.strategy) + if length(cellmat) > 0 + coords = first(cellmat).coordinates + n += _count_matrix_entries(a.matrix_type,rows_cache,cols_cache,cell_rows,cell_cols,a.strategy,coords) + end end + n +end +function count_matrix_and_vector_nnz_coo(a::MultiFieldSparseMatrixAssembler,data) + matvecdata, matdata, vecdata = data + n = count_matrix_nnz_coo(a,matdata) + celldofs_rows = get_cell_dofs(a.test) + celldofs_cols = get_cell_dofs(a.trial) + for (cellmatvec_rc,cellidsrows,cellidscols) in zip(matvecdata...) + cell_rows = reindex(celldofs_rows,cellidsrows) + cell_cols = reindex(celldofs_cols,cellidscols) + cellmatvec_r = apply_constraints_matrix_and_vector_cols(a.trial,cellmatvec_rc,cellidscols) + cellmatvec = apply_constraints_matrix_and_vector_rows(a.test,cellmatvec_r,cellidsrows) + rows_cache = array_cache(cell_rows) + cols_cache = array_cache(cell_cols) + @assert length(cell_cols) == length(cell_rows) + if length(cellmatvec) > 0 + coords = first(cellmatvec)[1].coordinates + n += _count_matrix_entries(a.matrix_type,rows_cache,cols_cache,cell_rows,cell_cols,a.strategy,coords) + end + end n end -@noinline function _count_matrix_entries(::Type{M},rows_cache,cols_cache,cell_rows,cell_cols,strategy) where M +@noinline function _count_matrix_entries(::Type{M},rows_cache,cols_cache,cell_rows,cell_cols,strategy,coords) where M n = 0 for cell in 1:length(cell_cols) _rows = getindex!(rows_cache,cell_rows,cell) _cols = getindex!(cols_cache,cell_cols,cell) - nfields_rows = length(_rows.blocks) - nfields_cols = length(_cols.blocks) - for field_col in 1:nfields_cols + for (field_row,field_col) in coords cols = _cols.blocks[field_col] - for field_row in 1:nfields_rows - rows = _rows.blocks[field_row] - for gidcol in cols - if gidcol > 0 && col_mask(strategy,gidcol) - _gidcol = col_map(strategy,gidcol) - for gidrow in rows - if gidrow > 0 && row_mask(strategy,gidrow) - _gidrow = row_map(strategy,gidrow) - if is_entry_stored(M,_gidrow,_gidcol) - n += 1 - end + rows = _rows.blocks[field_row] + for gidcol in cols + if gidcol > 0 && col_mask(strategy,gidcol) + _gidcol = col_map(strategy,gidcol) + for gidrow in rows + if gidrow > 0 && row_mask(strategy,gidrow) + _gidrow = row_map(strategy,gidrow) + if is_entry_stored(M,_gidrow,_gidcol) + n += 1 end end end @@ -142,41 +163,66 @@ end n end -function fill_matrix_coo_symbolic!(I,J,a::MultiFieldSparseMatrixAssembler,term_to_cellidsrows, term_to_cellidscols) +function fill_matrix_coo_symbolic!(I,J,a::MultiFieldSparseMatrixAssembler,matdata,n=0) celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) - nini = 0 - for (cellidsrows,cellidscols) in zip(term_to_cellidsrows,term_to_cellidscols) + nini = n + for (cellmat_rc,cellidsrows,cellidscols) in zip(matdata...) cell_rows = reindex(celldofs_rows,cellidsrows) cell_cols = reindex(celldofs_cols,cellidscols) + cellmat_r = apply_constraints_matrix_cols(a.trial,cellmat_rc,cellidscols) + cellmat = apply_constraints_matrix_rows(a.test,cellmat_r,cellidsrows) rows_cache = array_cache(cell_rows) cols_cache = array_cache(cell_cols) - nini = _allocate_matrix!(a.matrix_type,nini,I,J,rows_cache,cols_cache,cell_rows,cell_cols,a.strategy) + if length(cellmat) > 0 + coords = first(cellmat).coordinates + nini = _allocate_matrix!(a.matrix_type,nini,I,J,rows_cache,cols_cache,cell_rows,cell_cols,a.strategy,coords) + end end + nini end -@noinline function _allocate_matrix!(::Type{M},nini,I,J,rows_cache,cols_cache,cell_rows,cell_cols,strategy) where M +function fill_matrix_and_vector_coo_symbolic!(I,J,a::MultiFieldSparseMatrixAssembler,data,n=0) + matvecdata, matdata, vecdata = data + + nini = fill_matrix_coo_symbolic!(I,J,a,matdata,n) + + celldofs_rows = get_cell_dofs(a.test) + celldofs_cols = get_cell_dofs(a.trial) + for (cellmat_rc,cellidsrows,cellidscols) in zip(matvecdata...) + cell_rows = reindex(celldofs_rows,cellidsrows) + cell_cols = reindex(celldofs_cols,cellidscols) + cellmat_r = apply_constraints_matrix_and_vector_cols(a.trial,cellmat_rc,cellidscols) + cellmat = apply_constraints_matrix_and_vector_rows(a.test,cellmat_r,cellidsrows) + rows_cache = array_cache(cell_rows) + cols_cache = array_cache(cell_cols) + if length(cellmat) > 0 + coords = first(cellmat)[1].coordinates + nini = _allocate_matrix!(a.matrix_type,nini,I,J,rows_cache,cols_cache,cell_rows,cell_cols,a.strategy,coords) + end + end + nini +end + +@noinline function _allocate_matrix!( + ::Type{M},nini,I,J,rows_cache,cols_cache,cell_rows,cell_cols,strategy,coords) where M n = nini for cell in 1:length(cell_cols) _rows = getindex!(rows_cache,cell_rows,cell) _cols = getindex!(cols_cache,cell_cols,cell) - nfields_rows = length(_rows.blocks) - nfields_cols = length(_cols.blocks) - for field_col in 1:nfields_cols + for (field_row,field_col) in coords @inbounds cols = _cols.blocks[field_col] - for field_row in 1:nfields_rows - @inbounds rows = _rows.blocks[field_row] - for gidcol in cols - if gidcol > 0 && col_mask(strategy,gidcol) - _gidcol = col_map(strategy,gidcol) - for gidrow in rows - if gidrow > 0 && row_mask(strategy,gidrow) - _gidrow = row_map(strategy,gidrow) - if is_entry_stored(M,_gidrow,_gidcol) - n += 1 - @inbounds I[n] = _gidrow - @inbounds J[n] = _gidcol - end + @inbounds rows = _rows.blocks[field_row] + for gidcol in cols + if gidcol > 0 && col_mask(strategy,gidcol) + _gidcol = col_map(strategy,gidcol) + for gidrow in rows + if gidrow > 0 && row_mask(strategy,gidrow) + _gidrow = row_map(strategy,gidrow) + if is_entry_stored(M,_gidrow,_gidcol) + n += 1 + @inbounds I[n] = _gidrow + @inbounds J[n] = _gidcol end end end @@ -187,12 +233,11 @@ end n end -function assemble_matrix_add!( - mat,a::MultiFieldSparseMatrixAssembler, term_to_cellmat, term_to_cellidsrows, term_to_cellidscols) +function assemble_matrix_add!(mat,a::MultiFieldSparseMatrixAssembler, matdata) celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) - for (cellmat_rc,cellidsrows,cellidscols) in zip(term_to_cellmat,term_to_cellidsrows,term_to_cellidscols) + for (cellmat_rc,cellidsrows,cellidscols) in zip(matdata...) cell_rows = reindex(celldofs_rows,cellidsrows) cell_cols = reindex(celldofs_cols,cellidscols) cellmat_r = apply_constraints_matrix_cols(a.trial,cellmat_rc,cellidscols) @@ -232,13 +277,12 @@ function _assemble_matrix!(mat,vals_cache,rows_cache,cols_cache,cell_vals,cell_r end end -function fill_matrix_coo_numeric!( - I,J,V,a::MultiFieldSparseMatrixAssembler,term_to_cellmat,term_to_cellidsrows, term_to_cellidscols,n=0) +function fill_matrix_coo_numeric!(I,J,V,a::MultiFieldSparseMatrixAssembler,matdata,n=0) nini = n celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) - for (cellmat_rc,cellidsrows,cellidscols) in zip(term_to_cellmat,term_to_cellidsrows,term_to_cellidscols) + for (cellmat_rc,cellidsrows,cellidscols) in zip(matdata...) cell_rows = reindex(celldofs_rows,cellidsrows) cell_cols = reindex(celldofs_cols,cellidscols) cellmat_r = apply_constraints_matrix_cols(a.trial,cellmat_rc,cellidscols) @@ -287,9 +331,9 @@ end n end -function assemble_matrix_and_vector_add!( - A,b,a::MultiFieldSparseMatrixAssembler, matvecdata, matdata, vecdata) +function assemble_matrix_and_vector_add!(A,b,a::MultiFieldSparseMatrixAssembler, data) + matvecdata, matdata, vecdata = data celldofs_rows = get_cell_dofs(a.test) celldofs_cols = get_cell_dofs(a.trial) @@ -303,8 +347,8 @@ function assemble_matrix_and_vector_add!( vals_cache = array_cache(cellmatvec) _assemble_matrix_and_vector!(A,b,vals_cache,rows_cache,cols_cache,cellmatvec,cell_rows,cell_cols,a.strategy) end - assemble_matrix_add!(A,a,matdata...) - assemble_vector_add!(b,a,vecdata...) + assemble_matrix_add!(A,a,matdata) + assemble_vector_add!(b,a,vecdata) A, b end @@ -354,9 +398,9 @@ end end end -function fill_matrix_and_vector_coo_numeric!( - I,J,V,b,a::MultiFieldSparseMatrixAssembler,matvecdata, matdata, vecdata,n=0) +function fill_matrix_and_vector_coo_numeric!(I,J,V,b,a::MultiFieldSparseMatrixAssembler,data,n=0) + matvecdata, matdata, vecdata = data nini = n celldofs_rows = get_cell_dofs(a.test) @@ -376,13 +420,12 @@ function fill_matrix_and_vector_coo_numeric!( a.matrix_type,nini,I,J,V,b,vals_cache,rows_cache,cols_cache,cellmatvec,cell_rows,cell_cols,a.strategy) end - nini = fill_matrix_coo_numeric!(I,J,V,a,matdata...,nini) - assemble_vector_add!(b,a,vecdata...) + nini = fill_matrix_coo_numeric!(I,J,V,a,matdata,nini) + assemble_vector_add!(b,a,vecdata) nini end - @noinline function _assemble_matrix_and_vector_fill!( ::Type{M},nini,I,J,V,b,vals_cache,rows_cache,cols_cache,cell_vals,cell_rows,cell_cols,strategy) where M n = nini diff --git a/test/FESpacesTests/AffineFEOperatorsTests.jl b/test/FESpacesTests/AffineFEOperatorsTests.jl index a344271f7..2eca0c554 100644 --- a/test/FESpacesTests/AffineFEOperatorsTests.jl +++ b/test/FESpacesTests/AffineFEOperatorsTests.jl @@ -38,8 +38,10 @@ cellvec = integrate(v*f,trian,quad) cellids = collect(1:num_cells(trian)) assem = SparseMatrixAssembler(U,V) -A = assemble_matrix(assem,[cellmat],[cellids],[cellids]) -b = assemble_vector(assem,[cellvec],[cellids]) +matdata = ([cellmat],[cellids],[cellids]) +vecdata = ([cellvec],[cellids]) +A = assemble_matrix(assem,matdata) +b = assemble_vector(assem,vecdata) op = AffineFEOperator(U,V,A,b) @test A === get_matrix(op) diff --git a/test/FESpacesTests/FESolversTests.jl b/test/FESpacesTests/FESolversTests.jl index 907206802..47c70a3f1 100644 --- a/test/FESpacesTests/FESolversTests.jl +++ b/test/FESpacesTests/FESolversTests.jl @@ -37,8 +37,10 @@ cellvec = integrate(v*f,trian,quad) cellids = collect(1:num_cells(trian)) assem = SparseMatrixAssembler(U,V) -A = assemble_matrix(assem,[cellmat],[cellids],[cellids]) -b = assemble_vector(assem,[cellvec],[cellids]) +matdata = ([cellmat],[cellids],[cellids]) +vecdata = ([cellvec],[cellids]) +A = assemble_matrix(assem,matdata) +b = assemble_vector(assem,vecdata) x = A \ b x0 = zeros(length(x)) diff --git a/test/FESpacesTests/FETermsTests.jl b/test/FESpacesTests/FETermsTests.jl index 3d3223a27..0de3bc6d4 100644 --- a/test/FESpacesTests/FETermsTests.jl +++ b/test/FESpacesTests/FETermsTests.jl @@ -61,24 +61,24 @@ t_affine = AffineFETerm(a,l,trian,quad) matdata = collect_cell_matrix(u,v,[t_affine, t_linear]) vecdata = collect_cell_vector(uhd,v,[t_affine, t_linear, t_source]) -A = assemble_matrix(assem,matdata...) -b = assemble_vector(assem,vecdata...) +A = assemble_matrix(assem,matdata) +b = assemble_vector(assem,vecdata) x = A \ b @test x ≈ get_free_values(uh) data = collect_cell_matrix_and_vector(uhd,u,v,[t_affine, t_linear, t_source]) -A, b = allocate_matrix_and_vector(assem,data...) -assemble_matrix_and_vector!(A,b,assem,data...) +A, b = allocate_matrix_and_vector(assem,data) +assemble_matrix_and_vector!(A,b,assem,data) x = A \ b @test x ≈ get_free_values(uh) -A, b = assemble_matrix_and_vector(assem,data...) +A, b = assemble_matrix_and_vector(assem,data) x = A \ b @test x ≈ get_free_values(uh) matdata = collect_cell_jacobian(uh,u,v,[t_affine]) vecdata = collect_cell_residual(uh,v,[t_affine]) -A = assemble_matrix(assem,matdata...) -b = assemble_vector(assem,vecdata...) +A = assemble_matrix(assem,matdata) +b = assemble_vector(assem,vecdata) x = A \ -b @test (x.+1) ≈ ones(length(x)) @@ -89,15 +89,15 @@ t_source = FESource(l,trian,quad) matdata = collect_cell_matrix(u,v,[t_linear, t_source]) vecdata = collect_cell_vector(uhd,v,[t_linear, t_source]) -A = assemble_matrix(assem,matdata...) -b = assemble_vector(assem,vecdata...) +A = assemble_matrix(assem,matdata) +b = assemble_vector(assem,vecdata) x = A \ b @test x ≈ get_free_values(uh) matdata = collect_cell_jacobian(uh,u,v,[t_linear, t_source]) vecdata = collect_cell_residual(uh,v,[t_linear, t_source]) -A = assemble_matrix(assem,matdata...) -b = assemble_vector(assem,vecdata...) +A = assemble_matrix(assem,matdata) +b = assemble_vector(assem,vecdata) x = A \ -b @test (x.+1) ≈ ones(length(x)) @@ -107,14 +107,14 @@ t_nonlinear = FETerm(r,j,trian,quad) matdata = collect_cell_jacobian(uh,u,v,[t_nonlinear]) vecdata = collect_cell_residual(uh,v,[t_nonlinear]) -A = assemble_matrix(assem,matdata...) -b = assemble_vector(assem,vecdata...) +A = assemble_matrix(assem,matdata) +b = assemble_vector(assem,vecdata) x = A \ -b @test (x.+1) ≈ ones(length(x)) data = collect_cell_jacobian_and_residual(uh,u,v,[t_nonlinear]) -A, b = allocate_matrix_and_vector(assem,data...) -assemble_matrix_and_vector!(A,b,assem,data...) +A, b = allocate_matrix_and_vector(assem,data) +assemble_matrix_and_vector!(A,b,assem,data) x = A \ -b @test (x.+1) ≈ ones(length(x)) @@ -154,14 +154,14 @@ t_matvec_Ω = AffineFETermFromCellMatVec(matvecfun,trian) matdata = collect_cell_matrix(u,v,[t_matvec_Ω,]) vecdata = collect_cell_vector(uhd,v,[t_matvec_Ω,]) -A = assemble_matrix(assem,matdata...) -b = assemble_vector(assem,vecdata...) +A = assemble_matrix(assem,matdata) +b = assemble_vector(assem,vecdata) x = A \ b @test x ≈ get_free_values(uh) data = collect_cell_matrix_and_vector(uhd,u,v,[t_matvec_Ω,]) -A, b = allocate_matrix_and_vector(assem,data...) -assemble_matrix_and_vector!(A,b,assem,data...) +A, b = allocate_matrix_and_vector(assem,data) +assemble_matrix_and_vector!(A,b,assem,data) x = A \ b @test x ≈ get_free_values(uh) @@ -195,14 +195,14 @@ t_jacres_Ω = FETermFromCellJacRes(jacresfun,trian) matdata = collect_cell_jacobian(uh,u,v,[t_jacres_Ω]) vecdata = collect_cell_residual(uh,v,[t_jacres_Ω]) -A = assemble_matrix(assem,matdata...) -b = assemble_vector(assem,vecdata...) +A = assemble_matrix(assem,matdata) +b = assemble_vector(assem,vecdata) x = A \ -b @test (x.+1) ≈ ones(length(x)) data = collect_cell_jacobian_and_residual(uh,u,v,[t_jacres_Ω]) -A, b = allocate_matrix_and_vector(assem,data...) -assemble_matrix_and_vector!(A,b,assem,data...) +A, b = allocate_matrix_and_vector(assem,data) +assemble_matrix_and_vector!(A,b,assem,data) x = A \ -b @test (x.+1) ≈ ones(length(x)) diff --git a/test/FESpacesTests/SparseMatrixAssemblersTests.jl b/test/FESpacesTests/SparseMatrixAssemblersTests.jl index 01988f836..8e38657a7 100644 --- a/test/FESpacesTests/SparseMatrixAssemblersTests.jl +++ b/test/FESpacesTests/SparseMatrixAssemblersTests.jl @@ -55,9 +55,6 @@ term_to_cellvec = [cellvec, bcellvec] term_to_cellids = [cellids, bcellids] term_to_cellmatvec = [ cellmatvec, bcellmatvec ] -matvecdata = ( term_to_cellmatvec , term_to_cellids, term_to_cellids) -matdata = (term_to_cellmat,term_to_cellids,term_to_cellids) -vecdata = (term_to_cellvec,term_to_cellids) mtypes = [ SparseMatrixCSC, @@ -74,16 +71,24 @@ mtypes = [ for T in mtypes + matvecdata = ( term_to_cellmatvec , term_to_cellids, term_to_cellids) + matdata = (term_to_cellmat,term_to_cellids,term_to_cellids) + vecdata = (term_to_cellvec,term_to_cellids) + data = (matvecdata,matdata,vecdata) + assem = SparseMatrixAssembler(T,Vector{Float64},U,V) - test_assembler(assem,matvecdata,matdata,vecdata) + test_assembler(assem,matdata,vecdata,data) - mat = assemble_matrix(assem,[cellmat],[cellids],[cellids]) - vec = assemble_vector(assem,[cellvec],[cellids]) + matdata = ([cellmat],[cellids],[cellids]) + vecdata = ([cellvec],[cellids]) + + mat = assemble_matrix(assem,matdata) + vec = assemble_vector(assem,vecdata) x = mat \ vec - assemble_matrix!(mat,assem,[cellmat],[cellids],[cellids]) - assemble_vector!(vec,assem,[cellvec],[cellids]) + assemble_matrix!(mat,assem,matdata) + assemble_vector!(vec,assem,vecdata) x2 = mat \ vec @test x ≈ x2 @@ -97,9 +102,10 @@ for T in mtypes @test mat[2, 3] ≈ -0.33333333333333 @test mat[3, 3] ≈ 1.333333333333333 - mat, vec = allocate_matrix_and_vector(assem,([cellmatvec],[cellids],[cellids])) - assemble_matrix_and_vector!(mat,vec,assem,([cellmatvec],[cellids],[cellids])) - assemble_matrix_and_vector!(mat,vec,assem,([cellmatvec],[cellids],[cellids])) + data = (([cellmatvec],[cellids],[cellids]),([],[],[]),([],[])) + mat, vec = allocate_matrix_and_vector(assem,data) + assemble_matrix_and_vector!(mat,vec,assem,data) + assemble_matrix_and_vector!(mat,vec,assem,data) @test vec ≈ [0.0625, 0.125, 0.0625] @test mat[1, 1] ≈ 1.333333333333333 @@ -108,7 +114,7 @@ for T in mtypes x3 = mat \ vec @test x ≈ x3 - mat, vec = assemble_matrix_and_vector(assem,([cellmatvec],[cellids],[cellids])) + mat, vec = assemble_matrix_and_vector(assem,data) x4 = mat \ vec @test x ≈ x4 diff --git a/test/MultiFieldTests/MultiFieldSparseMatrixAssemblersTests.jl b/test/MultiFieldTests/MultiFieldSparseMatrixAssemblersTests.jl index f02755ed4..3a764fd17 100644 --- a/test/MultiFieldTests/MultiFieldSparseMatrixAssemblersTests.jl +++ b/test/MultiFieldTests/MultiFieldSparseMatrixAssemblersTests.jl @@ -43,19 +43,20 @@ cellvec = integrate(dv*2,trian,quad) cellids = get_cell_id(trian) cellmatvec = pair_arrays(cellmat,cellvec) -assem = SparseMatrixAssembler(SparseMatrixCSR{0},Y,X) +assem = SparseMatrixAssembler(SparseMatrixCSR{0},X,Y) matvecdata = ([cellmatvec],[cellids],[cellids]) matdata = ([cellmat],[cellids],[cellids]) vecdata = ([cellvec],[cellids]) +data = (matvecdata,matdata,vecdata) -test_assembler(assem,matvecdata,matdata,vecdata) +test_assembler(assem,matdata,vecdata,data) -A = assemble_matrix(assem,matdata...) +A = assemble_matrix(assem,matdata) -A = allocate_matrix(assem,matdata...) +A = allocate_matrix(assem,matdata) -assem = SparseMatrixAssembler(Y,X) -test_assembler(assem,matvecdata,matdata,vecdata) +assem = SparseMatrixAssembler(X,Y) +test_assembler(assem,matdata,vecdata,data) end # module