Mercurial > repos > public > sbplib_julia
comparison DiffOps/src/laplace.jl @ 284:0b8e041a1873 boundary_conditions
Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Also add a whole bunch of questions and todos
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Thu, 18 Jun 2020 22:07:10 +0200 |
| parents | 12a12a5cd973 |
| children | e21dcda55163 |
comparison
equal
deleted
inserted
replaced
| 283:12a12a5cd973 | 284:0b8e041a1873 |
|---|---|
| 1 struct Laplace{Dim,T<:Real,N,M,K} <: TensorOperator{T,Dim} | 1 struct Laplace{Dim,T<:Real,N,M,K} <: TensorOperator{T,Dim} |
| 2 grid::EquidistantGrid{Dim,T} | 2 grid::EquidistantGrid{Dim,T} # TODO: Should this be here? Should probably be possible to applay a Laplace object to any size grid function |
| 3 a::T # TODO: Better name? | 3 a::T # TODO: Better name? |
| 4 op::D2{T,N,M,K} | 4 op::D2{T,N,M,K} |
| 5 end | 5 end |
| 6 export Laplace | 6 export Laplace |
| 7 | 7 |
| 8 LazyTensors.domain_size(H::Laplace{Dim}, range_size::NTuple{Dim,Integer}) where Dim = size(L.grid) | 8 # At the moment the grid property is used all over. It could possibly be removed if we implement all the 1D operators as TensorMappings |
| 9 | |
| 10 LazyTensors.domain_size(H::Laplace{Dim}, range_size::NTuple{Dim,Integer}) where Dim = range_size | |
| 9 | 11 |
| 10 function LazyTensors.apply(L::Laplace{Dim,T}, v::AbstractArray{T,Dim}, I::NTuple{Dim,Index}) where {T,Dim} | 12 function LazyTensors.apply(L::Laplace{Dim,T}, v::AbstractArray{T,Dim}, I::NTuple{Dim,Index}) where {T,Dim} |
| 11 error("not implemented") | 13 error("not implemented") |
| 12 end | 14 end |
| 13 | 15 |
| 44 op::D2{T,N,M,K} | 46 op::D2{T,N,M,K} |
| 45 grid::EquidistantGrid{Dim,T} | 47 grid::EquidistantGrid{Dim,T} |
| 46 end | 48 end |
| 47 export Quadrature | 49 export Quadrature |
| 48 | 50 |
| 49 LazyTensors.domain_size(H::Quadrature{Dim}, range_size::NTuple{Dim,Integer}) where Dim = size(H.grid) | 51 LazyTensors.domain_size(H::Quadrature{Dim}, range_size::NTuple{Dim,Integer}) where Dim = range_size |
| 50 | 52 |
| 51 @inline function LazyTensors.apply(H::Quadrature{2,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where T | 53 @inline function LazyTensors.apply(H::Quadrature{2,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where T |
| 52 N = size(H.grid) | 54 N = size(H.grid) |
| 53 # Quadrature in x direction | 55 # Quadrature in x direction |
| 54 @inbounds q = apply_quadrature(H.op, spacing(H.grid)[1], v[I] , I[1], N[1]) | 56 @inbounds q = apply_quadrature(H.op, spacing(H.grid)[1], v[I] , I[1], N[1]) |
| 69 op::D2{T,N,M,K} | 71 op::D2{T,N,M,K} |
| 70 grid::EquidistantGrid{Dim,T} | 72 grid::EquidistantGrid{Dim,T} |
| 71 end | 73 end |
| 72 export InverseQuadrature | 74 export InverseQuadrature |
| 73 | 75 |
| 74 LazyTensors.domain_size(H_inv::InverseQuadrature{Dim}, range_size::NTuple{Dim,Integer}) where Dim = size(H_inv.grid) | 76 LazyTensors.domain_size(H_inv::InverseQuadrature{Dim}, range_size::NTuple{Dim,Integer}) where Dim = range_size |
| 75 | 77 |
| 76 @inline function LazyTensors.apply(H_inv::InverseQuadrature{2,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where T | 78 @inline function LazyTensors.apply(H_inv::InverseQuadrature{2,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where T |
| 77 N = size(H_inv.grid) | 79 N = size(H_inv.grid) |
| 78 # Inverse quadrature in x direction | 80 # Inverse quadrature in x direction |
| 79 @inbounds q_inv = apply_inverse_quadrature(H_inv.op, inverse_spacing(H_inv.grid)[1], v[I] , I[1], N[1]) | 81 @inbounds q_inv = apply_inverse_quadrature(H_inv.op, inverse_spacing(H_inv.grid)[1], v[I] , I[1], N[1]) |
| 96 end | 98 end |
| 97 export BoundaryValue | 99 export BoundaryValue |
| 98 | 100 |
| 99 # TODO: This is obviouly strange. Is domain_size just discarded? Is there a way to avoid storing grid in BoundaryValue? | 101 # TODO: This is obviouly strange. Is domain_size just discarded? Is there a way to avoid storing grid in BoundaryValue? |
| 100 # Can we give special treatment to TensorMappings that go to a higher dim? | 102 # Can we give special treatment to TensorMappings that go to a higher dim? |
| 101 LazyTensors.range_size(e::BoundaryValue{T}, domain_size::NTuple{1,Integer}) where T = size(e.grid) | 103 function LazyTensors.range_size(e::BoundaryValue{T}, domain_size::NTuple{1,Integer}) where T |
| 104 if dim(e.bId) == 1 | |
| 105 return (missing, domain_size[1]) | |
| 106 elseif dim(e.bId) == 2 | |
| 107 return (domain_size[1], missing) | |
| 108 end | |
| 109 end | |
| 102 LazyTensors.domain_size(e::BoundaryValue{T}, range_size::NTuple{2,Integer}) where T = (range_size[3-dim(e.bId)],) | 110 LazyTensors.domain_size(e::BoundaryValue{T}, range_size::NTuple{2,Integer}) where T = (range_size[3-dim(e.bId)],) |
| 111 # TODO: Make a nicer solution for 3-dim(e.bId) | |
| 103 | 112 |
| 104 # TODO: Make this independent of dimension | 113 # TODO: Make this independent of dimension |
| 105 function LazyTensors.apply(e::BoundaryValue{T}, v::AbstractArray{T}, I::NTuple{2,Index}) where T | 114 function LazyTensors.apply(e::BoundaryValue{T}, v::AbstractArray{T}, I::NTuple{2,Index}) where T |
| 106 i = I[dim(e.bId)] | 115 i = I[dim(e.bId)] |
| 107 j = I[3-dim(e.bId)] | 116 j = I[3-dim(e.bId)] |
| 126 end | 135 end |
| 127 export NormalDerivative | 136 export NormalDerivative |
| 128 | 137 |
| 129 # TODO: This is obviouly strange. Is domain_size just discarded? Is there a way to avoid storing grid in BoundaryValue? | 138 # TODO: This is obviouly strange. Is domain_size just discarded? Is there a way to avoid storing grid in BoundaryValue? |
| 130 # Can we give special treatment to TensorMappings that go to a higher dim? | 139 # Can we give special treatment to TensorMappings that go to a higher dim? |
| 131 LazyTensors.range_size(e::NormalDerivative, domain_size::NTuple{1,Integer}) = size(e.grid) | 140 function LazyTensors.range_size(e::NormalDerivative, domain_size::NTuple{1,Integer}) |
| 141 if dim(e.bId) == 1 | |
| 142 return (missing, domain_size[1]) | |
| 143 elseif dim(e.bId) == 2 | |
| 144 return (domain_size[1], missing) | |
| 145 end | |
| 146 end | |
| 132 LazyTensors.domain_size(e::NormalDerivative, range_size::NTuple{2,Integer}) = (range_size[3-dim(e.bId)],) | 147 LazyTensors.domain_size(e::NormalDerivative, range_size::NTuple{2,Integer}) = (range_size[3-dim(e.bId)],) |
| 133 | 148 |
| 134 # TODO: Not type stable D:< | 149 # TODO: Not type stable D:< |
| 135 # TODO: Make this independent of dimension | 150 # TODO: Make this independent of dimension |
| 136 function LazyTensors.apply(d::NormalDerivative{T}, v::AbstractArray{T}, I::NTuple{2,Index}) where T | 151 function LazyTensors.apply(d::NormalDerivative{T}, v::AbstractArray{T}, I::NTuple{2,Index}) where T |
