proteus 1.9.0
C/C++/Fortran libraries
Loading...
Searching...
No Matches
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
13extern double SU;
14
15void
16 Title_block(FILE*), Input_Data_block(FILE*);
17
18/**********************************************************************/
19int Read_data(void)
20/**********************************************************************/
21{
22Readtext(Title);
23iff(Title, FINISH) return(0);
24Read(MaxH,lf);
25fscanf(Input1,"%s", Case); Skip;
26iff(Case,Wavelength)
27 {
28 Read(L,lf);
29 Height = MaxH/L;
30 }
31iff(Case,Period)
32 {
33 Read(T,lf);
34 Height = MaxH/(T*T);
35 }
37Read(Current,lf);
38if(Current_criterion == 1) strcpy(Currentname, Current1);
39if(Current_criterion == 2) strcpy(Currentname, Current2);
40
41Read(n,d);
42Read(nstep,d);
43
44Input_Data_block(monitor);
45
46if(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
66Input2=fopen(Convergence_file,"r");
67fgets(dummy,400,Input2);
68fscanf(Input2,"%d", &number);fgets(dummy,400,Input2);
69fscanf(Input2,"%le", &crit);fgets(dummy,400,Input2);
70fclose(Input2);
71
72// Number of data points to present results for
73
74Input2 = fopen(Points_file,"r");
75fgets(dummy,400,Input2);
76// Number of points on surface profile (clustered quadratically near crest)
77fscanf(Input2,"%d", &Surface_points);fgets(dummy,400,Input2);
78// Number of vertical profiles
79fscanf(Input2,"%d", &Nprofiles);fgets(dummy,400,Input2);
80// Number of points in each profile
81fscanf(Input2,"%d", &Points);fgets(dummy,400,Input2);
82
83fclose(Input2);
84
85return(1);
86}
87
88// PRINT OUT TITLE BLOCKS
89
90void Input_Data_block(FILE* file)
91{
92fprintf(file,"# %s", Title);
93fprintf(file,"\n\n# Printing input data here to check");
94fprintf(file,"\n\n# Height/Depth:%6.3f", MaxH);
95iff(Case,Wavelength)
96 {
97 fprintf(file,"\n# Length/Depth:%7.2f", L);
98 }
99iff(Case,Period)
100 {
101 fprintf(file,"\n# Dimensionless Period T*sqrt(g/d):%7.2f", T);
102 }
103fprintf(file,"\n# Current criterion: %s, Dimensionless value:%6.3lf", Currentname, Current);
104
105if(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 }
116if(strcmp(Theory,"Fourier")==0)
117 sprintf(Method, "\n# Solution by %d-term Fourier series", n);
118
119fprintf(file,"\n%s\n", Method);
120}
121
122void Title_block(FILE* file)
123{
124// Highest wave - eqn (32) of Fenton (1990)
125L = 2*pi/z[1];
126Highest = (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);
128fprintf(file,"# %s", Title);
129fprintf(file,"\n%s\n", Method);
130fprintf(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);
132fprintf(file,"\n# Length/Depth:%7.2f", 2*pi/z[1]);
133fprintf(file,"\n# Dimensionless Period T*sqrt(g/d):%7.2f", z[3]/sqrt(z[1]));
134fprintf(file,"\n# Current criterion: %s, Dimensionless value:%6.3lf\n", Currentname, Current);
135}
136
137void Output(void)
138{
139int i, I;
140double X, eta, y;
141 double Surface(double);
142 void Point(double, double);
143
144fprintf(monitor,"\n\n# Solution summary:\n\n");
145Title_block(monitor);
146
147// Print out summary file of solution
148
149Title_block(Solution);
150
151kd = z[1];
152L=2*pi/z[1];
153H=z[2]/z[1];
154T=z[3]/sqrt(z[1]);
155c=z[4]/sqrt(z[1]);
156ce=z[5]/sqrt(z[1]);
157cs=z[6]/sqrt(z[1]);
158ubar=z[7]/sqrt(z[1]);
159Q=ubar-z[8]/pow(kd,1.5);
160R=1+z[9]/z[1];
161
162pulse=z[8]+z[1]*z[5];
163ke=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
167pe = 0;
168for(i=1;i<=n;++i)
169 pe += 0.25*pow(Y[i],2);
170
171ub2=2.*z[9]-z[4]*z[4];
172sxx=4.*ke-3.*pe+ub2*z[1]+2.*z[5]*(z[7]*z[1]-z[8]);
173f=z[4]*(3.*ke-2.*pe)+0.5*ub2*(pulse+z[4]*z[1])+z[4]*z[5]*(z[7]*z[1]-z[8]);
174q=z[7]*z[1]-z[8];
175r=z[9]+z[1];
176s=sxx-2.*z[4]*pulse+(z[4]*z[4]+0.5*z[1])*z[1];
177
178fprintf(Solution, "\n# Stokes-Ursell number %7.3f", 0.5*z[2]/pow(z[1],3));
179fprintf(Solution, "\n\n# Integral quantities - notation from Fenton (1988)");
180fprintf(Solution, "\n# (1) Quantity, (2) symbol, solution non-dimensionalised by (3) g & wavenumber, and (4) g & mean depth\n");
181fprintf(Solution, "\n# Water depth (d)" LO LO, z[1], 1.);
182fprintf(Solution, "\n# Wave length (lambda)" LO LO, 2*pi, L);
183fprintf(Solution, "\n# Wave height (H)" LO LO, z[2], H);
184fprintf(Solution, "\n# Wave period (tau)" LO LO, z[3], T);
185fprintf(Solution, "\n# Wave speed (c)" LO LO, z[4], c);
186fprintf(Solution, "\n# Eulerian current (u1_)" LO LO, z[5], ce);
187fprintf(Solution, "\n# Stokes current (u2_)" LO LO, z[6], cs);
188fprintf(Solution, "\n# Mean fluid speed in frame of wave (U_)" LO LO, z[7], ubar);
189fprintf(Solution, "\n# Volume flux due to waves (q)" LO LO, z[8], z[8]/pow(kd,1.5));
190fprintf(Solution, "\n# Bernoulli constant (r)" LO LO, z[9], z[9]/kd);
191fprintf(Solution, "\n# Volume flux (Q)" LO LO, Q*pow(kd,1.5), Q);
192fprintf(Solution, "\n# Bernoulli constant (R)" LO LO, R*kd, R);
193fprintf(Solution, "\n# Momentum flux (S)" LO LO, s, s/kd/kd );
194fprintf(Solution, "\n# Impulse (I)" LO LO, pulse, pulse/pow(kd,1.5));
195fprintf(Solution, "\n# Kinetic energy (T)" LO LO, ke, ke/kd/kd);
196fprintf(Solution, "\n# Potential energy (V)" LO LO, pe, pe/kd/kd);
197fprintf(Solution, "\n# Mean square of bed velocity (ub2_)" LO LO, ub2, ub2/kd);
198fprintf(Solution, "\n# Radiation stress (Sxx)" LO LO, sxx, sxx/kd/kd);
199fprintf(Solution, "\n# Wave power (F)" LO LO, f, f/pow(kd,2.5));
200
201fprintf(Solution, "\n\n# Dimensionless coefficients in Fourier series" );
202fprintf(Solution, "\n# Potential/Streamfn\tSurface elevations" );
203fprintf(Solution, "\n# j, B[j], & E[j], j=1..N\n" );
204for ( i=1 ; i <= n ; i++ )
205fprintf(Solution, "\n%2d\t%15.7e\t%15.7e", i, B[i], Y[i]);
206fprintf(Solution, "\n\n" );
207
208// Surface - print out coordinates of points on surface for plotting plus check of pressure on surface
209
210fprintf(Elevation, "# %s\n", Title);
211fprintf(Elevation, "%s\n", Method);
212fprintf(Elevation, "\n# Surface of wave - trough-crest-trough,");
213fprintf(Elevation, " note quadratic point spacing clustered around crest");
214fprintf(Elevation, "\n# Non-dimensionalised with respect to depth");
215fprintf(Elevation, "\n# X/d, eta/d, & check of surface pressure\n");
216
217for ( 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 }
224fprintf(Elevation, "\n\n");
225
226// Surface - print out Velocity and acceleration profiles plus check of Bernoulli
227
228fprintf(Flowfield, "# %s\n", Title);
229fprintf(Flowfield, "%s\n", Method);
230fprintf(Flowfield, "\n# Velocity and acceleration profiles and Bernoulli checks\n");
231fprintf(Flowfield, "\n# All quantities are dimensionless with respect to g and/or d\n");
232fprintf(Flowfield, "\n#*******************************************************************************");
233fprintf(Flowfield, "\n# y u v dphi/dt du/dt dv/dt du/dx du/dy Bernoulli check ");
234fprintf(Flowfield, "\n# - ------------- ------- ------ ----- ------------- --------------- ");
235fprintf(Flowfield, "\n# d sqrt(gd) gd g g sqrt(g/d) gd ");
236fprintf(Flowfield, "\n#*******************************************************************************");
237
238for(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 }
252fprintf(Flowfield, "\n\n");
253
254/*
255Procedure for recording every run - not activated in distribution versions
256If the lines below are not commented out the program will add a line to a
257file 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/***************************************************************************
271FILE *Output1;
272double Velo[Points+1], sum1, sum2, ucm;
273Output1 = fopen(Diagname,"a");
274
275X = 0.;
276eta = Surface(X);
277
278for(i=0 ; i <= Points; ++i)
279 {
280 y = (i)*eta/(Points);
281 Point(X, y);
282 Velo[i] = u;
283 }
284
285for(i=1, sum1=0; i <= Points-1; i+=2) sum1 += Velo[i];
286for(i=2, sum2=0; i <= Points-2; i+=2) sum2 += Velo[i];
287ucm = (Velo[0]+4*sum1+2*sum2+Velo[Points])/3./Points;
288
289I = strlen(Theory)+1;
290for(i=I; i <=8 ; ++i) strcat(Theory," ");
291fprintf(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
298double Surface(double x)
299{
300int j;
301static double kEta;
302
303kEta = kd;
304for ( j = 1 ; j < n ; j++ )
305 kEta += Y[j] * cos(j*x*kd);
306kEta += 0.5*Y[n] * cos(n*x*kd);
307return (kEta/kd);
308}
309
310// Velocities, accelerations, and pressure at a point
311
312void Point(double X, double y)
313{
314int j;
315double Cosh, Sinh, Sin, Cos;
316double coshdelta,sinhdelta;
317
318u = v = ux = vx = phi = psi = 0.;
319
320for ( 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
338phi /= pow(kd,1.5);
339u /= pow(kd,0.5);
340v /= pow(kd,0.5);
341ux *= pow(kd,0.5);
342vx *= pow(kd,0.5);
343
344u = ce + u;
345phi = ce * X + phi;
346dphidt = -c * u;
347
348ut = -c * ux;
349vt = -c * vx;
350uy = vx;
351vy = -ux;
352dudt = ut + u*ux + v*uy;
353dvdt = vt + u*vx + v*vy;
354Pressure = R - y - 0.5 * ((u-c)*(u-c)+v*v);
355Bernoulli_check = dphidt + Pressure + y + 0.5*(u*u+v*v)-(R-0.5*c*c);
356
357return;
358}
359
void Title_block(FILE *)
Definition Inout.cpp:122
double SU
Definition Fourier.cpp:25
void Output(void)
Definition Inout.cpp:137
#define Readtext(x)
Definition Headers.h:6
Double dvdt
Definition Headers.h:62
Int n
Definition Headers.h:28
Int Current_criterion
Definition Headers.h:27
Double Pressure
Definition Headers.h:77
#define pi
Definition Headers.h:2
Double ubar
Definition Headers.h:91
Double q
Definition Headers.h:81
Int Surface_points
Definition Headers.h:35
Double dphidt
Definition Headers.h:60
Double T
Definition Headers.h:87
Double sxx
Definition Headers.h:86
Double L
Definition Headers.h:72
Double r
Definition Headers.h:83
Double cs
Definition Headers.h:58
Double Height
Definition Headers.h:66
Double MaxH
Definition Headers.h:73
Double kd
Definition Headers.h:70
Double ce
Definition Headers.h:55
Int Nprofiles
Definition Headers.h:29
Int nstep
Definition Headers.h:31
Double Bernoulli_check
Definition Headers.h:53
Double ux
Definition Headers.h:93
Double H
Definition Headers.h:65
Double * B
Definition Headers.h:41
Int number
Definition Headers.h:33
Double f
Definition Headers.h:64
Double s
Definition Headers.h:84
Double u
Definition Headers.h:89
Double ke
Definition Headers.h:71
Double vy
Definition Headers.h:98
Double * z
Definition Headers.h:49
Double ut
Definition Headers.h:92
Double * Y
Definition Headers.h:48
Double uy
Definition Headers.h:94
Double Q
Definition Headers.h:80
Double vt
Definition Headers.h:96
Double v
Definition Headers.h:95
Double * Tanh
Definition Headers.h:47
Double R
Definition Headers.h:82
Double phi
Definition Headers.h:76
Double psi
Definition Headers.h:78
Double pe
Definition Headers.h:75
Double pulse
Definition Headers.h:79
Double dudt
Definition Headers.h:61
Double ub2
Definition Headers.h:90
Int Points
Definition Headers.h:34
Double vx
Definition Headers.h:97
#define Skip
Definition Headers.h:1
#define Read(x, y)
Definition Headers.h:7
#define LO
Definition Headers.h:5
Double Highest
Definition Headers.h:67
Double Current
Definition Headers.h:59
#define iff(x, y)
Definition Headers.h:3
Double crit
Definition Headers.h:56
void Point(double X, double y)
Definition Inout.cpp:312
double Surface(double x)
Definition Inout.cpp:298
void Input_Data_block(FILE *)
Definition Inout.cpp:90
int Read_data(void)
Definition Inout.cpp:19
char Case[]
#define c(i)
Definition jf.h:21