From f6e65543568365786d1548c11ef22843c1dc58b3 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Thu, 4 Jul 2019 14:52:53 +0200 Subject: [PATCH 1/7] Removed commented text --- src/FESpaces/Assemblers.jl | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/FESpaces/Assemblers.jl b/src/FESpaces/Assemblers.jl index 91c2d6a34..9d811ad1f 100644 --- a/src/FESpaces/Assemblers.jl +++ b/src/FESpaces/Assemblers.jl @@ -11,10 +11,6 @@ export SparseMatrixAssembler export assemble export assemble! -#@fverdugo for the moment the abstract interface of Assembler -# (and therefore its concrete implementations) -# assumes single field, and single term - """ Abstract assembly operator Parametrized by the type of returned matrix and vector @@ -122,33 +118,4 @@ function assemble!( mat.nzval .= m.nzval end -# Draft of multi field assembler -#function _assemble_sparse_matrix_values(mf_vals,mf_rows,mf_cols,I,E) -# aux_row = I[]; aux_col = I[]; aux_val = E[] -# for (mf_rows_c, mf_cols_c, mf_vals_c) in zip(mf_rows,mf_cols,mf_vals) -# for (vals_c, (ifield, jfield)) in eachblock(mf_vals_c) -# rows_c = mf_rows_c[ifield] -# cols_c = mf_cols_c[jfield] -# row_offset = row_offsets[ifield] -# col_offset = col_offsets[jfield] -# _asseble_cell_values!(aux_row,aux_col,aux_val,rows_c,cols_c,vals_c,col_offset,row_offset) -# end -# end -# (aux_row, aux_col, aux_val) -#end -# -#function _asseble_cell_values!(aux_row,aux_col,aux_val,rows_c,cols_c,vals_c,col_offset,row_offset) -# for (j,gidcol) in enumerate(cols_c) -# if gidcol > 0 -# for (i,gidrow) in enumerate(rows_c) -# if gidrow > 0 -# push!(aux_row, gidrow+row_offset) -# push!(aux_col, gidcol+col_offset) -# push!(aux_val, vals_c[i,j]) -# end -# end -# end -# end -#end - end # module Assemblers From b6b4c32c8c4b826a41ba64c770ac8a1c394e16f0 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Thu, 4 Jul 2019 15:45:21 +0200 Subject: [PATCH 2/7] Added IdentityCellNumber --- src/CellValues/IdentityCellNumbers.jl | 32 +++++++++++++++++++ src/CellValues/files.jl | 3 ++ .../IdentityCellNumbersTests.jl | 19 +++++++++++ test/CellValuesTests/runtests.jl | 2 ++ 4 files changed, 56 insertions(+) create mode 100644 src/CellValues/IdentityCellNumbers.jl create mode 100644 test/CellValuesTests/IdentityCellNumbersTests.jl diff --git a/src/CellValues/IdentityCellNumbers.jl b/src/CellValues/IdentityCellNumbers.jl new file mode 100644 index 000000000..2b70773ef --- /dev/null +++ b/src/CellValues/IdentityCellNumbers.jl @@ -0,0 +1,32 @@ +module IdentityCellNumbers + +using Gridap + +export IdentityCellNumber +import Gridap: reindex +import Base: size +import Base: getindex + +struct IdentityCellNumber{T} <: IndexCellValue{T,1} + length::Int +end + +function IdentityCellNumber(::Type{T},l::Integer) where T <: Integer + IdentityCellNumber{T}(l) +end + +function getindex(c::IdentityCellNumber{T},i::Integer) where T + @assert i > 0 + @assert i <= c.length + j::T = i + j +end + +size(c::IdentityCellNumber) = (c.length,) + +function reindex(values::IndexCellValue, indices::IdentityCellNumber) + @assert length(values) == length(indices) + values +end + +end # module diff --git a/src/CellValues/files.jl b/src/CellValues/files.jl index a7f407d64..3633e7523 100644 --- a/src/CellValues/files.jl +++ b/src/CellValues/files.jl @@ -53,4 +53,7 @@ include("CompressedCellValues.jl") include("NonIterableCellMaps.jl") @reexport using Gridap.NonIterableCellMaps +include("IdentityCellNumbers.jl") +@reexport using Gridap.IdentityCellNumbers + diff --git a/test/CellValuesTests/IdentityCellNumbersTests.jl b/test/CellValuesTests/IdentityCellNumbersTests.jl new file mode 100644 index 000000000..2383aef43 --- /dev/null +++ b/test/CellValuesTests/IdentityCellNumbersTests.jl @@ -0,0 +1,19 @@ +module IdentityCellNumbersTests + +using Test +using Gridap +using Gridap.CellValuesGallery + +a = [2,3,4,6,1,8,3,5] +cn = CellValueFromArray(a) + +l = length(a) +id = IdentityCellNumber(Int,l) +r = collect(1:l) +test_index_cell_number(id,r) + +cn2 = reindex(cn,id) + +@test cn2 === cn + +end # module diff --git a/test/CellValuesTests/runtests.jl b/test/CellValuesTests/runtests.jl index 33689e678..e0bd51660 100644 --- a/test/CellValuesTests/runtests.jl +++ b/test/CellValuesTests/runtests.jl @@ -42,5 +42,7 @@ include("MapsMocks.jl") @testset "NonIterableCellMaps" begin include("NonIterableCellMapsTests.jl") end +@testset "IdentityCellNumbers" begin include("IdentityCellNumbersTests.jl") end + end # module From b20e3ea7c175c09b91870774721f23625151bf2a Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Thu, 4 Jul 2019 15:55:02 +0200 Subject: [PATCH 3/7] Updated NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 3d9f6ffde..e01cb7395 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `NonIterableCellMap`, a cell map that has iteration intentionally disabled. Available since commit [956a537](https://github.com/gridap/Gridap.jl/commit/956a5374db6c3b9546e85e0d4d49ae0560057565). - `BoundaryTriangulation` an integration mesh used to integrate `CellField` and `CellBasis` objects restricted on a surface. Available since commit [e981f3c](https://github.com/gridap/Gridap.jl/commit/e981f3c221f3624cfc6764efa47f22652fc22b4f) - Function `restrict` for restricting `CellField` and `CellBasis` objects to surfaces. Available since commit [e981f3c](https://github.com/gridap/Gridap.jl/commit/e981f3c221f3624cfc6764efa47f22652fc22b4f) +- `IdentityCellNumber`, an indexable cell number that simply returns the given index. Also efficient implementation of `reindex` for this type (i.e. do nothing). Available since commit [b6b4c32](https://github.com/gridap/Gridap.jl/commit/b6b4c32c8c4b826a41ba64c770ac8a1c394e16f0) ### Changed ### Removed From 9a11ed9ad5db4e13bed2e41488f0d533b75ea0ea Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Fri, 5 Jul 2019 09:23:50 +0200 Subject: [PATCH 4/7] Saving untested changes --- src/FESpaces/Assemblers.jl | 89 ++++++++++++++++------ src/FESpaces/FESpaces.jl | 24 +++--- src/Gridap.jl | 4 +- src/MultiField/MultiAssemblers.jl | 89 ++++++++++++++++------ src/MultiField/MultiFESpaces.jl | 12 +-- test/FESpacesTests/FESpacesTests.jl | 7 +- test/MultiFieldTests/MultiFESpacesTests.jl | 7 +- test/runtests.jl | 4 +- 8 files changed, 162 insertions(+), 74 deletions(-) diff --git a/src/FESpaces/Assemblers.jl b/src/FESpaces/Assemblers.jl index 9d811ad1f..6f9513864 100644 --- a/src/FESpaces/Assemblers.jl +++ b/src/FESpaces/Assemblers.jl @@ -20,31 +20,53 @@ abstract type Assembler{M<:AbstractMatrix,V<:AbstractVector} end """ Assembly of a vector allocating output """ -function assemble(::Assembler{M,V},::CellVector)::V where {M,V} +function assemble( + ::Assembler{M,V}, + ::Vararg{Tuple{<:CellVector,<:CellNumber}})::V where {M,V} @abstractmethod end """ Assembly of a matrix allocating output """ -function assemble(::Assembler{M,V},::CellMatrix)::M where {M,V} +function assemble( + ::Assembler{M,V}, + ::Vararg{Tuple{<:CellMatrix,<:CellNumber}})::M where {M,V} @abstractmethod end """ In-place assembly of a vector (allows optimizations) """ -function assemble!(::V,::Assembler{M,V},::CellVector)::V where {M,V} +function assemble!( + ::V, + ::Assembler{M,V}, + ::Vararg{Tuple{<:CellVector,<:CellNumber}})::V where {M,V} @abstractmethod end """ In-place assembly of a matrix (allows a LOT of optimizations) """ -function assemble!(::M,::Assembler{M,V},::CellMatrix)::M where {M,V} +function assemble!( + ::M, + ::Assembler{M,V}, + ::Vararg{Tuple{<:CellMatrix,<:CellNumber}})::M where {M,V} @abstractmethod end +function assemble(a::Assembler,cv::CellArray) + l = length(cv) + ide = IdentityCellNumber(Int,l) + assemble(a,(cv,ide)) +end + +function assemble!(r,a::Assembler,cv::CellArray) + l = length(cv) + ide = IdentityCellNumber(Int,l) + assemble!(r,a,(cv,ide)) +end + """ Assembler that produces SparseMatrices from the SparseArrays package """ @@ -58,19 +80,28 @@ function SparseMatrixAssembler(test::FESpace{D,Z,T}, trial::FESpace{D,Z,T}) wher SparseMatrixAssembler{E}(trial,test) end -function assemble(this::SparseMatrixAssembler{E}, vals::CellVector) where E +function assemble( + this::SparseMatrixAssembler{E}, + vals::Vararg{Tuple{<:CellVector,<:CellNumber}}) where E + n = num_free_dofs(this.testfesp) vec = zeros(E,n) - assemble!(vec,this,vals) + assemble!(vec,this,vals...) vec end function assemble!( - vec::Vector{E},this::SparseMatrixAssembler{E}, vals::CellVector) where E - _vals = apply_constraints(this.testfesp, vals) - _rows = celldofids(this.testfesp) + vec::Vector{E}, + this::SparseMatrixAssembler{E}, + allvals::Vararg{Tuple{<:CellVector,<:CellNumber}}) where E + vec .= zero(E) - _assemble_vector!(vec, _vals, _rows) + rows = celldofids(this.testfesp) + for (vals, cellids) in allvals + _vals = apply_constraints(this.testfesp, vals, cellids) + _rows = reindex(rows,cellids) + _assemble_vector!(vec, _vals, _rows) + end end function _assemble_vector!(vec,vals,rows) @@ -83,17 +114,28 @@ function _assemble_vector!(vec,vals,rows) end end -function assemble(this::SparseMatrixAssembler{E}, vals::CellMatrix) where E - _vals = apply_constraints_rows(this.testfesp, vals) - rows_m = celldofids(this.testfesp) - _vals = apply_constraints_cols(this.trialfesp, _vals) - cols_m = celldofids(this.trialfesp) - args = _assemble_sparse_matrix_values(_vals,rows_m,cols_m,Int,E) - sparse(args...) -end +function assemble( + this::SparseMatrixAssembler{E}, + allvals::Vararg{Tuple{<:CellMatrix,<:CellNumber}}) where E -function _assemble_sparse_matrix_values(vals,rows,cols,I,E) + I = Int aux_row = I[]; aux_col = I[]; aux_val = E[] + + _rows_m = celldofids(this.testfesp) + _cols_m = celldofids(this.trialfesp) + + for (vals,cellids) in allvals + _vals = apply_constraints_rows(this.testfesp, vals, cellids) + rows_m = reindex(_rows_m, cellids) + vals_m = apply_constraints_cols(this.trialfesp, _vals, cellids) + cols_m = reindex(_cols_m, cellids) + _assemble_sparse_matrix_values!( + aux_row,aux_col,aux_val,vals_m,rows_m,cols_m) + end + sparse(aux_row,aux_col,aux_val) +end + +function _assemble_sparse_matrix_values!(aux_row,aux_col,aux_val,vals,rows,cols) for (rows_c, cols_c, vals_c) in zip(rows,cols,vals) for (j,gidcol) in enumerate(cols_c) if gidcol > 0 @@ -107,15 +149,16 @@ function _assemble_sparse_matrix_values(vals,rows,cols,I,E) end end end - (aux_row, aux_col, aux_val) end function assemble!( - mat::SparseMatrixCSC{E}, this::SparseMatrixAssembler{E}, vals::CellMatrix) where E + mat::SparseMatrixCSC{E}, + this::SparseMatrixAssembler{E}, + vals::Vararg{Tuple{<:CellMatrix,<:CellNumber}}) where E # This routine can be optimized a lot taking into a count the sparsity graph of mat # For the moment we create an intermediate matrix and then transfer the nz values - m = assemble(this,vals) + m = assemble(this,vals...) mat.nzval .= m.nzval end -end # module Assemblers +end # module diff --git a/src/FESpaces/FESpaces.jl b/src/FESpaces/FESpaces.jl index 727d12f15..1aace9b60 100644 --- a/src/FESpaces/FESpaces.jl +++ b/src/FESpaces/FESpaces.jl @@ -51,15 +51,15 @@ num_diri_dofs(::FESpace)::Int = @abstractmethod diri_tags(::FESpace)::Vector{Int} = @abstractmethod -function apply_constraints(::FESpace, cellvec::CellVector)::CellVector +function apply_constraints(::FESpace, cellvec::CellVector, cellids::CellNumber)::CellVector @abstractmethod end -function apply_constraints_rows(::FESpace, cellmat::CellMatrix)::CellMatrix +function apply_constraints_rows(::FESpace, cellmat::CellMatrix, cellids::CellNumber)::CellMatrix @abstractmethod end -function apply_constraints_cols(::FESpace, cellmat::CellMatrix)::CellMatrix +function apply_constraints_cols(::FESpace, cellmat::CellMatrix, cellids::CellNumber)::CellMatrix @abstractmethod end @@ -279,18 +279,18 @@ num_diri_dofs(f::FESpaceWithDirichletData) = num_diri_dofs(f.fespace) diri_tags(f::FESpaceWithDirichletData) = diri_tags(f.fespace) function apply_constraints( - f::FESpaceWithDirichletData, cellvec::CellVector) - apply_constraints(f.fespace,cellvec) + f::FESpaceWithDirichletData, cellvec::CellVector, cellids::CellNumber) + apply_constraints(f.fespace,cellvec,cellids) end function apply_constraints_rows( - f::FESpaceWithDirichletData, cellmat::CellMatrix) - apply_constraints_rows(f.fespace,cellmat) + f::FESpaceWithDirichletData, cellmat::CellMatrix, cellids::CellNumber) + apply_constraints_rows(f.fespace,cellmat,cellids) end function apply_constraints_cols( - f::FESpaceWithDirichletData, cellmat::CellMatrix) - apply_constraints_cols(f.fespace,cellmat) + f::FESpaceWithDirichletData, cellmat::CellMatrix, cellids::CellNumber) + apply_constraints_cols(f.fespace,cellmat,cellids) end function celldofids(f::FESpaceWithDirichletData) @@ -377,17 +377,17 @@ num_diri_dofs(this::ConformingFESpace) = this.num_diri_dofs diri_tags(f::ConformingFESpace) = f.diri_tags function apply_constraints( - this::ConformingFESpace, cellvec::CellVector) + this::ConformingFESpace, cellvec::CellVector, cellids::CellNumber) cellvec end function apply_constraints_rows( - this::ConformingFESpace, cellmat::CellMatrix) + this::ConformingFESpace, cellmat::CellMatrix, cellids::CellNumber) cellmat end function apply_constraints_cols( - this::ConformingFESpace, cellmat::CellMatrix) + this::ConformingFESpace, cellmat::CellMatrix, cellids::CellNumber) cellmat end diff --git a/src/Gridap.jl b/src/Gridap.jl index a2b15907f..9f539a75e 100644 --- a/src/Gridap.jl +++ b/src/Gridap.jl @@ -18,9 +18,9 @@ include("Geometry/files.jl") include("Algebra/files.jl") -include("FESpaces/files.jl") +#include("FESpaces/files.jl") -include("MultiField/files.jl") +#include("MultiField/files.jl") include("Visualization/files.jl") diff --git a/src/MultiField/MultiAssemblers.jl b/src/MultiField/MultiAssemblers.jl index 24b69019e..2e406f72c 100644 --- a/src/MultiField/MultiAssemblers.jl +++ b/src/MultiField/MultiAssemblers.jl @@ -15,24 +15,47 @@ import Gridap.Assemblers: SparseMatrixAssembler abstract type MultiAssembler{M<:AbstractMatrix,V<:AbstractVector} end -function assemble(::MultiAssembler{M,V},::MultiCellVector)::V where {M,V} +function assemble( + ::MultiAssembler{M,V}, + ::Vararg{Tuple{<:MultiCellVector,<:CellNumber}})::V where {M,V} @abstractmethod end -function assemble(::MultiAssembler{M,V},::MultiCellMatrix)::M where {M,V} +function assemble( + ::MultiAssembler{M,V}, + ::Vararg{Tuple{<:MultiCellMatrix,<:CellNumber}})::M where {M,V} @abstractmethod end -function assemble!(::V,::MultiAssembler{M,V},::MultiCellVector)::V where {M,V} +function assemble!( + ::V, + ::MultiAssembler{M,V}, + ::Vararg{Tuple{<:MultiCellVector,<:CellNumber}}) where {M,V} @abstractmethod end -function assemble!(::M,::MultiAssembler{M,V},::MultiCellMatrix)::M where {M,V} +function assemble!( + ::M, + ::MultiAssembler{M,V}, + ::Vararg{Tuple{<:MultiCellMatrix,<:CellNumber}}) where {M,V} @abstractmethod end +function assemble( + a::MultiAssembler,cv::MultiCellArray) + l = length(cv) + ide = IdentityCellNumber(Int,l) + assemble(a,(cv,ide)) +end + +function assemble!(r,a::MultiAssembler,cv::MultiCellArray) + l = length(cv) + ide = IdentityCellNumber(Int,l) + assemble!(r,a,(cv,ide)) +end + """ -Assembler that produces SparseMatrices from the SparseArrays package +MultiAssembler that produces SparseMatrices from the SparseArrays package """ struct MultiSparseMatrixAssembler{E} <: MultiAssembler{SparseMatrixCSC{E,Int},Vector{E}} testfesps::MultiFESpace{E} @@ -59,45 +82,65 @@ function MultiSparseMatrixAssembler( MultiSparseMatrixAssembler{E}(testfesps,trialfesps) end -function assemble(this::MultiSparseMatrixAssembler{E},vals::MultiCellVector) where E +function assemble( + this::MultiSparseMatrixAssembler{E}, + allvals::Vararg{Tuple{<:MultiCellVector,<:CellNumber}}) where E + n = num_free_dofs(this.testfesps) vec = zeros(E,n) - assemble!(vec,this,vals) + assemble!(vec,this,allvals...) vec end -function assemble!(vec::Vector{E},this::MultiSparseMatrixAssembler{E},mcv::MultiCellVector) where E +function assemble!( + vec::Vector{E}, + this::MultiSparseMatrixAssembler{E}, + allmcv::Vararg{Tuple{<:MultiCellVector,<:CellNumber}}) where E + vec .= zero(E) V = this.testfesps - mf_vals = apply_constraints(V,mcv) - mf_rows = celldofids(V) offsets = _compute_offsets(V) - i_to_fieldid = mf_vals.fieldids - _assemble_vec!(vec,mf_rows,mf_vals,i_to_fieldid,offsets) + _mf_rows = celldofids(V) + for (mcv,cellids) in allmcv + mf_vals = apply_constraints(V,mcv,cellids) + i_to_fieldid = mf_vals.fieldids + mf_rows = reindex(_mf_rows,cellids) + _assemble_vec!(vec,mf_rows,mf_vals,i_to_fieldid,offsets) + end end -function assemble(this::MultiSparseMatrixAssembler{E},mcm::MultiCellMatrix) where {E} +function assemble( + this::MultiSparseMatrixAssembler{E}, + allmcm::Vararg{Tuple{<:MultiCellMatrix,<:CellNumber}}) where {E} + V = this.testfesps U = this.trialfesps - mf_vals = apply_constraints_rows(V, mcm) - mf_rows = celldofids(V) - mf_vals = apply_constraints_cols(U,mf_vals) - mf_cols = celldofids(U) offsets_row = _compute_offsets(V) offsets_col = _compute_offsets(U) - i_to_fieldid = mf_vals.fieldids + _mf_rows = celldofids(V) + _mf_cols = celldofids(U) aux_row = Int[]; aux_col = Int[]; aux_val = E[] - _assemble_mat!( - aux_row,aux_col,aux_val,mf_rows,mf_cols,mf_vals, - i_to_fieldid,offsets_row,offsets_col) + + for (mcm,cellids) in allmcm + mf_vals = apply_constraints_rows(V, mcm, cellids) + mf_rows = reindex(_mf_rows, cellids) + mf_vals = apply_constraints_cols(U,mf_vals,cellids) + mf_cols = reindex(_mf_cols, cellids) + i_to_fieldid = mf_vals.fieldids + _assemble_mat!( + aux_row,aux_col,aux_val,mf_rows,mf_cols,mf_vals, + i_to_fieldid,offsets_row,offsets_col) + end sparse(aux_row, aux_col, aux_val) end function assemble!( - mat::SparseMatrixCSC{E}, this::MultiSparseMatrixAssembler{E}, vals::MultiCellMatrix) where E + mat::SparseMatrixCSC{E}, + this::MultiSparseMatrixAssembler{E}, + allvals::Vararg{Tuple{<:MultiCellMatrix,<:CellNumber}}) where E # This routine can be optimized a lot taking into a count the sparsity graph of mat # For the moment we create an intermediate matrix and then transfer the nz values - m = assemble(this,vals) + m = assemble(this,allvals...) mat.nzval .= m.nzval end diff --git a/src/MultiField/MultiFESpaces.jl b/src/MultiField/MultiFESpaces.jl index f6a693eb4..58e5732ff 100644 --- a/src/MultiField/MultiFESpaces.jl +++ b/src/MultiField/MultiFESpaces.jl @@ -60,40 +60,40 @@ iterate(self::MultiFESpace) = iterate(self.fespaces) iterate(self::MultiFESpace,state) = iterate(self.fespaces,state) -function apply_constraints(self::MultiFESpace, mcv::MultiCellVector{T}) where T +function apply_constraints(self::MultiFESpace, mcv::MultiCellVector{T}, cellids::CellNumber) where T blocks = mcv.blocks i_to_fieldid = mcv.fieldids newblocks = CellVector{T}[] for (i,block) in enumerate(blocks) ifield, = i_to_fieldid[i] Ui = self[ifield] - newblock = apply_constraints(Ui,block) + newblock = apply_constraints(Ui,block,cellids) push!(newblocks,newblock) end MultiCellVector(newblocks,i_to_fieldid) end -function apply_constraints_rows(self::MultiFESpace, mcm::MultiCellMatrix{T}) where T +function apply_constraints_rows(self::MultiFESpace, mcm::MultiCellMatrix{T}, cellids::CellNumber) where T blocks = mcm.blocks i_to_fieldid = mcm.fieldids newblocks = CellMatrix{T}[] for (i,block) in enumerate(blocks) ifield, = i_to_fieldid[i] Ui = self[ifield] - newblock = apply_constraints_rows(Ui,block) + newblock = apply_constraints_rows(Ui,block,cellids) push!(newblocks,newblock) end MultiCellMatrix(newblocks,i_to_fieldid) end -function apply_constraints_cols(self::MultiFESpace, mcm::MultiCellMatrix{T}) where T +function apply_constraints_cols(self::MultiFESpace, mcm::MultiCellMatrix{T}, cellids::CellNumber) where T blocks = mcm.blocks i_to_fieldid = mcm.fieldids newblocks = CellMatrix{T}[] for (i,block) in enumerate(blocks) _, jfield = i_to_fieldid[i] Ui = self[jfield] - newblock = apply_constraints_cols(Ui,block) + newblock = apply_constraints_cols(Ui,block,cellids) push!(newblocks,newblock) end MultiCellMatrix(newblocks,i_to_fieldid) diff --git a/test/FESpacesTests/FESpacesTests.jl b/test/FESpacesTests/FESpacesTests.jl index c104972c0..615965e6e 100644 --- a/test/FESpacesTests/FESpacesTests.jl +++ b/test/FESpacesTests/FESpacesTests.jl @@ -108,21 +108,22 @@ mmat = integrate(a(cellbasis,cellbasis),trian,quad) bvec = integrate(b(cellbasis),trian,quad) -bvec2 = apply_constraints(fespace,bvec) +cellids = IdentityCellNumber(Int,length(bvec)) +bvec2 = apply_constraints(fespace,bvec,cellids) dofs = celldofids(fespace) @test bvec2 === bvec @test dofs == fespace.cell_eqclass -mmat2 = apply_constraints_rows(fespace,mmat) +mmat2 = apply_constraints_rows(fespace,mmat,cellids) dofs = celldofids(fespace) @test mmat2 === mmat @test dofs == fespace.cell_eqclass -mmat3 = apply_constraints_cols(fespace,mmat) +mmat3 = apply_constraints_cols(fespace,mmat,cellids) dofs = celldofids(fespace) @test mmat3 === mmat diff --git a/test/MultiFieldTests/MultiFESpacesTests.jl b/test/MultiFieldTests/MultiFESpacesTests.jl index 36051e820..17b2e468b 100644 --- a/test/MultiFieldTests/MultiFESpacesTests.jl +++ b/test/MultiFieldTests/MultiFESpacesTests.jl @@ -54,16 +54,17 @@ vec2 = integrate(b(v2),trian,quad) vec = MultiCellVector([vec1,vec2],[(1,),(2,)]) -_vec = apply_constraints(U,vec) +cellids = IdentityCellNumber(Int,length(vec1)) +_vec = apply_constraints(U,vec,cellids) @test _vec.blocks[1] === vec1 @test _vec.blocks[2] === vec2 -_mat = apply_constraints_rows(U,mat) +_mat = apply_constraints_rows(U,mat,cellids) @test _mat.blocks[1] === mat11 @test _mat.blocks[2] === mat12 @test _mat.blocks[3] === mat22 -_mat = apply_constraints_cols(U,mat) +_mat = apply_constraints_cols(U,mat,cellids) @test _mat.blocks[1] === mat11 @test _mat.blocks[2] === mat12 @test _mat.blocks[3] === mat22 diff --git a/test/runtests.jl b/test/runtests.jl index 156251121..1d6a096fb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -16,9 +16,9 @@ using Test @time @testset "Algebra" begin include("AlgebraTests/runtests.jl") end -@time @testset "FESpaces" begin include("FESpacesTests/runtests.jl") end +#@time @testset "FESpaces" begin include("FESpacesTests/runtests.jl") end -@time @testset "MultiField" begin include("MultiFieldTests/runtests.jl") end +#@time @testset "MultiField" begin include("MultiFieldTests/runtests.jl") end @time @testset "Visualization" begin include("VisualizationTests/runtests.jl") end From 3488a0862117f5b0db9337cd09be39064aa75abd Mon Sep 17 00:00:00 2001 From: fverdugo Date: Fri, 5 Jul 2019 10:05:00 +0200 Subject: [PATCH 5/7] FE assembly working for several terms in single-field problems --- src/Gridap.jl | 2 +- test/FESpacesTests/AssemblersTests.jl | 22 ++++++++++++++++++++++ test/runtests.jl | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Gridap.jl b/src/Gridap.jl index 9f539a75e..f28e307a2 100644 --- a/src/Gridap.jl +++ b/src/Gridap.jl @@ -18,7 +18,7 @@ include("Geometry/files.jl") include("Algebra/files.jl") -#include("FESpaces/files.jl") +include("FESpaces/files.jl") #include("MultiField/files.jl") diff --git a/test/FESpacesTests/AssemblersTests.jl b/test/FESpacesTests/AssemblersTests.jl index faf8950ce..381fd4d9f 100644 --- a/test/FESpacesTests/AssemblersTests.jl +++ b/test/FESpacesTests/AssemblersTests.jl @@ -52,4 +52,26 @@ x2 = mat \ vec @test mat[2, 3] ≈ -0.33333333333333 @test mat[3, 3] ≈ 1.333333333333333 +cellids = IdentityCellNumber(Int,length(bvec)) + +vec2 = assemble(assem, (bvec,cellids)) + +@test vec2 == vec + +vec3 = assemble(assem, (bvec,cellids), (bvec,cellids)) +@test vec3 ≈ 2*vec + +assemble!(vec3, assem, (bvec,cellids), (bvec,cellids)) +@test vec3 ≈ 2*vec + +mat2 = assemble(assem, (mmat,cellids) ) + +@test mat2 == mat + +mat3 = assemble(assem, (mmat,cellids), (mmat,cellids)) +@test mat3 ≈ 2*mat + +assemble!(mat3, assem, (mmat,cellids), (mmat,cellids)) +@test mat3 ≈ 2*mat + end # module AssemblersTests diff --git a/test/runtests.jl b/test/runtests.jl index 1d6a096fb..a4165a239 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -16,7 +16,7 @@ using Test @time @testset "Algebra" begin include("AlgebraTests/runtests.jl") end -#@time @testset "FESpaces" begin include("FESpacesTests/runtests.jl") end +@time @testset "FESpaces" begin include("FESpacesTests/runtests.jl") end #@time @testset "MultiField" begin include("MultiFieldTests/runtests.jl") end From 409479efc490c23f8ba9f0c160c43e3f0c7bf4dc Mon Sep 17 00:00:00 2001 From: fverdugo Date: Fri, 5 Jul 2019 10:38:19 +0200 Subject: [PATCH 6/7] FE assembly working for several terms in multi-field problems --- src/Gridap.jl | 2 +- src/MultiField/MultiCellArrays.jl | 6 ++++++ test/MultiFieldTests/MultiAssemblersTests.jl | 14 ++++++++++++++ test/MultiFieldTests/MultiCellArraysTests.jl | 9 +++++++++ test/MultiFieldTests/runtests.jl | 4 ++-- test/runtests.jl | 2 +- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Gridap.jl b/src/Gridap.jl index f28e307a2..a2b15907f 100644 --- a/src/Gridap.jl +++ b/src/Gridap.jl @@ -20,7 +20,7 @@ include("Algebra/files.jl") include("FESpaces/files.jl") -#include("MultiField/files.jl") +include("MultiField/files.jl") include("Visualization/files.jl") diff --git a/src/MultiField/MultiCellArrays.jl b/src/MultiField/MultiCellArrays.jl index 8ae4913fc..1eee596a5 100644 --- a/src/MultiField/MultiCellArrays.jl +++ b/src/MultiField/MultiCellArrays.jl @@ -9,6 +9,7 @@ export MultiCellMatrix export MultiCellVector import Base: iterate import Base: length +import Gridap: reindex struct MultiCellArray{T,N} blocks::Vector{<:CellValue{CachedArray{T,N,Array{T,N}}}} @@ -68,4 +69,9 @@ end (arrays, state) end +function reindex(mca::MultiCellArray,cn::CellNumber) + blocks = [ reindex(block,cn) for block in mca.blocks ] + MultiCellArray(blocks,mca.fieldids) +end + end # module diff --git a/test/MultiFieldTests/MultiAssemblersTests.jl b/test/MultiFieldTests/MultiAssemblersTests.jl index 6c726de57..959cc8936 100644 --- a/test/MultiFieldTests/MultiAssemblersTests.jl +++ b/test/MultiFieldTests/MultiAssemblersTests.jl @@ -61,4 +61,18 @@ mm = assemble(assem,mat) assemble!(mm,assem,mat) +cellids = IdentityCellNumber(Int,length(vec)) + +v2 = assemble(assem,(vec,cellids),(vec,cellids)) +@test v2 ≈ 2*v + +assemble!(v2,assem,(vec,cellids),(vec,cellids)) +@test v2 ≈ 2*v + +mm2 = assemble(assem,(mat,cellids),(mat,cellids)) +@test mm2 ≈ 2*mm + +assemble!(mm2,assem,(mat,cellids),(mat,cellids)) +@test mm2 ≈ 2*mm + end # module MultiAssemblersTests diff --git a/test/MultiFieldTests/MultiCellArraysTests.jl b/test/MultiFieldTests/MultiCellArraysTests.jl index b092c7856..dad1018ce 100644 --- a/test/MultiFieldTests/MultiCellArraysTests.jl +++ b/test/MultiFieldTests/MultiCellArraysTests.jl @@ -2,6 +2,7 @@ module MultiCellArraysTests using Test using Gridap +using Gridap.CellValuesGallery using Gridap.CachedArrays l = 10 @@ -38,4 +39,12 @@ scb = ConstantCellArray(sb,l) mca2 = MultiCellMatrix([sca,scb],[(1,5),(3,2)]) +ids = [1,3,4,2] +cellids = CellValueFromArray(ids) +mca3 = reindex(mca,cellids) + +for (ca3,ca) in zip(mca3.blocks,mca.blocks) + @test ca3 == reindex(ca,cellids) +end + end # module MultiCellArraysTests diff --git a/test/MultiFieldTests/runtests.jl b/test/MultiFieldTests/runtests.jl index eded19bac..1d0f6a68b 100644 --- a/test/MultiFieldTests/runtests.jl +++ b/test/MultiFieldTests/runtests.jl @@ -6,14 +6,14 @@ using Test @testset "MultiCellMaps" begin include("MultiCellMapsTests.jl") end -@testset "MultiAssemblers" begin include("MultiAssemblersTests.jl") end - @testset "MultiFESpaces" begin include("MultiFESpacesTests.jl") end @testset "MultiFEFunctions" begin include("MultiFEFunctionsTests.jl") end @testset "MultiFEBases" begin include("MultiFEBasesTests.jl") end +@testset "MultiAssemblers" begin include("MultiAssemblersTests.jl") end + @testset "MultiFEOperators" begin include("MultiFEOperatorsTests.jl") end @testset "MultiNonLinearFEOperators" begin include("MultiNonLinearFEOperatorsTests.jl") end diff --git a/test/runtests.jl b/test/runtests.jl index a4165a239..156251121 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -18,7 +18,7 @@ using Test @time @testset "FESpaces" begin include("FESpacesTests/runtests.jl") end -#@time @testset "MultiField" begin include("MultiFieldTests/runtests.jl") end +@time @testset "MultiField" begin include("MultiFieldTests/runtests.jl") end @time @testset "Visualization" begin include("VisualizationTests/runtests.jl") end From d7d54c0282917e2af9ecfe0ad4b22c48bcfca87d Mon Sep 17 00:00:00 2001 From: fverdugo Date: Fri, 5 Jul 2019 10:44:06 +0200 Subject: [PATCH 7/7] Updated NEWS.md --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index e01cb7395..a631d3a1c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `IdentityCellNumber`, an indexable cell number that simply returns the given index. Also efficient implementation of `reindex` for this type (i.e. do nothing). Available since commit [b6b4c32](https://github.com/gridap/Gridap.jl/commit/b6b4c32c8c4b826a41ba64c770ac8a1c394e16f0) ### Changed +- Changed the signature of `assemble`, `apply_constraints`, `apply_constraints_rows`, and `apply_constraints_cols` to support FE assembly of several terms, which are integrated in different domains. The old API of `asseble` is still functional, but not for the `apply_constraints` et al. + + ### Removed ### Deprecated ### Fixed