-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaplaceEquation3DSS_FixedPoint_Iteration.cpp
More file actions
90 lines (67 loc) · 2.45 KB
/
LaplaceEquation3DSS_FixedPoint_Iteration.cpp
File metadata and controls
90 lines (67 loc) · 2.45 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//************************************
// Solution of the 3D Steady State Laplace Equation with the finite difference method - Fixed Point Iteration
// Code Developed by N. Piroozan
//************************************
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main ()
{
const int size = 50; // Grid Size (number of grid points)
const int niter = 10000; // Number of Iterations
const double nx=50.0; // Number of steps in the x direction
const double ny=50.0; // Number of steps in the y direction
const double nz=50.0; // Number of steps in the z direction
const double dx=(20)/(nx-1); // Width of space step (x)
const double dy=(20)/(ny-1); // Width of space step (y)
const double dz=(20)/(nz-1); // Width of space step (z)
const double alpha1=dy * dy;
const double alpha2=dx * dx;
const double alpha3=dz * dz;
const double beta1=alpha1*alpha3;
const double beta2=alpha2*alpha3;
const double beta3=alpha1*alpha2;
const double beta4=2 * ((beta1) + (beta2) + (beta3));
const int Tb=300; // Initial temperature for the top edge
double Temp[size][size][size];
std::ofstream outfile ("Laplace3D_SS_Explicit.dat"); // Open an output file stream
for (int k = 0; k < size; k++) // Set up the boundary conditions
{
for (int j = 0; j < size; j++)
{
for (int i = 0; i < size; i++)
{
Temp[i][j][k]=0;
Temp[i][j][0]=Tb;
}
}
}
for (int iter = 1; iter <= niter; iter++)
{
for (int i=1; i < (size-1); i++) //x-direction
{
for (int j=1; j < (size-1); j++)
{
for (int k=1; k < (size-1); k++)
{
Temp[i][j][k] = (beta1*(Temp[i+1][j][k] + Temp[i-1][j][k]) + beta2*(Temp[i][j+1][k] + Temp[i][j-1][k]) + beta3*(Temp[i][j][k+1] + Temp[i][j][k-1]))/(beta4);
}
}
}
}
for (int k = 67; k < 68; k++)
{
for (int j = 0; j < size; j++)
{
for (int i = 0; i < size; i++)
{
outfile << Temp[i][j][2] << " ";
}
outfile << endl;
}
outfile << endl;
}
outfile.close ();
return (0);
}