Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gridap/Gridap.jl into generic_ass…
Browse files Browse the repository at this point in the history
…embly_strategy
  • Loading branch information
fverdugo committed Sep 6, 2021
2 parents 311015c + a502b1a commit 3c73171
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Inheritance relationship for DiscreteModelPortion. Since PR [#645](https://github.com/gridap/Gridap.jl/pull/645).
- Optimization to RT FEs. Since PR [#638](https://github.com/gridap/Gridap.jl/pull/638).

### Added
- Additional high level API assembly functions. Since PR [#652](https://github.com/gridap/Gridap.jl/pull/652).

## [0.16.4] - 2021-08-17

### Added
Expand Down
44 changes: 44 additions & 0 deletions src/FESpaces/Assemblers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,44 +285,88 @@ function assemble_matrix(f::Function,a::Assembler,U::FESpace,V::FESpace)
assemble_matrix(a,collect_cell_matrix(U,V,f(u,v)))
end

function assemble_matrix!(f::Function,A::AbstractMatrix,a::Assembler,U::FESpace,V::FESpace)
v = get_fe_basis(V)
u = get_trial_fe_basis(U)
assemble_matrix!(A,a,collect_cell_matrix(U,V,f(u,v)))
end

function assemble_vector(f::Function,a::Assembler,V::FESpace)
v = get_fe_basis(V)
assemble_vector(a,collect_cell_vector(V,f(v)))
end

function assemble_vector!(f::Function,b::AbstractVector,a::Assembler,V::FESpace)
v = get_fe_basis(V)
assemble_vector!(b,a,collect_cell_vector(V,f(v)))
end

function assemble_matrix_and_vector(f::Function,b::Function,a::Assembler,U::FESpace,V::FESpace)
v = get_fe_basis(V)
u = get_trial_fe_basis(U)
assemble_matrix_and_vector(a,collect_cell_matrix_and_vector(U,V,f(u,v),b(v)))
end

function assemble_matrix_and_vector!(f::Function,b::Function,M::AbstractMatrix,r::AbstractVector,a::Assembler,U::FESpace,V::FESpace)
v = get_fe_basis(V)
u = get_trial_fe_basis(U)
assemble_matrix_and_vector!(M,r,a,collect_cell_matrix_and_vector(U,V,f(u,v),b(v)))
end

function assemble_matrix(f,a::Assembler,U::FESpace,V::FESpace)
assemble_matrix(a,collect_cell_matrix(U,V,f))
end

function assemble_matrix!(f,A::AbstractMatrix,a::Assembler,U::FESpace,V::FESpace)
assemble_matrix!(A,a,collect_cell_matrix(U,V,f))
end

function assemble_vector(f,a::Assembler,V::FESpace)
assemble_vector(a,collect_cell_vector(V,f))
end

function assemble_vector!(f,b::AbstractVector,a::Assembler,V::FESpace)
assemble_vector!(b,a,collect_cell_vector(V,f))
end

function assemble_matrix_and_vector(f,b,a::Assembler,U::FESpace,V::FESpace)
assemble_matrix_and_vector(a,collect_cell_matrix_and_vector(U,V,f,b))
end

function assemble_matrix_and_vector!(f,b,M::AbstractMatrix,r::AbstractVector,a::Assembler,U::FESpace,V::FESpace)
assemble_matrix_and_vector!(M,r,a,collect_cell_matrix_and_vector(U,V,f,b))
end

function assemble_matrix(f,U::FESpace,V::FESpace)
a = SparseMatrixAssembler(U,V)
assemble_matrix(f,a,U,V)
end

function assemble_matrix!(f,A::AbstractMatrix,U::FESpace,V::FESpace)
a = SparseMatrixAssembler(U,V)
assemble_matrix!(f,A,a,U,V)
end

function assemble_vector(f,V::FESpace)
a = SparseMatrixAssembler(V,V)
assemble_vector(f,a,V)
end

function assemble_vector!(f,b::AbstractVector,V::FESpace)
a = SparseMatrixAssembler(V,V)
assemble_vector!(f,b,a,V)
end

function assemble_matrix_and_vector(f,b,U::FESpace,V::FESpace)
a = SparseMatrixAssembler(U,V)
assemble_matrix_and_vector(f,b,a,U,V)
end

function assemble_matrix_and_vector!(f,b,M::AbstractMatrix,r::AbstractVector,U::FESpace,V::FESpace)
a = SparseMatrixAssembler(U,V)
assemble_matrix_and_vector!(f,b,M,r,a,U,V)
end

# Abstract interface for computing the data to be sent to the assembler

function collect_cell_matrix(trial::FESpace,test::FESpace,mat_contributions)
Expand Down
41 changes: 34 additions & 7 deletions test/FESpacesTests/AssemblersTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,40 @@ A,b = assemble_matrix_and_vector(assem,data)
x = A\b
uh = FEFunction(U,x)

A = assemble_matrix(a,U,V)
b = assemble_vector(ℓ,V)
A,b = assemble_matrix_and_vector(a,ℓ,U,V)

A = assemble_matrix(a(du,dv),U,V)
b = assemble_vector((dv),V)
A,b = assemble_matrix_and_vector(a(du,dv),(dv),U,V)
A1 = assemble_matrix(a,U,V)
b1 = assemble_vector(ℓ,V)
A2,b2 = assemble_matrix_and_vector(a,ℓ,U,V)

A12 = copy(A1); A12[1,1]=rand()
b12 = copy(b1); b12[1]=rand()
A22 = copy(A2); A22[1,1]=rand()
b22 = copy(b2); b22[1]=rand()

tol = 1.e-14
assemble_matrix!(a,A12,U,V)
assemble_vector!(ℓ,b12,V)
assemble_matrix_and_vector!(a,ℓ,A22,b22,U,V)
@test norm(A12-A1) < tol
@test norm(b12-b1) < tol
@test norm(A22-A2) < tol
@test norm(b22-b2) < tol

A1 = assemble_matrix(a(du,dv),U,V)
b1 = assemble_vector((dv),V)
A2,b2 = assemble_matrix_and_vector(a(du,dv),(dv),U,V)

A12 = copy(A1); A12[1,1]=rand()
b12 = copy(b1); b12[1]=rand()
A22 = copy(A2); A22[1,1]=rand()
b22 = copy(b2); b22[1]=rand()

assemble_matrix!(a(du,dv),A12,U,V)
assemble_vector!((dv),b12,V)
assemble_matrix_and_vector!(a(du,dv),(dv),A22,b22,U,V)
@test norm(A12-A1) < tol
@test norm(b12-b1) < tol
@test norm(A22-A2) < tol
@test norm(b22-b2) < tol

V = TestFESpace(
model,
Expand Down

0 comments on commit 3c73171

Please sign in to comment.