comparison SbpOperators/src/constantstenciloperator.jl @ 280:fe9e8737ddfa boundary_conditions

Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Wed, 08 Jan 2020 00:00:29 +0100
parents ecd49ffe0bc8
children 36206445018b
comparison
equal deleted inserted replaced
279:79d350003339 280:fe9e8737ddfa
18 N = length(v) 18 N = length(v)
19 r = getregion(Int(index), closuresize(op), N) 19 r = getregion(Int(index), closuresize(op), N)
20 i = Index(Int(index), r) 20 i = Index(Int(index), r)
21 return apply_2nd_derivative(op, h_inv, v, i) 21 return apply_2nd_derivative(op, h_inv, v, i)
22 end 22 end
23
24 # Wrapper functions for using regular indecies without specifying regions
25 @inline function apply_2nd_derivative(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, i::Int)
26 return apply_2nd_derivative(op, h_inv, v, Index{Unknown}(i))
27 end
28 export apply_2nd_derivative 23 export apply_2nd_derivative
29 24
30 apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Index{Lower}, N::Integer) where T = v*h*op.quadratureClosure[Int(i)] 25 apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Index{Lower}, N::Integer) where T = v*h*op.quadratureClosure[Int(i)]
31 apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Index{Upper}, N::Integer) where T = v*h*op.quadratureClosure[N-Int(i)+1] 26 apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Index{Upper}, N::Integer) where T = v*h*op.quadratureClosure[N-Int(i)+1]
32 apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Index{Interior}, N::Integer) where T = v*h 27 apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Index{Interior}, N::Integer) where T = v*h
33 28
34 function apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, index::Index{Unknown}, N::Integer) where T 29 function apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, index::Index{Unknown}, N::Integer) where T
35 r = getregion(Int(index), closuresize(op), N) 30 r = getregion(Int(index), closuresize(op), N)
36 i = Index(Int(index), r) 31 i = Index(Int(index), r)
37 return apply_quadrature(op, h, v, i, N) 32 return apply_quadrature(op, h, v, i, N)
38 end
39
40 # Wrapper functions for using regular indecies without specifying regions
41 function apply_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Integer, N::Integer) where T
42 return apply_quadrature(op, h, v, Index{Unknown}(i), N)
43 end 33 end
44 export apply_quadrature 34 export apply_quadrature
45 35
46 # TODO: Evaluate if divisions affect performance 36 # TODO: Evaluate if divisions affect performance
47 apply_inverse_quadrature(op::ConstantStencilOperator, h_inv::Real, v::T, i::Index{Lower}, N::Integer) where T = h_inv*v/op.quadratureClosure[Int(i)] 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)]
52 r = getregion(Int(index), closuresize(op), N) 42 r = getregion(Int(index), closuresize(op), N)
53 i = Index(Int(index), r) 43 i = Index(Int(index), r)
54 return apply_inverse_quadrature(op, h_inv, v, i, N) 44 return apply_inverse_quadrature(op, h_inv, v, i, N)
55 end 45 end
56 46
57 # Wrapper functions for using regular indecies without specifying regions
58 function apply_inverse_quadrature(op::ConstantStencilOperator, h::Real, v::T, i::Integer, N::Integer) where T
59 return apply_inverse_quadrature(op, h, v, Index{Unknown}(i), N)
60 end
61 export apply_inverse_quadrature 47 export apply_inverse_quadrature
62 48
63 function apply_boundary_value_transpose(op::ConstantStencilOperator, v::AbstractVector, ::Type{Lower}) 49 function apply_boundary_value_transpose(op::ConstantStencilOperator, v::AbstractVector, ::Type{Lower})
64 @boundscheck if length(v) < closuresize(op) 50 @boundscheck if length(v) < closuresize(op)
65 throw(BoundsError()) 51 throw(BoundsError())
73 end 59 end
74 apply_stencil_backwards(op.eClosure,v,length(v)) 60 apply_stencil_backwards(op.eClosure,v,length(v))
75 end 61 end
76 export apply_boundary_value_transpose 62 export apply_boundary_value_transpose
77 63
78 function apply_boundary_value(op::ConstantStencilOperator, v::Number, N::Integer, i::Integer, ::Type{Lower}) 64 function apply_boundary_value(op::ConstantStencilOperator, v::Number, i::Index, N::Integer, ::Type{Lower})
79 @boundscheck if !(0<length(i) <= N) 65 @boundscheck if !(0<length(Int(i)) <= N)
80 throw(BoundsError()) 66 throw(BoundsError())
81 end 67 end
82 op.eClosure[i-1]*v 68 op.eClosure[Int(i)-1]*v
83 end 69 end
84 70
85 function apply_boundary_value(op::ConstantStencilOperator, v::Number, N::Integer, i::Integer, ::Type{Upper}) 71 function apply_boundary_value(op::ConstantStencilOperator, v::Number, i::Index, N::Integer, ::Type{Upper})
86 @boundscheck if !(0<length(i) <= N) 72 @boundscheck if !(0<length(Int(i)) <= N)
87 throw(BoundsError()) 73 throw(BoundsError())
88 end 74 end
89 op.eClosure[N-i]*v 75 op.eClosure[N-Int(i)]*v
90 end 76 end
91 export apply_boundary_value 77 export apply_boundary_value
92 78
93 function apply_normal_derivative_transpose(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, ::Type{Lower}) 79 function apply_normal_derivative_transpose(op::ConstantStencilOperator, h_inv::Real, v::AbstractVector, ::Type{Lower})
94 @boundscheck if length(v) < closuresize(op) 80 @boundscheck if length(v) < closuresize(op)
104 -h_inv*apply_stencil_backwards(op.dClosure,v,length(v)) 90 -h_inv*apply_stencil_backwards(op.dClosure,v,length(v))
105 end 91 end
106 92
107 export apply_normal_derivative_transpose 93 export apply_normal_derivative_transpose
108 94
109 function apply_normal_derivative(op::ConstantStencilOperator, h_inv::Real, v::Number, N::Integer, i::Integer, ::Type{Lower}) 95 function apply_normal_derivative(op::ConstantStencilOperator, h_inv::Real, v::Number, i::Index, N::Integer, ::Type{Lower})
110 @boundscheck if !(0<length(i) <= N) 96 @boundscheck if !(0<length(Int(i)) <= N)
111 throw(BoundsError()) 97 throw(BoundsError())
112 end 98 end
113 h_inv*op.dClosure[i-1]*v 99 h_inv*op.dClosure[Int(i)-1]*v
114 end 100 end
115 101
116 function apply_normal_derivative(op::ConstantStencilOperator, h_inv::Real, v::Number, N::Integer, i::Integer, ::Type{Upper}) 102 function apply_normal_derivative(op::ConstantStencilOperator, h_inv::Real, v::Number, i::Index, N::Integer, ::Type{Upper})
117 @boundscheck if !(0<length(i) <= N) 103 @boundscheck if !(0<length(Int(i)) <= N)
118 throw(BoundsError()) 104 throw(BoundsError())
119 end 105 end
120 -h_inv*op.dClosure[N-i]*v 106 -h_inv*op.dClosure[N-Int(i)]*v
121 end 107 end
122 108
123 export apply_normal_derivative 109 export apply_normal_derivative