From 48754310efeb5e3edf36c6bb81cdd0d59f209348 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 6 Dec 2023 16:15:21 +1100 Subject: [PATCH 1/5] Bugfix --- src/Algebra/AlgebraInterfaces.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Algebra/AlgebraInterfaces.jl b/src/Algebra/AlgebraInterfaces.jl index 61b61cac0..f2b70fe25 100644 --- a/src/Algebra/AlgebraInterfaces.jl +++ b/src/Algebra/AlgebraInterfaces.jl @@ -86,7 +86,7 @@ end Allocate a vector in the domain of matrix `matrix`. """ function allocate_in_domain(matrix::AbstractMatrix{T}) where T - allocate_in_range(Vector{T},matrix) + allocate_in_domain(Vector{T},matrix) end function allocate_in_domain(matrix::BlockMatrix{T}) where T From 2c5fbe135cb1cf2e24c670ebef96b4639fe38729 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 6 Dec 2023 23:56:58 +1100 Subject: [PATCH 2/5] allocate_vector now only allocates --- src/Algebra/AlgebraInterfaces.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Algebra/AlgebraInterfaces.jl b/src/Algebra/AlgebraInterfaces.jl index f2b70fe25..605c68076 100644 --- a/src/Algebra/AlgebraInterfaces.jl +++ b/src/Algebra/AlgebraInterfaces.jl @@ -37,8 +37,7 @@ function allocate_vector(::Type{V},indices) where V end function allocate_vector(::Type{V},n::Integer) where V - T = eltype(V) - zeros(T,n) + V(undef,n) end function allocate_vector(::Type{<:BlockVector{T,VV}},indices::BlockedUnitRange) where {T,VV} From a649dc982a80188cb14f6039ef52a7be6dc1153a Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 7 Dec 2023 10:53:48 +1100 Subject: [PATCH 3/5] Updated zero_free_values --- src/FESpaces/FESpaceInterface.jl | 4 +++- src/FESpaces/SingleFieldFESpaces.jl | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/FESpaces/FESpaceInterface.jl b/src/FESpaces/FESpaceInterface.jl index b2c2d7108..6cbadb122 100644 --- a/src/FESpaces/FESpaceInterface.jl +++ b/src/FESpaces/FESpaceInterface.jl @@ -87,7 +87,9 @@ num_free_dofs(f::FESpace) = length(get_free_dof_ids(f)) """ function zero_free_values(f::FESpace) V = get_vector_type(f) - allocate_vector(V,num_free_dofs(f)) + dir_values = allocate_vector(V,num_free_dofs(f)) + fill!(dir_values,zero(eltype(V))) + return dir_values end function get_vector_type(fs::FESpace) diff --git a/src/FESpaces/SingleFieldFESpaces.jl b/src/FESpaces/SingleFieldFESpaces.jl index ba0d88b41..674c9e209 100644 --- a/src/FESpaces/SingleFieldFESpaces.jl +++ b/src/FESpaces/SingleFieldFESpaces.jl @@ -16,7 +16,9 @@ num_dirichlet_dofs(f::SingleFieldFESpace) = length(get_dirichlet_dof_ids(f)) """ function zero_dirichlet_values(f::SingleFieldFESpace) V = get_vector_type(f) - allocate_vector(V,num_dirichlet_dofs(f)) + dir_values = allocate_vector(V,num_dirichlet_dofs(f)) + fill!(dir_values,zero(eltype(V))) + return dir_values end """ From 2e6ed8190ca970996d10622fa915b921f432ae33 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 7 Dec 2023 15:00:33 +1100 Subject: [PATCH 4/5] Fixes --- src/FESpaces/FESpaceInterface.jl | 6 +++--- src/FESpaces/UnconstrainedFESpaces.jl | 2 -- src/MultiField/MultiFieldFESpaces.jl | 7 ------- src/ODEs/TransientFETools/TransientFESpaces.jl | 4 +++- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/FESpaces/FESpaceInterface.jl b/src/FESpaces/FESpaceInterface.jl index 6cbadb122..6cb011fe2 100644 --- a/src/FESpaces/FESpaceInterface.jl +++ b/src/FESpaces/FESpaceInterface.jl @@ -87,9 +87,9 @@ num_free_dofs(f::FESpace) = length(get_free_dof_ids(f)) """ function zero_free_values(f::FESpace) V = get_vector_type(f) - dir_values = allocate_vector(V,num_free_dofs(f)) - fill!(dir_values,zero(eltype(V))) - return dir_values + free_values = allocate_vector(V,get_free_dof_ids(f)) + fill!(free_values,zero(eltype(V))) + return free_values end function get_vector_type(fs::FESpace) diff --git a/src/FESpaces/UnconstrainedFESpaces.jl b/src/FESpaces/UnconstrainedFESpaces.jl index 0a9ca2b05..3339c9205 100644 --- a/src/FESpaces/UnconstrainedFESpaces.jl +++ b/src/FESpaces/UnconstrainedFESpaces.jl @@ -48,7 +48,6 @@ end ConstraintStyle(::Type{<:UnconstrainedFESpace}) = UnConstrained() get_free_dof_ids(f::UnconstrainedFESpace) = Base.OneTo(f.nfree) -zero_free_values(f::UnconstrainedFESpace) = allocate_vector(f.vector_type,num_free_dofs(f)) get_fe_basis(f::UnconstrainedFESpace) = f.fe_basis get_fe_dof_basis(f::UnconstrainedFESpace) = f.fe_dof_basis get_cell_dof_ids(f::UnconstrainedFESpace) = f.cell_dofs_ids @@ -61,7 +60,6 @@ get_cell_is_dirichlet(f::UnconstrainedFESpace) = f.cell_is_dirichlet get_dirichlet_dof_ids(f::UnconstrainedFESpace) = Base.OneTo(f.ndirichlet) num_dirichlet_tags(f::UnconstrainedFESpace) = f.ntags -zero_dirichlet_values(f::UnconstrainedFESpace) = allocate_vector(f.vector_type,num_dirichlet_dofs(f)) get_dirichlet_dof_tag(f::UnconstrainedFESpace) = f.dirichlet_dof_tag function scatter_free_and_dirichlet_values(f::UnconstrainedFESpace,free_values,dirichlet_values) diff --git a/src/MultiField/MultiFieldFESpaces.jl b/src/MultiField/MultiFieldFESpaces.jl index 0df1528a7..47cf02210 100644 --- a/src/MultiField/MultiFieldFESpaces.jl +++ b/src/MultiField/MultiFieldFESpaces.jl @@ -137,13 +137,6 @@ function FESpaces.get_free_dof_ids(f::MultiFieldFESpace,::BlockMultiFieldStyle{N return BlockArrays.blockedrange(block_num_dofs) end -function FESpaces.zero_free_values(f::MultiFieldFESpace{<:BlockMultiFieldStyle{NB,SB,P}}) where {NB,SB,P} - block_ranges = get_block_ranges(NB,SB,P) - block_num_dofs = map(range->sum(map(num_free_dofs,f.spaces[range])),block_ranges) - block_vtypes = map(range->get_vector_type(first(f.spaces[range])),block_ranges) - return mortar(map(allocate_vector,block_vtypes,block_num_dofs)) -end - FESpaces.get_dof_value_type(f::MultiFieldFESpace{MS,CS,V}) where {MS,CS,V} = eltype(V) FESpaces.get_vector_type(f::MultiFieldFESpace) = f.vector_type diff --git a/src/ODEs/TransientFETools/TransientFESpaces.jl b/src/ODEs/TransientFETools/TransientFESpaces.jl index b6312b96b..29c3bb733 100644 --- a/src/ODEs/TransientFETools/TransientFESpaces.jl +++ b/src/ODEs/TransientFETools/TransientFESpaces.jl @@ -206,7 +206,9 @@ function zero_free_values(f::TransientMultiFieldTrialFESpace{<:BlockMultiFieldSt block_ranges = get_block_ranges(NB,SB,P) block_num_dofs = map(range->sum(map(num_free_dofs,f.spaces[range])),block_ranges) block_vtypes = map(range->get_vector_type(first(f.spaces[range])),block_ranges) - return mortar(map(allocate_vector,block_vtypes,block_num_dofs)) + values = mortar(map(allocate_vector,block_vtypes,block_num_dofs)) + fill!(values,zero(eltype(values))) + return values end get_dof_value_type(f::TransientMultiFieldTrialFESpace{MS,CS,V}) where {MS,CS,V} = eltype(V) From 5438ce0766e8d87666af6f1c6da5bbd7ffb65d57 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 7 Dec 2023 16:58:21 +1100 Subject: [PATCH 5/5] Updated NEWS --- NEWS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index 333d7726f..ab1508adf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Changed how `allocate_vector` works. Now it only allocates, instead of allocating+initialising to zero. Since PR[#963](https://github.com/gridap/Gridap.jl/pull/963). + ## [0.17.21] - 2023-12-04 ### Added