问题描述
根据已知下列非齐次两点边值问题(1.2.28)
{ L u = − d d x ( p d u d x ) + q u = f , a < x < b , u ( a ) = α , u ′ ( b ) = β , \begin{cases} \boldsymbol{L} u=-\frac{\mathrm{d}}{\mathrm{d} x}\left(p \frac{\mathrm{d} u}{\mathrm{~d} x}\right)+q u=f, a < x < b, \\ u(a)=\alpha, u^{\prime}(b)=\beta, \end{cases} {Lu=−dxd(p dxdu)+qu=f,a<x<b,u(a)=α,u′(b)=β,
与下列变分问题等价:求𝑢 ∈ 𝐻^1, 𝑢(𝑎) = 𝛼,使
J
(
u
∗
)
=
min
u
∈
H
1
u
(
a
)
=
α
J
(
u
)
J(u_{*})=\min\limits_{u \in H^1 \atop u(a) = \alpha} J(u)
J(u∗)=u(a)=αu∈H1minJ(u)
其中
J
(
u
)
=
1
2
a
(
u
,
u
)
−
(
f
,
u
)
−
p
(
b
)
β
u
(
b
)
\begin{array}{c} J(u)=\frac{1}{2} a(u, u)-(f, u)-p(b) \beta u(b) \end{array}
J(u)=21a(u,u)−(f,u)−p(b)βu(b)
a
(
u
,
v
)
=
∫
a
b
(
p
d
u
d
x
d
v
d
x
+
q
u
v
)
d
x
,
(
g
,
u
)
=
∫
a
b
g
u
d
x
.
a(u, v)=\int_{a}^{b}\left(p \frac{d u}{d x} \frac{d v}{d x}+q u v\right) d x,\quad(g, u)=\int_{a}^{b} g u d x . \\
a(u,v)=∫ab(pdxdudxdv+quv)dx,(g,u)=∫abgudx.
设
[
a
,
b
]
=
[
−
1
,
1
]
,
p
(
x
)
≡
−
(
π
2
−
1
)
−
1
,
q
(
x
)
≡
1
,
α
=
0
,
β
=
−
π
e
,
以及
\text{设} [a, b]=[-1,1], p(x) \equiv-\left(\pi^{2}-1\right)^{-1}, q(x) \equiv 1, \alpha=0, \beta=-\pi e , \text{以及} \\
设[a,b]=[−1,1],p(x)≡−(π2−1)−1,q(x)≡1,α=0,β=−πe,以及
f
(
x
)
=
2
π
π
2
−
1
⋅
cos
(
π
x
)
⋅
e
x
f(x)=\frac{2 \pi}{\pi^{2}-1} \cdot \cos (\pi x) \cdot e^{x}
f(x)=π2−12π⋅cos(πx)⋅ex
任务1:请认真阅读并完成以下子任务
- 分别取 h = 0.20 , 0.10 , 0.05 , 0.02 ℎ = 0.20, 0.10, 0.05, 0.02 h=0.20,0.10,0.05,0.02 时, 将求解域
- 分别使用高斯消去法和雅可比迭代法(迭代 30 次),求解上述有限元方程
- 计算得到有限元解绘制有限元解 的函数图像.
任务2:已知 u ( x ) = sin ( π x ) ⋅ e x u(x)=\sin(\pi x) \cdot e^x u(x)=sin(πx)⋅ex 是上述边值问题的解析解,针对不同的步长 h h h 线性方程组解法得到的数值解 u h u_h uh ,绘制误差函数 ( u h − u ) (u_h − u) (uh−u) 的函数图像,且进行观察分析。
任务1
划分求解域
[ a , b ] = [ − 1 , 1 ] , h = 0.2 , 0.1 , 0.05 , 0.02 , n = 10 , 20 , 40 , 100 [a, b] = [-1, 1], h = 0.2, 0.1, 0.05, 0.02, n = 10, 20, 40, 100 [a,b]=[−1,1],h=0.2,0.1,0.05,0.02,n=10,20,40,100
-
h = 0.2 , n = 10 , x = [ − 1 , − 0.8 , ⋯ , 0.8 , 1 ] h = 0.2, \quad n = 10,\quad x=[-1, -0.8, \cdots, 0.8, 1] h=0.2,n=10,x=[−1,−0.8,⋯,0.8,1]
-
h = 0.1 , n = 20 , x = [ − 1 , − 0.9 , ⋯ , 0.9 , 1 ] h = 0.1, \quad n = 20, \quad x=[-1, -0.9, \cdots, 0.9, 1] h=0.1,n=20,x=[−1,−0.9,⋯,0.9,1]
-
h = 0.05 , n = 40 , x = [ − 1 , − 0.95 , ⋯ , 0.95 , 1 ] h = 0.05, \quad n = 40, \quad x=[-1, -0.95, \cdots, 0.95, 1] h=0.05,n=40,x=[−1,−0.95,⋯,0.95,1]
-
h = 0.02 , n = 100 , x = [ − 1 , − 0.98 , ⋯ , 0.98 , 1 ] h = 0.02,\quad n = 100, \quad x=[-1, -0.98, \cdots, 0.98, 1] h=0.02,n=100,x=[−1,−0.98,⋯,0.98,1]
分析并构建Ritz-Galerkin方程
-
基函数构造,设计 φ 0 ( x ) \varphi_0(x) φ0(x)
φ i ( x ) = { 1 + x − x i h i , x i − 1 ≤ x ≤ x i 1 − x − x i h i + 1 , x i ≤ x ≤ x i + 1 0 , otherwise \varphi_i(x) = \begin{cases} 1+\frac{x-x_i}{h_i}, x_{i-1} \leq x \leq x_i \\ 1-\frac{x-x_i}{h_{i+1}}, x_i \leq x \leq x_{i + 1} \\ 0, \text{otherwise} \\ \end{cases} φi(x)=⎩ ⎨ ⎧1+hix−xi,xi−1≤x≤xi1−hi+1x−xi,xi≤x≤xi+10,otherwise
- 左边值条件齐次: u ( a ) = α = 0 u(a)=\alpha=0 u(a)=α=0 ,右边值条件非齐次: u ′ ( b ) = β u'(b)=\beta u′(b)=β
- 则增加基函数:
φ 0 ( x ) = { 1 − x − x 0 h 1 , x 0 ≤ x ≤ x 1 0 , otherwise \varphi_0(x) = \begin{cases} 1-\frac{x-x_0}{h_1}, x_0 \leq x \leq x_1\\ 0, \text{otherwise} \\ \end{cases} φ0(x)={1−h1x−x0,x0≤x≤x10,otherwise
- 满足 u ∈ H 1 , u ( a ) = α u\in H^1, u(a)=\alpha u∈H1,u(a)=α 的试探函数可以写成:
u h ( x ) = ∑ i = 0 n σ i φ i ( x ) = α φ 0 ( x ) + ∑ i = 1 n σ i φ i ( x ) = ∑ i = 1 n σ i φ i ( x ) , ( σ 0 = α ) u_h(x)= \sum_{i=0}^n \sigma_i \varphi_i(x) = \alpha \varphi_0 (x) + \sum_{i=1}^{n} \sigma_i \varphi_i(x)=\sum_{i=1}^{n} \sigma_i \varphi_i(x), \quad(\sigma_0 = \alpha) uh(x)=i=0∑nσiφi(x)=αφ0(x)+i=1∑nσiφi(x)=i=1∑nσiφi(x),(σ0=α)
- 于是:
J ( u h ) = 1 2 a ( u h , u h ) − ( f , u h ) − p ( b ) β ( b ) u h ( b ) = ∑ i = 1 n ∑ j = 1 n σ i σ j a ( φ i ( x ) , φ j ( x ) ) 2 − ∑ i = 1 n σ i ( f , φ i ( x ) ) − ∑ i = 1 n σ i p ( b ) β φ i ( b ) \begin{aligned} J(u_h)=&\frac{1}{2} a(u_h, u_h) - (f, u_h) -p(b)\beta(b) u_h(b)\\ =&\sum_{i=1}^n \sum_{j=1}^n \sigma_i \sigma_j \frac{a(\varphi_i(x), \varphi_j(x))}{2} -\sum_{i=1}^n \sigma_i (f, \varphi_i(x)) - \sum_{i=1}^n \sigma_i p(b) \beta \varphi_i(b) \\ \end{aligned} J(uh)==21a(uh,uh)−(f,uh)−p(b)β(b)uh(b)i=1∑nj=1∑nσiσj2a(φi(x),φj(x))−i=1∑nσi(f,φi(x))−i=1∑nσip(b)βφi(b)
- Ritz-Galerkin方程:
∂ J ( u h ) ∂ σ i = ∑ i = 1 n σ i a ( φ i , φ j ) − ( f , φ j ) − p ( b ) β φ j ( b ) = 0 , j = 1 , 2 , ⋯ , n ⇒ ∑ i = 1 n σ i a ( φ i , φ j ) = ( f , φ j ) + p ( b ) β φ j ( b ) , j = 1 , 2 , ⋯ , n \begin{aligned} &\frac{\partial J(u_h)}{\partial \sigma_i}=\sum_{i=1}^n \sigma_i a(\varphi_i, \varphi_j)-(f, \varphi_j)-p(b) \beta \varphi_j(b)=0, \quad j=1, 2, \cdots, n \\ &\Rightarrow \sum_{i=1}^n \sigma_i a(\varphi_i, \varphi_j)=(f, \varphi_j)+p(b) \beta \varphi_j(b), \quad j=1, 2, \cdots, n \\ \end{aligned} ∂σi∂J(uh)=i=1∑nσia(φi,φj)−(f,φj)−p(b)βφj(b)=0,j=1,2,⋯,n⇒i=1∑nσia(φi,φj)=(f,φj)+p(b)βφj(b),j=1,2,⋯,n
- 编程构建Ritz-Galerkin方程并求解,核心代码:
femsolver.py
有限元解的函数图像
-
高斯消去法求解结果
-
雅可比迭代法求解结果
任务2:绘制误差函数图像
-
高斯消去法求解结果
-
-
雅可比迭代法求解结果
结果分析
- 从高斯消去法求解的结果来看, u h u_h uh函数近似估计精确解的效果很好,节点处的数值解与精确解的值几乎是重合的,而且随着h的减小误差也不断减少,当h=0.01时,误差的尺度为1e-5至1e-4,基本可以忽略不计。
- 从雅可比迭代法求解的结果来看, u h u_h uh函数近似估计精确解的效果不太好,节点处的数值解与精确解的值之间误差较大,而且随着h的减少,误差下降到一定程度(1e-2至1e-1)后不再下降。经过程序检验发现造成雅可比迭代不收敛的原因在于对有限元方程构建的总刚度矩阵是一个非对角占优矩阵,即不满足雅可比迭代的收敛要求,所以通过雅可比迭代法求解线性方程组 K U = F KU=F KU=F 无法得到收敛的数值解。
程序源码
https://download.csdn.net/download/DeepLearning_/88201562