I wrote a 2D array for an equilibrum boundary condition problem that is a basic heat transfer problem. Now I need to go to 3D using this same code, if anyone could help it would greatly be appreciated.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main(int argc, char** argv)
{
int m ; // number of nodes in x direction
int n ; // number of nodes in y direction
int iters; // number of iterations
int i, j, k; // initial variables
FILE* output1;
output1 = fopen("outputfinal.dat","w");
FILE* output2;
output2 = fopen("outputcenter.dat","w");
cout << "Enter nodes in y:";
cin >> m;
cout << "Enter nodes in x:";
cin >> n;
cout << "Enter number of iterations:";
cin >> iters;
double T[m][n]; // poor mans way of making an array
for(i=0; i<m; i++) // loop over left
for(j=0; j<n; j++)
T[i][j] = 0.0;
for(i=0; i<m; i++) // loop over right
T[i][0] = 50.0;
for(i=0; i<m; i++) // loop over top
T[i][n-1] = 50.0;
for(j=0; j<n; j++) // loop over bottom
T[m-1][j] = 50.0;
for(j=0; j<n; j++)
T[0][j] = 50.0;
for(k=0; k<iters; k++)
{
for(i=1; i<m-1; i++)
for(j=1; j<n-1; j++)
T[i][j] = .25*(T[i-1][j]+T[i+1][j]+T[i][j-1]+T[i][j+1]);
fprintf(output2, "%d %.3f \n", k, T[int((m-1)/2)][int((n-1)/2)]);
}
for(i=m-1; i>=0; i--)
{
for(j=0; j<n; j++)
fprintf(output1, "%.3f ", T[i][j]);
fprintf(output1, "\n");
}
return 0;
}
and the formula or algorithm is in the code -- > line 50
i will have to make a new formula for when it is in 3D but it will be the same jist as line 50 in the code. Something like
T[i][j][0] = .625*(T[i-1][j][0]+T[i+1][j][0]+T[i][j-1][0]+T[i][j+1][0]);
I have only ever coded in vb and used it for basic numerical method, so i understand alot of the loops and array stuff but i can not visualize it it 3D
i guess what i am really asking is if someone can help me expand upon the for loops to turn code into 3D by adding new variables like
[code]
int main(int argc, char** argv)
{
int m ; // number of nodes in x direction
int n ; // number of nodes in y direction
int g; // number of nodes in z direction
int iters; // number of iterations
int i, j, k; // initial variables x,y and iters
int b; // initial variables z
double T[m][n][g]; // poor mans way of making an array