"docs.it4i/git@code.it4i.cz:sccs/docs.it4i.cz.git" did not exist on "65e3b297def916513c5744bcca505cc761c13636"
Newer
Older
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# include "poisson.h"
double r8mat_rms ( int nx, int ny, double **a )
//****************************************************************************80
//
// Purpose:
//
// R8MAT_RMS returns the RMS norm of a vector stored as a matrix.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 01 March 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int NX, NY, the number of rows and columns in A.
//
// Input, double A[NX][NY], the vector.
//
// Output, double R8MAT_RMS, the root mean square of the entries of A.
//
{
int i;
int j;
double v;
v = 0.0;
for ( j = 0; j < ny; j++ )
{
for ( i = 0; i < nx; i++ )
{
v = v + a[i][j] * a[i][j];
}
}
v = sqrt ( v / ( double ) ( nx * ny ) );
return v;
}
//****************************************************************************80
void rhs ( int nx, int ny, double **f )
//****************************************************************************80
//
// Purpose:
//
// RHS initializes the right hand side "vector".
//
// Discussion:
//
// It is convenient for us to set up RHS as a 2D array. However, each
// entry of RHS is really the right hand side of a linear system of the
// form
//
// A * U = F
//
// In cases where U(I,J) is a boundary value, then the equation is simply
//
// U(I,J) = F(i,j)
//
// and F(I,J) holds the boundary data.
//
// Otherwise, the equation has the form
//
// (1/DX^2) * ( U(I+1,J)+U(I-1,J)+U(I,J-1)+U(I,J+1)-4*U(I,J) ) = F(I,J)
//
// where DX is the spacing and F(I,J) is the value at X(I), Y(J) of
//
// pi^2 * ( x^2 + y^2 ) * sin ( pi * x * y )
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 28 October 2011
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int NX, NY, the X and Y grid dimensions.
//
// Output, double F[NX][NY], the initialized right hand side data.
//
{
double fnorm;
int i;
int j;
double x;
double y;
//
// The "boundary" entries of F store the boundary values of the solution.
// The "interior" entries of F store the right hand sides of the Poisson equation.
//
for ( j = 0; j < ny; j++ )
{
y = ( double ) ( j ) / ( double ) ( ny - 1 );
for ( i = 0; i < nx; i++ )
{
x = ( double ) ( i ) / ( double ) ( nx - 1 );
if ( i == 0 || i == nx - 1 || j == 0 || j == ny - 1 )
{
f[i][j] = u_exact ( x, y );
}
else
{
f[i][j] = - uxxyy_exact ( x, y );
}
}
}
fnorm = r8mat_rms ( nx, ny, f );
cout << " RMS of F = " << fnorm << "\n";
return;
}
//****************************************************************************80
void sweep ( int nx, int ny, double dx, double dy, double **f,
double **u, double **unew )
//****************************************************************************80
//
// Purpose:
//
// SWEEP carries out one step of the Jacobi iteration.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 26 October 2011
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int NX, NY, the X and Y grid dimensions.
//
// Input, double DX, DY, the spacing between grid points.
//
// Input, double F[NX][NY], the right hand side data.
//
// Input, double U[NX][NY], the previous solution estimate.
//
// Output, double UNEW[NX][NY], the updated solution estimate.
//
{
int i;
int j;
for ( j = 0; j < ny; j++ )
{
for ( i = 0; i < nx; i++ )
{
if ( i == 0 || j == 0 || i == nx - 1 || j == ny - 1 )
{
unew[i][j] = f[i][j];
}
else
{
unew[i][j] = 0.25 * (
u[i-1][j] + u[i][j+1] + u[i][j-1] + u[i+1][j] + f[i][j] * dx * dy );
}
}
}
return;
}
//****************************************************************************80
double u_exact ( double x, double y )
//****************************************************************************80
//
// Purpose:
//
// U_EXACT evaluates the exact solution.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 25 October 2011
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double X, Y, the coordinates of a point.
//
// Output, double U_EXACT, the value of the exact solution
// at (X,Y).
//
{
double pi = 3.141592653589793;
double value;
value = sin ( pi * x * y );
return value;
}
//****************************************************************************80
double uxxyy_exact ( double x, double y )
//****************************************************************************80
//
// Purpose:
//
// UXXYY_EXACT evaluates ( d/dx d/dx + d/dy d/dy ) of the exact solution.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 25 October 2011
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double X, Y, the coordinates of a point.
//
// Output, double UXXYY_EXACT, the value of
// ( d/dx d/dx + d/dy d/dy ) of the exact solution at (X,Y).
//
{
double pi = 3.141592653589793;
double value;
value = - pi * pi * ( x * x + y * y ) * sin ( pi * x * y );
return value;
}