Finding Galerkin L^2-based Operators for B-spline discretizations
description
Transcript of Finding Galerkin L^2-based Operators for B-spline discretizations
![Page 1: Finding Galerkin L^2-based Operators for B-spline discretizations](https://reader035.fdocuments.in/reader035/viewer/2022081907/55160b05497959f81d8b512a/html5/thumbnails/1.jpg)
Test data for B-spline operators based on Galerkin L2 projection.
Wrap Mathematica's B-spline routines so they match the GNU Scientific Library's semantics. Note that Mathematica workswith piecewise polynomial degree while the GSL uses piecewise order plus one.
In[1]:= Knots@k_, b_D := Join@ConstantArray@First@bD, k - 1D, b, ConstantArray@Last@bD, k - 1DDLastdof@k_, b_D := Length@Knots@k, bDD - Hk - 1L - 2;Basis@k_, b_D := BSplineBasis@8k - 1, Knots@k, bD<, ð1, ð2D &
Provide some sample breakpoints for testing purposes and visualize some different basis orders:
In[4]:= b = Sort@80, 1, 3 � 2, 2, 9 � 8, 3<D;
In[5]:= Plotem@k_D := Plot@Table@Basis@k, bD@i, xD, 8i, 0, Lastdof@k, bD<D,8x, First@bD, Last@bD<, PlotRange ® Full, PlotLabel ® kD
Table@Plotem@kD, 8k, 1, 4<D
Out[6]= :
0.5 1.0 1.5 2.0 2.5 3.0
0.2
0.4
0.6
0.8
1.01
,
0.2
0.4
0.6
0.8
1.02
,
,
![Page 2: Finding Galerkin L^2-based Operators for B-spline discretizations](https://reader035.fdocuments.in/reader035/viewer/2022081907/55160b05497959f81d8b512a/html5/thumbnails/2.jpg)
Out[6]=
0.5 1.0 1.5 2.0 2.5 3.0
,
0.5 1.0 1.5 2.0 2.5 3.0
0.2
0.4
0.6
0.8
1.03
,
0.5 1.0 1.5 2.0 2.5 3.0
0.2
0.4
0.6
0.8
1.04
>
Compute the Galerkin L2-based mass matrices for the above bases:
In[7]:= MassMatrix@k_, b_D := Module@8B = Basis@k, bD, n = Lastdof@k, bD
<, Table@Integrate@B@i, xD B@j, xD, 8x, First@bD, Last@bD<D,8i, 0, n<, 8j, 0, n<D
D;
In[8]:= MassMatrix@1, bD �� MatrixFormMassMatrix@2, bD �� MatrixFormMassMatrix@3, bD �� MatrixFormMassMatrix@4, bD �� MatrixForm
2 BsplineGalerkinL2Operators.nb
![Page 3: Finding Galerkin L^2-based Operators for B-spline discretizations](https://reader035.fdocuments.in/reader035/viewer/2022081907/55160b05497959f81d8b512a/html5/thumbnails/3.jpg)
Out[8]//MatrixForm=
1 0 0 0 0
0 18
0 0 0
0 0 38
0 0
0 0 0 12
0
0 0 0 0 1Out[9]//MatrixForm=
13
16
0 0 0 0
16
38
148
0 0 0
0 148
16
116
0 0
0 0 116
724
112
0
0 0 0 112
12
16
0 0 0 0 16
13
Out[10]//MatrixForm=
15
14135
4135
0 0 0 0
14135
19120
65576
18640
0 0 0
4135
65576
107360
85115 120
92240
0 0
0 18640
85115 120
528
191920 160
1315
0
0 0 92240
191920 160
59168
16105
145
0 0 0 1315
16105
730
19
0 0 0 0 145
19
15
BsplineGalerkinL2Operators.nb 3
![Page 4: Finding Galerkin L^2-based Operators for B-spline discretizations](https://reader035.fdocuments.in/reader035/viewer/2022081907/55160b05497959f81d8b512a/html5/thumbnails/4.jpg)
Out[11]//MatrixForm=
17
1211620
16567
4945
0 0 0 0
1211620
2572520
790196 768
66 5532 903040
12 903040
0 0 0
16567
790196 768
926360 480
1112051 016064
63 10925401 600
27627200
0 0
4945
66 5532 903040
1112051 016064
56 569211680
18 281211680
34735 840
18820
0
0 12 903040
63 10925401 600
18 281211680
85 759352800
5073073 763200
2718820
41575
0 0 27627200
34735 840
5073073 763200
75392
6475880
4175
0 0 0 18820
2718820
6475880
16105
1031260
0 0 0 0 41575
4175
1031260
17
Quite annoyingly, Mathematica will not successfully differentiate the first and last basis function:
In[12]:= D@Basis@3, bD@0, xD, xDD@Basis@3, bD@Lastdof@3, bD, xD, xD
Power::infy : Infinite expression1
0encountered. �
Out[12]= ComplexInfinity
Power::infy : Infinite expression1
0encountered. �
Out[13]= ComplexInfinity
The problem steps from the support of the basis functions ending (as it technically should) outside the knots:
4 BsplineGalerkinL2Operators.nb
![Page 5: Finding Galerkin L^2-based Operators for B-spline discretizations](https://reader035.fdocuments.in/reader035/viewer/2022081907/55160b05497959f81d8b512a/html5/thumbnails/5.jpg)
In[14]:= Table@PiecewiseExpand@Basis@3, bD@i, xDD, 8i, 0, Lastdof@3, bD<D �� MatrixForm
Out[14]//MatrixForm=
1 - 2 x + x2 0 £ x £ 1
0 True1
9I18 x - 17 x2M 0 £ x < 1
1
9I81 - 144 x + 64 x2M 1 £ x £
9
8
0 True8 x2
90 £ x < 1
4
3I9 - 12 x + 4 x2M
9
8£ x £
3
2
-8
9I27 - 54 x + 26 x2M 1 £ x <
9
8
0 True16
7I4 - 4 x + x2M
3
2£ x £ 2
16 I1 - 2 x + x2M 1 £ x <9
8
-8
21I39 - 60 x + 22 x2M
9
8£ x <
3
2
0 True2
3I9 - 6 x + x2M 2 £ x £ 3
-2
21I117 - 138 x + 38 x2M
3
2£ x < 2
1
21I81 - 144 x + 64 x2M
9
8£ x <
3
2
0 True1
3I-27 + 24 x - 5 x2M 2 £ x £ 3
1
3I9 - 12 x + 4 x2M
3
2£ x < 2
0 True
4 - 4 x + x2 2 £ x £ 3
0 True
While this is correct, it leads to ComplexInfinity problems during differentiation.
We circumvent the problem by working with the piecewise polynomial representation and promising on some ancestor to never,ever evaluate outside the knots:
In[15]:= RefinedBasis@k_, b_D :=
Refine@PiecewiseExpand@Basis@k, bD@ð1, ð2DD, First@bD < ð2 < Last@bDD &
Notice that we lied and will most certainly evaluate at the two endpoints!
Finally, we can define and symbolically evaluate Galerkin L2-based B-spline operators:
In[16]:= OperatorMatrix@k_, b_, d_D := Module@8B = RefinedBasis@k, bD, n = Lastdof@k, bD, y
<, Table@Integrate@B@i, xD H D@B@j, yD, 8y, d<D ��. y ® xL, 8x, First@bD, Last@bD<D,8i, 0, n<, 8j, 0, n<D
D;
Some sample outputs for the previous bases are :
In[17]:= With@8k = 2<, Do@Print@OperatorMatrix@k, b, dD �� MatrixFormD, 8d, 0, k - 1<DD
BsplineGalerkinL2Operators.nb 5
![Page 6: Finding Galerkin L^2-based Operators for B-spline discretizations](https://reader035.fdocuments.in/reader035/viewer/2022081907/55160b05497959f81d8b512a/html5/thumbnails/6.jpg)
13
16
0 0 0 0
16
38
148
0 0 0
0 148
16
116
0 0
0 0 116
724
112
0
0 0 0 112
12
16
0 0 0 0 16
13
-12
12
0 0 0 0
-12
0 12
0 0 0
0 -12
0 12
0 0
0 0 -12
0 12
0
0 0 0 -12
0 12
0 0 0 0 -12
12
In[18]:= With@8k = 3<, Do@Print@OperatorMatrix@k, b, dD �� MatrixFormD, 8d, 0, k - 1<DD
6 BsplineGalerkinL2Operators.nb
![Page 7: Finding Galerkin L^2-based Operators for B-spline discretizations](https://reader035.fdocuments.in/reader035/viewer/2022081907/55160b05497959f81d8b512a/html5/thumbnails/7.jpg)
15
14135
4135
0 0 0 0
14135
19120
65576
18640
0 0 0
4135
65576
107360
85115 120
92240
0 0
0 18640
85115 120
528
191920 160
1315
0
0 0 92240
191920 160
59168
16105
145
0 0 0 1315
16105
730
19
0 0 0 0 145
19
15
-12
1954
427
0 0 0 0
-1954
0 2572
1216
0 0 0
-427
-2572
0 167378
356
0 0
0 -1
216-
167378
0 209504
263
0
0 0 -356
-209504
0 514
19
0 0 0 -263
-514
0 718
0 0 0 0 -19
-718
12
23
-3427
1627
0 0 0 0
2027
-43
49
427
0 0 0
1627
49
-329
368189
47
0 0
0 427
368189
-6421
4463
1663
0
0 0 47
4463
-4021
421
49
0 0 0 1663
421
-43
89
0 0 0 0 49
-109
23
In[19]:= With@8k = 4<, Do@Print@OperatorMatrix@k, b, dD �� MatrixFormD, 8d, 0, k - 1<DD
BsplineGalerkinL2Operators.nb 7
![Page 8: Finding Galerkin L^2-based Operators for B-spline discretizations](https://reader035.fdocuments.in/reader035/viewer/2022081907/55160b05497959f81d8b512a/html5/thumbnails/8.jpg)
17
1211620
16567
4945
0 0 0 0
1211620
2572520
790196 768
66 5532 903040
12 903040
0 0 0
16567
790196 768
926360 480
1112051 016064
63 10925401 600
27627200
0 0
4945
66 5532 903040
1112051 016064
56 569211680
18 281211680
34735 840
18820
0
0 12 903040
63 10925401 600
18 281211680
85 759352800
5073073 763200
2718820
41575
0 0 27627200
34735 840
5073073 763200
75392
6475880
4175
0 0 0 18820
2718820
6475880
16105
1031260
0 0 0 0 41575
4175
1031260
17
-12
257810
62405
4135
0 0 0 0
-257810
0 3531728
585751 840
151 840
0 0 0
-62405
-3531728
0 29 48990 720
14 293453600
911 200
0 0
-4
135-
585751 840
-29 48990 720
0 18614725
485367 200
1630
0
0 -1
51 840-
14 293453600
-18614725
0 19 09367 200
3893150
4225
0 0 -9
11 200-
485367 200
-19 09367 200
0 121525
19150
0 0 0 -1
630-
3893150
-121525
0 1645
0 0 0 0 -4
225-
19150
-1645
12
65
-274135
88135
845
0 0 0 0
131135
-1915
-23180
4571080
11080
0 0 0
88135
-23180
-109
4731890
30619450
9700
0 0
845
4571080
4731890
-668315
5263
1740
2105
0
0 11080
30619450
5263
-836525
-37
140038105
875
0 0 9700
1740
-37
1400-
67
-435
1425
0 0 0 2105
38105
-435
-75
1715
0 0 0 0 875
1425
-2815
65
8 BsplineGalerkinL2Operators.nb
![Page 9: Finding Galerkin L^2-based Operators for B-spline discretizations](https://reader035.fdocuments.in/reader035/viewer/2022081907/55160b05497959f81d8b512a/html5/thumbnails/9.jpg)
-32
21754
-9227
89
0 0 0 0
-9154
92
-349
2527
127
0 0 0
-5227
349
0 -844189
2308945
635
0 0
-89
-2527
844189
0 -1408315
5735
421
0
0 -127
-2308945
1408315
0 -10335
44105
815
0 0 -635
-5735
10335
0 -10335
95
0 0 0 -421
-44105
10335
-92
136
0 0 0 0 -815
115
-196
32
BsplineGalerkinL2Operators.nb 9