Programming a CFD Code:
These two points are essentail, not following these steps will give a hard time in writting your code.
1-THE NUMBER ONE RULE IN PROGRAMMING IS SOLVING YOUR PROBLEM ON PAPER AT FIRST THEN WRITE YOUR CODE.
2-Geometrical problems need to be drawn on paper before coding.
1-THE NUMBER ONE RULE IN PROGRAMMING IS SOLVING YOUR PROBLEM ON PAPER AT FIRST THEN WRITE YOUR CODE.
2-Geometrical problems need to be drawn on paper before coding.
Example Quick Data Generation for building the Numerical Modelling
While building your numerical model you will need to generate a random set of data just to check that the code is working, once the code gets working validating it comes next.
a-Using the pascal command.
b-Using the magic command.
c-Using the rand and randn command to generate a matrix full of random data example k=fix(10*rand(3,3), 10 means from 0 to 10 choose a value, (3,3) means matrix dimensions.
d-Using the spy command,this command is usefull to see the filled cells of the formed matrix without seeing the values of the cells, as an example weither its satisfies diagnal structure or not.
e-Using the intermediate process between several operations some times requires the use of a matix full of ones,example A=ones(3). or the use of a matrix full of zero values example B=ZEROS(3)
a-Using the pascal command.
b-Using the magic command.
c-Using the rand and randn command to generate a matrix full of random data example k=fix(10*rand(3,3), 10 means from 0 to 10 choose a value, (3,3) means matrix dimensions.
d-Using the spy command,this command is usefull to see the filled cells of the formed matrix without seeing the values of the cells, as an example weither its satisfies diagnal structure or not.
e-Using the intermediate process between several operations some times requires the use of a matix full of ones,example A=ones(3). or the use of a matrix full of zero values example B=ZEROS(3)
Coding Bulding Blocks
clc
clear
input =menu('Selection List','Random Matrix for 5',' Random Matrix for 10','Generate Random Number Matrix for 5','Generate Random Number Matrix for 5')
switch input
case 1
clc
clear
n=5
for i=1:n;
a(i)=randn(1,1);
end
case 2
clc
clear
n=10
for i=1:n;
a(i)=randn(1,1);
end
case 3
clc
clear
n=5;
for i=1:n;
a(i)=randn(1,1);
end
for i=1:n;
b(i)=a(i);
end
case 4
clc
clear
n=10;
for i=1:n;
a(i)=randn(1,1);
end
for i=1:n;
b(i)=a(i);
end
end
clear
input =menu('Selection List','Random Matrix for 5',' Random Matrix for 10','Generate Random Number Matrix for 5','Generate Random Number Matrix for 5')
switch input
case 1
clc
clear
n=5
for i=1:n;
a(i)=randn(1,1);
end
case 2
clc
clear
n=10
for i=1:n;
a(i)=randn(1,1);
end
case 3
clc
clear
n=5;
for i=1:n;
a(i)=randn(1,1);
end
for i=1:n;
b(i)=a(i);
end
case 4
clc
clear
n=10;
for i=1:n;
a(i)=randn(1,1);
end
for i=1:n;
b(i)=a(i);
end
end
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com