proteus
1.9.0
C/C++/Fortran libraries
Toggle main menu visibility
Loading...
Searching...
No Matches
work
cekees
proteus
proteus
fenton
Inout.cpp
Go to the documentation of this file.
1
#include <math.h>
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
6
#define Subprograms
7
#define Int extern int
8
#define Double extern double
9
#include "
Headers.h
"
10
11
12
13
extern
double
SU
;
14
15
void
16
Title_block
(FILE*),
Input_Data_block
(FILE*);
17
18
/**********************************************************************/
19
int
Read_data
(
void
)
20
/**********************************************************************/
21
{
22
Readtext
(Title);
23
iff
(Title, FINISH)
return
(0);
24
Read
(
MaxH
,lf);
25
fscanf(Input1,
"%s"
,
Case
);
Skip
;
26
iff
(
Case
,Wavelength)
27
{
28
Read
(
L
,lf);
29
Height
=
MaxH
/
L
;
30
}
31
iff
(
Case
,Period)
32
{
33
Read
(
T
,lf);
34
Height
=
MaxH
/(
T
*
T
);
35
}
36
Read
(
Current_criterion
,d);
37
Read
(
Current
,lf);
38
if
(
Current_criterion
== 1) strcpy(Currentname, Current1);
39
if
(
Current_criterion
== 2) strcpy(Currentname, Current2);
40
41
Read
(
n
,d);
42
Read
(
nstep
,d);
43
44
Input_Data_block
(monitor);
45
46
if
(strcmp(Theory,
"Stokes"
)==0)
47
{
48
iff
(
Case
,Wavelength)
49
if
(
L
> 10.)
50
{
51
printf(
"\nThe dimensionless wavelength is greater than 10."
);
52
printf(
"\nStokes theory should not be applied. Exiting."
);
53
exit(1);
54
}
55
iff
(
Case
,Period)
56
if
(
T
> 10.)
57
{
58
printf(
"\nThe dimensionless period is greater than 10."
);
59
printf(
"\nStokes theory should not be applied. Exiting."
);
60
exit(1);
61
}
62
}
63
64
// Convergence criteria
65
66
Input2=fopen(Convergence_file,
"r"
);
67
fgets(dummy,400,Input2);
68
fscanf(Input2,
"%d"
, &
number
);fgets(dummy,400,Input2);
69
fscanf(Input2,
"%le"
, &
crit
);fgets(dummy,400,Input2);
70
fclose(Input2);
71
72
// Number of data points to present results for
73
74
Input2 = fopen(Points_file,
"r"
);
75
fgets(dummy,400,Input2);
76
// Number of points on surface profile (clustered quadratically near crest)
77
fscanf(Input2,
"%d"
, &
Surface_points
);fgets(dummy,400,Input2);
78
// Number of vertical profiles
79
fscanf(Input2,
"%d"
, &
Nprofiles
);fgets(dummy,400,Input2);
80
// Number of points in each profile
81
fscanf(Input2,
"%d"
, &
Points
);fgets(dummy,400,Input2);
82
83
fclose(Input2);
84
85
return
(1);
86
}
87
88
// PRINT OUT TITLE BLOCKS
89
90
void
Input_Data_block
(FILE* file)
91
{
92
fprintf(file,
"# %s"
, Title);
93
fprintf(file,
"\n\n# Printing input data here to check"
);
94
fprintf(file,
"\n\n# Height/Depth:%6.3f"
,
MaxH
);
95
iff
(
Case
,Wavelength)
96
{
97
fprintf(file,
"\n# Length/Depth:%7.2f"
,
L
);
98
}
99
iff
(
Case
,Period)
100
{
101
fprintf(file,
"\n# Dimensionless Period T*sqrt(g/d):%7.2f"
,
T
);
102
}
103
fprintf(file,
"\n# Current criterion: %s, Dimensionless value:%6.3lf"
, Currentname,
Current
);
104
105
if
(strcmp(Theory,
"Stokes"
)==0)
106
{
107
if
(
n
<=5) sprintf(Method,
"\n# Solution by %d-order Stokes theory"
,
n
);
108
else
109
{
110
n
= 5;
111
sprintf(Method,
"\n# Solution by %d-order Stokes theory"
,
n
);
112
printf(
"\n\n# (A value of N > 5 has been specified for the Stokes theory."
);
113
printf(
"\n# I do not have a theory for that. The program has set N = 5)"
);
114
}
115
}
116
if
(strcmp(Theory,
"Fourier"
)==0)
117
sprintf(Method,
"\n# Solution by %d-term Fourier series"
,
n
);
118
119
fprintf(file,
"\n%s\n"
, Method);
120
}
121
122
void
Title_block
(FILE* file)
123
{
124
// Highest wave - eqn (32) of Fenton (1990)
125
L
= 2*
pi
/
z
[1];
126
Highest
= (0.0077829*
L
*
L
*
L
+0.0095721*
L
*
L
+0.141063*
L
)
127
/(0.0093407*
L
*
L
*
L
+0.0317567*
L
*
L
+0.078834*
L
+1);
128
fprintf(file,
"# %s"
, Title);
129
fprintf(file,
"\n%s\n"
, Method);
130
fprintf(file,
"\n# Height/Depth:%6.3f, %3.0lf\%% of the maximum of H/d =%6.3f for this length:"
,
131
z
[2]/
z
[1],
z
[2]/
z
[1]/
Highest
*100.,
Highest
);
132
fprintf(file,
"\n# Length/Depth:%7.2f"
, 2*
pi
/
z
[1]);
133
fprintf(file,
"\n# Dimensionless Period T*sqrt(g/d):%7.2f"
,
z
[3]/sqrt(
z
[1]));
134
fprintf(file,
"\n# Current criterion: %s, Dimensionless value:%6.3lf\n"
, Currentname,
Current
);
135
}
136
137
void
Output
(
void
)
138
{
139
int
i, I;
140
double
X, eta, y;
141
double
Surface
(
double
);
142
void
Point
(
double
,
double
);
143
144
fprintf(monitor,
"\n\n# Solution summary:\n\n"
);
145
Title_block
(monitor);
146
147
// Print out summary file of solution
148
149
Title_block
(Solution);
150
151
kd
=
z
[1];
152
L
=2*
pi
/
z
[1];
153
H
=
z
[2]/
z
[1];
154
T
=
z
[3]/sqrt(
z
[1]);
155
c
=
z
[4]/sqrt(
z
[1]);
156
ce
=
z
[5]/sqrt(
z
[1]);
157
cs
=
z
[6]/sqrt(
z
[1]);
158
ubar
=
z
[7]/sqrt(
z
[1]);
159
Q
=
ubar
-
z
[8]/pow(
kd
,1.5);
160
R
=1+
z
[9]/
z
[1];
161
162
pulse
=
z
[8]+
z
[1]*
z
[5];
163
ke
=0.5*(
z
[4]*
pulse
-
z
[5]*
Q
*pow(
kd
,1.5));
164
165
// Calculate potential energy, not by computing the mean of 1/2 (eta-d)^2
166
// but by exploiting orthogonality of the cosine functions to give the sum of 1/4 Y[i]^2
167
pe
= 0;
168
for
(i=1;i<=
n
;++i)
169
pe
+= 0.25*pow(
Y
[i],2);
170
171
ub2
=2.*
z
[9]-
z
[4]*
z
[4];
172
sxx
=4.*
ke
-3.*
pe
+
ub2
*
z
[1]+2.*
z
[5]*(
z
[7]*
z
[1]-
z
[8]);
173
f
=
z
[4]*(3.*
ke
-2.*
pe
)+0.5*
ub2
*(
pulse
+
z
[4]*
z
[1])+
z
[4]*
z
[5]*(
z
[7]*
z
[1]-
z
[8]);
174
q
=
z
[7]*
z
[1]-
z
[8];
175
r
=
z
[9]+
z
[1];
176
s
=
sxx
-2.*
z
[4]*
pulse
+(
z
[4]*
z
[4]+0.5*
z
[1])*
z
[1];
177
178
fprintf(Solution,
"\n# Stokes-Ursell number %7.3f"
, 0.5*
z
[2]/pow(
z
[1],3));
179
fprintf(Solution,
"\n\n# Integral quantities - notation from Fenton (1988)"
);
180
fprintf(Solution,
"\n# (1) Quantity, (2) symbol, solution non-dimensionalised by (3) g & wavenumber, and (4) g & mean depth\n"
);
181
fprintf(Solution,
"\n# Water depth (d)"
LO
LO
,
z
[1], 1.);
182
fprintf(Solution,
"\n# Wave length (lambda)"
LO
LO
, 2*
pi
,
L
);
183
fprintf(Solution,
"\n# Wave height (H)"
LO
LO
,
z
[2],
H
);
184
fprintf(Solution,
"\n# Wave period (tau)"
LO
LO
,
z
[3],
T
);
185
fprintf(Solution,
"\n# Wave speed (c)"
LO
LO
,
z
[4],
c
);
186
fprintf(Solution,
"\n# Eulerian current (u1_)"
LO
LO
,
z
[5],
ce
);
187
fprintf(Solution,
"\n# Stokes current (u2_)"
LO
LO
,
z
[6],
cs
);
188
fprintf(Solution,
"\n# Mean fluid speed in frame of wave (U_)"
LO
LO
,
z
[7],
ubar
);
189
fprintf(Solution,
"\n# Volume flux due to waves (q)"
LO
LO
,
z
[8],
z
[8]/pow(
kd
,1.5));
190
fprintf(Solution,
"\n# Bernoulli constant (r)"
LO
LO
,
z
[9],
z
[9]/
kd
);
191
fprintf(Solution,
"\n# Volume flux (Q)"
LO
LO
,
Q
*pow(
kd
,1.5),
Q
);
192
fprintf(Solution,
"\n# Bernoulli constant (R)"
LO
LO
,
R
*
kd
,
R
);
193
fprintf(Solution,
"\n# Momentum flux (S)"
LO
LO
,
s
,
s
/
kd
/
kd
);
194
fprintf(Solution,
"\n# Impulse (I)"
LO
LO
,
pulse
,
pulse
/pow(
kd
,1.5));
195
fprintf(Solution,
"\n# Kinetic energy (T)"
LO
LO
,
ke
,
ke
/
kd
/
kd
);
196
fprintf(Solution,
"\n# Potential energy (V)"
LO
LO
,
pe
,
pe
/
kd
/
kd
);
197
fprintf(Solution,
"\n# Mean square of bed velocity (ub2_)"
LO
LO
,
ub2
,
ub2
/
kd
);
198
fprintf(Solution,
"\n# Radiation stress (Sxx)"
LO
LO
,
sxx
,
sxx
/
kd
/
kd
);
199
fprintf(Solution,
"\n# Wave power (F)"
LO
LO
,
f
,
f
/pow(
kd
,2.5));
200
201
fprintf(Solution,
"\n\n# Dimensionless coefficients in Fourier series"
);
202
fprintf(Solution,
"\n# Potential/Streamfn\tSurface elevations"
);
203
fprintf(Solution,
"\n# j, B[j], & E[j], j=1..N\n"
);
204
for
( i=1 ; i <=
n
; i++ )
205
fprintf(Solution,
"\n%2d\t%15.7e\t%15.7e"
, i,
B
[i],
Y
[i]);
206
fprintf(Solution,
"\n\n"
);
207
208
// Surface - print out coordinates of points on surface for plotting plus check of pressure on surface
209
210
fprintf(Elevation,
"# %s\n"
, Title);
211
fprintf(Elevation,
"%s\n"
, Method);
212
fprintf(Elevation,
"\n# Surface of wave - trough-crest-trough,"
);
213
fprintf(Elevation,
" note quadratic point spacing clustered around crest"
);
214
fprintf(Elevation,
"\n# Non-dimensionalised with respect to depth"
);
215
fprintf(Elevation,
"\n# X/d, eta/d, & check of surface pressure\n"
);
216
217
for
( i=-
Surface_points
/2 ; i <=
Surface_points
/2; i++)
218
{
219
X = 2 *
L
* (i * fabs(i)/
Surface_points
/
Surface_points
);
//NB Quadratic point spacing, clustered near crest
220
eta =
Surface
(X);
221
Point
(X,eta);
222
fprintf(Elevation,
"\n%8.4lf\t%7.4f\t%7.0e"
, X, eta,
Pressure
);
223
}
224
fprintf(Elevation,
"\n\n"
);
225
226
// Surface - print out Velocity and acceleration profiles plus check of Bernoulli
227
228
fprintf(Flowfield,
"# %s\n"
, Title);
229
fprintf(Flowfield,
"%s\n"
, Method);
230
fprintf(Flowfield,
"\n# Velocity and acceleration profiles and Bernoulli checks\n"
);
231
fprintf(Flowfield,
"\n# All quantities are dimensionless with respect to g and/or d\n"
);
232
fprintf(Flowfield,
"\n#*******************************************************************************"
);
233
fprintf(Flowfield,
"\n# y u v dphi/dt du/dt dv/dt du/dx du/dy Bernoulli check "
);
234
fprintf(Flowfield,
"\n# - ------------- ------- ------ ----- ------------- --------------- "
);
235
fprintf(Flowfield,
"\n# d sqrt(gd) gd g g sqrt(g/d) gd "
);
236
fprintf(Flowfield,
"\n#*******************************************************************************"
);
237
238
for
(I = 0; I <=
Nprofiles
; ++I)
239
{
240
X = 0.5 *
L
* I/(
Nprofiles
);
241
eta =
Surface
(X);
242
fprintf(Flowfield,
"\n\n# X/d = %8.4f, Phase = %6.1f�\n"
, X, X/
L
*360);
243
244
for
(i=0 ; i <=
Points
; ++i)
245
{
246
y = (i)*eta/(
Points
);
247
Point
(X, y);
248
fprintf(Flowfield,
"\n%7.4f\t%7.4f\t%7.4f\t%7.4f\t%7.4f\t%7.4f\t%7.4f\t%7.4f\t%7.4f"
,
249
y,
u
,
v
,
dphidt
,
ut
,
vt
,
ux
,
uy
,
Bernoulli_check
);
250
}
251
}
252
fprintf(Flowfield,
"\n\n"
);
253
254
/*
255
Procedure for recording every run - not activated in distribution versions
256
If the lines below are not commented out the program will add a line to a
257
file Catalogue.res, which could have this as a header:
258
259
# A continuing record of all runs with Fourier, Cnoidal, or Stokes.
260
# Any run of those programs adds a line to it.
261
# This can be edited at any time.
262
# Columns are: name of theory, N, H/d, L/d, Stokes-Ursell Number,
263
# wave height as a percentage of the highest possible for that L/d,
264
# mean horizontal velocity on a vertical line under the crest.
265
266
# Theory n H/d L/d S-U Highest% u_crest_mean
267
*/
268
269
// To activate, de-comment these lines
270
/***************************************************************************
271
FILE *Output1;
272
double Velo[Points+1], sum1, sum2, ucm;
273
Output1 = fopen(Diagname,"a");
274
275
X = 0.;
276
eta = Surface(X);
277
278
for(i=0 ; i <= Points; ++i)
279
{
280
y = (i)*eta/(Points);
281
Point(X, y);
282
Velo[i] = u;
283
}
284
285
for(i=1, sum1=0; i <= Points-1; i+=2) sum1 += Velo[i];
286
for(i=2, sum2=0; i <= Points-2; i+=2) sum2 += Velo[i];
287
ucm = (Velo[0]+4*sum1+2*sum2+Velo[Points])/3./Points;
288
289
I = strlen(Theory)+1;
290
for(i=I; i <=8 ; ++i) strcat(Theory," ");
291
fprintf(Output1,"\n%s%2d\t%7.4f\t%8.3f\t%7.3f\t%3.0f\t%7.4f",
292
Theory, n, H, L, 0.5*z[2]/pow(z[1],3), z[2]/z[1]/Highest*100., ucm);
293
*************************************************************************/
294
}
295
296
// Surface elevation
297
298
double
Surface
(
double
x)
299
{
300
int
j;
301
static
double
kEta;
302
303
kEta =
kd
;
304
for
( j = 1 ; j <
n
; j++ )
305
kEta +=
Y
[j] * cos(j*x*
kd
);
306
kEta += 0.5*
Y
[
n
] * cos(
n
*x*
kd
);
307
return
(kEta/
kd
);
308
}
309
310
// Velocities, accelerations, and pressure at a point
311
312
void
Point
(
double
X,
double
y)
313
{
314
int
j;
315
double
Cosh, Sinh, Sin, Cos;
316
double
coshdelta,sinhdelta;
317
318
u
=
v
=
ux
=
vx
=
phi
=
psi
= 0.;
319
320
for
( j = 1 ; j <=
n
; j++ )
321
{
322
Cos = cos(j*X*
kd
);
323
Sin = sin(j*X*
kd
);
324
coshdelta = cosh(j*
kd
*(y-1.));
325
sinhdelta = sinh(j*
kd
*(y-1.));
326
Cosh = coshdelta+sinhdelta*
Tanh
[j];
327
Sinh = sinhdelta+coshdelta*
Tanh
[j];
328
phi
+=
B
[j] * Cosh * Sin;
329
u
+= j *
B
[j] * Cosh * Cos;
330
v
+= j *
B
[j] * Sinh * Sin;
331
ux
+= - j * j *
B
[j] * Cosh * Sin;
332
vx
+= j * j *
B
[j] * Sinh * Cos;
333
}
334
335
// All PHI, PSI, u, v, ux and vx are dimensionless w.r.t. g & k.
336
// Now convert to dimensionless w.r.t. d.
337
338
phi
/= pow(
kd
,1.5);
339
u
/= pow(
kd
,0.5);
340
v
/= pow(
kd
,0.5);
341
ux
*= pow(
kd
,0.5);
342
vx
*= pow(
kd
,0.5);
343
344
u
=
ce
+
u
;
345
phi
=
ce
* X +
phi
;
346
dphidt
= -
c
*
u
;
347
348
ut
= -
c
*
ux
;
349
vt
= -
c
*
vx
;
350
uy
=
vx
;
351
vy
= -
ux
;
352
dudt
=
ut
+
u
*
ux
+
v
*
uy
;
353
dvdt
=
vt
+
u
*
vx
+
v
*
vy
;
354
Pressure
=
R
- y - 0.5 * ((
u
-
c
)*(
u
-
c
)+
v
*
v
);
355
Bernoulli_check
=
dphidt
+
Pressure
+ y + 0.5*(
u
*
u
+
v
*
v
)-(
R
-0.5*
c
*
c
);
356
357
return
;
358
}
359
Title_block
void Title_block(FILE *)
Definition
Inout.cpp:122
SU
double SU
Definition
Fourier.cpp:25
Output
void Output(void)
Definition
Inout.cpp:137
Headers.h
Readtext
#define Readtext(x)
Definition
Headers.h:6
dvdt
Double dvdt
Definition
Headers.h:62
n
Int n
Definition
Headers.h:28
Current_criterion
Int Current_criterion
Definition
Headers.h:27
Pressure
Double Pressure
Definition
Headers.h:77
pi
#define pi
Definition
Headers.h:2
ubar
Double ubar
Definition
Headers.h:91
q
Double q
Definition
Headers.h:81
Surface_points
Int Surface_points
Definition
Headers.h:35
dphidt
Double dphidt
Definition
Headers.h:60
T
Double T
Definition
Headers.h:87
sxx
Double sxx
Definition
Headers.h:86
L
Double L
Definition
Headers.h:72
r
Double r
Definition
Headers.h:83
cs
Double cs
Definition
Headers.h:58
Height
Double Height
Definition
Headers.h:66
MaxH
Double MaxH
Definition
Headers.h:73
kd
Double kd
Definition
Headers.h:70
ce
Double ce
Definition
Headers.h:55
Nprofiles
Int Nprofiles
Definition
Headers.h:29
nstep
Int nstep
Definition
Headers.h:31
Bernoulli_check
Double Bernoulli_check
Definition
Headers.h:53
ux
Double ux
Definition
Headers.h:93
H
Double H
Definition
Headers.h:65
B
Double * B
Definition
Headers.h:41
number
Int number
Definition
Headers.h:33
f
Double f
Definition
Headers.h:64
s
Double s
Definition
Headers.h:84
u
Double u
Definition
Headers.h:89
ke
Double ke
Definition
Headers.h:71
vy
Double vy
Definition
Headers.h:98
z
Double * z
Definition
Headers.h:49
ut
Double ut
Definition
Headers.h:92
Y
Double * Y
Definition
Headers.h:48
uy
Double uy
Definition
Headers.h:94
Q
Double Q
Definition
Headers.h:80
vt
Double vt
Definition
Headers.h:96
v
Double v
Definition
Headers.h:95
Tanh
Double * Tanh
Definition
Headers.h:47
R
Double R
Definition
Headers.h:82
phi
Double phi
Definition
Headers.h:76
psi
Double psi
Definition
Headers.h:78
pe
Double pe
Definition
Headers.h:75
pulse
Double pulse
Definition
Headers.h:79
dudt
Double dudt
Definition
Headers.h:61
ub2
Double ub2
Definition
Headers.h:90
Points
Int Points
Definition
Headers.h:34
vx
Double vx
Definition
Headers.h:97
Skip
#define Skip
Definition
Headers.h:1
Read
#define Read(x, y)
Definition
Headers.h:7
LO
#define LO
Definition
Headers.h:5
Highest
Double Highest
Definition
Headers.h:67
Current
Double Current
Definition
Headers.h:59
iff
#define iff(x, y)
Definition
Headers.h:3
crit
Double crit
Definition
Headers.h:56
Point
void Point(double X, double y)
Definition
Inout.cpp:312
Surface
double Surface(double x)
Definition
Inout.cpp:298
Input_Data_block
void Input_Data_block(FILE *)
Definition
Inout.cpp:90
Read_data
int Read_data(void)
Definition
Inout.cpp:19
Case
char Case[]
c
#define c(i)
Definition
jf.h:21
Generated on
for proteus by
1.18.0