-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS2Tarea.cpp
More file actions
122 lines (102 loc) · 2.71 KB
/
S2Tarea.cpp
File metadata and controls
122 lines (102 loc) · 2.71 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
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
/*
#include <iostream>
#include <vector>
#include <cmath>
// constants
const double DELTA = 0.05;
const double L = 1.479;
const int N = int(L/DELTA)+1;
const int STEPS = 200;
typedef std::vector<double> Matrix;
void initial_conditions(Matrix & m);
void boundary_conditions(Matrix & m);
void evolve(Matrix & m);
void print(const Matrix & m);
void init_gnuplot(void);
void plot_gnuplot(const Matrix & m);
int main(void)
{
Matrix data(N*N);
initial_conditions(data);
boundary_conditions(data);
//init_gnuplot();
for (int istep = 0; istep < STEPS; ++istep) {
evolve(data);
//plot_gnuplot(data);
}
print(data);
return 0;
}
void initial_conditions(Matrix & m)
{
for(int ii=0; ii<N; ++ii) {
for(int jj=0; jj<N; ++jj) {
m[ii*N + jj] = 1.0;
}
}
}
void boundary_conditions(Matrix & m)
{
int ii = 0, jj = 0;
ii = 0;
for (jj = 0; jj < N; ++jj)
m[ii*N + jj] = 100;
ii = N-1;
for (jj = 0; jj < N; ++jj)
m[ii*N + jj] = -50;
jj = 0;
for (ii = 1; ii < N-1; ++ii)
m[ii*N + jj] = 0;
jj = N-1;
for (ii = 1; ii < N-1; ++ii)
m[ii*N + jj] = 0;
int r = 5;
for(int ii=0; ii<N; ++ii) {
for(int jj=0; jj<N; ++jj) {
if((ii-14)*(ii-14) + (jj-14)*(jj-14) <= r*r)
{
int d = 5;
m[ii*N + jj] = 50/d;
}
}
}
}
void evolve(Matrix & m)
{
for(int ii=0; ii<N; ++ii) {
for(int jj=0; jj<N; ++jj) {
// check if boundary
if(ii == 0) continue;
if(ii == N-1) continue;
if(jj == 0) continue;
if(jj == N-1) continue;
// evolve non boundary
m[ii*N+jj] = (m[(ii+1)*N + jj] +
m[(ii-1)*N + jj] +
m[ii*N + jj + 1] +
m[ii*N + jj - 1] )/4.0;
}
}
}
void print(const Matrix & m)
{
for(int ii=0; ii<N; ++ii) {
for(int jj=0; jj<N; ++jj) {
std::cout << ii*DELTA << " " << jj*DELTA << " " << m[ii*N + jj] << "\n";
}
std::cout << "\n";
}
}
void init_gnuplot(void)
{
std::cout << "set contour " << std::endl;
std::cout << "set terminal gif animate " << std::endl;
std::cout << "set out 'anim.gif' " << std::endl;
}
void plot_gnuplot(const Matrix & m)
{
std::cout << "splot '-' w pm3d " << std::endl;
print(m);
std::cout << "e" << std::endl;
}
*/