cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Tri-diagonal Matrix Algorithm (TDMA)

festivus-disabl
1-Newbie

Tri-diagonal Matrix Algorithm (TDMA)

Is there anybody who has coded the Tri-Diagonal Matrix Algorithm (TDMA or Thomas algorithm) in mathcad and would be willing to share it?
8 REPLIES 8
jbanks
5-Regular Member
(To:festivus-disabl)

Dear Festivus, I had seen your message today for the first time since

I am migrating to Mathcad Prime 7.0. Attached is the TDMA that I had

developed in 1985 (The Fortran source code which I had used as

basis is my TDMA and it states the date). 

 

I have successfully used TDMA in two distinct heat transfer simulations

in a transient interior ballistics solution of a RLPG (Regenerative Liquid

Propulsion Gun and also in a steady state thermal liner heat transfer in

F100 thermal liner.

 

It is my pleasure to freely share my IR&D (Independent Research

and Development) algorithms.

 

Attached are the "Algorithm derivation along with the Fortran solution

implementation" in one PDF file. The second file is my implementation

of TDMA imported into Mathcad Prime v7.0 from the Mathcad v15 original

file.

 

I hope that these TDMA files will serve well our PTC Community.

 

Sincerely

 

Julio C. Banks

For those with only Prime Express, here's a version that uses range variables.

 

2021 10 11 D.png

 

2021 10 11 A.png

 

2021 10 11 B.png

 

2021 10 11 C.png

 

Stuart

jbanks
5-Regular Member
(To:StuartBruff)

Dear Stuart, the solution that you have provided is more complex

than the one I provided. Please review the files I have provided

to confirm the simplicity of the '"One algorithm within a single

solution function" - Thanks for your participation in the TDMA

solution methods. 


@jbanks wrote:

Dear Stuart, the solution that you have provided is more complex

than the one I provided. Please review the files I have provided

to confirm the simplicity of the '"One algorithm within a single

solution function" - Thanks for your participation in the TDMA

solution methods. 


Hello, Julio

 

I'm not sure the solution I gave is more complex.  It lacks the flexibility of a program, but that's through necessity.  Mathcad Prime Express 7 doesn't have any 'programming' capability (after the 30-day trial period),  so I'm afraid that your nice, compact solution isn't available to Express users.   

 

In addition, your solution assumes the prior existence of the a, b, and c diagonal vectors rather than just the matrix.   I don't know how such matrices arise in the formulation of real-world problems, so I assumed the tridiagonal matrix as the starting point.   It's easy to fix that though in the method I showed.

 

The simple reusability of a program may be approximated by embedding a range variable solution within a Text Area.  Embedding Math Regions in Text Areas is quite a neat way of achieving portability for range variables, and, equally importantly, documenting a solution (even programs). (*)

 

2021 10 13 A.png

 

2021 10 13 B.png

 

2021 10 13 C.png

 

2021 10 13 D.png

 

2021 10 13 E.png

 

To reuse a set of calculations, all one need do is copy the Text Area and everything within it gets copied too.

 

Stuart

 

(*)  I have a looonnnggg-standing feature request to be able to create and embed "mini" Mathcad worksheets in a "main" Mathcad worksheet, with the option to allow them to be assigned to variables as functions.

jbanks
5-Regular Member
(To:StuartBruff)

Dear Stuart, I have used the TDMA in the solution of steady state heat transfer of turbojet thermal liner which includes thermal radiation, conduction, convection and advection. I have also used in the transient heat transfer solution of the combustion chamber of a liquid-propellant regenerative gun in the radial  direction at a given axial  location. In both of these applications, I was in complete control of the upper, lower and right-hand vectors. That is, I never had the need to "create a matrix set of equations of the form [K]{T} = {BC}" where {BC} is a vector derived from the "Boundary Conditions". Therefore, I hereby hope to clarify that the solution I provided is the simplest form of the TDMA since there is no need to provide the full-matrix as input.


@jbanks wrote:

Dear Stuart, I have used the TDMA in the solution of steady state heat transfer of turbojet thermal liner which includes thermal radiation, conduction, convection and advection. I have also used in the transient heat transfer solution of the combustion chamber of a liquid-propellant regenerative gun in the radial  direction at a given axial  location. In both of these applications, I was in complete control of the upper, lower and right-hand vectors. That is, I never had the need to "create a matrix set of equations of the form [K]{T} = {BC}" where {BC} is a vector derived from the "Boundary Conditions". Therefore, I hereby hope to clarify that the solution I provided is the simplest form of the TDMA since there is no need to provide the full-matrix as input.


Thanks for that clarification, Julio.  I suspected that might be the case.   I was going by the Wikipedia article which does start from the matrix.

 

As I noted, your solution is the simplest form for a program, but it isn't usable in Mathcad Prime Express as Express doesn't support programming.   

 

An Express implementation can be reduced to pretty much a few lines, as shown below (I've also changed the variable names used within the TDMA so as to not overwrite the predefined values of a,b,c and d.  This isn't a problem for a function as these names are local to the function).

 

2021 10 15 A.png

 

All an Express user need do is copy and paste whichever version (pink or green) they want as many times as they need.   It would be interesting to compare the accuracy and times for evaluation of the Thomas algorithm vs matrix inversion, but I've got way too many other things to be doing!

 

Stuart

jbanks
5-Regular Member
(To:StuartBruff)

Dear Stuart, I need to clarify the use of TDMA to solve steady state and transient heat transfer solution for "One-dimensional Heat Transfer" (1D). This clarification will assist the visualization of the heat flow direction. The steady state TDMA input vectors were derived from establishing a series of 1D Heat Transfer Balance equations which would be iterated to account for the change in temperature-dependent coolant flow transport properties (Specific Heat, viscosity, etc) as well as the thermal conductivity of the liner layers separating the coolant flow from the turbojet engine core-flow temperature. The first solution of TDMA uses the average temperature on each side of the liner as the initial liner layer temperature. The second, and all subsequent iterations would obtain the transport and conductivity properties, and the process stops when the temperature of the  liner in direct contact with the core temperature is 1-degree-F. The number of TDMA iterations would mostly by not more than 3 iterations. The transient heat transfer is derived from casting the 1D partial differential  equations (PDE) through the thickness of the combustion  chamber which is "the radial direction". One other feature of the TDMA solution I must expand is that I determined to be effective for each row to be divided by the main diagonal element to form a "normalized" Lower Diagonal Vector, {a}, Upper Diagonal vector, {b} and the RHS (Right Hand Side) vector, {c}. Therefore, the input vectors are {a}, {b}, and {c} which is one-vector storage less than the "standard" TDMA solution. The 1D Steady State Heat Transfer solution requires the generation of all vectors,  {a}{b}, and {c}, due to change in temperature-dependent properties while the Transient 1D Heat Transfer Solution requires only the RHS vector to be updated with each time-step as the boundary conditions change with time since the "thermal diffusivity" of the chamber wall is assumed to be constant.  The heat transfer equations have the off-diagonal elements negative and therefore this sign is incorporated in the normalized vectors {a} and {b}. What you call "forward sweep" and "reverse substitution" are known to me as "Forward elimination" and "Back substitution", respectively. Julio.

Thanks for that insight, Julio.  Very interesting.

 

Stuart

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."