Mercurial > repos > public > sbplib_julia
comparison DiffOps/src/laplace.jl @ 235:a5fdc00d5070 boundary_conditions
Fix a bunch of compilation errors
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Wed, 26 Jun 2019 17:54:32 +0200 |
| parents | 5acef2d5db2e |
| children | 60011a10e17d |
comparison
equal
deleted
inserted
replaced
| 234:d119dfdd749c | 235:a5fdc00d5070 |
|---|---|
| 1 struct NormalDerivative{N,M,K} | 1 """ |
| 2 op::D2{Float64,N,M,K} | 2 NormalDerivative{T,N,M,K} <: TensorMapping{T,2,1} |
| 3 | |
| 4 Implements the boundary operator `d` as a TensorMapping | |
| 5 """ | |
| 6 struct NormalDerivative{T,N,M,K} <: TensorMapping{T,2,1} | |
| 7 op::D2{T,N,M,K} | |
| 3 grid::EquidistantGrid | 8 grid::EquidistantGrid |
| 4 bId::CartesianBoundary | 9 bId::CartesianBoundary |
| 5 end | 10 end |
| 6 | 11 export NormalDerivative |
| 7 function apply_transpose(d::NormalDerivative, v::AbstractArray, I::Integer) | |
| 8 u = selectdim(v,3-dim(d.bId),I) | |
| 9 return apply_d(d.op, d.grid.inverse_spacing[dim(d.bId)], u, region(d.bId)) | |
| 10 end | |
| 11 | 12 |
| 12 # Not correct abstraction level | 13 # Not correct abstraction level |
| 13 # TODO: Not type stable D:< | 14 # TODO: Not type stable D:< |
| 14 function apply(d::NormalDerivative, v::AbstractArray, I::Tuple{Integer,Integer}) | 15 function apply(d::NormalDerivative, v::AbstractArray, I::CartesianIndex{2}) |
| 15 i = I[dim(d.bId)] | 16 i = I[dim(d.bId)] |
| 16 j = I[3-dim(d.bId)] | 17 j = I[3-dim(d.bId)] |
| 17 N_i = d.grid.size[dim(d.bId)] | 18 N_i = d.grid.size[dim(d.bId)] |
| 18 | 19 |
| 19 r = getregion(i, closureSize(d.op), N_i) | 20 r = getregion(i, closureSize(d.op), N_i) |
| 28 elseif r == Upper | 29 elseif r == Upper |
| 29 return d.grid.inverse_spacing[dim(d.bId)]*d.op.dClosure[N_i-j]*v[j] | 30 return d.grid.inverse_spacing[dim(d.bId)]*d.op.dClosure[N_i-j]*v[j] |
| 30 end | 31 end |
| 31 end | 32 end |
| 32 | 33 |
| 33 struct BoundaryValue{N,M,K} | 34 function apply_transpose(d::NormalDerivative, v::AbstractArray, I::CartesianIndex{1}) |
| 34 op::D2{Float64,N,M,K} | 35 u = selectdim(v,3-dim(d.bId),I) |
| 36 return apply_d(d.op, d.grid.inverse_spacing[dim(d.bId)], u, region(d.bId)) | |
| 37 end | |
| 38 | |
| 39 | |
| 40 """ | |
| 41 BoundaryValue{T,N,M,K} <: TensorMapping{T,2,1} | |
| 42 | |
| 43 Implements the boundary operator `e` as a TensorMapping | |
| 44 """ | |
| 45 struct BoundaryValue{T,N,M,K} <: TensorMapping{T,2,1} | |
| 46 op::D2{T,N,M,K} | |
| 35 grid::EquidistantGrid | 47 grid::EquidistantGrid |
| 36 bId::CartesianBoundary | 48 bId::CartesianBoundary |
| 37 end | 49 end |
| 50 export BoundaryValue | |
| 38 | 51 |
| 39 function apply(e::BoundaryValue, v::AbstractArray, I::Tuple{Integer,Integer}) | 52 # TODO: This is obviouly strange. Is domain_size just discarded? Is there a way to avoid storing grid in BoundaryValue? |
| 53 # Can we give special treatment to TensorMappings that go to a higher dim? | |
| 54 LazyTensors.range_size(e::BoundaryValue{T}, domain_size::NTuple{1,Integer}) where T = size(e.grid) | |
| 55 LazyTensors.domain_size(e::BoundaryValue{T}, range_size::NTuple{2,Integer}) where T = (range_size[3-dim(e.bId)],); | |
| 56 | |
| 57 function LazyTensors.apply(e::BoundaryValue, v::AbstractArray, I::CartesianIndex{2}) | |
| 40 i = I[dim(e.bId)] | 58 i = I[dim(e.bId)] |
| 41 j = I[3-dim(e.bId)] | 59 j = I[3-dim(e.bId)] |
| 42 N_i = e.grid.size[dim(e.bId)] | 60 N_i = e.grid.size[dim(e.bId)] |
| 43 | 61 |
| 44 r = getregion(i, closureSize(e.op), N_i) | 62 r = getregion(i, closureSize(e.op), N_i) |
| 53 elseif r == Upper | 71 elseif r == Upper |
| 54 return e.op.eClosure[N_i-j]*v[j] | 72 return e.op.eClosure[N_i-j]*v[j] |
| 55 end | 73 end |
| 56 end | 74 end |
| 57 | 75 |
| 58 function apply_transpose(e::BoundaryValue, v::AbstractArray, I::Integer) | 76 function LazyTensors.apply_transpose(e::BoundaryValue, v::AbstractArray, I::CartesianIndex{1}) |
| 59 u = selectdim(v,3-dim(e.bId),I) | 77 u = selectdim(v,3-dim(e.bId),I) |
| 60 return apply_e(e.op, u, region(e.bId)) | 78 return apply_e(e.op, u, region(e.bId)) |
| 61 end | 79 end |
| 80 | |
| 81 | |
| 62 | 82 |
| 63 struct Laplace{Dim,T<:Real,N,M,K} <: DiffOpCartesian{Dim} | 83 struct Laplace{Dim,T<:Real,N,M,K} <: DiffOpCartesian{Dim} |
| 64 grid::EquidistantGrid{Dim,T} | 84 grid::EquidistantGrid{Dim,T} |
| 65 a::T | 85 a::T |
| 66 op::D2{Float64,N,M,K} | 86 op::D2{Float64,N,M,K} |
