annotate src/SbpOperators/constantstenciloperator.jl @ 637:4a81812150f4 feature/volume_and_boundary_operators

Change qudrature closure from tuple of reals to tuple of Stencils. Also remove parametrization of stencil width in D2 since this was illformed for the 2nd order case.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sun, 03 Jan 2021 18:15:14 +0100
parents d1929491180b
children
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
542
011ca1639153 Remove Index{Unknown} and replace with general Any implementations
Jonatan Werpers <jonatan@werpers.com>
parents: 333
diff changeset
17 @inline function apply_2nd_derivative(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, i)
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
542
011ca1639153 Remove Index{Unknown} and replace with general Any implementations
Jonatan Werpers <jonatan@werpers.com>
parents: 333
diff changeset
29 function apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i, N::Integer) where T
011ca1639153 Remove Index{Unknown} and replace with general Any implementations
Jonatan Werpers <jonatan@werpers.com>
parents: 333
diff changeset
30 r = getregion(i, closuresize(op), N)
560
d1929491180b Change variable names for som indecies to make them all concistent
Jonatan Werpers <jonatan@werpers.com>
parents: 543
diff changeset
31 return apply_quadrature(op, h, v, Index(i, r), N)
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
32 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
33 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
34
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
35 # 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
36 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
37 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
38 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
39
542
011ca1639153 Remove Index{Unknown} and replace with general Any implementations
Jonatan Werpers <jonatan@werpers.com>
parents: 333
diff changeset
40 function apply_inverse_quadrature(op::ConstantStencilOperator, h_inv::Real, v::T, i, N::Integer) where T
011ca1639153 Remove Index{Unknown} and replace with general Any implementations
Jonatan Werpers <jonatan@werpers.com>
parents: 333
diff changeset
41 r = getregion(i, closuresize(op), N)
560
d1929491180b Change variable names for som indecies to make them all concistent
Jonatan Werpers <jonatan@werpers.com>
parents: 543
diff changeset
42 return apply_inverse_quadrature(op, h_inv, v, Index(i, r), N)
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
43 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
44
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
45 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
46
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 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
48 @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
49 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
50 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
51 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
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
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 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
55 @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
56 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
57 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
58 -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
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
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 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
62
543
1a53eb83ed24 Remove some unecessary Index types
Jonatan Werpers <jonatan@werpers.com>
parents: 542
diff changeset
63 function apply_normal_derivative(op::ConstantStencilOperator, h_inv::Real, v::Number, i, N::Integer, ::Type{Lower})
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
64 @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
65 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
66 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
67 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
68 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
69
543
1a53eb83ed24 Remove some unecessary Index types
Jonatan Werpers <jonatan@werpers.com>
parents: 542
diff changeset
70 function apply_normal_derivative(op::ConstantStencilOperator, h_inv::Real, v::Number, i, N::Integer, ::Type{Upper})
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
71 @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
72 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
73 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
74 -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
75 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
76
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 export apply_normal_derivative