Mercurial > repos > public > sbplib_julia
comparison DiffOps/src/DiffOps.jl @ 223:b3506cfbb9d8 package_refactor
Add some missing exports
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 26 Jun 2019 13:57:50 +0200 |
parents | 235f0a771c8f |
children | eb8525066f9b 5acef2d5db2e |
comparison
equal
deleted
inserted
replaced
222:6e3cdf57f0a1 | 223:b3506cfbb9d8 |
---|---|
1 module DiffOps | 1 module DiffOps |
2 | 2 |
3 using RegionIndices | 3 using RegionIndices |
4 using SbpOperators | 4 using SbpOperators |
5 using Grids | 5 using Grids |
6 | |
7 export Laplace | |
6 | 8 |
7 abstract type DiffOp end | 9 abstract type DiffOp end |
8 | 10 |
9 # TBD: The "error("not implemented")" thing seems to be hiding good error information. How to fix that? Different way of saying that these should be implemented? | 11 # TBD: The "error("not implemented")" thing seems to be hiding good error information. How to fix that? Different way of saying that these should be implemented? |
10 function apply(D::DiffOp, v::AbstractVector, i::Int) | 12 function apply(D::DiffOp, v::AbstractVector, i::Int) |
27 u[I] = apply(D, v, I) | 29 u[I] = apply(D, v, I) |
28 end | 30 end |
29 | 31 |
30 return nothing | 32 return nothing |
31 end | 33 end |
34 export apply! | |
32 | 35 |
33 function apply_region!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}) where T | 36 function apply_region!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}) where T |
34 apply_region!(D, u, v, Lower, Lower) | 37 apply_region!(D, u, v, Lower, Lower) |
35 apply_region!(D, u, v, Lower, Interior) | 38 apply_region!(D, u, v, Lower, Interior) |
36 apply_region!(D, u, v, Lower, Upper) | 39 apply_region!(D, u, v, Lower, Upper) |
49 @inbounds indextuple = (Index{r1}(I[1]), Index{r2}(I[2])) | 52 @inbounds indextuple = (Index{r1}(I[1]), Index{r2}(I[2])) |
50 @inbounds u[I] = apply(D, v, indextuple) | 53 @inbounds u[I] = apply(D, v, indextuple) |
51 end | 54 end |
52 return nothing | 55 return nothing |
53 end | 56 end |
57 export apply_region! | |
54 | 58 |
55 function apply_tiled!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}) where T | 59 function apply_tiled!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}) where T |
56 apply_region_tiled!(D, u, v, Lower, Lower) | 60 apply_region_tiled!(D, u, v, Lower, Lower) |
57 apply_region_tiled!(D, u, v, Lower, Interior) | 61 apply_region_tiled!(D, u, v, Lower, Interior) |
58 apply_region_tiled!(D, u, v, Lower, Upper) | 62 apply_region_tiled!(D, u, v, Lower, Upper) |
75 u[I] = apply(D, v, (Index{r1}(I[1]), Index{r2}(I[2]))) | 79 u[I] = apply(D, v, (Index{r1}(I[1]), Index{r2}(I[2]))) |
76 end | 80 end |
77 end | 81 end |
78 return nothing | 82 return nothing |
79 end | 83 end |
84 export apply_region_tiled! | |
80 | 85 |
81 function apply(D::DiffOp, v::AbstractVector)::AbstractVector | 86 function apply(D::DiffOp, v::AbstractVector)::AbstractVector |
82 u = zeros(eltype(v), size(v)) | 87 u = zeros(eltype(v), size(v)) |
83 apply!(D,v,u) | 88 apply!(D,v,u) |
84 return u | 89 return u |
85 end | 90 end |
91 | |
92 export apply | |
86 | 93 |
87 struct NormalDerivative{N,M,K} | 94 struct NormalDerivative{N,M,K} |
88 op::D2{Float64,N,M,K} | 95 op::D2{Float64,N,M,K} |
89 grid::EquidistantGrid | 96 grid::EquidistantGrid |
90 bId::CartesianBoundary | 97 bId::CartesianBoundary |
148 | 155 |
149 struct Laplace{Dim,T<:Real,N,M,K} <: DiffOpCartesian{Dim} | 156 struct Laplace{Dim,T<:Real,N,M,K} <: DiffOpCartesian{Dim} |
150 grid::EquidistantGrid{Dim,T} | 157 grid::EquidistantGrid{Dim,T} |
151 a::T | 158 a::T |
152 op::D2{Float64,N,M,K} | 159 op::D2{Float64,N,M,K} |
153 e::BoundaryValue | 160 # e::BoundaryValue |
154 d::NormalDerivative | 161 # d::NormalDerivative |
155 end | 162 end |
156 | 163 |
157 function apply(L::Laplace{Dim}, v::AbstractArray{T,Dim} where T, I::CartesianIndex{Dim}) where Dim | 164 function apply(L::Laplace{Dim}, v::AbstractArray{T,Dim} where T, I::CartesianIndex{Dim}) where Dim |
158 error("not implemented") | 165 error("not implemented") |
159 end | 166 end |
160 | 167 |
161 # u = L*v | 168 # u = L*v |
162 function apply(L::Laplace{1}, v::AbstractVector, i::Int) | 169 function apply(L::Laplace{1}, v::AbstractVector, i::Int) |
163 uᵢ = L.a * apply(L.op, L.grid.spacing[1], v, i) | 170 uᵢ = L.a * SbpOperators.apply(L.op, L.grid.spacing[1], v, i) |
164 return uᵢ | 171 return uᵢ |
165 end | 172 end |
166 | 173 |
167 @inline function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::Tuple{Index{R1}, Index{R2}}) where {R1, R2} | 174 @inline function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::Tuple{Index{R1}, Index{R2}}) where {R1, R2} |
168 # 2nd x-derivative | 175 # 2nd x-derivative |
169 @inbounds vx = view(v, :, Int(I[2])) | 176 @inbounds vx = view(v, :, Int(I[2])) |
170 @inbounds uᵢ = L.a*apply(L.op, L.grid.inverse_spacing[1], vx , I[1]) | 177 @inbounds uᵢ = L.a*SbpOperators.apply(L.op, L.grid.inverse_spacing[1], vx , I[1]) |
171 # 2nd y-derivative | 178 # 2nd y-derivative |
172 @inbounds vy = view(v, Int(I[1]), :) | 179 @inbounds vy = view(v, Int(I[1]), :) |
173 @inbounds uᵢ += L.a*apply(L.op, L.grid.inverse_spacing[2], vy, I[2]) | 180 @inbounds uᵢ += L.a*SbpOperators.apply(L.op, L.grid.inverse_spacing[2], vy, I[2]) |
181 # NOTE: the package qualifier 'SbpOperators' can problably be removed once all "applying" objects use LazyTensors | |
174 return uᵢ | 182 return uᵢ |
175 end | 183 end |
176 | 184 |
177 # Slow but maybe convenient? | 185 # Slow but maybe convenient? |
178 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, i::CartesianIndex{2}) | 186 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, i::CartesianIndex{2}) |