Mercurial > repos > public > sbplib_julia
comparison src/DiffOps/DiffOps.jl @ 333:01b851161018 refactor/combine_to_one_package
Start converting to one package by moving all the files to their correct location
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Fri, 25 Sep 2020 13:06:02 +0200 |
| parents | DiffOps/src/DiffOps.jl@d5475ad78b28 |
| children | f4e3e71a4ff4 |
comparison
equal
deleted
inserted
replaced
| 332:535f1bff4bcc | 333:01b851161018 |
|---|---|
| 1 module DiffOps | |
| 2 | |
| 3 using RegionIndices | |
| 4 using SbpOperators | |
| 5 using Grids | |
| 6 using LazyTensors | |
| 7 | |
| 8 """ | |
| 9 DiffOp | |
| 10 | |
| 11 Supertype of differential operator discretisations. | |
| 12 The action of the DiffOp is defined in the method | |
| 13 apply(D::DiffOp, v::AbstractVector, I...) | |
| 14 """ | |
| 15 abstract type DiffOp end | |
| 16 | |
| 17 function apply end | |
| 18 | |
| 19 function matrixRepresentation(D::DiffOp) | |
| 20 error("not implemented") | |
| 21 end | |
| 22 | |
| 23 abstract type DiffOpCartesian{Dim} <: DiffOp end | |
| 24 | |
| 25 # DiffOp must have a grid of dimension Dim!!! | |
| 26 function apply!(D::DiffOpCartesian{Dim}, u::AbstractArray{T,Dim}, v::AbstractArray{T,Dim}) where {T,Dim} | |
| 27 for I ∈ eachindex(D.grid) | |
| 28 u[I] = apply(D, v, I) | |
| 29 end | |
| 30 | |
| 31 return nothing | |
| 32 end | |
| 33 export apply! | |
| 34 | |
| 35 function apply_region!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}) where T | |
| 36 apply_region!(D, u, v, Lower, Lower) | |
| 37 apply_region!(D, u, v, Lower, Interior) | |
| 38 apply_region!(D, u, v, Lower, Upper) | |
| 39 apply_region!(D, u, v, Interior, Lower) | |
| 40 apply_region!(D, u, v, Interior, Interior) | |
| 41 apply_region!(D, u, v, Interior, Upper) | |
| 42 apply_region!(D, u, v, Upper, Lower) | |
| 43 apply_region!(D, u, v, Upper, Interior) | |
| 44 apply_region!(D, u, v, Upper, Upper) | |
| 45 return nothing | |
| 46 end | |
| 47 | |
| 48 # Maybe this should be split according to b3fbef345810 after all?! Seems like it makes performance more predictable | |
| 49 function apply_region!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}, r1::Type{<:Region}, r2::Type{<:Region}) where T | |
| 50 for I ∈ regionindices(D.grid.size, closuresize(D.op), (r1,r2)) | |
| 51 @inbounds indextuple = (Index{r1}(I[1]), Index{r2}(I[2])) | |
| 52 @inbounds u[I] = apply(D, v, indextuple) | |
| 53 end | |
| 54 return nothing | |
| 55 end | |
| 56 export apply_region! | |
| 57 | |
| 58 function apply_tiled!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}) where T | |
| 59 apply_region_tiled!(D, u, v, Lower, Lower) | |
| 60 apply_region_tiled!(D, u, v, Lower, Interior) | |
| 61 apply_region_tiled!(D, u, v, Lower, Upper) | |
| 62 apply_region_tiled!(D, u, v, Interior, Lower) | |
| 63 apply_region_tiled!(D, u, v, Interior, Interior) | |
| 64 apply_region_tiled!(D, u, v, Interior, Upper) | |
| 65 apply_region_tiled!(D, u, v, Upper, Lower) | |
| 66 apply_region_tiled!(D, u, v, Upper, Interior) | |
| 67 apply_region_tiled!(D, u, v, Upper, Upper) | |
| 68 return nothing | |
| 69 end | |
| 70 | |
| 71 using TiledIteration | |
| 72 function apply_region_tiled!(D::DiffOpCartesian{2}, u::AbstractArray{T,2}, v::AbstractArray{T,2}, r1::Type{<:Region}, r2::Type{<:Region}) where T | |
| 73 ri = regionindices(D.grid.size, closuresize(D.op), (r1,r2)) | |
| 74 # TODO: Pass Tilesize to function | |
| 75 for tileaxs ∈ TileIterator(axes(ri), padded_tilesize(T, (5,5), 2)) | |
| 76 for j ∈ tileaxs[2], i ∈ tileaxs[1] | |
| 77 I = ri[i,j] | |
| 78 u[I] = apply(D, v, (Index{r1}(I[1]), Index{r2}(I[2]))) | |
| 79 end | |
| 80 end | |
| 81 return nothing | |
| 82 end | |
| 83 export apply_region_tiled! | |
| 84 | |
| 85 function apply(D::DiffOp, v::AbstractVector)::AbstractVector | |
| 86 u = zeros(eltype(v), size(v)) | |
| 87 apply!(D,v,u) | |
| 88 return u | |
| 89 end | |
| 90 | |
| 91 export apply | |
| 92 | |
| 93 """ | |
| 94 A BoundaryCondition should implement the method | |
| 95 sat(::DiffOp, v::AbstractArray, data::AbstractArray, ...) | |
| 96 """ | |
| 97 abstract type BoundaryCondition end | |
| 98 | |
| 99 | |
| 100 end # module |
