-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spectral_Operators_Leg.jl
131 lines (76 loc) · 2.3 KB
/
Spectral_Operators_Leg.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
export LegTransform_gen, RadauTransform_gen, RadauBackwardTransform_gen, ∫φ_Leg
using LegendrePolynomials
using FastGaussQuadrature
function generate_nodes_weights_leg(n)
nodes, weights = gausslegendre( n )
return nodes, weights
end
function generate_Λ_matrix(n, nodes)
Λ = zeros((n,n))
for i=1:n
for j=1:n
Λ[i,j] = Plm(i-1,0,nodes[j])
end
end
return Λ
end
# function leg_trans(φ, Λ, weights, normLeg_poly)
#
# return normLeg_poly.*( LT*(weights.*φ) )
#
# end
function leg_inv(φ̂, Λ)
return transpose(Λ)*φ̂
end
function LegTransform_gen(n)
normLeg_poly = 0.5:1.0:(n - 0.5)
nodes, weights = gaussradau(n)
Λ = generate_Λ_matrix(n, nodes)
legtrans(φ) = normLeg_poly.*( Λ*(weights.*φ) )
legtrans_inv(φ̂) = transpose(Λ)*φ̂
return legtrans, legtrans_inv, nodes, weights
end
function RadauTransform_gen(n)
#the grid includes the initial point
normLeg_poly = 0.5:1.0:(n - 0.5)
nodes, weights = gaussradau(n)
Λ = generate_Λ_matrix(n, nodes)
radtrans(φ) = normLeg_poly.*( Λ*(weights.*φ) )
radtrans_inv(φ̂) = transpose(Λ)*φ̂
return radtrans, radtrans_inv, nodes, weights
end
function RadauBackwardTransform_gen(n)
#the grid includes the end point
normLeg_poly = 0.5:1.0:(n - 0.5)
nodes, weights = gaussradau(n)
nodes = -reverse(nodes)
weights = reverse(weights)
Λ = generate_Λ_matrix(n, nodes)
radtrans(φ) = normLeg_poly.*( Λ*(weights.*φ) )
radtrans_inv(φ̂) = transpose(Λ)*φ̂
return radtrans, radtrans_inv, nodes, weights
end
function integrator_legspace(φ̂)
n = size(φ̂)[1]
∫φ̂ = zeros((n,1))
∫φ̂[1] = φ̂[1] - φ̂[2]/3
∫φ̂[2] = φ̂[1]-φ̂[3]/5
∫φ̂[n] = φ̂[n-1]/(2*(n-1) -1)
for j=2:(n-2)
∫φ̂[j+1] = φ̂[j]/(2*j - 1) - φ̂[j+2]/(2*j+3)
end
return ∫φ̂
end
function δ₁_leg(φ̂)
return sum(φ̂)
end
function ∫φ_Leg(φ, legtrans, legtrans_inv, L)
#L is the length of the domain
φ̂ = legtrans(φ)
∫φ̂ = integrator_legspace(φ̂)*(L/2)
return legtrans_inv(∫φ̂)
end
function ∫ₐᵇφ(φ, weights, L)
return sum(φ .* weights)*(L/2)
end
# R, R⁻¹, nodesR, weightsR = RadauBackwardTransform_gen(n)