@@ -5,6 +5,14 @@ export Evaluation,ivp,bvp,Dirichlet,Neumann
5
5
abstract type Evaluation{T}<: Operator{T} end
6
6
7
7
@functional Evaluation
8
+ evaluation_point (C:: Evaluation ) = C. x
9
+
10
+ @enum Boundary RightEndPoint= 1 LeftEndPoint= - 1
11
+
12
+ isleftendpoint (:: typeof (leftendpoint)) = true
13
+ isrightendpoint (:: typeof (rightendpoint)) = true
14
+ isrightendpoint (x:: Boundary ) = x == RightEndPoint
15
+ isleftendpoint (x:: Boundary ) = x == LeftEndPoint
8
16
9
17
# M = leftendpoint/rightendpoint if endpoint
10
18
struct ConcreteEvaluation{S,M,OT,T} <: Evaluation{T}
33
41
34
42
Evaluation (sp:: Space ,x,order) = Evaluation (rangetype (sp),sp,x,order)
35
43
36
- Evaluation (d:: Space ,x:: Union{Number,typeof(leftendpoint),typeof(rightendpoint)} ) = Evaluation (d,x,0 )
37
- Evaluation (:: Type{T} ,d:: Space ,n... ) where {T} = error (" Override Evaluation for $(typeof (d)) " )
38
- Evaluation (:: Type{T} ,d,n... ) where {T} = Evaluation (T,Space (d),n... )
39
- Evaluation (S:: Space ,n... ) = error (" Override Evaluation for $(typeof (S)) " )
40
- Evaluation (d,n... ) = Evaluation (Space (d),n... )
41
- Evaluation (x:: Union{Number,typeof(leftendpoint),typeof(rightendpoint)} ) = Evaluation (UnsetSpace (),x,0 )
42
- Evaluation (x:: Union{Number,typeof(leftendpoint),typeof(rightendpoint)} ,k:: Integer ) =
43
- Evaluation (UnsetSpace (),x,k)
44
-
45
- rangespace (E:: ConcreteEvaluation{<:AmbiguousSpace} ) = ConstantSpace ()
46
- rangespace (E:: ConcreteEvaluation ) = ConstantSpace (Point (E. x))
44
+ const SpecialEvalPtType = Union{typeof (leftendpoint),typeof (rightendpoint),Boundary}
45
+ const EvalPtType = Union{Number,SpecialEvalPtType}
46
+
47
+ error_space (d:: Space ) = error (" Override Evaluation for $(typeof (d)) " )
48
+ error_space (d) = nothing
49
+
50
+ Evaluation (d:: Space ,x:: EvalPtType ) = Evaluation (d,x,0 )
51
+ Evaluation (:: Type{T} ,d,n... ) where {T} = (error_space (d); Evaluation (T,Space (d),n... ))
52
+ Evaluation (d,n... ) = (error_space (d); Evaluation (Space (d),n... ))
53
+ Evaluation (x:: EvalPtType ,k:: Integer = 0 ) = Evaluation (UnsetSpace (),x,k)
54
+
55
+ _rangespace_eval (E:: ConcreteEvaluation , :: AmbiguousSpace , :: SpecialEvalPtType ) = UnsetSpace ()
56
+ _rangespace_eval (E:: ConcreteEvaluation , :: AmbiguousSpace , :: Any ) = ConstantSpace ()
57
+ _rangespace_eval (E:: ConcreteEvaluation , :: Space , :: Any ) = ConstantSpace (Point (E. x))
58
+ function _rangespace_eval (E:: ConcreteEvaluation , :: Space , :: SpecialEvalPtType )
59
+ d = domain (domainspace (E))
60
+ isambiguous (d) && return ConstantSpace ()
61
+ dop = boundaryfn (E. x)
62
+ return ConstantSpace (Point (dop (d)))
63
+ end
64
+ rangespace (E:: ConcreteEvaluation ) = _rangespace_eval (E, E. space, evaluation_point (E))
47
65
48
66
49
67
function convert (:: Type{Operator{T}} ,E:: ConcreteEvaluation ) where T
57
75
58
76
59
77
# # default getindex
78
+ _eval (f, x) = f (x)
79
+ _eval (f, x:: SpecialEvalPtType ) = boundaryevalfn (x)(f)
60
80
function getindex (D:: ConcreteEvaluation ,k:: Integer )
61
81
T = prectype (domainspace (D))
62
82
f = Fun (D. space, [zeros (T,k- 1 ); one (T)])
63
83
df = differentiate (f,D. order)
64
- v = df ( D. x)
84
+ v = _eval (df, D. x)
65
85
strictconvert (eltype (D), v)
66
86
end
67
87
68
- # special leftendpoint/rightendpoint overrides
69
- for (dop, fop) in ((:leftendpoint ,:first ), (:rightendpoint ,:last ))
70
- @eval begin
71
- rangespace (E:: ConcreteEvaluation{<:AmbiguousSpace,typeof($dop)} ) = UnsetSpace ()
72
- function rangespace (E:: ConcreteEvaluation{<:Any,typeof($dop)} )
73
- d = domain (domainspace (E))
74
- isambiguous (d) && return ConstantSpace ()
75
- return ConstantSpace (Point ($ dop (d)))
76
- end
77
- function getindex (D:: ConcreteEvaluation{<:Any,typeof($dop)} ,k:: Integer )
78
- P = prectype (domainspace (D))
79
- R = eltype (D)
80
- R ($ fop (differentiate (Fun (D. space,[zeros (P,k- 1 );one (P)]),D. order)))
81
- end
82
- end
83
- end
84
-
88
+ boundaryfn (x:: typeof (rightendpoint)) = x
89
+ boundaryfn (x:: typeof (leftendpoint)) = x
90
+ boundaryfn (x:: Boundary ) = isleftendpoint (x) ? leftendpoint : rightendpoint
91
+ boundaryevalfn (:: typeof (rightendpoint)) = last
92
+ boundaryevalfn (:: typeof (leftendpoint)) = first
93
+ boundaryevalfn (x:: Boundary ) = isleftendpoint (x) ? first : last
85
94
86
95
87
96
@@ -132,7 +141,7 @@ ivp(d,k) = [ldiffbc(d,i) for i=0:k-1]
132
141
bvp (d,k) = vcat ([ldiffbc (d,i) for i= 0 : div (k,2 )- 1 ],
133
142
[rdiffbc (d,i) for i= 0 : div (k,2 )- 1 ])
134
143
135
- periodic (d,k) = [Evaluation (d,leftendpoint,i) - Evaluation (d,rightendpoint ,i) for i= 0 : k]
144
+ periodic (d,k) = [ldiffbc (d,i) - rdiffbc (d ,i) for i= 0 : k]
136
145
137
146
# shorthand for second order
138
147
ivp (d) = ivp (d,2 )
0 commit comments