annotate src/SbpOperators/constantstenciloperator.jl @ 371:241bd2512c20 feature/lazy_function

Add a LazyFunctionArray that evaluates a function for each index.
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 30 Sep 2020 19:48:17 +0200
parents 01b851161018
children 011ca1639153
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
249
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
1 abstract type ConstantStencilOperator end
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
2
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
3 # Apply for different regions Lower/Interior/Upper or Unknown region
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
4 @inline function apply_2nd_derivative(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, i::Index{Lower})
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
5 return @inbounds h_inv*h_inv*apply_stencil(op.closureStencils[Int(i)], v, Int(i))
249
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
6 end
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
7
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
8 @inline function apply_2nd_derivative(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, i::Index{Interior})
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
9 return @inbounds h_inv*h_inv*apply_stencil(op.innerStencil, v, Int(i))
249
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
10 end
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
12 @inline function apply_2nd_derivative(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, i::Index{Upper})
249
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
13 N = length(v)
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
14 return @inbounds h_inv*h_inv*Int(op.parity)*apply_stencil_backwards(op.closureStencils[N-Int(i)+1], v, Int(i))
249
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
15 end
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
16
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
17 @inline function apply_2nd_derivative(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, index::Index{Unknown})
249
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
18 N = length(v)
271
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
19 r = getregion(Int(index), closuresize(op), N)
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
20 i = Index(Int(index), r)
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
21 return apply_2nd_derivative(op, h_inv, v, i)
249
7cb4492ccd60 Refactor package SbpOperators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
22 end
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
23 export apply_2nd_derivative
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
24
271
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
25 apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Index{Lower}, N::Integer) where T = v*h*op.quadratureClosure[Int(i)]
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
26 apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Index{Upper}, N::Integer) where T = v*h*op.quadratureClosure[N-Int(i)+1]
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
27 apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Index{Interior}, N::Integer) where T = v*h
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
28
271
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
29 function apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, index::Index{Unknown}, N::Integer) where T
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
30 r = getregion(Int(index), closuresize(op), N)
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
31 i = Index(Int(index), r)
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
32 return apply_quadrature(op, h, v, i, N)
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
33 end
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
34 export apply_quadrature
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
35
271
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
36 # TODO: Evaluate if divisions affect performance
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
37 apply_inverse_quadrature(op::ConstantStencilOperator, h_inv::Real, v::T, i::Index{Lower}, N::Integer) where T = h_inv*v/op.quadratureClosure[Int(i)]
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
38 apply_inverse_quadrature(op::ConstantStencilOperator, h_inv::Real, v::T, i::Index{Upper}, N::Integer) where T = h_inv*v/op.quadratureClosure[N-Int(i)+1]
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
39 apply_inverse_quadrature(op::ConstantStencilOperator, h_inv::Real, v::T, i::Index{Interior}, N::Integer) where T = v*h_inv
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
40
271
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
41 function apply_inverse_quadrature(op::ConstantStencilOperator, h_inv::Real, v::T, index::Index{Unknown}, N::Integer) where T
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
42 r = getregion(Int(index), closuresize(op), N)
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
43 i = Index(Int(index), r)
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
44 return apply_inverse_quadrature(op, h_inv, v, i, N)
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
45 end
ecd49ffe0bc8 Dispatch apply_quadrature and apply_inverse_quadrature on Index-type. Add convenience functions dispatching on integer-indices
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 269
diff changeset
46
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
47 export apply_inverse_quadrature
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
48
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
49 function apply_normal_derivative_transpose(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, ::Type{Lower})
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
50 @boundscheck if length(v) < closuresize(op)
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
51 throw(BoundsError())
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
52 end
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
53 h_inv*apply_stencil(op.dClosure,v,1)
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
54 end
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
55
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
56 function apply_normal_derivative_transpose(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, ::Type{Upper})
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
57 @boundscheck if length(v) < closuresize(op)
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
58 throw(BoundsError())
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
59 end
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
60 -h_inv*apply_stencil_backwards(op.dClosure,v,length(v))
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
61 end
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
62
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
63 export apply_normal_derivative_transpose
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
64
280
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 271
diff changeset
65 function apply_normal_derivative(op::ConstantStencilOperator, h_inv::Real, v::Number, i::Index, N::Integer, ::Type{Lower})
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 271
diff changeset
66 @boundscheck if !(0<length(Int(i)) <= N)
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
67 throw(BoundsError())
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
68 end
280
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 271
diff changeset
69 h_inv*op.dClosure[Int(i)-1]*v
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
70 end
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
71
280
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 271
diff changeset
72 function apply_normal_derivative(op::ConstantStencilOperator, h_inv::Real, v::Number, i::Index, N::Integer, ::Type{Upper})
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 271
diff changeset
73 @boundscheck if !(0<length(Int(i)) <= N)
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
74 throw(BoundsError())
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
75 end
280
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 271
diff changeset
76 -h_inv*op.dClosure[N-Int(i)]*v
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
77 end
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
78
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 253
diff changeset
79 export apply_normal_derivative