Reputation: 1
I’m able to compile the program but not able to run it. I need to plug in the N = 11, dtmax = 0.0003 and do trials with M = 11, 21, 41 and 61. I tried to input values using constants and also by stating them in the writeln
but it does not work.
Below in my writeln
statements, the values of 11 is where I tried to input them. I don’t know what’s wrong.
uses
crt, printer;
const
N = 11; {radial nodes}
M = 21; {axial nodes}
k = 40.0; {thermal conductivity (W/mK)}
alpha = 1e-5; {thermal diffusivity (m^2/s)}
Rs = 0.025; {disk radius (m)}
Zs = 0.005; {disk thickness (m)}
qmax = 3.0e6; {peak flux (W/m^2)}
Ro = 0.05; {parameter in flux equation (m)}
Tinit = 20.0; {initial temperature (C)}
Tmax = 300.0; {maximum desired temperature at top of axis (C)}
var
dr, dz, rhoC, dtMax, dt, time : real;
i, j : Longint;
C, R, L, U, D : array [1..N,1..M] of real;
q, V, Aco, Aci, Af : array [1..N] of real;
Told, Tnew : array [1..N+1,1..M+1] of real;
begin
{Size of the control volumes}
dr := Rs/(N - 1);
dz := Zs/(M - 1);
rhoC:= k/alpha;
{Control volume surface areas and volumes}
Af[1] := pi*dr*dr/4.0;
Af[N] := pi*dr*(Rs - dr/4.0);
for i := 2 to N - 1 do
Af[i] := 2.0*pi*dr*dr*(i - 1);
for i := 1 to N do
V[i] := Af[i]*dz;
Aco[N] := 2.0*pi*Rs*dz;
for i := 1 to N - 1 do
Aco[i] := 2.0*pi*dr*dz*(i - 0.5);
Aci[1] := 0.0;
for i := 2 to N do
Aci[i] := 2.0*pi*dr*dz*(i - 1.5);
{Absorbed flux as function of i}
q [1] := pi/4.0*qmax*dr*dr*(1.0 - 0.9/8.0*sqr(dr/Ro));
q [N] := pi*qmax*dr*dr*(N - 1.25-0.9/8.0*sqr(dr/Ro)*(2.0*N*N*N -7.5*N*N
+ 9.5*N - 65.0/16.0));
for i := 2 to N - 1 do
q [i] := pi*qmax*dr*dr*(2.0*(1 - 1.0) - 0.9/4.0*sqr(dr/Ro)*(4.0*i*i*i - 12.0*i*
i + 13.0*i - 5.0));
{Coefficient matrices}
for i := 1 to N do
for j := 1 to M do
begin
R[i, j] := 0.0;
L[i, j] := 0.0;
U[i, j] := 0.0;
D[i, j] := 0.0;
C[i, j] := 0.0;
end;
For i := 2 to N - 1 do
For j := 2 to M - 1 do
begin;
R[i, j] := Aco[i]/dr;
L[i, j] := Aci[i]/dr;
U[i, j] := Af[i]/dz;
D[i, j] := Af[i]/dz;
end;
i := 1;
for j := 2 to M - 1 do
begin
R[i, j] := Aco[i]/dr;
U[i, j] := Af[i]/dz;
D[i, j] := Af[i]/dz;
end;
i := 1;
j := M;
R[i, j] := Aco[i]/dr;
D[i, j] := Af[i]/dz;
i := 1;
j := 1;
R[i, j] := Aco[i]/dr;
U[i, j] := Af[i]/dz;
i := N;
for j := 2 to M - 1 do
begin
L[i, j] := Aci[i]/dr;
U[i, j] := Af[i]/dz;
D[i, j] := Af[i]/dz;
end;
i := N;
j := M;
L[i, j] := Aci[i]/dr;
D[i, j] := Af[i]/dz;
i := N;
j := 1;
L[i, j] := Aci[i]/dr;
U[i, j] := Af[i]/dz;
j := M;
for I := 2 to N - 1 do
begin
R[i, j] := Aco[i]/dr;
L[i, j] := Aci[i]/dr;
D [i, j] := Af[i]/dz;
end;
j := 1;
for I := 2 to N - 1 do
begin
R [i, j] := Aco[i]/dr;
L [i, j] := Aci[i]/dr;
U [i, j] := Af[i]/dz;
end;
{Maximum permissible dt}
dtMax := 0.0;
for i := 1 to N do
for j := 1 to M do
begin
dt := V[i]/alpha/(R[i, j] + L[i, j] + U[i, j] + D[i, j]);
if dt > dtMax then
dtMax := dt;
end;
dt := 0.5*dtMax; {actual value}
{fill in the cij matrix}
for i := 1 to N do
C[1, M] := dt*q [i]/rhoC/V[i];
{Initial conditions}
for i := 1 to N do
for j := 1 to M do
Told [i, j] := Tinit;
{carry out the solution}
time := 0.0;
repeat
time:= time + dt;
writeln (time: 10:5);
for i:= 1 to N do
for j:= 1 to M do
Tnew [i,j] := Told [i,j]*(1.0 - alpha*dt/V[i]*(R[i,j]+ L[i,j]+ U[i,j]+
D[i,j])
+ alpha*dt/V[i]*(R[i, j]*Told [i + 1, j] + L[i, j]*Told [i - 1, j] + U[i, j]*Told
[i, j + 1] + D[i, j]*Told [i, j - 1]) + C[i, j]);
if Tnew[1,m] > Tmax then {print out distribution and quit}
begin
writeln(11, time : 8 : 4, 'sec dt =', dt : 15 : 10);
write(11,' ');
for i := 1 to N do
write (11, 1 : 10);
writeln(11);
for j := M downto 1 do
begin
write(11, j : 4);
for i := 1 to N do
write(11, Tnew[i,j]: 10 : 5);
writeln(11);
end;
writeln(11);
halt;
end;
for i := 1 to N do
for j := 1 to M do
Told[i, j]:= Tnew[i, j];
until time < - 1.0;
end.
I looked up how to debug exit code 201 and changed the integer
to Longint
but it didn’t solve it. I tried to plug in values in the writeln
statements but it doesn’t work. I’m able to see a screen pop up but I can’t read it since it disappears.
Upvotes: 0
Views: 99
Reputation: 1560
Pascal exit code 201
The programming language Pascal does not define any exit codes, but rather your implementation (FreePascal in this case). A different Pascal implementation may report different exit codes, if at all.
[…] I looked up how to debug exit code 201 and changed the integer to Longin but it [didn’t] solve it. […]
The FreePascal Compiler defines RTE 201 to be a range‑check error. You must have enabled them, and in general you should always enable them, or at least during the development phase if speed matters.
As Stuart already pointed out, the expression of the tNew
assignment in line 157 and following accesses, or ''attempts'' to access if range‑checking is turned on, non‑existent array elements.
This is caused by your + 1
and − 1
calculations.
In the spirit of your coding style, a quick‑and‑dirty fix is to replace
i + 1
with i + ord(i < N)
,i ‑ 1
with i ‑ ord(i > 1)
,j + 1
with j + ord(j < M)
andj ‑ 1
with j ‑ ord(j > 1)
.Another wasteful pseudo‑solution is to extend your table by the necessary additional row and column.
Told, Tnew : array [0..N+1,0..M+1] of real;
Note the new minimum is zero for both dimensions. This works well if you have initialized the additional row and column to values that do not impact your calculations (e. g. neutral element of addition or multiplication as appropriate).
Sidenotes:
uses
clause can be removed.
It reduces the size of the executable binary.11
s (argument to writeLn
).
This appears to be a “magic” constant, so better declare and use a const
ant for this.time < −1.0
.
Unless you invented a time machine, I recommend that you strictly progress forward in time, i. e. ensure that dt
(for time ≔ time + dt
) cannot be but positive.row
or columnMaximum
identifiers if you cannot come up with better names that reveal their meaning at a glance.program
.
Splitting the tasks into routines may seem to introduce complexity, but at the benefit of increasing readability.
Remember, you program for humans; the fact that a computer may want to process your code, too, is (almost) none of your concern.
Or at least use big‑ass comments visually dividing your code, which is something I do when programming in assembly.Upvotes: 0