Mercurial > repos > public > sbplib_julia
changeset 1023:52f07c77299d refactor/sbpoperators/inflation
Merge refactor/lazy_tensors
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 21 Mar 2022 09:51:07 +0100 |
parents | bbbc31953367 (diff) 56fe037641ef (current diff) |
children | 5be17f647018 |
files | src/LazyTensors/lazy_tensor_operations.jl src/SbpOperators/boundaryops/boundary_operator.jl src/SbpOperators/volumeops/volume_operator.jl test/LazyTensors/lazy_tensor_operations_test.jl |
diffstat | 4 files changed, 32 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl Mon Mar 21 09:26:13 2022 +0100 +++ b/src/LazyTensors/lazy_tensor_operations.jl Mon Mar 21 09:51:07 2022 +0100 @@ -268,6 +268,20 @@ LazyOuterProduct(tms::Vararg{LazyTensor}) = foldl(LazyOuterProduct, tms) + +""" + inflate(tm, sz, dir) + +Inflate `tm` with identity tensors in all directions `d` for `d != dir`. + +# TODO: Describe when it is useful +""" +function inflate(tm::LazyTensor, sz, dir) + Is = IdentityTensor{eltype(tm)}.(sz) + parts = Base.setindex(Is, tm, dir) + return foldl(⊗, parts) +end + function check_domain_size(tm::LazyTensor, sz) if domain_size(tm) != sz throw(DomainSizeMismatch(tm,sz))
--- a/src/SbpOperators/boundaryops/boundary_operator.jl Mon Mar 21 09:26:13 2022 +0100 +++ b/src/SbpOperators/boundaryops/boundary_operator.jl Mon Mar 21 09:51:07 2022 +0100 @@ -12,19 +12,14 @@ function boundary_operator(grid::EquidistantGrid, closure_stencil, boundary::CartesianBoundary) #TODO:Check that dim(boundary) <= Dim? - # Create 1D boundary operator - r = region(boundary) d = dim(boundary) - op = BoundaryOperator(restrict(grid, d), closure_stencil, r) + op = BoundaryOperator(restrict(grid, d), closure_stencil, region(boundary)) # Create 1D IdentityTensors for each coordinate direction one_d_grids = restrict.(Ref(grid), Tuple(1:dimension(grid))) Is = IdentityTensor{eltype(grid)}.(size.(one_d_grids)) - # Formulate the correct outer product sequence of the identity mappings and - # the boundary operator - parts = Base.setindex(Is, op, d) - return foldl(⊗, parts) + return LazyTensors.inflate(op, size(grid), d) end """
--- a/src/SbpOperators/volumeops/volume_operator.jl Mon Mar 21 09:26:13 2022 +0100 +++ b/src/SbpOperators/volumeops/volume_operator.jl Mon Mar 21 09:51:07 2022 +0100 @@ -12,16 +12,10 @@ function volume_operator(grid::EquidistantGrid, inner_stencil, closure_stencils, parity, direction) #TODO: Check that direction <= Dim? - # Create 1D volume operator in along coordinate direction op = VolumeOperator(restrict(grid, direction), inner_stencil, closure_stencils, parity) - # Create 1D IdentityTensors for each coordinate direction - one_d_grids = restrict.(Ref(grid), Tuple(1:dimension(grid))) - Is = IdentityTensor{eltype(grid)}.(size.(one_d_grids)) - # Formulate the correct outer product sequence of the identity mappings and - # the volume operator - parts = Base.setindex(Is, op, direction) - return foldl(⊗, parts) + return LazyTensors.inflate(op, size(grid), direction) end +# TBD: Should the inflation happen here or should we remove this method and do it at the caller instead? """ VolumeOperator{T,N,M,K} <: TensorOperator{T,1} @@ -59,3 +53,4 @@ r = getregion(i, closure_size(op), op.size[1]) return LazyTensors.apply(op, v, Index(i, r)) end +# TODO: Move this to LazyTensors when we have the region communication down.
--- a/test/LazyTensors/lazy_tensor_operations_test.jl Mon Mar 21 09:26:13 2022 +0100 +++ b/test/LazyTensors/lazy_tensor_operations_test.jl Mon Mar 21 09:51:07 2022 +0100 @@ -358,3 +358,16 @@ @test I1⊗Ã⊗I2 == InflatedLazyTensor(I1, Ã, I2) end end + +@testset "inflate" begin + I = LazyTensors.inflate(IdentityTensor(),(3,4,5,6), 2) + @test I isa LazyTensor{Float64, 3,3} + @test range_size(I) == (3,5,6) + @test domain_size(I) == (3,5,6) + + # TODO: More tests + + # Check that the dir is inbounds + + # tm = ScalingOperator(2., (4,)) +end