1. Case 1: One-Dimensional Linear Advection1Given a hyperbolic PDE as follows. ut+cux=f(x,t)with the following initial condition:u(x,0)=u0(x)where c is a positive real number. Here, we want to to find the solution to (1). When f(x,t)=0, its analytical solution is given by: u(x,t)=u0(x-ct). Simply put, u0 propagates along x with a constant speed of c. This kind of PDE is widely used for real-time modeling and control applications. Therefore, it is essential to investigate its non-homogenous version to allow the implementation of a PDE system further. A PDE system is composed of more than one interacting PDE. For example, there are at least two PDEs in a heat exchanger: one for the hot system and another one for the cold system. The two PDEs interact by exchanging heat between them.
1.1. Forward in Time Centered in Space (FTCS)This method is a finite difference method but with central difference for the distance to increase the approximation. To approximate ut, we use the following approximation.ut≈u(x,t+𝛥t)-u(x,t)
𝛥tWhile to approach ux, we use the following approximation.ux≈u(x+𝛥x,t)-u(x-𝛥x,t)
2𝛥xNext, substituting (3) and (4) back to (1) gives usa
ut
≈-cux+f(x,t)
u(x,t+𝛥t)-u(x,t)
𝛥t
≈-cu(x+𝛥x,t)-u(x-𝛥x,t)
2𝛥x+f(x,t)
u(x,t+𝛥t)-u(x,t)
≈-c𝛥t
2𝛥xau(x+𝛥x,t)-u(x-𝛥x,t)a+f(x,t)𝛥t
u(x,t+𝛥t)
≈u(x,t)-c𝛥t
2𝛥xau(x+𝛥x,t)-u(x-𝛥x,t)a+f(x,t)𝛥t
FTCS method is unconditionally unstable. It should never be used. Nevertheless, FTCS is the fundamental building block for another methods, such as the Lax method.
1.2. Upwind Method (c>0)By using finite difference method, we can approximate both ut and ux. To approximate ut, we use the following approximation.ut≈u(x,t+𝛥t)-u(x,t)
𝛥tWhile to approach ux, we use the following approximation.ux≈u(x,t)-u(x-𝛥x,t)
𝛥xBy substituting (5) and (6) to (1), we then have: a
ut
≈-cux+f(x,t)
u(x,t+𝛥t)-u(x,t)
𝛥t
≈-cu(x,t)-u(x-𝛥x,t)
𝛥x+f(x,t)
u(x,t+𝛥t)+u(x,t)
≈-c𝛥t
𝛥xau(x,t)-u(x-𝛥x,t)a+f(x,t)
u(x,t+𝛥t)
≈u(x,t)-c𝛥t
𝛥xau(x,t)-u(x-𝛥x,t)a+f(x,t)𝛥t
Let us consider c𝛥t
𝛥x=r, Uj,k=u(xj,tk), Fj,k=f(xj,tk), xj=j𝛥x and tk=k𝛥t, we then have the following shorter terms:
Uj,k+1=Uj,k-r(Uj,k-Uj-1,k)+Fj,k𝛥t
MATLAB implementation of the upwind method (7) is as follows.
Next, we will implement the PDE in (8) into the MATLAB upwind function above. ut+0.5ux=0u(x,0)=e-(x-2)20⩽x⩽10The implementation is provided in the listing below. The length of the rod is divided into 100 segments (dx=0.1) and the time is divided into 400 segments (dt=0.05).
1L =10;2dx =0.1;3x =0:dx:L;45dt =0.05;6T =20;7t =0:dt:T;89c =0.5;% Upwind1011u =zeros(length(x),1);12f =zeros(length(x),1);1314for k =1:length(x)15u(k)=exp(-(x(k)-2).^2);16end1718figure;19h =plot(0,0);20title('Upwind')21ylim([01]);2223for k =1:length(t)24 u =upwind(u,f, c, dt, dx);25set(h,'XData',x,'Ydata',u);26 drawnow;27end
The analytical solution to the PDE on (8) is u(x,t)=e-((x-0.5t)-2)2. However, when executed, the code above will generate a numerical solution as in Figure 1. As we can see, the numerical solution is not exactly the same as its analytical solution. Over time, its amplitude is decreasing.
Figure 1:Upwind method for ut+0.5uxx=0
1.3. Downwind Method (c<0)By using finite difference method, we can approximate both ut and ux. To approximate ut, we use the following approximation.ut≈u(x,t+𝛥t)-u(x,t)
𝛥tWhile to approach ux, we use the following approximation.ux≈u(x+𝛥x,t)-u(x,t)
𝛥xSubstituting (9) and (10) back to (1) yields the following.a
ut
=-cux+f(x,t)
u(x,t+𝛥t)-u(x,t)
𝛥t
≈-cu(x+𝛥x,t)-u(x,t)
𝛥x+f(x,t)
u(x,t+𝛥t)+u(x,t)
≈-c𝛥t
𝛥xau(x+𝛥x,t)-u(x,t)a+f(x,t)𝛥t
u(x,t+𝛥t)
≈u(x.t)-c𝛥t
𝛥xau(x+𝛥x,t)-u(x,t)a+f(x,t)𝛥t
Let us consider c𝛥t
𝛥x=r, Uj,k=u(xj,tk), Fj,k=f(xj,tk), xj=j𝛥x and tk=k𝛥t, we can then have the following shorter terms.
Uj,k+1=Uj,k-r(Uj+1,k-Uj,k)+Fj,k𝛥t
MATLAB implementation of an upwind method expressed in (11) is as follows.
To test the listing above, let us solve the following first order linear PDE.ut-0.5ux=0u(x,0)=e-(x-8)20⩽x⩽10The implementation is provided in the listing below. The length of the rod is divided into 100 segments (dx=0.1) and the time is divided into 400 segments (dt=0.05).
1L =10;2dx =0.1;3x =0:dx:L;45dt =0.05;6T =20;7t =0:dt:T;89c =-0.5;% Downwind1011u =zeros(length(x),1);12f =zeros(length(x),1);1314for k =1:length(x)15u(k)=exp(-(x(k)-8).^2);16end1718figure;19h =plot(0,0);20title('Downwind')21ylim([01]);2223for k =1:length(t)24 u =downwind(u,f, c, dt, dx);25set(h,'XData',x,'Ydata',u);26 drawnow;27end
The analytical solution of (12) is u(x,t)=e-((x+0.5t)-8)2. However, when executed, the provided listing above generates the a solutoinas in Figure 2. As we can see, the numerical solution is not exactly the same as its analytical solution. Over time, its amplitude is actually decreasing, similar to the upwind cases.
Figure 2:Downwind method for ut-0.5uxx=0
1.4. The Lax MethodThe Lax method is based on the FTCS method. ut≈u(x,t+𝛥t)-
u(x,t)
𝛥tHowever, u(x,t) is replaced by an average of its two neighbors.u(x,t)=u(x+𝛥x,t)+u(x-𝛥x,t)
2 Thus, by substituting (14) to (13), the approximation of ut can be rewritten asut≈u(x,t+𝛥t)-au(x+𝛥x,t)+u(x-𝛥x,t)
2a
𝛥tOn the other hand, ux can be approximated asux≈u(x+𝛥x,t)-u(x-𝛥x,t)
𝛥x, Uj,k=u(xj,tk), Fj,k=f(xj,tk), xj=j𝛥x, tk=k𝛥t, Uj,k+1=u(xj,tk+𝛥t) and Uj-1,k=u(xj-𝛥x,tk), we can then have the following shorter terms.
Uj,k+1=Uj+1,k+Uj-1,k
2-r
2(Uj+1,k-Uj,k)+Fj,k𝛥t
The Lax method can handle both upwind and downwind direction. There is no need for us to check the sign of c as in the previous methods. The listing below shows MATLAB implementation of the Lax method.
1function next_u_array =lax(u_array, f_array, c, dt, dx)23N =length(u_array);4next_u_array = u_array;56r = c*dt/dx;78fori=2:N-1% i = 1 and i = N are untouched !!!9next_u_array(i)=0.5*(u_array(i+1)+u_array(i-1))-...100.5*r*(u_array(i+1)-u_array(i-1))+...11f_array(i)*dt;12end1314% fill up the two ends by using upwind or downwind method 15if c >016next_u_array(N)=u_array(N)- r*...17(u_array(N)-u_array(N-1))+f_array(N).*dt;1819elseif c <020next_u_array(1)=u_array(1)- r*...21(u_array(2)-u_array(1))+f_array(1).*dt;2223end
There is another practical issue with the Lax method. The Lax method leaves the two end segments untouched. This can be seen from the for loop statement that starts from 2 to N-1 (see the above listing, line 8). To address this issue, we can apply the upwind and downwind method for the two untouched ends.Further, to increase the efficiency of the Lax method, we can turn the MATLAB code above in to vectorized operations as follows.
1function next_u_array =lax(u_array, f_array, c, dt, dx)23N =length(u_array);4next_u_array = u_array;56r = c*dt/dx;78next_u_array(2:N-1)=0.5.*(u_array(3:N)+(u_array(1:N-2)))-...9(0.5*r).*(u_array(3:N)-u_array(1:N-2))+...10f_array(2:N-1).*dt;111213% fill up the two ends by using upwind or downwind method 14if c >015next_u_array(N)=u_array(N)- r*...16(u_array(N)-u_array(N-1))+f_array(N).*dt;1718elseif c <019next_u_array(1)=u_array(1)- r*...20(u_array(2)-u_array(1))+f_array(1).*dt;2122end
Next, let us test the code above for both the upwind and the downwind cases. For the upwind case, we will use the PDE in (8). As for the downwind direction, we will use the PDE in (12). For both methods, the length of the rod is divided into 100 segments (dx=0.1) and the time is divided into 400 segments (dt=0.05). The listing below is the implementation of (8) and (12).
1L =10;2dx =0.05;3x =0:dx:L;45dt =0.05;6T =20;7t =0:dt:T;89u =zeros(length(x),1);10f =zeros(length(x),1);1112%% --------------------------------------------------------------13c =0.5;% moving to right 1415for k =1:length(x)16u(k)=exp(-10*(x(k)-2).^2);17end1819figure;20h1 =plot(0,0);21title('Lax, moving to the right c = 0.5')22ylim([01]);2324for k =1:length(t)25 u =lax(u,f, c, dt, dx);26set(h1,'XData',x,'Ydata',u);27 drawnow;28end2930%% --------------------------------------------------------------31c =-0.5;% moving to left3233for k =1:length(x)34u(k)=exp(-10*(x(k)-8).^2);35end3637figure;38h2 =plot(0,0);39title('Lax, moving to the left, c = -0.5')40ylim([01]);4142for k =1:length(t)43 u =lax(u,f, c, dt, dx);44set(h2,'XData',x,'Ydata',u);45 drawnow;46end
When executed, the above listing will generate Figure 3 and Figure 4 where we can see the resulting amplitude is also decreasing over time.
Figure 3:Lax method for ut-0.5uxx=0
Figure 4:Lax method for ut+0.5uxx=0
1.5. The Lax-Wendroff Method2We start from the Taylor series definition off(x+𝛥x)f(x+𝛥x)=f(x)+𝛥xf′(x)+𝛥x2
2!f′′(x)+𝛥x3
3!f′′′(x)+…Thus, taking only up to the second order, we can writea
u(x+𝛥x,t)
=u(x,t)+𝛥xux+𝛥x2
2uxx
Remember thatut=u(x,t+𝛥t)-u(x,t)
𝛥tand ux=u(x+𝛥x,t)-u(x,t)
𝛥xThus, ut=-cux+f(x,t) can be rewritten as u(x,t+𝛥t)-u(x,t)
Since c is the propagation speed of u(x,t)=u0(x-ct), thus, let us take𝛥x=-c𝛥t. As the result, now we have the following equation.
u(x,t+𝛥t)=≈u(x,t)-c𝛥tux+c2𝛥t2
2uxx+f(x,t)𝛥t
Next, we need to approximate ux and uxx. For ux, we use central difference method as follows.ux≈u(x+𝛥x,t)-u(x-𝛥x,t)
2𝛥xAs for uxx, we do not use the central difference method, instead, we take ux≈u(x+𝛥x,t)-u(x,t)
𝛥x. Therefore, we can express uxx as follows.
uxx
≈ux(x+𝛥x,t)-ux(x,t)
𝛥x
≈u(x+𝛥x,t)-u(x,t)
𝛥x-u(x,t)-u(x-𝛥x,t)
𝛥x
𝛥x
≈u(x+𝛥x,t)-2u(x,t)+u(x-𝛥x,t)
𝛥x2
Now that we have (24) and (25), we can substitute them back to (23):
u(x,t+𝛥t)
≈u(x,t)-c𝛥tux+c2𝛥t2
2uxx+f(x,t)𝛥t
a≈u(x,t)-c𝛥t[u(x+𝛥x,t)-u(x-𝛥x,t)
2𝛥x]+ c2𝛥t2
2[u(x+𝛥x,t)-2u(x,t)+u(x-𝛥x,t)
𝛥x2]+f(x,t)𝛥t
a≈u(x,t)-c𝛥t
2𝛥x[u(x+𝛥x,t)-u(x-𝛥x,t)]+c2𝛥t2
2𝛥x2[u(x+𝛥x,t)-2u(x,t)+u(x-𝛥x,t)]+f(x,t)𝛥t
Now let us consider r=c𝛥t
𝛥x, Uj,k=u(xj,tk), Fj,k=f(xj,tk), xj=j𝛥x, tk=k𝛥t, Uj,k+1=u(xj,tk+𝛥t) and Uj-1,k=u(xj-𝛥x,tk), we can then have the following shorter terms.
Uj,k+1=Uj,k-r
2(Uj+1,k-Uj-1,k)+r2
2(Uj+1,k-2Uj,k+Uj-1,k)+Fj,k𝛥t
MATLAB implementation of (26) is as follows (see line 6 to 11).
1function next_u_array =lax_wendroff(u_array, f_array, c, dt, dx)23N =length(u_array);4next_u_array = u_array;56r = c*dt/dx;7fori=2:N-18next_u_array(i)=u_array(i)-0.5*r*(u_array(i+1)-u_array(i-1))...9+0.5*r^2*(u_array(i+1)-2*u_array(i)+u_array(i-1))...10+f_array(i)*dt;11end1213% fill up the two ends by using upwind or downwind method 14if c >015next_u_array(N)=u_array(N)- r*...16(u_array(N)-u_array(N-1))+f_array(N)*dt;1718elseif c <019next_u_array(1)=u_array(1)- r*...20(u_array(2)-u_array(1))+f_array(1)*dt;2122end
Here, we encounter the same issue as in the previous Lax method. The Lax-Wendroff method also leaves the two end segments untouched. This can be seen clearly from the for-statement that starts from 2 to N-1 (see line 7 of the listing above). To address this issue, we apply upwind and downwind method for the two ends only (see line 14 to 20 of the listing above).Further, to increase its efficiency, we can turn the MATLAB code above in to vectorized operations as follows.
1function next_u_array =lax_wendroff(u_array, f_array, c, dt, dx)23N =length(u_array);4next_u_array = u_array;56r = c*dt/dx;78next_u_array(2:N-1)=u_array(2:N-1)-0.5*r*(u_array(3:N)-u_array(1:N-2))...9+0.5*r^2*(u_array(3:N)-2*u_array(2:N-1)+u_array(1:N-2))...10+f_array(2:N-1)*dt;1112% fill up the two ends by using upwind or downwind method 13if c >014next_u_array(N)=u_array(N)- r*...15(u_array(N)-u_array(N-1))+f_array(N)*dt;1617elseif c <018next_u_array(1)=u_array(1)- r*...19(u_array(2)-u_array(1))+f_array(1)*dt;2021end
Next, let us test the code listings above for both the upwind and the downwind cases. For the upwind case, we will use the same system as in (8) As for the downwind direction, we will also use the same system as in (12). We will divide the length of the rod into 200 segments (dx=0.05) and the time into 200 segments as well (dt=0.05). See the listing below.
1L =10;2dx =0.05;3x =0:dx:L;45dt =0.05;6T =20;7t =0:dt:T;89u =zeros(length(x),1);10f =zeros(length(x),1);1112%% ------------------------------------------------------------13c =0.5;% moving to right1415for k =1:length(x)16u(k)=exp(-10*(x(k)-2).^2);17end1819h = figure;20h1 =plot(0,0);21title('Lax-Wendroff, moving to the right c = 0.5')22ylim([01]);2324for k =1:length(t)25 u =lax_wendroff(u,f, c, dt, dx);26set(h1,'XData',x,'Ydata',u);27 drawnow28end2930%% ------------------------------------------------------------31c =-0.5;% moving to left3233for k =1:length(x)34u(k)=exp(-10*(x(k)-8).^2);35end3637h = figure;38h1 =plot(0,0);39title('Lax-Wendroff, moving to the left, c = -0.5')40ylim([01]);4142for k =1:length(t)43 u =lax_wendroff(u,f, c, dt, dx);44set(h1,'XData',x,'Ydata',u);45 drawnow46end
When executed, the listing above will generate the Figure 5 and Figure 6. As shown by those two figures, the, Lax-Wendroff method does provide more stable solutions. Even tough the amplitudes are still decreasing, the decrease in the amplitude is much smaller than other methods that have been previously discussed.
Figure 5:Lax method for ut-0.5uxx=0
Figure 6:Lax method for ut+0.5uxx=0
1.6. Cross Current Heat Exchanger as An Example3A heat exchanger is modeled with two or more interacting non-homogenous PDEs. The simplest model involves two PDEs only: the hot flow and the cold flow. Yet another simple method, three PDEs are involved: the hot flow, the cold flow, and the wall between them.1.6.1. Two-Equation ModelFlowing liquid inside a container can be modeled as an advective PDE. When external environment is involved, the PDE becomes non-homogenous (see Drawing 1). Interaction with the environment is modeled with Fourier's Law. The overall process can be modeled as follows.𝜕T(x,t)
𝜕t+v𝜕T(x,t)
𝜕z⏠⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏢Advection=-UAS
𝜌ACp(T(x,t)-TS(x,t))⏠⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏢Fourier's lawwhereCp is the liquid specific heat capacityA is cross sectional are of the tube where the liquid is flowingAS is the heat transfer area (blue surface)U is the overall heat transfer coefficient between the tube to its environment𝜌 is the density of the liquidAs𝜌ACpUAs(Ts-T)TS(x,t)T(x,t)A
Drawing 1:Flowing liquid in red container while transferring heat to its environment
A diagram of a simplest heat exchanger is presented in Drawing 2. From Drawing 2, we can see that hot liquid flows from left to right and cold liquid flows from right to left. Source temperature of the hot flow is kept at TH0. While source temperature of the cold flow is kept at TC0. Those two temperatures never change. This condition is called Dirichlet condition.L
TH(0,t)=TH0
TC(L,t)=TC0
TH(x,0)=TH0
TC(x,0)=TC0
c2c1d1d2TH(x,t)c1 and c2 are in m/sd1 and d2 are in 1
Drawing 2:Cross-current heat exchanger modeled with two PDEs
The system model of a heat exchanger based on Drawing 2 can be described as follows. a
𝜕
𝜕tTH(x,t)+c1𝜕
𝜕xTH(x,t)
=-d1(TH(x,t)-TC(x,t))
𝜕
𝜕tTC(x,t)-c2𝜕
𝜕xTC(x,t)
=-d2(TC(x,t)-TH(x,t))
ora
𝜕
𝜕tTH(x,t)
=-c1𝜕
𝜕xTH(x,t)-d1(TH(x,t)-TC(x,t))
𝜕
𝜕tTC(x,t)
=c2𝜕
𝜕xTC(x,t)+d2(TH(x,t)-TC(x,t))
where: • d1 and d2 describe convective heat transfer between the the two flowing liquids: from hot liquid to cold liquid and from cold liquid to hot liquid, respectively. • c1 and c2 describes advective heat transfer inside the the hot and cold liquid, respectively. This is analogous to the actual movement of the liquids since the heat moves together with the liquids.• For the simulation, we will set the parameters according to the paper by Zobiri et.al.4 In their paper, it is mentioned that they use upwind-downwind method. However, we will solve the system above by using both the upwind-downwind method and the Lax-Wendroff method so that we can compare their results. The listing below shows the implementation of a cross-current heat exchanger as in (28) which runs for 20s with 0.01s step-time.
From line 41 to 44 of the listing above, we use the upwind method for the hot flow since the flow moves from left to right. As for the cold flow, we use the downwind method since the cold flow moves from right to left. As for the Lax-Wendroff method, there is only one function that we call (line 73 to 76). However, we still need to call that function twice, one for the cold flow, another one is for the hot flow. When executed, the provided lisiting above will generate animations of the temperature evolutions for both methods.Figure 7 and Figure 8 below show the temperature distribution of the modeled heat exchanger after 20 seconds for two different methods. From Figure 8, we can see that Lax-Wendroff method generates flat curve in its middle area. Theoretically, this makes more sense when compared to the results acquired from the upwind-downwind method. However, if we think with a practical perspective, the upwind-and downwind method might be more desirable since a theoretically perfect advection might be impossible in a real world.
Figure 7:After 20 s, with upwind-downwind method
Figure 8:After 20 s, with Lax-Wendroff method
1.6.2. Three-Equation ModelL
TH(0,t)=TH0
TC(L,t)=TC0
TH(x,0)=TH0
TC(x,0)=TC0
v2v1TH(x,t)TC(x,t)d1d2TW(x,t)TW(x,0)=TW0
∂
∂tTW(L,t)=0
∂
∂tTW(0,t)=0
v3NeumannNeumannDirichletDirichletd3d4
Drawing 3:Cross-current heat exchanger modeled with three PDEs
In three-equation model (see Drawing 3), we consider the wall between the hot flow and the cold flow. In general, we can summarize how the heat are being exchanged as follows.• d1 and d2 describe convective heat transfer from the the liquid to the wall: from the hot liquid to the wall and from the cold liquid to the wall, respectively. • d3 and d4 describe convective heat transfer from the the wall to the liquid: from the wall to the hot liquid and from the wall to the cold liquid, respectively. • v1 and v2 describes advective heat transfer inside the the hot and cold liquid, respectively. This is analogous to the actual movement of the liquids since the heat moves together with the liquids.• v3 describes diffusive/conductive heat transfer inside the tube wall.• Therefore, the three-equation model of a cross-current heat exchanger can be expressed as follows.a
The initial and boundary conditions are:TH(0,t)=360 and TH(x,0)=360TC(L,t)=300 and TC(x,0)=300TW(x,0)=330, ∂TW(0,t)
∂x=0, and ∂TW(L,t)
∂x=0In (30), the third equation is different than the first two equations. The third equation is a non-homogeneous one-dimensional heat equation (diffusion) with Neumann boundary conditions. We will discuss this in the next section. Nevertheless, we will directly show the implementation of the three-equation model of a heat exchanger in MATLAB. For the first and second equations, we will use upwind and downwind method, respectively (see line 51 to 55). The rest of the code can be understood after reading the next section.
When executed for 20 seconds, temperature distributions of different parts of the heat exchanger are shown in Drawing 4.Phantom node∂TW(0,t)
∂x=0Phantom node∂TW(L,t)
∂x=0TH(0,t)=360TC(L,t)=300n-th segment
Drawing 4:Temperature distributions after 5 seconds
Figure 9:Animation of the temperature evolution of the heat exchanger
2. Case 2: One-Dimensional Heat Equation6The equation of temperature distribution (u) in a one-dimensional rod (see Drawing 5) over a certain distance (x) and time (t) is given by (31). 𝛼 is the diffusivity coefficient. When g(x,t)=0, the system is homogenous.𝛼²uxx-ut=g(x,t)t⩾0 and 0⩽x⩽Lwhen at t=0, the following initial condition is applied.u(x,0)=f(x)x=0x=Lu(x,0)=f(x)Boundary conditionBoundary condition
Drawing 5:Temperature distribution (u) in a very thin rod
2.1. Explicit MethodWith finite difference method, we can approach ut and uxx. To approximate ut, we use the following approximation.ut≈u(x,t+𝛥t)-u(x,t)
𝛥tux≈u(x+𝛥x,t)-u(x,t)
𝛥xWhile to approach ux, we use the following approximation.
uxx
≈ux(x+𝛥x,t)-ux(x,t)
𝛥x
≈u(x+𝛥x,t)-u(x,t)
𝛥x-u(x,t)-u(x-𝛥x,t)
𝛥x
𝛥x
≈u(x+𝛥x,t)-2u(x,t)+u(x-𝛥x,t)
(𝛥x)2
Substituting (32) and (33) back to (31) gives us the following equations.a
ut
≈𝛼2uxx+g(x,t)
u(x,t+𝛥t)-u(x,t)
𝛥t
≈𝛼2u(x+𝛥x,t)-2u(x,t)+u(x-𝛥x,t)
𝛥x2+g(x,t)
u(x,t+𝛥t)-u(x,t)
≈𝛼2𝛥t
𝛥x2(u(x+𝛥x,t)-2u(x,t)+u(x-𝛥x,t))+g(x,t)𝛥t
u(x,t+𝛥t)
≈𝛼2𝛥t
𝛥x2u(x+𝛥x,t)+(1-2𝛼2𝛥t
𝛥x2)u(x,t)+𝛼2𝛥t
𝛥x2u(x-𝛥x,t)+g(x,t)𝛥t
≈ru(x+𝛥x,t)+(1-2r)u(x,t)+ru(x-𝛥x,t)+g(x,t)𝛥t
≈u(x,t)+rau(x+𝛥x,t)-2u(x,t)+u(x-𝛥x,t)a
where r=𝛼2𝛥t
(𝛥x)2. Now, let us consider Uj,k=u(xj,tk), Gj,k=g(xj,tk), xj=j𝛥x, tk=k𝛥t, Uj,k+1=u(xj,tk+𝛥t) and Uj-1,k=u(xj-𝛥x,tk), we can then have the following shorter terms.a
Uj,k+1=Uj,k+raUj+1,k-2Uj,k+Uj-1,ka+Gj,k𝛥t
2.1.1. Dirichlet Boundary ConditionsIn (31), certain conditions are applied and kept true at all time. These conditions are called boundary conditions. There are several types of boundary conditions. One of them is Dirichlet boundary condition. A typical Dirichlet boundary condition would be u(0,t)=Au(L,t)=Bwhere A and B are real numbers. The implementation of the Dirichlet boundary condition is very straightforward by directly controlling values at the two end nodes.2.1.2. Neumann Boundary ConditionAnother type of boundary condition is the Neumann boundary condition. In Neumann boundary condition, the derivative of the solution function (∂u(x,t)/∂x or ∂u(x,t)/∂t) is kept constant. However, here we will only implement the derivative of the solution with respect to x.∂u(x,t)
∂x=Cwhere C is a real number. At the boundary when x=0, we can write u(𝛥x,t)-u(-𝛥x,t)
2𝛥x=C thereforeu(-𝛥x,t)=u(𝛥x,t)-2𝛥xCAt another boundary when x=Lu(L+𝛥x,t)-u(L-𝛥x,t)
2𝛥x=D where D is a real number. Thereforeu(L+𝛥x,t)=u(L-𝛥x,t)+2𝛥xDThe implementation of Neumann boundary condition will be done by adding additional phantom nodes as shown in Drawing 6.u(0,tk)u(L,tk)u(𝛥x,tk)u(L+𝛥x,tk)u(-𝛥x,tk)……x=0x=L
Drawing 6:Extra phantom nodes for Neumann boundary condition
2.1.3. MATLAB ImplementationMATLAB implementation of (35) is as follows.
The implementation above is already vectorized. In line 9 of the listing above, we can see that the diffusion is not applied to the first and last nodes. At those two end-nodes, we will apply the boundary conditions. Therefore, we also create two more functions for the initial and boundary conditions (see the listing below).
In the Neumann boundary condition, we need to add additional phantom nodes. There are some examples provided in the next section to understand how to use the aforementioned three functions.2.1.4. Example 1Given the following heat transfer equation:a
1.14uxx-ut=0, 0⩽x⩽10
with the following boundary and initial conditions:a
2.2. Implicit MethodThe main idea of an implicit method is to calculate uxx not only at the current time, but also at the time one step ahead. Let us consider:uxx(x,t)=(1-𝜃)uxx(x,t)+𝜃uxx(x,t+𝛥t), 0⩽𝜃⩽1where 𝜃 acts as a weighting factor. When 𝜃=0, (47) becomes similar to (35). What we currently have in this case is an explicit method. On the other hand, when 𝜃=1, in this case, what we have is an implicit method. However, when 𝜃=0.5, the method is called Crank-Nicolson method. In this section, let us focus on mathematical derivations of the Crank-Nicolson method.Expanding (47) bu first setting 𝜃=1
2 gives us:
uxx
=1
2ux(x+𝛥x,t)-ux(x,t)
𝛥x+1
2ux(x+𝛥x,t+𝛥t)-ux(x,t+𝛥t)
𝛥x
=u(x+𝛥x,t)-u(x,t)
𝛥x-u(x,t)-u(x-𝛥x,t)
𝛥x
2𝛥x+u(x+𝛥x,t+𝛥t)-u(x,t+𝛥t)
𝛥x-u(x,t+𝛥t)-u(x-𝛥x,t+𝛥t)
𝛥x
2𝛥x
a=u(x+𝛥x,t)-2u(x,t)+u(x-𝛥x,t)
2𝛥x2+u(x+𝛥x,t+𝛥t)-2u(x,t+𝛥t)+u(x-𝛥x,t+𝛥t)
2𝛥x2
which can be shortened asuxx=Uj+1,k-2Uj,k+Uj-1,k+Uj+1,k+1-2Uj,k+1+Uj-1,k+1
2𝛥x2Substituting (48) back to: ut=𝛼²uxx gives us:a
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢BRed means the values are known. In (52), we can notice that some known values reside in U. We must remove these known values from U and put them to the right side. The goal is to have a perfect AU=B system where all the unknowns are all in U. [a
2(1+r)
-r
⋯
0
-r
2(1+r)
-r
⋮
⋱
-r
2(1+r)
-r
⋯
-r
2(1+r)
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
U1,k+1
U2,k+1
⋮
UN-2,k+1
UN-1,k+1
]⏠⏣⏣⏣⏡⏣⏣⏣⏢Unew=[a
2(1-r)
r
⋯
⋯
r
2(1-r)
r
⋱
r
2(1-r)
r
⋯
r
2(1-r)
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢b[a
U1,k
U2,k
⋮
UN-2,k
UN-1,k
]⏠⏣⏣⏣⏡⏣⏣⏣⏢Unow+[a
rp((k+1)𝛥t)+rp(k𝛥t)
0
⋮
0
rq((k+1)𝛥t)+rq(k𝛥t)
]⏠⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏢c⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢B=(b·Unow)+cNow, we can find Unew=A-1B. In real implementation, this might not be plausible and we have to perform an iteration-based algorithm to find the optimal Unew. In Maple, we can use the Unew=LinearSolve(A,B) command. In MATLAB, we can use the popular Unew=A\B command. Other alternatives are using the Jacobi method and the Gauss-Siedel method as explained the Greenberg's book.3. Two-Dimensional Poisson Equation73.1. Dirichlet Boundaryu(0,y)=p(y)u(x,b)=s(x)u(a,y)=r(y)bau(x,0)=q(x)xyu(x,y)DyxD
Drawing 10:Heat distribution on a two-dimensional plane with Dirichlet boundary conditions
Heat transfer on a two-dimensional plane (see Drawing 10) is described as follows:uxx+uyy=f(x,y)0≤x≤a,0≤y≤bThe PDE in (54) is known as the Poisson equation. Its homogenous form is known as the Laplace equation.Finite difference method for the system above is as follows. First, uxx and uyy can be approximated as:a
uxx=𝜕2u
𝜕x2≈u(x-𝛥x,y)-2u(x,y)+u(x+𝛥x,y)
𝛥x2
uyy=𝜕2u
𝜕y2≈u(x,y-𝛥y)-2u(x,y)+u(x,y+𝛥y)
𝛥y2
Hence:a
uxx+uyy
=f(x,y)
u(x-𝛥x,y)-2u(x,y)+u(x+𝛥x,y)
𝛥x2+u(x,y-𝛥y)-2u(x,y)+u(x,y+𝛥y)
𝛥y2
=f(x,y)
For simplification purpose, let us take 𝛥x=𝛥x=h, therefore:a
uxx+uyy
=f(x,y)
u(x-h,y)-2u(x,y)+u(x+h,y)
h2+u(x,y-h)-2u(x,y)+u(x,y+h)
h2
=f(x,y)
Let us take Uj,k=u(xj,yk), Fj,k=f(xj,yk), xj=jh, yk=kh, Uj,k+1=u(xj,yk+h) and Uj-1,k=u(xj-h,yk), hence:a
u(x-h,y)-2u(x,y)+u(x+h,y)
h2+u(x,y-h)-2u(x,y)+u(x,y+h)
h2
=f(x,y)
Uj-1,k-2Uj.k+Uj+1,k+Uj,k-1-2Uj.k+Uj,k+1
=h2Fj,k
Uj-1,k+Uj+1,k+Uj,k-1+Uj,k+1-4Uj,k
=h2Fj,k
Therefore, the resulting discrete formula is as follows:
a
Uj-1,k+Uj+1,k+Uj,k-1+Uj,k+1-4Uj,k
=h2Fj,k
In order to solve (59), we need to reformulate it into a matrix form. In order to do so, we first define the following girds:Left edgeRight edgeTop edgeBottom edgek=0k=1……j=0j=1⋮⋮k=Nxj=Nyhhab
Drawing 11:Grid discretization of the 2D plate.
Next, based on the Drawing 11, we can then get the following equation:[a
-4
1
0
1
⋯
0
1
-4
1
0
1
⋮
⋱
⋱
⋱
⋱
⋱
0
1
-4
0
0
1
1
0
1
-4
1
0
1
1
0
1
-4
1
0
1
⋱
⋱
⋱
⋱
⋱
⋱
⋱
1
0
1
-4
1
0
1
⋱
⋱
⋱
⋱
⋱
1
0
0
-4
1
0
1
0
1
-4
1
⋮
⋱
⋱
⋱
⋱
0
…
1
0
1
-4
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
U1,1
U2,1
⋮
UNy-1,1
U1,2
U2,2
⋮
UNy-1,2
⋮
U1,Nx-1
U2,Nx-1
⋮
UNy-1,Nx-1
]⏠⏣⏣⏣⏣⏡⏣⏣⏣⏣⏢U=[a
-(U1,0+U0,1)+h2F1,1
-U2,0+h2F2,1
⋮
-(UNy-1,0+UNy,1)+h2FNy,1
-U0,2+h2F1,2
h2F2,2
⋮
-UNy,2+h2FNy-1,2
⋮
-(U1,Nx+U0,Nx-1)+h2F1,Nx-1
-U2,Nxh2F2,Nx-1
⋮
-(UNy-1,Nx+UNy,Nx-1)+h2FNy-1,Nx-1
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢cOnce we have (60), we can solve it to acquire U. In MATLAB, this can be easily done by using: U=A\c.Let us now take a more simple example. Given the following diffusion PDE:uxx+uyy=f(x,y)where:0⩽x⩽1, 0⩽y⩽1Nx=Ny=4p(y)=0q(x)=0r(y)=100sin(𝜋y)s(x)=0f(x,y)=0h=0.25Find u(x,y) at its steady state condition.First, we create the matrix U as follows:U=a
a
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
70.71
100
70.71
0
a
j=0
j=1
j=2
j=3
j=4
k=0k=1k=2k=3k=4Red colored numbers represents values at the boundaries. These values are calculated from p(y), q(x), r(y), and s(x). Next, we generate an equation similar (60) and calculate the U.a
a
-4
1
0
1
0
0
0
0
0
1
-4
1
0
1
0
0
0
0
0
1
-4
0
0
1
0
0
0
1
0
0
-4
1
0
1
0
0
0
1
0
1
-4
1
0
1
0
0
0
1
0
1
-4
0
0
1
0
0
0
1
0
0
-4
1
0
0
0
0
0
1
0
1
-4
1
0
0
0
0
0
1
0
1
-4
a
a
U1,1
U2,1
U3,1
U1,2
U2,2
U3,2
U1,3
U2,3
U3,3
=a
a
-U1,0-U0,1
-U2,0
-U3,0-U4,1
-U0,2
0
-U4,2
-U1,4-U0,3
-U2,4
-U3,4-U4,3
3.2. Neumann Boundary4. Two-Dimensional Unsteady Advection-DiffusionLet us consider the flowing PDE:𝜕T
𝜕t+u𝜕T
𝜕x+v𝜕T
𝜕y⏠⏣⏣⏣⏡⏣⏣⏣⏢2D Advection=𝛼(𝜕2T
𝜕x2+𝜕2T
𝜕y2⏠⏣⏣⏣⏡⏣⏣⏣⏢2D Diffusion)+f(61) is the general transient heat equation in 2D space. It is composed of advection process and diffusion process. 𝛼 is defines as:𝛼=K
𝜌cpwhere:cp is the specific heat at constant (J(kgK)𝜌 is the fluid density (kg/m3)K is the thermal conductivity (W(mK))f is the additional forcing componentIn order to discretize (61), we will use the simplest methods, which are the upwind/downwind method for the advection and the explicit FTCS method for the diffusion. 4.1. UPWIND-UPWIND MethodThe upwind-upwind method is used when both velocities are positive or zero. We start by discretizing (61) as follows:T(x,y,t+𝛥t)-T(x,y,t)
Taking: Ti,j,k=T(xi,yj,tk), xj=j𝛥x, yk=k𝛥y, and tk=k𝛥t, we can rewrite (64) as follows:
aTi,j,k+1=𝛼𝛥t((Ti+1,j,k-2Ti,j,k+Ti-1,j,k
𝛥x2)+(Ti,j+1,k-2Ti,j,k+Ti,j-1,k
𝛥y2))- 𝛥t(ui,j,k
𝛥x(Ti,j,k-Ti-1,j,k)+vi,j,k
𝛥y(Ti,j,k-Ti,j-1,k))+Ti,j,k+ 𝛥t fi,j,k
4.2. DOWNWIND-DOWNWIND MethodThe downwind-downwind method is used when both velocities are negative or zero. The discretization process is similar to the upwind method. The only difference is in the advection part. The discretization is done as follows:T(x,y,t+𝛥t)-T(x,y,t)
Taking: Ti,j,k=T(xi,yj,tk), xj=j𝛥x, yk=k𝛥y, and tk=k𝛥t, we can rewrite (67) as follows:
aTi,j,k+1=𝛼𝛥t((Ti+1,j,k-2Ti,j,k+Ti-1,j,k
𝛥x2)+(Ti,j+1,k-2Ti,j,k+Ti,j-1,k
𝛥y2))- 𝛥t(ui,j,k
𝛥x(Ti+1,j,k-Ti,j,k)+vi,j,k
𝛥y(Ti,j+1,k-Ti,j,k))+Ti,j,k+ 𝛥t fi,j,k
4.3. DOWNWIND-UPWIND MethodThe downwind-upwind method is used when the x-velocity is negative and the y-velocity is positive.
aTi,j,k+1=𝛼𝛥t((Ti+1,j,k-2Ti,j,k+Ti-1,j,k
𝛥x2)+(Ti,j+1,k-2Ti,j,k+Ti,j-1,k
𝛥y2))- 𝛥t(ui,j,k
𝛥x(Ti+1,j,k-Ti,j,k)+vi,j,k
𝛥y(Ti,j,k-Ti,j-1,k))+Ti,j,k+ 𝛥t fi,j,k
4.4. UPWIND-DOWNWIND MethodThe downwind-upwind method is used when the x-velocity is positive and the y-velocity is negative.
aTi,j,k+1=𝛼𝛥t((Ti+1,j,k-2Ti,j,k+Ti-1,j,k
𝛥x2)+(Ti,j+1,k-2Ti,j,k+Ti,j-1,k
𝛥y2))- 𝛥t(ui,j,k
𝛥x(Ti,j,k-Ti-1,j,k)+vi,j,k
𝛥y(Ti,j+1,k-Ti,j,k))+Ti,j,k+ 𝛥t fi,j,k
4.5. MATLAB ImplementationFirst, we apply a grid discretization to the the two-dimensional rectangle as follows:ROWCOLUMNi or yj or x𝛥y𝛥x(1,1)(Nx,Ny)vu
Drawing 12:A discretized two-dimensional plane
Next, we can then implement (65) and (68) in MATLAB, as follows:
In the code listing above, we can see that the implemented functions never update the boundaries. Thus, we can conveniently set the boundary condition only once for the Dirichlet boundary condition. However, for he Neumann boundary condition, we will need to create phantom nodes. This topic will be further discussed in the next section.Now that we have covered all possible directions for the velocity vector and implemented them in MATLAB, we will then test our MATLAB implementation in the following scenario. First, we will define a circular vector field on a thin plate. This vector field represents the velocity vector. Next, we constrained the temperature at a certain location in that plate (heat source) and watch how the heat propagates.
Figure 10:Heat advection on a plate with circular velocity vector field
4.6.1. Left EdgeAssuming that boundary condition for the left edge is 𝜕T(x,0,t)
𝜕x=A. thus we have:T(i,2)-T(i,0)
2𝛥x=AHence:
T(i,0)=T(i,2)-2𝛥xA
4.6.2. Right EdgeAssuming that boundary condition for the left edge is 𝜕T(x,h,t)
𝜕x=B. thus we have:T(i,Nx+1)-T(i,Nx-1)
2𝛥x=BHence
T(i,Nx+1)=T(i,Nx-1)+2𝛥xB
4.6.3. Top EdgeAssuming that boundary condition for the left edge is 𝜕T(0,y,t)
𝜕y=C. thus we have:T(2,j)-T(0,j)
2𝛥y=CHence
T(0,j)=T(2,j)-2𝛥yC
4.6.4. Bottom EdgeAssuming that boundary condition for the left edge is 𝜕T(ℓ,y,t)
𝜕y=D. thus we have:T(Nx+1,j)-T(Nx-1,j)
2𝛥y=DHence
T(Ny+1,j)=T(Ny-1,j)+2𝛥yD
4.7. Energy Balance Model: Out-of-Plane Heat Transfer for a Thin PlateUp to now, we only deal with homogenous equation. However, when the system interacts with its environment or with other system, the governing equations become non non-homogenous. To demonstrate this, we will implement the following scenario in MATLAB and compare the result with COMSOL. This scenario is taken from the COMSOL Application Gallery8. A very thin plate (1 m×1 m, and thickness of 0.001 m) is heated only at the left edge. The temperature applied heat is 800 K. Other edges are thermally insulated. Heat transfer to the external environment only happens from the two surfaces of the plate.4.7.1. Transient CaseFor the transient case, the governing heat equation of the system above is as follows:a
dz𝜌cp𝜕T
𝜕t
=dzK(𝜕2T
𝜕x2+𝜕2T
𝜕y2)-hu(T-T∞)-hd(T-T∞)
-𝜀u𝜎(T4-T4∞)-𝜀d𝜎(T4-T4∞)
wheredz=0.01 mhu=hd=h=10 W/(m2K)𝜀u=𝜀d=𝜀=0.5𝜎=5.67×10-8W/(m2K4)The material is copper where:cp=385 J/(kgK)K=400 W/(mK)𝜌=8960 kg/m3We can simplify (79) as follows:a
𝜕T
𝜕t
=K
𝜌cp(𝜕2T
𝜕x2+𝜕2T
𝜕y2)-2h
dz𝜌cp(T-T∞)-2𝜀𝜎
dz𝜌cp(T4-T4∞)
The first thing we can do to see of the formula in (80) is correct is by checking the correctness of the unis. To check the units, we do it as follows:K
s=W/(mK)
kg/m3J/(kgK)(K
m2+K
m2)-W/(m2K)
mkg/m3J/(kgK)K-W/(m2K4)
mkg/m3J/(kgK)K4K
s=K
s-K
s-K
sThe units are indeed correct.MATLAB implementation of (80) is as follows:
1dz =0.01;2cp =385;3K =400;4rho =8960;5alpha = K/(rho*cp);6beta = dz*rho*cp;78dx =0.01;9dy =0.01;10dt =0.001;% Small enough to not cause instability1112ly =1;% 1x1 m^213lx =1;14Nx = lx/dx;15Ny = ly/dy;16Nt = tF/dt;1718tF =10000;% Simulation time, modify accordingly1920h =10;21sigma =5.67e-8;22e =0.5;23T_inf =300;2425clear T_array u_array v_array f_array;2627% Some extra nodes for phantom nodes28u_array =zeros(Nx+2,Ny+1);% Disable advection29v_array =zeros(Nx+2,Ny+1);% Disable advection30T_array =297.15*ones(Nx+2,Ny+1);31f_array =zeros(Nx+2,Ny+1);3233% Preparation for plotting34hfig = figure;35axis off;36hold on;37title('Diffusion')38caxis([300800])3940for k =1: Nt 41% Heat source at the center of the plate, keep it true at all time42 T_array =apply_bc(T_array, dx, dy,...43["Dirichlet", "Neumann", "Neumann", "Neumann"],...44[800,0,0,0]);4546% Calculate the forcing component47f_array(2:end-1,2:end-1)=-(2*h/beta*(T_array(2:end-1,2:end-1)- T_inf)...48+2*e*sigma/beta*(T_array(2:end-1,2:end-1).^4- T_inf^4));4950% Solve the PDE 51 T_array =advection_diffusion_upwind(T_array,...52 u_array,...53 v_array,...54 dt,...55 dx,...56 dy,...57 alpha,...58 f_array);59end6061heatmap(T_array, false);
In the listing above, we disable the advection by setting u=v=0. The main iteration starts from line 40 to line 59. There are three things we put in the iteration: boundary condition update, external forcing component calculation, and PDE solving. After 10000 second, we will acquire the following result:
Figure 11:Temperature distribution of the plate
We can compare the result with COMSOL. However, the provided COMSOL file only simulates the stationary case.4.7.2. Stationary CaseFor the stationary case, the governing heat equation of the system above is as follows:a
0
=K
𝜌cp(𝜕2T
𝜕x2+𝜕2T
𝜕y2)-hu
dz𝜌cp(T-T∞)-hd
dz𝜌cp(T-T∞)
-𝜀u𝜎
dz𝜌cp(T4-T4∞)-𝜀d𝜎
dz𝜌cp(T4-T4∞)
The system in (81) is a 2D Poisson PDE, which we can solve it by using the five-point difference method.5. Navier-Stokes with Heat TransferIn this section, we will model a cross-current heat exchanger by using the famous Navier-Stokes equation for fluid flows with heat transfer. We will start with one flow first. After that, we will implement both flows and the occurring heat transfer between them.5.1. Channel Flow with Heat EquationWe will model the flow of the fluid as a two-dimensional flow. The flow is driven by pressure gradient (planar Poiseuille flow). Flow InNo-slip wallNo-slip wall𝜕p
Drawing 14:Heat transfer in a two-dimensional channel flow
Conservation of mass:𝜕u
𝜕x+𝜕v
𝜕y⏠⏣⏣⏣⏡⏣⏣⏣⏢Divergence=0Conservation of linear momentum:𝜕u
𝜕t+u𝜕u
𝜕x+v𝜕u
𝜕y=-1
𝜌𝜕p
𝜕x+𝜈(𝜕2u
𝜕x2+𝜕2u
𝜕y2)𝜕v
𝜕t+u𝜕v
𝜕x+v𝜕v
𝜕y=-1
𝜌𝜕p
𝜕y⏠⏣⏣⏡⏣⏣⏢Gradient+𝜈(𝜕2v
𝜕x2+𝜕2v
𝜕y2)⏠⏣⏣⏣⏡⏣⏣⏣⏢LaplacianConservation of energy:𝜌cp(𝜕T
𝜕t+u𝜕T
𝜕x+v𝜕T
𝜕y)=k(𝜕2T
𝜕x2+𝜕2T
𝜕y2)where:u(x,y,t) is the x-velocity at location (x,y) at time tv(x,y,t) is the y-velocity at location (x,y) at time tp(x,y,t) is the pressure at location (x,y) at time tT(x,y,t) is the temperature at location (x,y) at time t𝜈 is the fluid viscosity coefficient.cp is the specific heat at constant𝜌 is the fluid densityk is the thermal diffusivity rateIn planar Poiseuille flow, the flow is only in x-direction. u becomes a function of only y. Therefore: v=0, 𝜕v
𝜕t=0, 𝜕v
𝜕y=0, 𝜕2v
𝜕y2=0, 𝜕u
𝜕t=0, 𝜕u
𝜕x=0, and 𝜕p
𝜕x=0. As a result, (82) to (84) can be simplified as follows:1
𝜌(𝜕p
𝜕x)=𝜈𝜕2u
𝜕y2Since 𝜕p
𝜕x is known, we are left with only finding u(y) as the solution to (86). Thus, now we have an ODE instead of a PDE. As an ODE, we can directly solve 1
𝜌(dp
dx)=𝜈d2u
dy2 as follows:u(y)=1
𝜌𝜈(dp
dx)y2
2+C1y+C2At no-slip condition, u(0)=0 and u(ly)=0. By using these conditions, we can find C1 and C2. Let us the first boundary condition:u(0)=0=C2Next, let us take the second boundary:u(ly)=0=1
𝜌𝜈(dp
dx)l2y
2+C1lyC1=-1
𝜌𝜈(dp
dx)ly
2Hence:a
u(y)
=1
𝜌𝜈(dp
dx)y2
2+(-1
𝜌𝜈(dp
dx)ly
2)⏠⏣⏣⏣⏡⏣⏣⏣⏢C1y
=1
𝜌𝜈(dp
dx)y
2(y-ly)
5.2. Two Counter-Direction Channel Flows with Heat EquationsGiven below a simple two-dimensional model of a cross-current heat exchanger. The model is compose of two channel flows. Between the two channel, heat transfer occurs.Flow InFlow OutlyNo-slip wallℓx𝜕p(x,y,t)
Drawing 15:Heat transfer in a Two-dimensional model of a cross-current heat exchanger
Conservation of mass:𝜕u
𝜕x+𝜕v
𝜕y=0Conservation of linear momentum:𝜕u
𝜕t+u𝜕u
𝜕x+v𝜕u
𝜕y=-1
𝜌𝜕p
𝜕x+𝜈(𝜕2u
𝜕x2+𝜕2u
𝜕y2)𝜕v
𝜕t+u𝜕v
𝜕x+v𝜕v
𝜕y=-1
𝜌𝜕p
𝜕y+𝜈(𝜕2v
𝜕x2+𝜕2v
𝜕y2)Conservation of energy:𝜌cp(𝜕TH
𝜕t+u𝜕TH
𝜕x+v𝜕TH
𝜕y)=𝛼1(𝜕2TH
𝜕x2+𝜕2TH
𝜕y2)𝜌cp(𝜕TC
𝜕t+u𝜕TC
𝜕x+v𝜕TC
𝜕y)=𝛼2(𝜕2TC
𝜕x2+𝜕2TC
𝜕y2)6. Navier-Stokes in A 2D Rectangular World with Explicit Pressure Equation9The Navier-Stokes equations are used to govern dynamics of moving fluid. In a two dimensional word, the fluid has two velocity components: the velocity along the x-axis (u) and the velocity along the y-axis (v). Additionally, within the fluid, there is pressure (p). (93) and (94) are the Navier Stokes equations. However, there are only two equations with three unknowns (u, v, and p). Therefore, since the fluid in this case is assumed to be incompressible, the mass conservation law must be fulfilled as well. With a help from (92), we can generate the equation for the pressure as in (95).Conservation of mass (continuity equation):𝜕u
𝜕x+𝜕v
𝜕y=0Conservation of linear momentum:𝜕u
𝜕t+u𝜕u
𝜕x+v𝜕u
𝜕y=-1
𝜌𝜕p
𝜕x+𝜈(𝜕2u
𝜕x2+𝜕2u
𝜕y2)𝜕v
𝜕t+u𝜕v
𝜕x+v𝜕v
𝜕y=-1
𝜌𝜕p
𝜕y+𝜈(𝜕2v
𝜕x2+𝜕2v
𝜕y2)Poisson equation for the pressure:𝜕2p
𝜕x2+𝜕2p
𝜕y2≈𝜌
𝜕t(𝜕u
𝜕x+𝜕v
𝜕y)In order to derive the Poisson equation for the pressure, first, let us expand (93) and (94) by using the forward Euler method.a
u(x,y,t+𝛥t)
=u(x,y,t)-𝛥t(u𝜕u
𝜕x+v𝜕u
𝜕y+1
𝜌𝜕p
𝜕x+𝜈(𝜕2u
𝜕x2+𝜕2u
𝜕y2))
a
v(x,y,t+𝛥t)
=v(x,y,t)-𝛥t(u𝜕v
𝜕x+v𝜕v
𝜕y+1
𝜌𝜕p
𝜕y+𝜈(𝜕2u
𝜕x2+𝜕2u
𝜕y2))
Next, we take the derivative of u(x,y,t+𝛥t) with respect to x and v(x,y,t+𝛥t) with respect to y:𝜕u(x,y,t+𝛥t)
𝜕x=𝜕u(x,y,t)
𝜕x-𝛥t(1
𝜌𝜕2p
𝜕x2+𝜕
𝜕x(u𝜕u
𝜕x+v𝜕u
𝜕y+𝜈(𝜕2u
𝜕x2+𝜕2u
𝜕y2))⏠⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏢A)𝜕v(x,y,t+𝛥t)
𝜕y=𝜕v(x,y,t)
𝜕y-𝛥t(1
𝜌𝜕2p
𝜕y2+𝜕
𝜕y(u𝜕v
𝜕x+v𝜕v
𝜕y+𝜈(𝜕2v
𝜕x2+𝜕2v
𝜕y2))⏠⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏢B)We then add (98) to (99), giving us the following:𝜕u(x,y,t+𝛥t)
𝜕x+𝜕v(x,y,t+𝛥t)
𝜕y⏠⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏢=0=𝜕u(x,y,t)
𝜕x+𝜕v(x,y,t)
𝜕y-𝛥t
𝜌(𝜕2p
𝜕x2+𝜕2p
𝜕y2)-A𝛥t-B𝛥tWe set the left hand side of (100) to zero since the continuity equation (92) must be fulfilled. Rearranging (100) then gives us:
𝜕2p
𝜕x2+𝜕2p
𝜕y2=𝜌
𝛥t[𝜕u(x,y,t)
𝜕x+𝜕v(x,y,t)
𝜕y]-𝜌[A+B]⏠⏣⏣⏣⏡⏣⏣⏣⏢ignore this part
Since 𝜌
𝛥t≫𝜌, we can then ignore the rightmost term of (101). 6.1. Discretizing the x-momentum Equation(93) is discretized as follows:a
Drawing 16:Typical boundary conditions for a cavity flow.
6.5. Channel Flow6.5.1. Example 1xyu=0v=0u=0v=0u=0v=0u=0v=0𝜕p
𝜕y=0𝜕p
𝜕y=0p=5lx=3ly=0.1p=2InletOutet
Drawing 17:Typical boundary conditions for a channel flow.
6.5.2. Example 2xyu=0v=0u=0v=0u=0v=0u=0v=0𝜕p
𝜕y=0𝜕p
𝜕y=0p=5lx=3ly=0.1p=2InletOutet
Drawing 18:Typical boundary conditions for a channel flow.
7. Steady Simple Euler-Bernoulli BeamIn this section, we will discuss a simple cantilever problem. Simple means, it single span beam. Its maximum number of supports is two, located at both ends of the beam. Multispan cantilever beam will requires a more sophisticated boundary value problem solver. 7.1. Mathematical ModelingThe Euler–Bernoulli equation describes the relationship between the beam's deflection and the applied load.f(x)x=0x=Lx
Drawing 19:An Euler-Bernoulli Beam
For a one-dimensional elastic beam with a length of L, its deflection is governed by the Euler-Bernoulli equation as follows:d2
dx2[EI d2w(x)
dx2]=f(x)In (107), w(x) and f(x) are the beam's deflection and the external load at location x, respectively. E is the Young's modulus, and I is the area moment of inertia. We start by assuming that E and I are constants. Hence, (107) can be rewritten as:d4w(x)
dx4=1
EI f(x)The initial conditions to (108) are made by:a
d2w(x)
dx2
=1
EI M(x)
Internal moment at x
d3w(x)
dx3
=1
EI F(x)
Internal shear force at x
In a central difference method we know that:a
dw(x)
dxaxi≈wi-1-wi+1
2𝛥x
d2w(x)
dx2axi≈wi-1-2wi+wi+1
𝛥x2
d3w(x)
x3axi≈-wi-2+2wi-1-2wi+1+wi+2
2𝛥x3
d4w(x)
dxaxi≈wi-2-4wi-1+6wi-4wi+1+wi+2
𝛥x4
where wi=w(i𝛥x) and 𝛥x is the segment length.Hence, we can rewrite (108) as follows"a
d4w(x)
dx4
=1
EI f(x)
n∑i=0wi-2-4wi-1+6wi-4wi+1+wi+2
(𝛥x)4
=1
EI fi
where fi=f(i𝛥x).We can also express in its matrix form as follows:a
[a
1
0
…
0
0
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
…
0
⋮
⋱
⋱
⋱
⋱
⋱
⋮
0
…
0
1
-4
6
-4
1
0
…
0
1
0
0
…
0
1
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w-2
w-1
w0
w1
⋮
wn
wn+1
wn+2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W
=𝛥x4
EI[a
L2
L1
f0
f1
⋮
fn
R1
R2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F
where w-1, w-2, wn, wn+1, L1, L2, R1, and R2 are all the properties of additional nodes that we must add . We call them as the phantom nodes (see Drawing 20).w0…wnw1wn+1w-1w2w3w-2wn+2Phantom nodesPhantom nodesf0f1f2L1L2R1R2f3… fn
Drawing 20:. Finite difference model of a one-dimensional problem with extra phantom nodes for the boundary conditions
7.2. Engineering InterpretationThe solutions to (108) are subjected to the given initial conditions (an initial value problem). However, in engineering, it is more common to call these initial values as boundary conditions since the independent variables are spatial and not temporal. Also, (108) is actually originated from a partial differential equation. There are three possible boundary conditions for each end, which are:• Fixed-end (clamped), which means that there is no displacement at the current end. Additionally, at the current end, its horizontal tangent is also zero.• Pinned-end, which means that there is no displacement at the current end. Also, at the current end, its bending moment is also zero.• Free-end, which means that both bending moment and shear force are zero at the current end.As additional information, bending moment is the second derivative of w with respect to x and shear force is the third derivative of w with respect to x.The combinations of those three boundaries create nine possible configurations. However, we will focus only on 6 configuration as shown in Drawing 21.f(x)f(x)f(x)f(x)f(x)Both ends are fixed/supportedOne end is fixed andanother end is freeMOne end is supported andan explicit torque is applied at another end
Drawing 21:Engineering interpretation of the Euler-Bernoulli equation
Now, let us explore the boundary conditions together with their discrete forms in details.7.2.1. Boundary Conditions at the Left Enda) Fixed-end Boundary (Clamped)• No position displacement means that w(0)=0. This then translates into:w0=0• Zero horizontal tangent means that dw(0)
dx=0. which then translates into:w-1-w1
2𝛥x=0⟹w-1=w1b) Pinned-end Boundary• No position displacement means that w(0)=0, which translates to:w0=0• No bending moment means thatd2w(0)
dx2=0, which then translates to:w-1-2w0+w1
(𝛥x)2=0⟹w-1=-w1c) Free-end Boundary• No bending moment means that dw2(0)
dx2=0, which then translates into:w-1-2w0+w1
(𝛥x)2=0⟹w-1=-w1+2w0• No shear force means that d3w(0)
dx3=0, which then translate into:-w-2+2w-1-2w1+w2
2(𝛥x)3=0⟹w-2=2w-1-2w1+w2Substituting (116) to (117) gives us:a
w-2
=2w-1-2w1+w2
=2(2w0-w1)-2w1+w2
=4w0-2w1-2w1+w2
=4w0-4w1+w2
7.2.2. Boundary Conditions at the Right Enda) Fixed-end Boundary (Clamped)• No position displacement means that w(L)=0, which then translates into:wn=0• Zero horizontal tangent means that dw(L)
dx=0, which then translates into:wn-1-wn+1
2𝛥x=0⟹wn+1=wn-1b) Pinned-end Boundary • No position displacement means that w(L)=0, which then translates into:wn=0• No bending moment means that d2w(L)
dx2=0, which then translates into:wn-1-2wn+wn+1
(𝛥x)2=0⟹wn+1=-wn-1c) Free-end Boundary• No bending moment means that dw2(L)
dx2=0, which translates into:wn-1-2wn+wn+1
(𝛥x)2=0⟹wn+1=-wn-1+2wn• No shear force means that d3w(L)
dx3=0, which then translates into:-wn-2+2wn-1-2wn+1+wn+2
2(𝛥x)3=0⟹wn+2=wn-2-2wn-1+2wn+1By substituting (123) to (124), we can then acquire:a
wn+2
=wn-2-2wn-1+2wn+1
=wn-2-2wn-1+2(-wn-1+2wn)
=wn-2-2wn-1-2wn-1+4wn
=wn-2-4wn-1+4wn
To summarize, we put (112) to (125) into a table as follows.
Left
Right
Fixed-end
aL2=×L1=w1w0=0
aR1=wn-1R2=×wn=0
Pinned-end
aL2=×L1=-w1w0=0
R1=-wn-1R2=×wn=0
Free-end
aL2=4w0-4w1+w2L1=-w1+2w0
aR1=-wn-1+2wnR2=wn-2-4wn-1+4wn
Table 1:All possible boundary conditions
Now, we can update the L1, L2. R1, and R2 in (111) depending on the current boundary conditions.7.3. System Matrices for Different BoundariesIn order to solve (111) , we must first make sure that matrix A and F contain only numbers and not variables. Currently, L1, L2, R1, R2 still contain some variables (w). This is not a desirable format since we can not apply the linear solve command to solve Aw=F. ➔ Free-freef(x)Free-free boundary condition is not going to work for the Euler Bernoulli equation since the matrix that we get is not a full rank matrix. Hence, its system equation can not be solved. However, this free-free case is a a good example on how we should adapt (111) to include some boundary conditions. By including the boundaries into (111) we get the following equation.a
[a
1
0
…
0
0
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
…
0
⋮
⋱
⋱
⋱
⋱
⋱
⋮
0
…
0
1
-4
6
-4
1
0
…
0
1
0
0
…
0
1
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w-2
w-1
w0
w1
⋮
wn
wn+1
wn+2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W
=𝛥x4
EI[a
4w0-4w1+w2
-w1+2w0
f0
f1
⋮
fn
-wn-1+2wn
wn-2-4wn-1+4wn
]⏠⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏢F
Starting from the left end, we write down the equations made by Row 1 to Row 4:a
Row 1:
w-2=4w0-4w1+w2
Row 2 :
w-1=-w1+2w0
Row 3 :
w-2-4w-1+6w0-4w1+w2=f0
Row 4 :
w-1-4w0+6w1-4w2+w3=f0
By substituting Row 1 and Row 2 to Row 3, we get the following:4w0-4w1+w2-4(-w1+2w0)+6w0-4w1+w2=fo2w0-4w1+2w2=f0Next, by substituting Row 1 and Row 2 to Row 4, we get the following:-w1+2w0-4wo+6w1-4w2+w3=f1-2w0+5w1-4w2+w3=f1As for the right end, we can do the similar steps. By substituting Row n+1 and Row n+2 to Row n, we get the following:wn-2-4wn-1+6wn-4(-wn-1+2wn)+wn-2-4wn-1+4wn=fn2wn-2-4wn-1+2wn=fnNext, by substituting Row n+1 and Row n+2 to Row n-1, we get the following:wn-3-4wn-2+6wn-1-4wn-wn-1+2wn=fn-1wn-3-4wn-2+5wn-1-2wn=fn-1Now, we can remove Row 1, Row 2, Row n+1, and Row n+2. These rows are all made by the phantom nodes and must first be removed. As a result, we can update (127) into:[a
2
-4
2
0
…
0
-2
5
-4
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
0
…
0
⋮
⋱
⋱
⋱
⋱
⋱
⋱
⋮
0
…
0
1
-4
6
-4
1
0
…
0
1
-4
5
-2
0
…
0
2
-4
2
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w0
w1
w2
⋮
wn-2
wn-1
wn
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W=𝛥x4
EI[a
f0
⋮
fn
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F7.3.1. Fixed-fixed (fixed ended)f(x)For a case where both ends are fixed, we use the following equations.a
7
-4
1
0
…
0
-4
6
-4
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
0
…
0
⋱
⋱
⋱
⋱
⋱
⋮
⋮
⋱
⋱
⋱
⋱
⋱
0
…
0
1
-4
6
-4
0
…
0
1
-4
7
⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w1
w2
⋮
wn-2
wn-1
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W=𝛥x4
EI[a
f1
⋮
fn-1
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F7.3.2. Pinned-pinned (simply supported)f(x)For a case where both ends are pinned, we use the following equations.a
5
-4
1
0
…
0
-4
6
-4
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
0
…
0
⋱
⋱
⋱
⋱
⋱
⋮
⋮
⋱
⋱
⋱
⋱
⋱
0
…
0
1
-4
6
-4
0
…
0
1
-4
5
⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w1
w2
⋮
wn-2
wn-1
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W=𝛥x4
EI[a
f1
⋮
fn-1
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F7.3.3. Fixed-pinned (cantilever, simply supported)f(x)For a case where the left end is fixed while the right end is pinned, we use the following equations.a
7
-4
1
0
…
0
-4
6
-4
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
0
…
0
⋱
⋱
⋱
⋱
⋱
⋮
⋮
⋱
⋱
⋱
⋱
⋱
0
…
0
1
-4
6
-4
0
…
0
1
-4
5
⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w1
w2
⋮
wn-2
wn-1
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W=𝛥x4
EI[a
f1
⋮
fn-1
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F7.3.4. Pinned-fixed (simply supported, cantilever)f(x)For a case where the left end is pinned while the right end is fixed, we use the following equations.a
5
-4
1
0
…
0
-4
6
-4
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
0
…
0
⋱
⋱
⋱
⋱
⋱
⋮
⋮
⋱
⋱
⋱
⋱
⋱
0
…
0
1
-4
6
-4
0
…
0
1
-4
7
⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w1
w2
⋮
wn-2
wn-1
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W=𝛥x4
EI[a
f1
⋮
fn-1
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F7.3.5. Fixed-free (cantilever)f(x)For a case where the left end is fixed while the right end is free, we use the following equations.[a
7
-4
1
0
…
0
-4
6
-4
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
0
…
0
⋱
⋱
⋱
⋱
⋱
⋱
⋮
…
0
1
-4
6
-4
1
0
…
0
1
-4
6
-4
1
⋮
…
0
1
-4
5
-2
0
…
0
2
-4
2
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w1
w2
⋮
wn-1
wn
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W=𝛥x4
EI[a
f1
⋮
fn
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F7.3.6. Fixed-explicit momentMAn explicit moment in a beam is another type of boundary condition. Although it may look an applied input to the beam, it is not. Euler-Bernoulli equation only takes force/pressure as its input. It does not accept torque.A pure torque M that causes bending is applied at the right end:• A manually-defined constant bending moment of M or dw2(L)
dx2=M. This then translates into:wn-1-2wn+wn+1
𝛥x2=M⟹wn+1=M𝛥x2-wn-1+2wn• No shear force means that d3w(L)
dx3=0, which then translates into:-wn-2+2wn-1-2wn+1+wn+2
2 𝛥x3=0⟹wn+2=wn-2-2wn-1+2wn+1By substituting to (139), to (141) we can then acquire:a
wn+2
=wn-2-2wn-1+2wn+1
=wn-2-2wn-1+2(M𝛥x2-wn-1+2wn)
=wn-2-2wn-1-2wn-1+4wn+2M𝛥x2
=wn-2-4wn-1+4wn
We can summarize the boundary as follows:
Left Boundary(Fixed-end)
Right Boundary(Applied pure torque)
aL1=×L2=w1w0=0
aR1=M𝛥x2-wn-1+2wnR2=wn-2-4wn-1+4wn
Applying these boundaries to the general system matrix gives us:[a
1
0
…
0
0
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
…
0
⋮
⋱
⋱
⋱
⋱
⋱
⋮
0
…
0
1
-4
6
-4
1
0
…
0
1
0
0
…
0
1
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w-2
w-1
w0=0
w1
⋮
wn
wn+1
wn+2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W=𝛥x4
EI[a
×
w1
0
0
⋮
fn
M𝛥x2-wn-1+2wn
2M𝛥x2+wn-2-4wn-1+4wn
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏢FSince we have already addressed the left boundary, hence, we only need to address the right boundary.From the second-to-the last row:wn-2-4wn-1+6wn-4wn+1+wn+2=fnwn-2-4wn-1+6wn-4(M𝛥x2-wn-1+2wn)+(2M𝛥x2+wn-2-4wn-1+4wn)=fnwn-2-4wn-1+6wn-2M𝛥x2+4wn-1-8wn+wn-2-4wn-1+4wn=fn2wn-2-4wn-1+2wn=fn+2M𝛥x2From the third-to-the last row:wn-3-4wn-2+6wn-1-4wn+M𝛥x2-wn-1+2wn=fn-1wn-3-4wn-2+5wn-1-2wn=fn-1-M𝛥x2a
7
-4
1
0
…
0
-4
6
-4
1
0
…
0
1
-4
6
-4
1
0
…
0
⋱
⋱
⋱
⋱
⋱
⋱
⋱
⋱
0
…
0
1
-4
6
-4
1
0
…
0
1
-4
7
⏠⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏢AThus, (142) cab be rewritten as:[a
7
-4
1
0
…
0
-4
6
-4
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
0
…
0
⋮
⋱
⋱
⋱
⋱
⋱
⋱
⋮
0
…
0
1
-4
6
-4
1
0
…
0
1
-4
5
1
-2
0
…
0
2
-4
2
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w1
w2
w3
w4
⋮
wn-2
wn-1
wn
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W=1
EI[a
0
0
0
0
⋮
0
-M𝛥x2
2M𝛥x2
]⏠⏣⏣⏣⏣⏡⏣⏣⏣⏣⏢FWe can then fine W by using the linear solve function in MATLAB. 8. Unsteady Simple Euler-Bernoulli BeamSimilar to the previous section, in this section, we still discuss a simple cantilever problem. The dynamic model of an Euler-Bernoulli beam is governed by the following equation:𝜇𝜕2w
𝜕t2(x,t)=-EI𝜕4w
𝜕x4(x,t)+f(x,t)where 𝜇 is the mass per unit length, E is the Young's modulus, and I is the area moment of inertia.a
𝜕2w
𝜕t2(x,t)
=-EI
𝜇n∑i=0wi-2,j-4wi-1,j+6wi,j-4wi+1,j+wi+2,j
(𝛥x)4+ fi,j
𝜕2w
𝜕t2(x,t)
=-EI
𝜇𝛥x4[a
1
0
…
0
0
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
…
0
⋮
⋱
⋱
⋱
⋱
⋱
⋮
0
…
0
1
-4
6
-4
1
0
…
0
1
0
0
…
0
1
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w-2
w-1
w0
w1
⋮
wn
wn+1
wn+2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W+[a
L2
L1
f0
f1
⋮
fn
R1
R2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F
Discretizing 𝜕2w
𝜕t2(x,t) in (147) gives us: w(x,t-𝛥t)-2w(x,t)+w(x,t+𝛥t)
𝛥t2=-EI
𝜇𝛥x4[a
1
0
…
0
0
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
…
0
⋮
⋱
⋱
⋱
⋱
⋱
⋮
0
…
0
1
-4
6
-4
1
0
…
0
1
0
0
…
0
1
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w-2
w-1
w0
w1
⋮
wn
wn+1
wn+2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W+[a
L2
L1
f0
f1
⋮
fn
R1
R2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢Fw(x,t+𝛥t)=-EI𝛥t2
𝜇𝛥x4[a
1
0
…
0
0
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
…
0
⋮
⋱
⋱
⋱
⋱
⋱
⋮
0
…
0
1
-4
6
-4
1
0
…
0
1
0
0
…
0
1
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w-2
w-1
w0
w1
⋮
wn
wn+1
wn+2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W+𝛥t2[a
L2
L1
f0
f1
⋮
fn
R1
R2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F+2w(x,t)-w(x,t-𝛥t)Another way is to use a MATLAB built-in ODE solver. In order to do so, let us take v=𝜕w
𝜕t and 𝛼=EI
𝜇𝛥x4, hence:a
𝜕v
𝜕t(x,t)
=-EI
𝜇𝛥x4[a
1
0
…
0
0
1
0
…
0
1
-4
6
-4
1
0
…
0
0
1
-4
6
-4
1
…
0
⋮
⋱
⋱
⋱
⋱
⋱
⋮
0
…
0
1
-4
6
-4
1
0
…
0
1
0
0
…
0
1
]⏠⏣⏣⏣⏣⏣⏣⏣⏣⏡⏣⏣⏣⏣⏣⏣⏣⏣⏢A[a
w-2
w-1
w0
w1
⋮
wn
wn+1
wn+2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢W+[a
L2
L1
f0
f1
⋮
fn
R1
R2
]⏠⏣⏣⏣⏡⏣⏣⏣⏢F
Now, we can write:a
a
𝜕w
𝜕t
𝜕v
𝜕t
=a
0
I
-𝛼A
0
a
W
V
+a
0
F
where V=[v-2… vn+2]. and I is an identity matrix. Now, we can use (150) for MATLAB a built-in ODE solver.