Skip to content

Commit 71cd312

Browse files
committed
Added near_nullspace_linear_elasticity
1 parent 39bbe74 commit 71cd312

File tree

4 files changed

+155
-6
lines changed

4 files changed

+155
-6
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1414
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1515
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1616
SparseMatricesCSR = "a0a7dd2c-ebf4-11e9-1f05-cf50bc540ca1"
17+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1718

1819
[compat]
1920
CircularArrays = "1"
@@ -22,6 +23,7 @@ FillArrays = "0.10, 0.11, 0.12, 0.13, 1"
2223
IterativeSolvers = "0.9"
2324
MPI = "0.16, 0.17, 0.18, 0.19, 0.20"
2425
SparseMatricesCSR = "0.6"
26+
StaticArrays = "1"
2527
julia = "1.1"
2628

2729
[extras]

src/PartitionedArrays.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using SparseMatricesCSR
55
using LinearAlgebra
66
using Printf
77
using CircularArrays
8+
using StaticArrays
89
import MPI
910
import IterativeSolvers
1011
import Distances
@@ -179,6 +180,8 @@ include("p_timer.jl")
179180
export laplacian_fdm
180181
export laplacian_fem
181182
export linear_elasticity_fem
183+
export node_coorinates_unit_cube
184+
export near_nullspace_linear_elasticity
182185
include("gallery.jl")
183186

184187
end # module

src/gallery.jl

Lines changed: 144 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,18 @@ function linear_elasticity_fem(
378378
myI,myJ,myV
379379
end
380380
node_partition = uniform_partition(parts,parts_per_dir,nodes_per_dir)
381+
dof_partition = node_to_dof_partition(node_partition,length(nodes_per_dir))
382+
cell_partition = uniform_partition(parts,parts_per_dir,cells_per_dir)
383+
I,J,V = map(cell_partition) do cells
384+
setup(cells,Ti,Tv)
385+
end |> tuple_of_arrays
386+
I,J,V,dof_partition,dof_partition
387+
end
388+
389+
function node_to_dof_partition(node_partition,D)
381390
global_node_to_owner = global_to_owner(node_partition)
382391
dof_partition = map(node_partition) do mynodes
383-
D = length(nodes_per_dir)
392+
@assert ghost_length(mynodes) == 0
384393
own_to_global_node = own_to_global(mynodes)
385394
n_own_nodes = length(own_to_global_node)
386395
own_to_global_dof = zeros(Int,D*n_own_nodes)
@@ -403,11 +412,140 @@ function linear_elasticity_fem(
403412
mydofs = OwnAndGhostIndices(own_dofs,ghost_dofs,global_dof_to_owner)
404413
mydofs
405414
end
406-
cell_partition = uniform_partition(parts,parts_per_dir,cells_per_dir)
407-
I,J,V = map(cell_partition) do cells
408-
setup(cells,Ti,Tv)
409-
end |> tuple_of_arrays
410-
I,J,V,dof_partition,dof_partition
415+
dof_partition
411416
end
412417

418+
function node_coorinates_unit_cube(
419+
nodes_per_dir, # free (== interior) nodes
420+
parts_per_dir,
421+
parts,
422+
;
423+
split_format = Val(true),
424+
value_type::Type{Tv} = Float64,) where Tv
425+
426+
function setup!(own_x,mynodes)
427+
D = length(nodes_per_dir)
428+
h_per_dir = map(i->1/(i+1),nodes_per_dir)
429+
global_node_to_cartesian_global_node = CartesianIndices(nodes_per_dir)
430+
n_own_nodes = own_length(mynodes)
431+
own_to_global_node = own_to_global(mynodes)
432+
for own_node in 1:n_own_nodes
433+
global_node = own_to_global_node[own_node]
434+
cartesian_global_node = global_node_to_cartesian_global_node[global_node]
435+
xi = Tuple(cartesian_global_node)
436+
own_x[own_node] = h_per_dir .* xi
437+
end
438+
end
439+
node_partition = uniform_partition(parts,parts_per_dir,nodes_per_dir)
440+
T = SVector{length(nodes_per_dir),Tv}
441+
x = pzeros(T,node_partition;split_format)
442+
foreach(setup!,own_values(x),node_partition)
443+
x
444+
end
445+
446+
function near_nullspace_linear_elasticity(x,
447+
row_partition = node_to_dof_partition(partition(axes(x,1)),length(eltype(x)))
448+
)
449+
T = eltype(x)
450+
D = length(T)
451+
Tv = eltype(T)
452+
if D == 1
453+
nb = 1
454+
elseif D==2
455+
nb=3
456+
elseif D == 3
457+
nb = 6
458+
else
459+
error("case not implemented")
460+
end
461+
dof_partition = row_partition
462+
split_format = Val(eltype(partition(x)) <: SplitVector)
463+
B = [ pzeros(Tv,dof_partition;split_format) for _ in 1:nb ]
464+
near_nullspace_linear_elasticity!(B,x)
465+
end
466+
467+
function near_nullspace_linear_elasticity!(B,x)
468+
D = length(eltype(x))
469+
if D == 1
470+
foreach(own_values(B[1])) do own_b
471+
fill!(own_b,1)
472+
end
473+
elseif D==2
474+
foreach(own_values(B[1]),own_values(B[2]),own_values(x)) do own_b1,own_b2,own_x
475+
T = eltype(own_b1)
476+
n_own_nodes = length(own_x)
477+
for own_node in 1:n_own_nodes
478+
dof_x1 = (own_node-1)*2 + 1
479+
dof_x2 = (own_node-1)*2 + 2
480+
#
481+
own_b1[dof_x1] = one(T)
482+
own_b1[dof_x2] = zero(T)
483+
#
484+
own_b2[dof_x1] = zero(T)
485+
own_b2[dof_x2] = one(T)
486+
end
487+
end
488+
foreach(own_values(B[3]),own_values(x)) do own_b3,own_x
489+
T = eltype(own_b3)
490+
n_own_nodes = length(own_x)
491+
for own_node in 1:n_own_nodes
492+
x1,x2 = own_x[own_node]
493+
dof_x1 = (own_node-1)*2 + 1
494+
dof_x2 = (own_node-1)*2 + 2
495+
#
496+
own_b3[dof_x1] = -x2
497+
own_b3[dof_x2] = x1
498+
end
499+
end
500+
elseif D == 3
501+
foreach(own_values(B[1]),own_values(B[2]),own_values(B[3]),own_values(x)) do own_b1,own_b2,own_b3,own_x
502+
T = eltype(own_b1)
503+
n_own_nodes = length(own_x)
504+
for own_node in 1:n_own_nodes
505+
dof_x1 = (own_node-1)*3 + 1
506+
dof_x2 = (own_node-1)*3 + 2
507+
dof_x3 = (own_node-1)*3 + 3
508+
#
509+
own_b1[dof_x1] = one(T)
510+
own_b1[dof_x2] = zero(T)
511+
own_b1[dof_x3] = zero(T)
512+
#
513+
own_b2[dof_x1] = zero(T)
514+
own_b2[dof_x2] = one(T)
515+
own_b2[dof_x3] = zero(T)
516+
#
517+
own_b3[dof_x1] = zero(T)
518+
own_b3[dof_x2] = zero(T)
519+
own_b3[dof_x3] = one(T)
520+
end
521+
end
522+
foreach(own_values(B[4]),own_values(B[5]),own_values(B[6]),own_values(x)) do own_b4,own_b5,own_b6,own_x
523+
T = eltype(own_b4)
524+
n_own_nodes = length(own_x)
525+
for own_node in 1:n_own_nodes
526+
x1,x2,x3 = own_x[own_node]
527+
dof_x1 = (own_node-1)*3 + 1
528+
dof_x2 = (own_node-1)*3 + 2
529+
dof_x3 = (own_node-1)*3 + 3
530+
#
531+
own_b4[dof_x1] = -x2
532+
own_b4[dof_x2] = x1
533+
own_b4[dof_x3] = zero(T)
534+
#
535+
own_b5[dof_x1] = zero(T)
536+
own_b5[dof_x2] = -x3
537+
own_b5[dof_x3] = x2
538+
#
539+
own_b6[dof_x1] = x3
540+
own_b6[dof_x2] = zero(T)
541+
own_b6[dof_x3] = -x1
542+
end
543+
end
544+
else
545+
error("case not implemented")
546+
end
547+
B
548+
end
549+
550+
413551

test/gallery_tests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ function gallery_tests(distribute,parts_per_dir)
4141
Y = A*pones(axes(A,2))
4242
@test isa(y,PVector)
4343

44+
x = node_coorinates_unit_cube(nodes_per_dir,parts_per_dir,ranks)
45+
B = near_nullspace_linear_elasticity(x)
46+
@test isa(B[1],PVector)
47+
B = near_nullspace_linear_elasticity(x,partition(axes(A,2)))
48+
@test isa(B[1],PVector)
49+
4450
end
4551

4652

0 commit comments

Comments
 (0)