Heat transfer 2D to 3d

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 #include <iostream>
#include <cstdlib>

using namespace 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;
}
Last edited on
Heat transfer 2D to 3d

Can you give us the algorithm?
Also provide us with your current output.
Output is :
50.000 50.000 50.000 50.000 50.000 50.000 50.000 50.000 50.000 50.000
50.000 47.160 44.915 43.434 42.831 43.132 44.244 45.957 47.978 50.000
50.000 44.418 39.985 37.032 35.794 36.345 38.524 41.922 45.957 50.000
50.000 42.238 36.037 31.857 30.042 30.733 33.745 38.524 44.244 50.000
50.000 40.985 33.738 28.795 26.569 27.268 30.733 36.345 43.132 50.000
50.000 40.829 33.427 28.333 25.964 26.569 30.042 35.794 42.831 50.000
50.000 41.765 35.116 30.519 28.333 28.795 31.857 37.032 43.434 50.000
50.000 43.698 38.623 35.116 33.427 33.738 36.037 39.985 44.915 50.000
50.000 46.501 43.698 41.765 40.829 40.985 42.238 44.418 47.160 50.000
50.000 50.000 50.000 50.000 50.000 50.000 50.000 50.000 50.000 50.000

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
Last edited on
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

for(i=0; i<m; i++) // initialize loop
for(j=0; j<n; j++)
for(g=0;g<b; g++)
T[i][j][g] = 0.0;

[\code]
Last edited on
Topic archived. No new replies allowed.