proteus
1.9.0
C/C++/Fortran libraries
Toggle main menu visibility
Loading...
Searching...
No Matches
work
cekees
proteus
proteus
fenton
Fourier.cpp
Go to the documentation of this file.
1
2
// Steady wave program - C++ version
3
4
#include <math.h>
5
#include <stdio.h>
6
#include <sys/types.h>
7
#include <string.h>
8
#include <stdlib.h>
9
#define ANSI
10
#include "
Allocation.h
"
11
12
void
13
init
(
void
),
Solve
(
void
),
Title_block
(FILE*),
Output
(
void
);
14
int
15
flushall
(
void
);
16
17
#define Main
18
#define Int int
19
#define Double double
20
#include "
Headers.h
"
21
//#define Diagnostic
22
//#ifdef Diagnostic
23
//char Diagname[30], Theory[10];
24
//#endif
25
double
SU
;
26
27
void
runfourier
()
28
{
29
int
i, j, iter, m;
30
int
Read_data
(
void
);
31
32
double
Newton
(
int
), dhe, dho, error, **CC;
33
void
Powell(
double
*,
double
**,
int
,
double
,
int
*,
double
*,
double
(*)(
double
*));
34
35
Input1 = fopen(
"Data.dat"
,
"r"
);
36
37
strcpy(Convergence_file,
"Convergence.dat"
);
38
strcpy(Points_file,
"Points.dat"
);
39
monitor = stdout;
40
strcpy(Theory,
"Fourier"
);
41
strcpy(Diagname,
"Catalogue.res"
);
42
43
for
(
wave
=1 ;
wave
<2;
wave
++ )
44
{
45
if
(
Read_data
() == 0)
break
;
46
num
=2*
n
+10;
47
dhe=
Height
/
nstep
;
48
dho=
MaxH
/
nstep
;
49
50
CC =
dmatrix
(1,
num
,1,
num
);
51
for
( j=1; j <=
num
; ++j)
52
{
53
for
( i=1; i <=
num
; ++i)
54
CC[j][i] = 0.;
55
CC[j][j] = 1.;
56
}
57
Y
=
dvector
(0,
num
);
58
z
=
dvector
(1,
num
);
59
rhs1
=
dvector
(1,
num
);
60
rhs2
=
dvector
(1,
num
);
61
coeff
=
dvector
(0,
n
);
62
cosa
=
dvector
(0,2*
n
);
63
sina
=
dvector
(0,2*
n
);
64
sol
=
dmatrix
(0,
num
,1,2);
65
B
=
dvector
(1,
n
);
66
Tanh
=
dvector
(1,
n
);
67
68
// Commence stepping through steps in wave height
69
70
for
(
ns
= 1 ;
ns
<=
nstep
;
ns
++ )
71
{
72
height
=
ns
*dhe;
73
Hoverd
=
ns
*dho;
74
fprintf(monitor,
"\n\nHeight step %2d of %2d\n"
,
ns
,
nstep
);
75
76
// Calculate initial linear solution
77
78
if
(
ns
<= 1)
init
();
79
80
// Or, extrapolate for next wave height, if necessary
81
82
else
83
for
( i=1 ; i <=
num
; i++ )
84
z
[i]=2.*
sol
[i][2]-
sol
[i][1];
85
86
// Commence iterative solution
87
88
for
(iter=1 ; iter <=
number
; iter++ )
89
{
90
fprintf(monitor,
"\nIteration%3d:"
, iter);
91
92
// Calculate right sides of equations and differentiate numerically
93
// to obtain Jacobian matrix, then solve matrix equation
94
95
error =
Newton
(iter);
96
97
// Convergence criterion satisfied?
98
99
fprintf(stdout,
" Mean of corrections to free surface: %8.1e"
, error);
100
if
(
ns
==
nstep
)
criter
= 1.e-10 ;
101
else
criter
=
crit
;
102
if
((error <
criter
* fabs(
z
[1])) && iter > 1 )
break
;
103
if
(iter ==
number
)
104
{
105
fprintf(stdout,
"\nNote that the program still had not converged to the degree specified\n"
);
106
}
107
108
// Operations for extrapolations if more than one height step used
109
110
if
(
ns
== 1)
111
for
( i=1 ; i<=
num
; i++ )
112
sol
[i][2] =
z
[i];
113
else
114
for
( i=1 ; i<=
num
; i++ )
115
{
116
sol
[i][1] =
sol
[i][2];
117
sol
[i][2] =
z
[i];
118
}
119
}
120
121
// Fourier coefficients (for surface elevation by slow Fourier transform)
122
123
for
(
Y
[0] = 0., j = 1 ; j <=
n
; j++ )
124
{
125
B
[j]=
z
[j+
n
+10];
126
sum
= 0.5*(
z
[10]+
z
[
n
+10]*pow(-1.,(
double
)j));
127
for
( m = 1 ; m <=
n
-1 ; m++ )
128
sum
+=
z
[10+m]*
cosa
[(m*j)%(
n
+
n
)];
129
Y
[j] = 2. *
sum
/
n
;
130
}
131
}
// End stepping through wave heights
132
133
// Print results
134
135
Solution=fopen(
"Solution.res"
,
"w"
);
136
Elevation = fopen(
"Surface.res"
,
"w"
);
137
Flowfield = fopen(
"Flowfield.res"
,
"w"
);
138
Output
();
139
fflush(NULL);
140
141
free_dmatrix
(CC,1,
num
,1,
num
);
142
free_dvector
(
Y
,0,
num
);
143
free_dvector
(
z
, 1,
num
);
144
free_dvector
(
rhs1
, 1,
num
);
145
free_dvector
(
rhs2
, 1,
num
);
146
free_dvector
(
coeff
, 0,
n
);
147
free_dvector
(
cosa
, 0,2*
n
);
148
free_dvector
(
sina
, 0,2*
n
);
149
free_dmatrix
(
sol
, 0,
num
,1,2);
150
free_dvector
(
B
, 1,
n
);
151
free_dvector
(
Tanh
, 1,
n
);
152
}
// End stepping through waves
153
154
printf(
"\nFinished\n"
);
155
}
156
157
int
main
(
void
)
158
{
159
runfourier
();
160
}
// End main program
Allocation.h
free_dmatrix
void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
Definition
Util.cpp:44
dmatrix
double ** dmatrix(long nrl, long nrh, long ncl, long nch)
Definition
Util.cpp:16
free_dvector
void free_dvector(double *v, long nl, long nh)
Definition
Util.cpp:38
dvector
double * dvector(long nl, long nh)
Definition
Util.cpp:7
init
void init(void)
Title_block
void Title_block(FILE *)
Definition
Inout.cpp:122
runfourier
void runfourier()
Definition
Fourier.cpp:27
flushall
int flushall(void)
main
int main(void)
Definition
Fourier.cpp:157
SU
double SU
Definition
Fourier.cpp:25
Output
void Output(void)
Definition
Inout.cpp:137
Solve
void Solve(void)
Headers.h
n
Int n
Definition
Headers.h:28
rhs1
Double * rhs1
Definition
Headers.h:44
wave
Int wave
Definition
Headers.h:36
sol
Double ** sol
Definition
Headers.h:40
Hoverd
Double Hoverd
Definition
Headers.h:68
sum
Double sum
Definition
Headers.h:85
height
Double height
Definition
Headers.h:69
Height
Double Height
Definition
Headers.h:66
MaxH
Double MaxH
Definition
Headers.h:73
cosa
Double * cosa
Definition
Headers.h:43
nstep
Int nstep
Definition
Headers.h:31
B
Double * B
Definition
Headers.h:41
number
Int number
Definition
Headers.h:33
criter
Double criter
Definition
Headers.h:57
num
Int num
Definition
Headers.h:32
ns
Int ns
Definition
Headers.h:30
sina
Double * sina
Definition
Headers.h:46
z
Double * z
Definition
Headers.h:49
Y
Double * Y
Definition
Headers.h:48
Tanh
Double * Tanh
Definition
Headers.h:47
coeff
Double * coeff
Definition
Headers.h:42
rhs2
Double * rhs2
Definition
Headers.h:45
crit
Double crit
Definition
Headers.h:56
Read_data
int Read_data(void)
Definition
Inout.cpp:19
Newton
double Newton(int count)
Definition
Subroutines.cpp:138
Generated on
for proteus by
1.18.0