-
Notifications
You must be signed in to change notification settings - Fork 0
/
LUL.cpp
143 lines (121 loc) · 3.27 KB
/
LUL.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <omp.h>
//using namespace std;
using std::cout;
using std::endl;
using std::ofstream;
using std::fopen;
using std::setw;
using std::setprecision;
/* bound.cond.
*
* 000000000000
0 0
0 0
0 0
111111111111
*/
void calc(){
ofstream fout;
fout.open("Results.txt");
if(fout.is_open()==true){
cout<<"The file has been opened!"<<endl;
}
else{
cout<<"error with openning!"<<endl;
cout<<"The program has been stopped!"<<endl;
}
int n=100;
int i, d_X, j, d_Y;
double T[100][100] //result array for temperature
, Tn[100][100]; //auxiliary array for saving info
double h, eps, dt,
Tsn, Ts; // variables for exit of loop
double t1,t2;
d_X = 20;
d_Y = 20;
h = 1. / (d_X - 1);
eps = 0.0000001;
dt = 0.2*h*h;
t1 = omp_get_wtime();
// Make all arrays equal to zero for correct working with them
#pragma omp for
for (i = 0; i < d_X; i++)
for (j = 0; j < d_Y; j++) {
T[i][j] = 0;
Tn[i][j] = 0;
}
Ts = 1; //for enter to while-loop
Tsn = 0;
#pragma omp for
// initial conditions: heating right side of the lamel from bottom to top
for (j = 0; j < d_X; j++) {
T[d_X - 1][j] = 1;
}
cout<<"Writing to file..."<<endl;
while ((fabs(Ts - Tsn)) > eps*Ts) {
Ts = 0;
Tsn = 0;
#pragma omp for
// auxiliary array Tn[][] is using T[][], which initital conditions acting on
for (i = 1; i < d_X-1; i++) {
for (j = 1; j < d_Y-1; j++) {
Tn[i][j] = T[i][j] + (dt /( h * h))*(T[i + 1][j] - 2 * T[i][j] + T[i - 1][j] + T[i][j + 1] - 2 * T[i][j] + T[i][j - 1]);
// fout <<setw(9)<<setprecision(3)<< Tn[i][j] << " ";
}
}
#pragma omp for
for (i = 0; i < d_X; i++) { //ãðàí óñëîâèÿ
Tn[i][0] = 1;
Tn[i][d_Y - 1] = (4 * Tn[i][d_Y - 2] - T[i][d_Y - 3]) / 3.;
}
#pragma omp for
for (j = 0; j < d_X; j++) { //ãðàí óñëîâèÿ
Tn[0][j] = 0;
Tn[d_X - 1][j] = 0;
}
#pragma omp for
for (i = 1; i < d_X - 1; i++) {
for (j = 1; j < d_X - 1; j++) {
Tsn += Tn[i][j];
Ts += T[i][j];
}
}
#pragma omp for
// saving array T[][]
for (i = 1; i < d_X - 1; i++) {
for (j = 1; j < d_X - 1; j++) {
T[i][j] = Tn[i][j];
}
}
Tsn = Tsn / d_X;
Ts = Ts / d_X;
}
#pragma omp for
// saving to result.txt
for (i = 0; i < d_X; i++) {
for (j = 0; j < d_X; j++) {
fout <<setw(9)<<setprecision(3)<< T[i][j] ;
}
fout << endl;
}
fout<<endl;
fout.close();
t2 = omp_get_wtime() - t1;
if(fout.is_open()==false){
cout<<"The file has been closed!"<<endl;
cout<<"Time "<< t2 <<endl;
}
else{
cout<<"The file has NOT been closed!"<<endl;
}
}
int main()
{
calc();
system("pause");
return 0;
}