Professional Documents
Culture Documents
09
MSM 732 Assignment 1b 2009
Table of Contents
Introduction .................................................................................................................................................. 3
Inputs ............................................................................................................................................................ 3
Source Function ........................................................................................................................................ 4
Gauss-Seidel Mesh ........................................................................................................................................ 5
In Short ...................................................................................................................................................... 5
V-Cycle Multi-grid Mesh ............................................................................................................................... 6
Gauss-Seidel Function ............................................................................................................................... 6
Step 1 Fine Mesh .................................................................................................................................... 7
Step 2 Restriction ................................................................................................................................... 7
Step 3 Prolongation................................................................................................................................ 7
Step 4 Correction ................................................................................................................................... 7
Results ........................................................................................................................................................... 8
The error ................................................................................................................................................... 9
Conclusion ................................................................................................................................................... 10
Appendix Code ......................................................................................................................................... 11
Appendix Function ................................................................................................................................... 15
2 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
Introduction
In this assignment a Gauss-Seidel solver diffusion solver with be compare to a Multi-grid V-cycle solver.
This question has been set up in the thermal domain with some fixed input variables.
The author originally used this as a opportunity to learn VBA code and did the initial Gauss-Seidel and
Multi-Grid solver in Excel VBA. Though do to time constraints and requirement s that was put on hold to
complete the project in Matlab. Thus informally there is an Excel incomplete version of the program in
the software.
When comparing the code for the Multi-Grid versus the standard Gauss. It was clear that the set of
equations are generally similar. Thus a single Gaussian function was used to calculate the Gauss-Seidel,
Multi-grid fine mesh and the Multi-grid coarse error meshes.
Inputs
The fix inputs for the project are defined below and taken from the Matlab code:
% ================================ %
% --> Initial Varibles %
% ================================ %
kth = 1; % --> Material Diffusivity: Thermal
lg = 1; % --> Length
nn = 129; % --> Number of nodes
ini = 0; % --> Initial Condition
tol = 1e-4; % --> Convergence Tolerance
it_g = 100; % --> No. Iterations Gauss
it_m = 6; % --> No. Iterations Multigrid
v1 = 2; % --> Multigrid relaxation (v1)
v2 = 3; % --> Multigrid relaxation (v2)
v3 = v1+v2; % --> Multigrid relaxation (v3)
lvl = 6; % --> V-Cycle Steps
srcf = inline('(x.^2 + 3*x).*exp(x)'); % --> Source Function
del_x = inline('lg/(nn - 1)','lg','nn');% --> Element length(Delta x)
3 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
Source Function
The Source function was given in the following format:
4 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
Gauss-Seidel Mesh
The Gauss-Seidel solver for a steady-state is solved through a set of linear equations.
Though this was not necessary for the simulation to converge, though still required a residual was
calculated using the following method:
% --> r = f - A * phi_a
res(i,1) = src(i,1) + A_phi;
In Short
The Gauss-Seidel process takes the fundamental equation and iterates through body then iterates the
process again in order to get convergence.
5 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
Gauss-Seidel Function
The Gauss function use in the process for both the Unknown and the error is well documented in the
code and is shown below:
for k = 1:iter
% Zero the Residual Error
res_err = 0;
end
for i = 2:(nodes-1)
% --> Build A * phi_a matrix
A_phi = kth*(phi(i+1) - 2*phi(i) + phi(i-1))/delx^2;
% --> r = f - A * phi_a
res(i,1) = src(i,1) + A_phi;
6 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
The multi-grid method was divided into four steps. These steps are described in detail:
A residual is then calculated out of the process and that is passed on to the coarser mesh. This process is
called the Restriction process.
Step 2 Restriction
The restriction process only works with the errors and the residuals. Once the residual is passed down
from the fine mesh it has to be broken down. A linear process is used to reduce the residual to the new
mesh size.
The next step is to calculate the error. This formula follows the same principles as the initial set of
equations, hence the reason why only one simple function is required.
Step 3 Prolongation
In this process instead of the residual being carried to the next mesh, the error is carried to the next
process.
Using the same methods and the same Gauss-Seidel Function the error term is interpolated onto the
finer meshes. This corrects the errors in the low frequency.
Errors were from the previous step down cycle were included in this process as described in the
textbook.
Step 4 Correction
In this step the prolonged errors are added to the correct the Unknown in this case heat.
7 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
Results
The results for the simulations are compared below to each other and also the analytical form:
It is clear that the V-cycle far surpasses the standard Gauss-Seidel methods. In addition the error
between the real and the simulated is tiny.
8 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
The error
9 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
Conclusion
The results look good and it is impressive to see the convergence of the V-cycle process. A concern was
the values calculated in the errors. Though after much manual calculation it makes sense that they are
not linear either, considering that the initial error is take from zero.
Very interesting information to study, the author has thoroughly enjoyed this work.
10 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
Appendix Code
clc; clear all; %close all;format long;
% ================================ %
% 1D Heat: Gaus-Seidel and V-Cycle multigrid Finite Element Approximation
%
% MSM 732 - Assignment 2(b)
% ================================ %
% Written by: Alexander R. Mauchle
% Tel: 083 273 2926
% Date: 15 September 2009
%
% REQUIRES FUNCTONS:
% --> Gauss_Seidel.m
%
% ================================ %
disp('1D Heat: Gauss-Seidel and V-Cycle');
disp('MSM 732 - Assignment 2(b) ');
disp('Written by: Alexander R. Mauchle');
% ================================ %
% --> Initial Varibles %
% ================================ %
kth = 1; % --> Material Diffusivity: Thermal
lg = 1; % --> Length
nn = 129; % --> Number of nodes
ini = 0; % --> Initial Condition
tol = 1e-4; % --> Convergence Tolerance
it_g = 100; % --> No. Iterations Gauss
it_m = 6; % --> No. Iterations Multigrid
v1 = 2; % --> Multigrid relaxation (v1)
v2 = 3; % --> Multigrid relaxation (v2)
v3 = v1+v2; % --> Multigrid relaxation (v3)
lvl = 6; % --> V-Cycle Steps
srcf = inline('(x.^2 + 3*x).*exp(x)'); % --> Source Function
del_x = inline('lg/(nn - 1)','lg','nn');% --> Element length(Delta x)
[phi_g,res_g,It_err_g] = Gauss_Seidel(phi,res,src,kth,delx,iter,nodes,relax);
11 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
% ============ CALL ============== %
% --> Multi-Grid: V-cyc Func. %
% ================================ %
[phi,res,r_err] = Gauss_Seidel(phi,res,src,kth,delx,iter,nodes,relax);
[err_n,res_n,r_err] = Gauss_Seidel...
(err_o,[] ,res_o,kth,delx,1 ,nodes,relax);
% --> (phi(**),res,f ,kth,delx,iter,nodes,relax);
12endAlexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
err(1:n2,i-1) = err_n;
end
13 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
14 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
Appendix Function
% 1D Gauss-Seidel Solver
%
% MSM 732 - Assignment 2(b)
% ================================ %
% Written by: Alexander R. Mauchle
% Tel: 083 273 2926
% Date: 15 September 2009
%
% This function is build on the "Algebraic" Gauss method(discribed below)
%
% Gauss-Seidel method (including Relax):
% ======================================
% A * phi = f
% r = f - A * phi_a
%
% --> it_g iterations
% --> nn Number of Nodes
% --> ini Initial values
% --> delx Element length - Delta X
% --> kth Thermal Conductivity
% --> srcv [] Source Vector
% <-- temp [] Temperature Vector
% <-- res [] Residual Vector
% <-- err [] Error Vector
%
% ================================ %
function [phi,res,r_err] = Gauss_Seidel(phi,res,src,kth,delx,iter,nodes,relax)
for k = 1:iter
% Zero the Residual Error
res_err = 0;
end
for i = 2:(nodes-1)
% --> Build A * phi_a matrix
A_phi = kth*(phi(i+1) - 2*phi(i) + phi(i-1))/delx^2;
15 Alexander Mauchle
#23382572
MSM 732 Assignment 1b 2009
% --> r = f - A * phi_a
res(i,1) = src(i,1) + A_phi;
16 Alexander Mauchle
#23382572