This document describes solving a steady scalar transport equation using an ADI algorithm with upwind differencing of the convective terms. The problem involves convection and diffusion of a scalar quantity in a stagnation point flow. Boundary conditions are given. The algorithm is modified from Problem Set 2 to include upwind differencing. Grid independent solutions are obtained for diffusion parameters of 0.1 and 0.01. Iteration time and accuracy are analyzed for different grid sizes.
Fluid Dynamics describes the physics of fluids at level of Undergraduate in science (physics, math, engineering). For comments or improvements please contact solo.hermelin@gmail.com. Thanks.
For more presentations on different subjects visit my website at http://www.solohermelin.com.
Contents of the presentation:
- ABOUT ME
- Bisection Method using C#
- False Position Method using C#
- Gauss Seidel Method using MATLAB
- Secant Mod Method using MATLAB
- Report on Numerical Errors
- Optimization using Golden-Section Algorithm with Application on MATLAB
Fluid Dynamics describes the physics of fluids at level of Undergraduate in science (physics, math, engineering). For comments or improvements please contact solo.hermelin@gmail.com. Thanks.
For more presentations on different subjects visit my website at http://www.solohermelin.com.
Contents of the presentation:
- ABOUT ME
- Bisection Method using C#
- False Position Method using C#
- Gauss Seidel Method using MATLAB
- Secant Mod Method using MATLAB
- Report on Numerical Errors
- Optimization using Golden-Section Algorithm with Application on MATLAB
Applied Numerical Methods Curve Fitting: Least Squares Regression, InterpolationBrian Erandio
Correction with the misspelled langrange.
and credits to the owners of the pictures (Fantasmagoria01, eugene-kukulka, vooga, and etc.) . I do not own all of the pictures used as background sorry to those who aren't tagged.
The presentation contains topics from Applied Numerical Methods with MATHLAB for Engineers and Scientist 6th and International Edition.
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docxRAHUL126667
CALIFORNIA STATE UNIVERSITY, NORTHRIDGE
MECHANICAL ENGINEERING DEPARTMENT
MARCH 30 2015
ME 309
HOMEWORK #3
Ahmed Mohammed
Problem statement
1. Write a general computer code to solve system of up to five couples first order initial value problems using Heun and Newton iteration trapezoidal methods. These are combined in the same algor4thim in such way that Heun’s method is automatically employed to provide the initial guess at each time step for the Newton iteration required by fully implicit Heun’s method, and no iterations are needed. The complete pseudo-language algorithm is attached.
Test this code by solving the following problem.
Use step size h= 0.1, 0.05 and 0.025. Solve the problem first with explicit Hun’s method, and then with implicit Newton iteration integration for each value of h. employ a convergence tolerance E= 0.000001 for the Newton iteration of the trapezoidal method. The exact solution to this problem is,
Make a table of results of convergence tests (based on the exact solution) at t=1, 2, 3, 4 & 6. This table should include the exact value, the computed solution, the error and the error ratios from successive step size for each of the required values of t. discuss how these results compare with theory. Also discuss what factors should influence the choice of convergence tolerance E for the Newton iterations, and whether the specified value given above is appropriate.
2. Solve the following problem using only the newton iteration trapezoidal method.
Employ step size h=0.1, 0.05, 0.01 and iteration convergence tolerance E= 0.000001. Consider the h=0.01 solution to be the “exact” in order to carry out convergence testes between the h= 0.1 and h=0.05 solutions at t=0.5, 1, 1.5, 2. Make a table, similar to the table in problem number 1.
Mathematical Description
HEUN’S METHOD
Heun’s Method, explained in a short manner, uses the line tangent to the function at the beginning of an interval. Now if a small step is applied to it, the error with the function result will be small. Heun’s method can be explained in more detailed in the following way:
2.-
To obtain solution point (t1,y1) we can use the fundamental theorem of calculus and integrate y’(t) over [t0,t1] to get
3.- Solving for y(t1) we find,
4.- We can use a numerical integration to approximate definite integral. If we use trapezoidal rule with step size h = t1 – t0, then we get
5.- We still need to find, y(t1) but an estimation for this value will work. After this we get the following, which is the Heun’s method.
6.- When this process is repeated it generates a sequence of points that approximate the solution curve y =y(t). At each step, Euler’s method is used as a prediction then the trapezoidal rule helps to make the correction to obtain the final value. [1]
Newton’s Method
It is way to approximate the roots of an equation by taking out the curve in the equation and then replace with a tangent line. Then, it find ...
I am Demi Jenkins.I love exploring new topics. Academic writing seemed an exciting option for me. After working for many years with matlabassignmentexperts.com, I have assisted many students with their assignments. I can proudly say, each student I have served is happy with the quality of the solution that I have provided. I acquired my master's from Stanford University, USA.
I am Andy K. I am a Calculus Homework Solver at mathhomeworksolver.com. I hold a Master's in Mathematics From Sydney, Australia. I have been helping students with their homework for the past 9 years. I solve homework related to Calculus.
Visit mathhomeworksolver.com or email support@mathhomeworksolver.com. You can also call on +1 678 648 4277 for any assistance with Calculus Homework.
Finite Volume Method Advanced Numerical Analysis by Md.Al-AminMd. Al-Amin
Finite Volume Method Advanced Numerical Analysis by Md.Al-Amin
Imam Hasan Al-Amin, professionally known as MD Al-Amin, He was born on December 25th, 1999, and brought up in Pirojpur. He is a Bangladeshi entrepreneur and mathematician. He graduated from Khulna University, Khulna, Bangladesh also Bangladesh University of Engineering and Technology(BUET) in mathematics. He is the co-founder and CEO of Juhod Shop-যুহদ শপ, which is mainly an online shop in Bangladesh. Here, you can buy products online with a few clicks or convenient phone calls. Also, he is the founder and CEO of Juhod IT-Care, a full-service digital media agency that partners with clients to boost their personal and business outcomes. His expertise in marketing has allowed him to help a number of businesses increase their revenue by tremendous amounts. From childhood, he wanted to do something different that would be fruitful for mankind. He started working as a vocal artist when he was only 18 years old.
I am Frank P. I am a SPSS Homework Solver at statisticshomeworksolver.com. I hold a Ph.D. in statistics, from Sunway University, Malaysia. I have been helping students with their homework for the past 6 years. I solve homework related to SPSS.
Visit statisticshomeworksolver.com or email support@statisticshomeworksolver.com. You can also call on +1 678 648 4277 for any assistance with SPSS Homework.
Episode 50 : Simulation Problem Solution Approaches Convergence Techniques S...SAJJAD KHUDHUR ABBAS
Episode 50 : Simulation Problem Solution Approaches Convergence Techniques Simulation Strategies
3.2.3.3. Quasi-Newton (QN) Methods
These methods represent a very important class of techniques because of their extensive use in practical alqorithms. They attempt to use an approximation to the Jacobian and then update this at each step thus reducing the overall computational work.
The QN method uses an approximation Hk to the true Jacobian i and computes the step via a Newton-like iteration. That is,
SAJJAD KHUDHUR ABBAS
Ceo , Founder & Head of SHacademy
Chemical Engineering , Al-Muthanna University, Iraq
Oil & Gas Safety and Health Professional – OSHACADEMY
Trainer of Trainers (TOT) - Canadian Center of Human
Development
Stochastic Analysis of Van der Pol OscillatorModel Using Wiener HermiteExpans...IJERA Editor
We study a model related to Van der Poloscillatorunder an external stochastic excitation described by white
noise process. This study is limited to find the Gaussian behavior of the stochastic solution processes related to
the model. Under the application ofWiener-Hermite expansion, a deterministic system is generated to describe
the Gaussian solution parameters (Mean and Variance).The deterministic system solution is approximated by
applying the multi-stepdifferential transformedmethodand the results are compared with NDSolveMathematica
10 package. Some case studies are considered to illustrate some comparisons for the obtained results related to
the Gaussian behavior parameters.
Stochastic Analysis of Van der Pol OscillatorModel Using Wiener HermiteExpans...IJERA Editor
We study a model related to Van der Poloscillatorunder an external stochastic excitation described by white
noise process. This study is limited to find the Gaussian behavior of the stochastic solution processes related to
the model. Under the application ofWiener-Hermite expansion, a deterministic system is generated to describe
the Gaussian solution parameters (Mean and Variance).The deterministic system solution is approximated by
applying the multi-stepdifferential transformedmethodand the results are compared with NDSolveMathematica
10 package. Some case studies are considered to illustrate some comparisons for the obtained results related to
the Gaussian behavior parameters.
Applied Numerical Methods Curve Fitting: Least Squares Regression, InterpolationBrian Erandio
Correction with the misspelled langrange.
and credits to the owners of the pictures (Fantasmagoria01, eugene-kukulka, vooga, and etc.) . I do not own all of the pictures used as background sorry to those who aren't tagged.
The presentation contains topics from Applied Numerical Methods with MATHLAB for Engineers and Scientist 6th and International Edition.
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docxRAHUL126667
CALIFORNIA STATE UNIVERSITY, NORTHRIDGE
MECHANICAL ENGINEERING DEPARTMENT
MARCH 30 2015
ME 309
HOMEWORK #3
Ahmed Mohammed
Problem statement
1. Write a general computer code to solve system of up to five couples first order initial value problems using Heun and Newton iteration trapezoidal methods. These are combined in the same algor4thim in such way that Heun’s method is automatically employed to provide the initial guess at each time step for the Newton iteration required by fully implicit Heun’s method, and no iterations are needed. The complete pseudo-language algorithm is attached.
Test this code by solving the following problem.
Use step size h= 0.1, 0.05 and 0.025. Solve the problem first with explicit Hun’s method, and then with implicit Newton iteration integration for each value of h. employ a convergence tolerance E= 0.000001 for the Newton iteration of the trapezoidal method. The exact solution to this problem is,
Make a table of results of convergence tests (based on the exact solution) at t=1, 2, 3, 4 & 6. This table should include the exact value, the computed solution, the error and the error ratios from successive step size for each of the required values of t. discuss how these results compare with theory. Also discuss what factors should influence the choice of convergence tolerance E for the Newton iterations, and whether the specified value given above is appropriate.
2. Solve the following problem using only the newton iteration trapezoidal method.
Employ step size h=0.1, 0.05, 0.01 and iteration convergence tolerance E= 0.000001. Consider the h=0.01 solution to be the “exact” in order to carry out convergence testes between the h= 0.1 and h=0.05 solutions at t=0.5, 1, 1.5, 2. Make a table, similar to the table in problem number 1.
Mathematical Description
HEUN’S METHOD
Heun’s Method, explained in a short manner, uses the line tangent to the function at the beginning of an interval. Now if a small step is applied to it, the error with the function result will be small. Heun’s method can be explained in more detailed in the following way:
2.-
To obtain solution point (t1,y1) we can use the fundamental theorem of calculus and integrate y’(t) over [t0,t1] to get
3.- Solving for y(t1) we find,
4.- We can use a numerical integration to approximate definite integral. If we use trapezoidal rule with step size h = t1 – t0, then we get
5.- We still need to find, y(t1) but an estimation for this value will work. After this we get the following, which is the Heun’s method.
6.- When this process is repeated it generates a sequence of points that approximate the solution curve y =y(t). At each step, Euler’s method is used as a prediction then the trapezoidal rule helps to make the correction to obtain the final value. [1]
Newton’s Method
It is way to approximate the roots of an equation by taking out the curve in the equation and then replace with a tangent line. Then, it find ...
I am Demi Jenkins.I love exploring new topics. Academic writing seemed an exciting option for me. After working for many years with matlabassignmentexperts.com, I have assisted many students with their assignments. I can proudly say, each student I have served is happy with the quality of the solution that I have provided. I acquired my master's from Stanford University, USA.
I am Andy K. I am a Calculus Homework Solver at mathhomeworksolver.com. I hold a Master's in Mathematics From Sydney, Australia. I have been helping students with their homework for the past 9 years. I solve homework related to Calculus.
Visit mathhomeworksolver.com or email support@mathhomeworksolver.com. You can also call on +1 678 648 4277 for any assistance with Calculus Homework.
Finite Volume Method Advanced Numerical Analysis by Md.Al-AminMd. Al-Amin
Finite Volume Method Advanced Numerical Analysis by Md.Al-Amin
Imam Hasan Al-Amin, professionally known as MD Al-Amin, He was born on December 25th, 1999, and brought up in Pirojpur. He is a Bangladeshi entrepreneur and mathematician. He graduated from Khulna University, Khulna, Bangladesh also Bangladesh University of Engineering and Technology(BUET) in mathematics. He is the co-founder and CEO of Juhod Shop-যুহদ শপ, which is mainly an online shop in Bangladesh. Here, you can buy products online with a few clicks or convenient phone calls. Also, he is the founder and CEO of Juhod IT-Care, a full-service digital media agency that partners with clients to boost their personal and business outcomes. His expertise in marketing has allowed him to help a number of businesses increase their revenue by tremendous amounts. From childhood, he wanted to do something different that would be fruitful for mankind. He started working as a vocal artist when he was only 18 years old.
I am Frank P. I am a SPSS Homework Solver at statisticshomeworksolver.com. I hold a Ph.D. in statistics, from Sunway University, Malaysia. I have been helping students with their homework for the past 6 years. I solve homework related to SPSS.
Visit statisticshomeworksolver.com or email support@statisticshomeworksolver.com. You can also call on +1 678 648 4277 for any assistance with SPSS Homework.
Episode 50 : Simulation Problem Solution Approaches Convergence Techniques S...SAJJAD KHUDHUR ABBAS
Episode 50 : Simulation Problem Solution Approaches Convergence Techniques Simulation Strategies
3.2.3.3. Quasi-Newton (QN) Methods
These methods represent a very important class of techniques because of their extensive use in practical alqorithms. They attempt to use an approximation to the Jacobian and then update this at each step thus reducing the overall computational work.
The QN method uses an approximation Hk to the true Jacobian i and computes the step via a Newton-like iteration. That is,
SAJJAD KHUDHUR ABBAS
Ceo , Founder & Head of SHacademy
Chemical Engineering , Al-Muthanna University, Iraq
Oil & Gas Safety and Health Professional – OSHACADEMY
Trainer of Trainers (TOT) - Canadian Center of Human
Development
Stochastic Analysis of Van der Pol OscillatorModel Using Wiener HermiteExpans...IJERA Editor
We study a model related to Van der Poloscillatorunder an external stochastic excitation described by white
noise process. This study is limited to find the Gaussian behavior of the stochastic solution processes related to
the model. Under the application ofWiener-Hermite expansion, a deterministic system is generated to describe
the Gaussian solution parameters (Mean and Variance).The deterministic system solution is approximated by
applying the multi-stepdifferential transformedmethodand the results are compared with NDSolveMathematica
10 package. Some case studies are considered to illustrate some comparisons for the obtained results related to
the Gaussian behavior parameters.
Stochastic Analysis of Van der Pol OscillatorModel Using Wiener HermiteExpans...IJERA Editor
We study a model related to Van der Poloscillatorunder an external stochastic excitation described by white
noise process. This study is limited to find the Gaussian behavior of the stochastic solution processes related to
the model. Under the application ofWiener-Hermite expansion, a deterministic system is generated to describe
the Gaussian solution parameters (Mean and Variance).The deterministic system solution is approximated by
applying the multi-stepdifferential transformedmethodand the results are compared with NDSolveMathematica
10 package. Some case studies are considered to illustrate some comparisons for the obtained results related to
the Gaussian behavior parameters.
Stochastic Analysis of Van der Pol OscillatorModel Using Wiener HermiteExpans...
ilovepdf_merged
1. MMAE 517
Computational Fluid Dynamics
Problem Set # 3
Problem 1:
Consider the problem of the transport (via both convection and diffusion)
of a scalar quantity, such as temperature, in the velocity field near a stagnation
point flow. Recall from Problem Set # 2 that the velocities in the x and y
directions in one-half of the symmetric stagnation point flow from a potential
flow solution are given by u = x and v = −y, respectively, i.e. the streamlines
are lines of ψ(x, y) = xy = constant. Note that this is somewhat artificial in
that the velocities are taken from a potential flow solution, which is inviscid,
while the convection-diffusion equation for φ(x, y) is viscous.
∂φ
∂y
= 0
OutletWall
Inlet
Stag. Pt.
1
y
x0
Symmetry
φ(x, y)
φ = 0
1
∂φ
∂x
= 0φ = 1 − y
The steady scalar transport equation is given by
u
∂φ
∂x
+ v
∂φ
∂y
= α
∂2
φ
∂x2
+
∂2
φ
∂y2
, (1)
where α is the diffusion parameter. The computational domain is 0 ≤ x ≤
1, 0 ≤ y ≤ 1. The boundary conditions are
φ = 1 − y, at x = 0, (2)
1
2. ∂φ
∂x
= 0, at x = 1, (3)
∂φ
∂y
= 0, at y = 0, (4)
φ = 0, at y = 1, (5)
Modify your ADI algorithm from Problem Set # 2 to include upwind-downwind
differencing of the convective terms on the left-hand-side of equation (1). Look-
ing ahead to Problem Set # 4, do not assume that u > 0 and v < 0. Obtain
grid independent solutions for φ(x, y) with values of α equal to 0.1 and 0.01.
Note that you may need to use a different convergence criterion and/or ac-
celeration parameters as compared to problem set #2. In addition, different
values of α may require different acceleration parameters.
2
3. Marcello de Oliveira Gomes MMAE 517
PROBLEM SET #3
The goal of this problem set is to solve the steady scalar equation with the following
boundary conditions
ݑ
∂ϕ
∂x
+ ݒ
߲߶
߲ݔ
= ߙ[
߲ଶ
߶
߲ݔଶ
+
߲ଶ
߶
߲ݕଶ
]
Solution will use upwind and downwind differencing in an ADI code similar to the one
used in problem set #2. Some improvements from the last code include a better way of
determining the parameters for Thomas call. Instead of a for loop calculating each
single value of a,b, c, and d, matrix multiplication is applied throughout the entire line
or column. This makes the code run about 10% faster.
Left and top boundaries are defined before calling the upwind/downwind function and
are not iterated inside it. Approximation is done by using central difference on the
diffusion terms and forward or backward difference on the convective terms, depending
on u and v sign.
For u>0
ߙ߶ାଵ, − ൫ݑ,Δݔ + 2ߙ൯߶, + ൫ߙ + ݑ,Δݔ൯߶ିଵ, [1]
4. For u<0
൫ߙ − ݑ,Δݔ൯߶ାଵ, − ൫−ݑ,Δݔ + 2ߙ൯߶, + ߙ߶ିଵ, [2]
For v>0
Δഥ[−ߙΔഥ߶,ାଵ + ൫2ߙΔഥ + ݒ,Δݔ൯߶, − ൫ߙΔഥ + Δݒݔ,൯߶,ିଵ [3]
For v<0
Δഥ[൫−ߙΔഥ + Δݒݔ,൯߶,ାଵ + ൫2ߙΔഥ − ݒ,Δݔ൯߶, − ߙΔഥ߶,ିଵ] [4]
The acceleration parameter,ߪ, should be inserted inside ߶, brackets in both sides of the
equations. If sweeping across constant lines, Thomas parameters a,b, and c will be the
ones for u>0 or u<0. In this case, −ߪ߶, should be inserted in both sides of the
equation. For u>0 and v<0 and sweeping in constant y lines the equation should look
like the following.
ߙ߶ାଵ, − ൫ݑ,Δݔ + 2ߙ + ߪ൯߶, + ൫ߙ + ݑ,Δݔ൯߶ିଵ, = Δഥ[൫−ߙΔഥ + Δݒݔ,൯߶,ାଵ +
ቀ2ߙΔഥ + ݒ,Δݔ −
ఙ
ഥ
ቁ ߶, − ߙΔഥ߶,ିଵ] [5]
Boundary conditions are treated as usual. For this problem left and top boundaries are
Dirichlet and do not need to be iterated. Treatment of right and bottom results in the
following equations.
For i=I and for u>0
−൫ݑ,Δݔ + 2ߙ − ߪ൯߶, + ൫2ߙ + ݑ,Δݔ൯߶ିଵ, [6]
For j=1 and v<0
Δഥ[൫−2ߙΔഥ + Δݒݔ,൯߶,ାଵ + ൫2ߙΔഥ + ݒ,Δݔ − ߪ൯߶, − ߙΔഥ߶,ିଵ] [7]
Best value for the parameter ߪ is found by iterating solution in a 11x11 mesh and kept
as being the one which returns the lowest number of iterations. Considering an error of
10ିସ
for ADI iterations is a major mistake leading to fast convergence, returning a very
small number of iterations and wrong solutions for the problem as shown in Figure 1.
Decreasing grid size only diverges solution, making the right boundary approach zero
5. for a mesh of 501x501 (in this case, new phi zero matrix was defined for each iteration,
leading to the approximation of zero value for right boundary condition). Real best
value that suits both ߙ was found to be around ߪ =0.2 for error of 10ି
.
Figure 1 - Solution for sigma =0.18 and error = 10^-4 in 50x50 and 301x301 mesh
Figure 2 - Sigma values x needed iterations
Grid independent solution was determined by inspecting maximum difference between
121 fixed points in the domain. Even though maximum difference is expected to happen
between right and bottom boundaries, convergence code was kept this way for future
uses, contemplating more general cases. Initial matrix had a size of 51x51, and
increased linearly up to the point where error between solutions was 1%. Though, every
time matrix increases the last solution was used to populate new matrix phi. This way,
instead of reaching solution from zero matrixes, code will use previous solution,
6. reducing computation time in more than half. Although it is already a great gain, this
approach still can be further improved for faster solutions. Scheme is show in Figure 3
Figure 3 - Solution reutilization
By inspections of the boundaries, left side of the domain is a straight line starting at y=1
and ending at y=0, while top is x =0, Figure 4 and Figure 5, which confirms boundary
conditions given in the problem. As can be noted by comparison, solution does not vary
significantly. Maximum error between solutions was found to be 0.0072 and 0.0051
with grid independent solutions of 101x101 and 151x151 for ߙ values of 0.1 and 0.01
respectively. Iteration time for ߙ equals to 0.1 and 0.01 were 37s and 518s respectively.
Figure 4 - Solution for ࢻ= 0.1, 51x51 mesh
8. Figure 7 - Solution for ࢻ = 0.01, 151x151 mesh
Figure 8 - Constant streamlines ࢻ=0.01
Backward and forward approximations bring the truncation error of the solution to the
order of Δ.ݔ An estimative of the true ߙ value that is being calculated can be taken by
equation 8. Variation of ߙ with grid size is shown in Figure 9
ߙ = ߙ −
௫
ଶ
[8]
9. Figure 9-Real alpha due to upwind/downwind approximation
Figure 9 shows that to obtain an error of only 5% in ߙ values for maximum velocity it is
needed a mesh size of 101x101 and 1001x1001 for ߙ = 0.1 and 0.01 respectively. This
task is doable for 101 points in each direction but not for a 1001. Computation time gets
extremely long and code tends to be not viable anymore when bigger problems are
concerned.
0
5
10
15
20
25
30
35
40
45
50
0 200 400 600 800 1000
Differencein%
Mesh size (NxN)
alpha = 0.1
alpha=0.01
10. Main Code
clear all
clc
error = 10^-6; % error for ending iteration
alpha = 0.1;
sigma = 0.2;
cnt = 5; %this variable will increase grid size
compare = zeros(11,11,2);
A = zeros(50,50); % this matrix will store results for 50x50
max_dif = 5; %just a random large number
BC1=0;
BC2 = 0;
figure(1)
hold on
grid on
while max_dif>10^-2
I = (cnt*10)+1;
J = (cnt*10)+1;
delta_x = 1/(I-1);
delta_y = 1/(J-1);
y = (0:delta_y:1); %vector containing y positions
x = (0:delta_x:1);
u= zeros(I,J);
v = zeros(I,J);
%ALL THE COMMENTS INSIDE THIS BOX ARE FOR DETERMINING BEST SIGMA
VALUE-----
% figure(1)
% grid on
% hold on
% sigma = (1.1:0.01:1.2); %what's best value for sigma???
n_min=10^15; %minimum number of iterations. Set to be a high value
to avoid problems
%determining best value of sigma
% for z=1:size(sigma,2)
phi = zeros(I,J);
for i=1:cnt/5
for j=1:cnt/5
phi((i-1)*size(A,2)+1:size(A,2)*i,(j-
1)*size(A,2)+1:size(A,2)*j)= A;
end
end
for i=1:J
phi(1,i) = 1- y(i);
u(i,:) = delta_x*(i-1);
end
for i=1:I
phi(i,I) = 0;
v(:,i) = -delta_y*(i-1);
end
left = [1 0 0; 0 1 0]; %since left boundary for x is dependenton y, it
will be taken in account inside upwing code.
right = [0 1 0; 1 0 0];
tic
11. [phi,N] =
updown_wind_tentative(alpha,phi,I,J,u,v,delta_x,delta_y,error,sigma,BC
1,BC2,left,right);
A = phi(1:50,1:50);
% if isnan(phi) %this if checks if any of phi values are NaN
% N=0;
% end
%
% if N<n_min && N~=0 %keeping fastest sigma
% n_min=N;
% value = z; %stores when minimum number of iterations
happened
% end
% plot(sigma(z),N,'dk')
% fprintf('iteration %dn',z)
% % end
%
% xlabel('Sigma','FontSize',13)
% ylabel('Number of Iterations','FontSize',13)
% title('Sigma x Number of Iterations','FontSize',17)
% hold off
% end
%
######################################################################
###
%---------------------------------------------------------------------
-----
%For checking convergence, uncomment this section and while on line 19
plot(I,max_dif,'dk')
[max_dif,compare]= convergence(compare,phi,cnt);
xlabel('Grid size','FontSize',13)
ylabel('Maximum error','FontSize',13)
title('Error between previous and current solution','FontSize',17)
cnt = cnt+5;
end
time = toc
hold off
figure(2)
mesh(x,y,phi)
title('3-D phi')
xlabel('X')
ylabel('Y')
zlabel('PHI')
figure(3)
hold on
grid on
contour(x,y,phi','ShowText','on')
title('Constant streamlines')
xlabel('X')
ylabel('Y')
hold off
% %-------------------------------------------------------------------
12. updown_wind_tentative
% I is the number of nodes in x direction
% J is the number of nodes in y direction
% sigma is the acceleration parameter
% error is the minimum acceptable difference between iterations
% u is the velocity vector, size IxJ
% v is the velocity vector, size IxJ
% BC1 is the value for the Neumann boundary condition on the right
side
% BC2 is the bottom boundary condition
% left and right are the boundary conditions as specified in Thomas ->
% First line indicates X(constant j lines) and second line indicates
% Y(constant i lines)
function [phi,n_iterations] =
updown_wind_tentative(alpha,phi,I,J,u,v,delta_x,delta_y,error,sigma,BC
1,BC2,left,right)
% %Defining parameters
leftx = left(1,:);
lefty = left(2,:);
rightx = right(1,:);
righty = right(2,:);
delta_bar = (delta_x/delta_y); % ATTENTION it is defined differently
here!!!!!!
er_max = 2; %random value
n_iterations=0; %counter
a = zeros(I,1);
b = zeros(I,1);
c = zeros(I,1);
d = zeros(I,1);
old_value = zeros(1,J);
while er_max>=error
er_max = 0;
%sweeping across constant j lines
%phi values will be stored as matrix collumns
j = 1;
b(:,1) = -(abs(u(:,j)*delta_x)+ 2*alpha+sigma);
a(:,1) = u(:,j)*delta_x+alpha;
c(:,1) = alpha;
d(:,1)= delta_bar*((-v(:,j)*delta_x+2*alpha*delta_bar -
sigma/delta_bar).*phi(:,j) +(v(:,j)*delta_x-
2*alpha*delta_bar).*phi(:,j+1)+2*alpha*delta_bar*delta_y*BC1);
leftx(1,3)= 1-delta_y*(j-1);
test = thomas(I-1,delta_x,a,b,c,d,leftx,rightx);
phi(:,j) = test;
for j=2:J-1 %Dirichlet boundary at j=J is not iterated
b(:,1) = -(abs(u(:,j)*delta_x)+ 2*alpha+sigma);
a(:,1) = u(:,j)*delta_x+alpha;
c(:,1) = alpha;
d(:,1)= delta_bar*((-v(:,j)*delta_x+2*alpha*delta_bar -
sigma/delta_bar).*phi(:,j) -alpha*delta_bar.*phi(:,j-1)
+(v(:,j)*delta_x-alpha*delta_bar).*phi(:,j+1));
%fixing boundary condition, dependence on y!
leftx(1,3)= 1-delta_y*(j-1);
test = thomas(I-1,delta_x,a,b,c,d,leftx,rightx);
phi(:,j) = test;
end
%---------------------------------------------------------------------
13. %phi values will be stored as matrix lines
for i=2:I-1
old_value(1,:) = phi(i,:);
b(:,1) = delta_bar*((abs(v(i,:)*delta_x)+2*alpha*delta_bar +
sigma/delta_bar));
a(:,1) = -alpha*delta_bar^2;
c(:,1) = delta_bar*(v(i,:)*delta_x-alpha*delta_bar);
d(:,1)= -(u(i,:)*delta_x+2*alpha-sigma).*phi(i,:)+
(u(i,:)*delta_x+alpha).*phi(i-1,:)+alpha.*phi(i+1,:);
%thomas returns a collumn vector. It has to be fixed before assigning
it to phi
test = thomas(J-1,delta_y,a,b,c,d,lefty,righty);%temporary
variable to store results
phi(i,:) = test(:,1);
er_point = max(abs(phi(i,:)-
old_value))/max(max(abs(phi)));%maximum error in constant i line
if er_point>er_max
er_max = er_point;
end
end
i=I;
old_value(1,:) = phi(i,:);
b(:,1) = delta_bar*((abs(v(i,:)*delta_x)+2*alpha*delta_bar +
sigma/delta_bar));
a(:,1) = -alpha*delta_bar^2;
c(:,1) = delta_bar*(v(i,:)*delta_x-alpha*delta_bar);
d(:,1) = -(u(i,:)*delta_x+2*alpha-sigma).*phi(i,:)+
(u(i,:)*delta_x+2*alpha).*phi(i-1,:)+2*alpha*BC2*delta_x;
test = thomas(J-1,delta_y,a,b,c,d,lefty,righty);%temporary variable to
store results
phi(i,:) = test(:,1);
er_point = max(abs(phi(i,:)-old_value))/max(max(abs(phi)));%maximum
error in constant i line
if er_point>er_max
er_max = er_point;
end
n_iterations=n_iterations+1;
end
end