-
Notifications
You must be signed in to change notification settings - Fork 1
/
halfrangehermite.t
155 lines (132 loc) · 8.26 KB
/
halfrangehermite.t
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
local alloc = require("alloc")
local dvector = require("dvector")
local err = require("assert")
local gauss = require("gauss")
local tmath = require("mathfuns")
local function staticarray(tab)
return terralib.constant(terralib.new(double[#tab], tab))
end
local points = {}
local weights = {}
points[1] = staticarray({0.5641895835477563})
weights[1] = staticarray({0.886226925452758})
points[2] = staticarray({0.3001939310608394,1.252421045333717})
weights[2] = staticarray({0.6405291796843786,0.2456977457683794})
points[3] = staticarray({0.190554149798192,0.8482518675445767,1.799776578415728})
weights[3] = staticarray({0.4460297704666581,0.3964682669983355,0.04372888798776444})
points[4] = staticarray({0.1337764469960676,0.62432469018719,
1.342537825644992,2.262664477010362})
weights[4] = staticarray({0.325302999756919,0.4211071018520622,
0.1334425003575195,0.006374323486257276})
points[5] = staticarray({0.1002421519682156,0.4828139660462007,
1.060949821525717,1.779729418520261,2.669760356087656})
weights[5] = staticarray({0.2484061520284426,0.3923310666523991,0.2114181930760567,
0.03324666035134392,0.0008248533445156285})
points[6] = staticarray({0.07860065941309792,0.3867394102706306,0.8664294716820439,
1.465698049663516,2.172707796938999,3.036820169322866})
weights[6] = staticarray({0.1968496754885982,0.3491542015253951,0.2572595205844211,
0.07601313758400571,0.006851918625135966,0.0000984716452019267})
points[7] = staticarray({0.0637164846067008,0.3181920188886186,0.724198989258373,
1.238035599215089,1.838528220270947,2.531488151327676,
3.373456430124583})
weights[7] = staticarray({0.1606099651492607,0.3063198081580993,0.2755271417849055,
0.1206301931307841,0.0218922863438067,0.001236446728310565,
0.00001108415759110591})
points[8] = staticarray({0.05297864393185113,0.2673983721677654,0.6163028841823999,
1.064246312116224,1.588855862270055,2.183921153095859,
2.863133883708075,3.686007162724397})
weights[8] = staticarray({0.1341091884533596,0.268330754472639,0.2759533979884218,
0.1574482826187903,0.04481410991746293,0.005367935756025334,
0.0002020636491324108,1.192596926595344e-6})
points[9] = staticarray({0.0449390308011905,0.2286053055605226,0.5321958443316226,
0.927280745338049,1.392923855195846,1.918843099197395,
2.5062478340057,3.172692133481198,3.97889886978974})
weights[9] = staticarray({0.1140889702421113,0.2359407912236759,0.2664254736302523,
0.1832516791016711,0.0713440493066984,0.01398141841556245,
0.001163852720785424,0.0000305670214897907,1.237905113375337e-7})
points[10] = staticarray({0.03873852432569939,0.1982333040129488,0.4652011118145069,
0.8168618855919073,1.23454132402774,1.706798149688649,
2.22994008892444,2.809103746898253,3.463872419495373,
4.255361806365613})
weights[10] = staticarray({0.0985520975190362,0.2086780666080757,0.252051688403725,
0.19868434003846,0.097198422760155,0.02702441643558718,
0.003804649622503724,0.0002288862430452975,4.345344798459451e-6,
1.247737148183252e-8})
points[11] = staticarray({0.03383932123177446,0.1739557277102363,0.4108738409723874,
0.7262717842598971,1.103863246464907,1.532295034575371,
2.005782902468136,2.524352141519208,3.095351709869225,
3.739478609943578,4.517835967187362})
weights[11] = staticarray({0.08622070553482039,0.1857673189544318,0.2358261241291562,
0.2058503268421006,0.1195811706164384,0.04314432758877886,
0.008867649894959828,0.000927141875111555,0.00004157193216836889,
5.868576468647473e-7,1.227145140008817e-9})
points[12] = staticarray({0.02988970076966438,0.1542048782658252,0.3661439629743124,
0.6508810158452046,0.994366869880792,1.385891203649565,
1.818848608428232,2.290842738672855,2.804096793393624,
3.367270704162927,4.001683475673482,4.768216287989858})
weights[12] = staticarray({0.07624614679304309,0.1664460688794738,0.2193948981287074,
0.2070165086790944,0.1372643627964736,0.06050567434891643,
0.0165538019564075,0.002586083788356673,0.0002062375410674887,
7.066509867527055e-6,7.591315472565978e-8,1.181954171667723e-10})
points[13] = staticarray({0.0266511266223847,0.1378918554699391,0.3288286751583444,
0.5873785314737065,0.901480884535392,1.261296502582378,
1.66003713190544,2.094109004187487,2.563207025254677,
3.070912341029641,3.62669201180255,4.252207400479318,
5.008008343237775})
weights[13] = staticarray({0.06804639044185624,0.15005721170664,0.2036066396917442,
0.2041043551987293,0.1501192282511192,0.07745363156328891,
0.02648916672925082,0.005623430312110253,0.000683241179366847,
0.0000424853319211805,1.135571013605639e-6,9.4645364590637e-9,
1.118104616993773e-11})
points[14] = staticarray({0.02395678924410742,0.1242403441099138,0.2973385689164815,
0.5333292144432879,0.8218731891169355,1.154067073874413,
1.523274791445724,1.925338210477104,2.358600766644775,
2.824093754844971,3.326269358705141,3.875104990987576,
4.492438071606916,5.238431362675289})
weights[14] = staticarray({0.06121098121960296,0.1360620586385194,0.1888568017420458,
0.1985778287930954,0.1586173392257595,0.0928167848032935,
0.03793164029294467,0.01025639155686673,0.001722771913010717,
0.0001659563530552859,8.195893956404786e-6,1.738766263765218e-7,
1.142939916390559e-9,1.041200236916552e-12})
points[15] = staticarray({0.02168694269885122,0.112684196952642,0.2704926203889976,
0.4869022892342736,0.7530435742305187,1.060930872005833,
1.404254809370578,1.778646218520443,2.181707962845513,
2.613060672513555,3.074617939497499,3.571407977467349,
4.113735918455993,4.723512894970653,5.460488773864858})
weights[15] = staticarray({0.05544335429971261,0.1240277156956029,0.1752909209537161,
0.1914883325923961,0.1634738094969465,0.1059376603780783,
0.05002704004358421,0.01644297800461653,0.003573206793068924,
0.0004828969424775539,0.00003749090518569465,1.493685973281742e-6,
2.552708581326493e-8,1.342178924114873e-10,9.56229145184875e-14})
local terra select(n: int64)
err.assert(n > 0 and n <= [#points])
escape
for i = 1, #points do
local x = points[i]
local w = weights[i]
emit quote if n == i then return &[x][0], &[w][0] end end
end
end
end
local dvecDouble = dvector.DynamicVector(double)
local Alloc = alloc.Allocator
local struct halfrangehermite_t {}
gauss.QuadruleBase(halfrangehermite_t, dvecDouble, dvecDouble)
local terra halfrangehermite(alloc: Alloc, n: int64): halfrangehermite_t
var x, w = select(n)
var wq = dvecDouble.new(alloc, n)
var xq = dvecDouble.new(alloc, n)
for i = 0, n do
wq(i) = tmath.sqrt(2.0) * w[i] / tmath.sqrt(2.0 * math.pi)
xq(i) = tmath.sqrt(2.0) * x[i]
end
return xq, wq
end
return {
halfrangehermite_t = halfrangehermite_t,
halfrangehermite = halfrangehermite,
}