From 869cb3461fb9d2106cb3259cf94a7fc9ae68570d Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Fri, 16 Aug 2024 11:56:08 +0200 Subject: [PATCH 1/5] Fixed issue in nullspace_linear_elasticity --- src/PartitionedArrays.jl | 3 ++- src/gallery.jl | 15 ++++++++++----- test/gallery_tests.jl | 16 +++++++++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/PartitionedArrays.jl b/src/PartitionedArrays.jl index 5575613c..5604ce68 100644 --- a/src/PartitionedArrays.jl +++ b/src/PartitionedArrays.jl @@ -180,7 +180,8 @@ include("p_timer.jl") export laplacian_fdm export laplacian_fem export linear_elasticity_fem -export node_coorinates_unit_cube +export node_coordinates_unit_cube +export nullspace_linear_elasticity export near_nullspace_linear_elasticity include("gallery.jl") diff --git a/src/gallery.jl b/src/gallery.jl index 231dcce1..f68fec9d 100644 --- a/src/gallery.jl +++ b/src/gallery.jl @@ -415,12 +415,12 @@ function node_to_dof_partition(node_partition,D) dof_partition end -function node_coorinates_unit_cube( +function node_coordinates_unit_cube( nodes_per_dir, # free (== interior) nodes parts_per_dir, parts, ; - split_format = Val(true), + split_format = Val(false), value_type::Type{Tv} = Float64,) where Tv function setup!(own_x,mynodes) @@ -443,7 +443,12 @@ function node_coorinates_unit_cube( x end -function near_nullspace_linear_elasticity(x, +function near_nullspace_linear_elasticity(a...;b...) + @warn "near_nullspace_linear_elasticity is deprecated, use nullspace_linear_elasticity instead" + nullspace_linear_elasticity(a...;b...) +end + +function nullspace_linear_elasticity(x, row_partition = node_to_dof_partition(partition(axes(x,1)),length(eltype(x))) ) T = eltype(x) @@ -461,10 +466,10 @@ function near_nullspace_linear_elasticity(x, dof_partition = row_partition split_format = Val(eltype(partition(x)) <: SplitVector) B = [ pzeros(Tv,dof_partition;split_format) for _ in 1:nb ] - near_nullspace_linear_elasticity!(B,x) + nullspace_linear_elasticity!(B,x) end -function near_nullspace_linear_elasticity!(B,x) +function nullspace_linear_elasticity!(B,x) D = length(eltype(x)) if D == 1 foreach(own_values(B[1])) do own_b diff --git a/test/gallery_tests.jl b/test/gallery_tests.jl index 07fb9a13..10bac623 100644 --- a/test/gallery_tests.jl +++ b/test/gallery_tests.jl @@ -32,20 +32,26 @@ function gallery_tests(distribute,parts_per_dir) @test isa(y,PVector) A = psparse(SparseMatrixCSR{1,Float64,Int32},args...) |> fetch A |> centralize |> display - Y = A*pones(axes(A,2)) + y = A*pones(axes(A,2)) @test isa(y,PVector) args = linear_elasticity_fem(nodes_per_dir,parts_per_dir,ranks) A = psparse(args...) |> fetch A |> centralize |> display - Y = A*pones(axes(A,2)) + y = A*pones(axes(A,2)) @test isa(y,PVector) - x = node_coorinates_unit_cube(nodes_per_dir,parts_per_dir,ranks) - B = near_nullspace_linear_elasticity(x) + x = node_coordinates_unit_cube(nodes_per_dir,parts_per_dir,ranks) + B = nullspace_linear_elasticity(x) @test isa(B[1],PVector) - B = near_nullspace_linear_elasticity(x,partition(axes(A,2))) + y = A*pones(axes(A,2)) + @test isa(y,PVector) + B = nullspace_linear_elasticity(x,partition(axes(A,2))) @test isa(B[1],PVector) + y = A*pones(axes(A,2)) + @test isa(Y,PVector) + y = A*B[1] + @test isa(y,PVector) end From 48ca58d927aab8e328477f7070c64f3321b61ad6 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Fri, 16 Aug 2024 12:02:44 +0200 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 10 ++++++++++ src/PartitionedArrays.jl | 1 + test/gallery_tests.jl | 3 +++ 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62dad742..ed377fb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ 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). +## "main" branch + +### Fixed +- Typo: `node_coorinates_unit_cube` -> `node_coordinates_unit_cube`. +- Bug in `nullspace_linear_elasticity`. + +### Deprecated + +- `near_nullspace_linear_elasticity` in favor of `nullspace_linear_elasticity`. + ## [0.5.2] - 2024-08-13 ### Added diff --git a/src/PartitionedArrays.jl b/src/PartitionedArrays.jl index 5604ce68..eef27803 100644 --- a/src/PartitionedArrays.jl +++ b/src/PartitionedArrays.jl @@ -182,6 +182,7 @@ export laplacian_fem export linear_elasticity_fem export node_coordinates_unit_cube export nullspace_linear_elasticity +export nullspace_linear_elasticity! export near_nullspace_linear_elasticity include("gallery.jl") diff --git a/test/gallery_tests.jl b/test/gallery_tests.jl index 10bac623..e7bd25d8 100644 --- a/test/gallery_tests.jl +++ b/test/gallery_tests.jl @@ -52,6 +52,9 @@ function gallery_tests(distribute,parts_per_dir) @test isa(Y,PVector) y = A*B[1] @test isa(y,PVector) + nullspace_linear_elasticity!(B,x) + y = A*B[1] + @test isa(y,PVector) end From ef77eeaadb605581db77004aaac66ca162f84649 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Fri, 16 Aug 2024 12:11:38 +0200 Subject: [PATCH 3/5] Fixing PVector with split_format --- src/p_vector.jl | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/p_vector.jl b/src/p_vector.jl index ca7a7fac..ea75e03c 100644 --- a/src/p_vector.jl +++ b/src/p_vector.jl @@ -527,6 +527,7 @@ struct SplitVectorAssemblyCache{A,B,C,D} buffer_snd::C # NB buffer_rcv::C exchange_setup::D + reversed::Bool end function Base.reverse(a::SplitVectorAssemblyCache) SplitVectorAssemblyCache( @@ -537,6 +538,7 @@ function Base.reverse(a::SplitVectorAssemblyCache) a.buffer_rcv, a.buffer_snd, a.exchange_setup, + !(a.reversed), ) end function copy_cache(a::SplitVectorAssemblyCache) @@ -549,23 +551,29 @@ function copy_cache(a::SplitVectorAssemblyCache) a.own_indices_rcv, buffer_snd, buffer_rcv, - a.exchange_setup + a.exchange_setup, + a.reversed, ) end function p_vector_cache_impl(::Type{<:SplitVector},vector_partition,index_partition) neighbors_snd,neighbors_rcv= assembly_neighbors(index_partition) indices_snd,indices_rcv = assembly_local_indices(index_partition,neighbors_snd,neighbors_rcv) - map(indices_snd,indices_rcv,index_partition) do ids_snd,ids_rcv,myids + ghost_indices_snd = map(indices_snd) do ids + JaggedArray(copy(ids.data),ids.ptrs) + end + own_indices_rcv = map(indices_rcv) do ids + JaggedArray(copy(ids.data),ids.ptrs) + end + foreach(ghost_indices_snd,own_indices_rcv,index_partition) do ids_snd,ids_rcv,myids map_local_to_ghost!(ids_snd.data,myids) map_local_to_own!(ids_rcv.data,myids) end - ghost_indices_snd = indices_snd - own_indices_rcv = indices_rcv - buffers_snd,buffers_rcv = map(assembly_buffers,vector_partition,indices_snd,indices_rcv) |> tuple_of_arrays + buffers_snd,buffers_rcv = map(assembly_buffers,vector_partition,ghost_indices_snd,own_indices_rcv) |> tuple_of_arrays graph = ExchangeGraph(neighbors_snd,neighbors_rcv) exchange_setup = setup_exchange(buffers_rcv,buffers_snd,graph) - SplitVectorAssemblyCache(neighbors_snd,neighbors_rcv,ghost_indices_snd,own_indices_rcv,buffers_snd,buffers_rcv,exchange_setup) + reversed = false + SplitVectorAssemblyCache(neighbors_snd,neighbors_rcv,ghost_indices_snd,own_indices_rcv,buffers_snd,buffers_rcv,exchange_setup,reversed) end function p_vector_cache_impl(::Type{<:SplitVector{<:JaggedArray}},vector_partition,index_partition) @@ -610,6 +618,7 @@ function assemble_impl!(f,vector_partition,cache::JaggedArrayAssemblyCache) end function assemble_impl!(f,vector_partition,cache::SplitVectorAssemblyCache) + reversed = cache.reversed ghost_indices_snd=cache.ghost_indices_snd own_indices_rcv=cache.own_indices_rcv neighbors_snd=cache.neighbors_snd @@ -618,7 +627,11 @@ function assemble_impl!(f,vector_partition,cache::SplitVectorAssemblyCache) buffer_rcv=cache.buffer_rcv exchange_setup=cache.exchange_setup foreach(vector_partition,ghost_indices_snd,buffer_snd) do values,ghost_indices_snd,buffer_snd - ghost_vals = values.blocks.ghost + if reversed + ghost_vals = values.blocks.own + else + ghost_vals = values.blocks.ghost + end for (p,hid) in enumerate(ghost_indices_snd.data) buffer_snd.data[p] = ghost_vals[hid] end @@ -629,7 +642,11 @@ function assemble_impl!(f,vector_partition,cache::SplitVectorAssemblyCache) @fake_async begin wait(t) foreach(vector_partition,own_indices_rcv,buffer_rcv) do values,own_indices_rcv,buffer_rcv - own_vals = values.blocks.own + if reversed + own_vals = values.blocks.ghost + else + own_vals = values.blocks.own + end for (p,oid) in enumerate(own_indices_rcv.data) own_vals[oid] = f(own_vals[oid],buffer_rcv.data[p]) end From c15c5077e7aef6c4b1ce2f404e53a120f9124783 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Fri, 16 Aug 2024 12:11:58 +0200 Subject: [PATCH 4/5] Adding more tests --- test/gallery_tests.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/gallery_tests.jl b/test/gallery_tests.jl index e7bd25d8..20c4905a 100644 --- a/test/gallery_tests.jl +++ b/test/gallery_tests.jl @@ -56,6 +56,21 @@ function gallery_tests(distribute,parts_per_dir) y = A*B[1] @test isa(y,PVector) + x = node_coordinates_unit_cube(nodes_per_dir,parts_per_dir,ranks,split_format=true) + B = nullspace_linear_elasticity(x) + @test isa(B[1],PVector) + y = A*pones(axes(A,2)) + @test isa(y,PVector) + B = nullspace_linear_elasticity(x,partition(axes(A,2))) + @test isa(B[1],PVector) + y = A*pones(axes(A,2)) + @test isa(Y,PVector) + y = A*B[1] + @test isa(y,PVector) + nullspace_linear_elasticity!(B,x) + y = A*B[1] + @test isa(y,PVector) + end From 9a0806e1aefb50b954fad1b2673580a7fcbdd2dd Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Fri, 16 Aug 2024 12:13:08 +0200 Subject: [PATCH 5/5] Release 0.5.3 --- CHANGELOG.md | 3 ++- Project.toml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed377fb8..aa8b5d39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +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). -## "main" branch +## [0.5.3] - 2024-08-16 ### Fixed - Typo: `node_coorinates_unit_cube` -> `node_coordinates_unit_cube`. - Bug in `nullspace_linear_elasticity`. +- Bug in `PVector` when working in split format. ### Deprecated diff --git a/Project.toml b/Project.toml index 49939155..73c8b770 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PartitionedArrays" uuid = "5a9dfac6-5c52-46f7-8278-5e2210713be9" authors = ["Francesc Verdugo and contributors"] -version = "0.5.2" +version = "0.5.3" [deps] CircularArrays = "7a955b69-7140-5f4e-a0ed-f168c5e2e749"