Notes
Notes
1 Introduction
In the variational methods to solve differential equations, we had to assume functions in some fashion which looked
like
j=N
un = φ0 + ∑ c jφ j (1)
j=1
we assumed forms for φ0 and φ j depending on the boundary conditions. By assuming polynomials, our integration was
easier. However, the only way we had to improve the accuracy, was by increasing the order of the polynomials. This
is somewhat cumbersome. We now resort to slightly different kind of functions and the solution using these functions
is illustrated using examples.
2 Example
Consider the differential equation
d2u
− − u + x2 = 0 0 < x < 1 (2)
dx2
subject to boundary conditions
Weak Form
Z 1 Z 1
dwi duN
− wi uN dx = − wi x2 dx + (wi F)x=0 + (wi F)x=1 (5)
0 dx dx 0
Z 1 Z 1
dwi duN
− wi uN dx = − wi x2 dx + wi (0)F(0) + wi (1)F(1) (6)
0 dx dx 0
1
2. Must be differentiable as many times as needed by the weak form (Eq 48), which is once.
3. Must involve linearly independent functions to approximate the solution meaningfully.
3 Piecewise functions
We define the following three functions shown in the Figure below. The functions have the following expressions
ϕ1 ϕ2 ϕ3
1 1 1
ϕ1
ϕ2
ϕ3
0.5 0.5 0.5
0 0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
x x x
(
x
1 − 0.5 0 < x < 0.5
φ1 = (7)
0 0.5 < x < 1
(
x
0.5 0 < x < 0.5
φ2 = 1 (8)
0.5 (1 − x) 0.5 < x < 1
(
0 0 < x < 0.5
φ3 = 1 (9)
0.5 (x − 1) + 1 0.5 < x < 1
w1 = a1 φ1 (10)
w2 = a2 φ2 (11)
w3 = a3 φ3 (12)
Please note that if uN has to satisfy the given boundary conditions (first), then u1 = u3 must be 0 because
of the nature of φ1 and φ2 , they take on the value of 1 at x = 0 and x = 1, respectively.
3. Note that even if the first boundary condition in the strong from was
2
4 Solution of the problem for the first boundary condition
Let us now write the three equations we will get for the first boundary condition. We do this from the weak form
Eq. 48.
i=3
Z 1 d ∑ ui φi i=3 Z 1
d(c1 φ1 ) i=1
(c1 φ1 )x2 dx + c1 φ1 (0)F(0) + c1 φ1 (1)F(1)
− c1 φ1 ( ∑ ui φi ) dx = − (15)
0
dx dx i=1
0
i=3
Z 1 d ∑ ui φi i=3 Z 1
d(c2 φ2 ) i=1
(c2 φ2 )x2 dx + c2 φ2 (0)F(0) + c2 φ2 (1)F(1)
− c2 φ2 ( ∑ ui φi ) dx = − (16)
0
dx dx i=1
0
i=3
Z 1 d ∑ ui φi i=3 Z 1
d(c3 φ3 ) i=1
− c3 φ3 ( ∑ ui φi ) dx = − (c3 φ3 )x2 dx + c3 φ3 (0)F(0) + c3 φ3 (1)F(1)
(17)
0
dx dx i=1 0
given that c1 = c3 = 0, we have only one equation. But simultaneously note that c1 , c2 , c3 cancel on both sides of the
three equations, making it appear as if wi was chosen to be φi and not ci φi . Hence, the only equation left is
i=3
Z 1 d ∑ ui φi i=3 Z 1
d(φ2 ) i=1
− φ2 ( ∑ ui φi ) dx = − (φ2 )x2 dx
dx
(18)
0 dx i=1 0
which on account of that fact that uN must satisfy the boundary conditions, requires u1 = u3 = 0. Hence, Eq. 18
becomes,
Z 1 Z 1
dφ2 du2 φ2
− φ2 (u2 φ2 ) dx = − (φ2 )x2 dx (19)
0 dx dx 0
(20)
giving
Z 1 Z 1
dφ2 dφ2
− φ2 φ2 dx u2 = − (φ2 )x2 dx (21)
0 dx dx 0
because φ2 is different in different regions of the domain, we have to split the integral and write it as follows
Z 0.5 Z 1
dφ2 dφ2 dφ2 dφ2
− φ2 φ2 dx + − φ2 φ2 dx u2 =
0 dx dx 0.5 dx dx
Z 0.5 Z 1
− (φ2 )x2 dx − (φ2 )x2 dx (22)
0 0.5
We can now solve for u2 . Please do it. That is find u2 and compare to the exact solution at x = 12 . Note that at
x = 21 both φ1 and φ3 are identically 0, by definition. You should get u2 = −0.0397727272727273. The exact solution
is −0.04075910901317625. The solution at other points can be obtained as
3
Calculations_hat_functions_one_hat
February 6, 2025
[4]: x = smp.symbols("x")
phi21 = smp.symbols("phi_2^1")
phi22 = smp.symbols("phi_2^2")
u2 = smp.symbols("u_2")
[14]: Eq = smp.Eq(((L1+L2)*u2),(R1+R2))
[15]: Eq
[15]:
3.66666666666667u2 = −0.145833333333333
[16]: smp.solve((Eq),(u2))
[16]: [-0.0397727272727273]
[18]: u(0.5)
[18]: np.float64(-0.04075910901317625)
1
x2 = np.arange(0.5,1,0.001)
actual_sol = u(x0)
ax.plot(x0,actual_sol)
upart_1 = -0.0397727272727273*x1/0.5
upart_2 = -0.0397727272727273/0.5*(1-x2)
ax.plot(x1,upart_1)
ax.plot(x2,upart_2)
ax.set_xlim([0,1])
ax.set_ylim([-0.05,0])
ax.set_xlabel("x")
ax.set_ylabel("Solution")
ax.legend(["Actual Solution", "Approximate Solution"])
[ ]:
2
.
At this point, it is important for you to divide the subdomain into three equal parts and write hat functions for
each domain and solve the problem. You should solve for 2 unknowns and the approximate solution is likely to
be better than if you had only 2 subdivisions. This understanding is crucial in appreciating the finite element
method.
Now, suppose, we did not remove equations Eq. 15, 16 and 17 and simply cancelled out the constants c1 ,c2 , c3 , we
get the following,
i=3
Z 1 d ∑ u i φi i=3 Z 1
d(φ1 ) i=1 dx = − (φ1 )x2 dx + F(0)
dx − φ1 ( ∑ ui φi ) (25)
0 dx i=1
0
i=3
Z 1 d ∑ ui φi i=3 Z 1
d(φ2 ) i=1
(φ2 )x2 dx
dx − φ2 ( ∑ ui φi ) dx = − (26)
0 dx i=1
0
i=3
Z 1 d ∑ u i φi i=3 Z 1
d(φ3 ) i=1
− φ3 ( ∑ ui φi ) dx = − (φ3 )x2 dx + F(1)
dx
(27)
0 dx i=1 0
here,
Z 1
d(φi ) dφ j
ki j = − φi φ j dx (32)
0 dx dx
Z 1
fi = − φ1 x2 dx (33)
0
the above set of equation has three unknowns u2 , F(0), F(1). The only equation required for finding u2 is the second
one, which is (the first row, first column; last row, last column is not needed to find u2 )
k22 u2 = f2 (35)
6
which is the same as what we got before. However, by retaining the first and the last equations we also have a way to
find out the secondary variable at the points where u was specified, which is often necessary.
Because, our solution for the interior point did not depend on whether we removed those equations, and retain-
ing them gave us a way to find the secondary variables, we can retain them, without affecting our results. Also,
this way of solving the problem, allows us to conveniently apply the boundary conditions, after writing down
the matrix form of the equations. Consequently, we need not be bothered about the constants ci s from now on
and simply assume that wi are the φi s. One of the drawbacks of this approach is that, if there was a secondary
variable applied at the interior point x = 0.5 we would not be able to apply that, as φ2 is becoming 0 at both
ends. The finite element method, can overcome this issue and make several aspects of solving the problem far
more general. This is what we do next.
5 Local Functions
Let us now consider the approximation of the solution locally over each sub-domain. We have over each domain, we
see the following
1. Over the subdomain 0 < x < 0.5 we have
We could define locally a coordinate system x = x̄ + 0.5 and then we will have for Eq. 39. Note that x̄ = 0 when
x = 0.5
u2 1
ueN2 = (1 − x̄ − 0.5) + u3 (x̄ + 0.5 − 1) + 1 (40)
0.5 0.5
u2 1
ueN2 = (0.5 − x̄) + u3 (x̄ − 0.5) + 1 (41)
0.5 0.5
giving
d2u
− − u + x2 = 0 0 < x < 1 (43)
dx2
7
subject to boundary conditions
Instead of developing the weak form over the entire domain, we shall write it over each subdomain in the following
manner. We have
Z 0.5 1 1 Z 0.5
dwi duN 1 1
− wi uN dx = − w1i x2 dx + w1i (0)F(0) + wi (0.5)F(0.5) (45)
0 dx dx 0
dw2i du2N
Z 1 Z 1
− w2i u2N dx = − w2i x2 dx + w2i (0.5)F̄(0.5) + w2i (1)F(1) (46)
0.5 dx dx 0.5
The superfixes 1 and 2 over uN and wi indicate the subdomain and NOT square. Over the second domain, we may
simply write the weak form in local coordinates as follows.
Z 0.5 2 2 Z 0.5
d w̄i d ūN 2 2
− w̄i ūN d x̄ = − w̄2i (x̄ + 0.5)2 d x̄ + w̄2i (0)F̄(0.5) + w̄2i (0.5)F̄(1) (47)
0 d x̄ d x̄ 0
where the overbars on wi and uN indicate that the approximations are written over that domain, in local coordinate
system. We need to understand what the meaning of F is at this point, after we have written the weak form over each
subdomain. F was the natural boundary condition at the ends of the domain. What does it mean at a point interior to
the domain and how do we actually deal with it. To understand this, we will write these terms in terms of the actual
derivatives of uN in this subdomain as follows.
Z 0.5 1 1
du1N
0.5
1
dwi duN duN
Z
− w1i u1N dx = − w1i x2 dx + w1i (0) (−1) + w1i (0.5) (1) (48)
0 dx dx 0 dx x=0 dx x=0.5
Z 0.5 2 2 Z 0.5 2 2
d w̄i d ūN du du
− w̄2i ū2N d x̄ = − w̄2i (x̄ + 0.5)2 d x̄ + w̄2i (0) N
(−1) + w̄2i (0.5) N
(1) (49)
0 d x̄ d x̄ 0 dx x=0.5 dx x=1
we can write the second equation completely in local coordinates and we have the two weak forms as follows,
Z 0.5 1 1 1
du1N
Z 0.5
dwi duN 1 1 1 2 1 duN
− wi uN dx = − wi x dx + wi (0) (−1) + w1i (0.5) (1) (50)
0 dx dx 0 dx x=0 dx x=0.5
Z 0.5 2 2 Z 0.5 2 2
d w̄i d ūN d ū d ū
− w̄2i ū2N d x̄ = − w̄2i (x̄ + 0.5)2 d x̄ + w̄2i (0) N
(−1) + w̄2i (0.5) N
(1) (51)
0 d x̄ d x̄ 0 d x̄ x̄=0 d x̄ x̄=0.5
8
Now by substituting for w1i and u1N from Eq.52, 53 and 54 in Eq50 and for w2i and u2N from Eq.55, 56 and 57 in Eq51
and understanding that the ci s and c̄i s get canceled on both sides we get, the following. Carefully note the following.
These give the following four equations. This can be generated using the Jupyter notebook
9
[53]: import sympy as smp
[54]: x = smp.symbols("x")
u1 = smp.symbols("u_1")
u2 = smp.symbols("u_2")
u3 = smp.symbols("u_3")
psi1 = smp.symbols("psi_1")
psi2 = smp.symbols("psi_2")
[61]: print(Eq1LHS,"=",Eq1RHS_first_term)
print(Eq2LHS,"=",Eq2RHS_first_term)
print(Eq3LHS,"=",Eq3RHS_first_term)
print(Eq4LHS,"=",Eq4RHS_first_term)
10
1
11 25 1 duN
u1 − u2 = − + (−1) (67)
6 12 96 dx x=0
1
25 11 1 duN
− u1 + u2 = − + (1) (68)
12 6 32 dx x=0.5
2
11 25 11 d ūN
u2 − u3 = − + (−1) (69)
6 12 96 d x̄ x̄=0
2
25 11 17 d ūN
− u2 + u3 = − + (1) (70)
12 6 96 d x̄ x̄=0.5
Since, SV at right end of first subdomain and SV at left end of second subdomain are should be the same, we add the
second and the third of the above set of equations, giving a matrix form of the equations as follows
11 25 1
6 − 0
u1
−
Q11
12
96
25 22 25 14 1 2
− − u 2 = − + Q 2 + Q 1 (75)
12
6 12
96
Q22
25 11 u3 17
0 − + −
12 6 96
SV between the subdomains
In general, Q12 + Q21 is not zero. It is the value of the secondary variable applied at that location. It is zero, only
if no SV is applied there. The discontinuity in the slope is essentially created by the applied SV. Think about
bar problem with a point load somewhere in between
Consequently we have
• For the first boundary condition we can have
Unknown
11 25 0 1
− −
6 0 u
Q
71
12
>1
96
1
25 22 25 14
0
− − u 2 = − + Q 1
2 + Q
:
2
1
(76)
96
12 6 12
0
25 11
u
17
−
Unknown
0 − + 3
>
2
12 6 96 Q
7
2
11
• For the second boundary condition we can have
Unknown
11 25 0 1
− −
6 0 u
Q
71
12
1
>
96
1
25 22 25 14
0
− − u2 = − +
Q 1
2 + Q
:
2
1
(77)
12
6 12
96
25 11
unknown
17 1
u
0 − + 3
> −
2
12 6 96 Q7
2
Important points
1. With the exact same formulation, we were able to solve the problem with both the boundary condition.
While the set of equations remained the same, the boundary conditions could be applied more easily
2. The coefficient matrix, were the same for both the problems
3. The coefficient matrix was symmetric and also sparse (had zeros). This will be more clear, if you had
multiple subdomains.
4.
5. By definition of the local coordinates it was sufficient to integrate for the coefficient matrix only once
for the first subdomain. The equations for the subsequent subdomain, only involved replacing u1 with
u2 and u2 with u3
6. We can apply Secondary variable at the intermediate points also. This was not possible with the formu-
lations involving Global Hat functions.
12