@@ -5,6 +5,14 @@ export Evaluation,ivp,bvp,Dirichlet,Neumann
55abstract type  Evaluation{T}<: Operator{T}  end 
66
77@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
816
917#  M = leftendpoint/rightendpoint if endpoint
1018struct  ConcreteEvaluation{S,M,OT,T} <:  Evaluation{T} 
3341
3442Evaluation (sp:: Space ,x,order) =  Evaluation (rangetype (sp),sp,x,order)
3543
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))
4765
4866
4967function  convert (:: Type{Operator{T}} ,E:: ConcreteEvaluation ) where  T
5775
5876
5977# # default getindex
78+ _eval (f, x) =  f (x)
79+ _eval (f, x:: SpecialEvalPtType ) =  boundaryevalfn (x)(f)
6080function  getindex (D:: ConcreteEvaluation ,k:: Integer )
6181    T =  prectype (domainspace (D))
6282    f =  Fun (D. space, [zeros (T,k- 1 ); one (T)])
6383    df =  differentiate (f,D. order)
64-     v =  df ( D. x)
84+     v =  _eval (df,  D. x)
6585    strictconvert (eltype (D), v)
6686end 
6787
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
8594
8695
8796
@@ -132,7 +141,7 @@ ivp(d,k) = [ldiffbc(d,i) for i=0:k-1]
132141bvp (d,k) =  vcat ([ldiffbc (d,i) for  i= 0 : div (k,2 )- 1 ],
133142                [rdiffbc (d,i) for  i= 0 : div (k,2 )- 1 ])
134143
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]
136145
137146#  shorthand for second order
138147ivp (d) =  ivp (d,2 )
0 commit comments