AiryCoeffs.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "AiryCoeffs.H"
27 #include "mathematicalConstants.H"
28 
29 // * * * * * * * * * * * Private Static Member Functions * * * * * * * * * * //
30 
31 Foam::scalar Foam::waveModels::AiryCoeffs::calcLength
32 (
33  const scalar depth,
34  const scalar amplitude,
35  const scalar period,
36  const scalar g,
37  scalar (*celerityPtr)(const AiryCoeffs&)
38 )
39 {
40  scalar length0 = 0;
41  scalar length1 = 1.5*g*sqr(period)/(2*constant::mathematical::pi);
42 
43  // Bisect down to round off error to find the wave length
44  for (label i = 0; i < ceil(std::log2(1/small)); ++ i)
45  {
46  const scalar length = (length0 + length1)/2;
47 
48  const scalar t =
49  length/celerityPtr(AiryCoeffs(depth, amplitude, length, g));
50 
51  (t < period ? length0 : length1) = length;
52  }
53 
54  return (length0 + length1)/2;
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
61 (
62  const scalar depth,
63  const scalar amplitude,
64  const scalar length,
65  const scalar g
66 )
67 :
68  depth(depth),
69  amplitude(amplitude),
70  length(length),
71  g(g)
72 {}
73 
74 
76 (
77  const scalar depth,
78  const scalar amplitude,
79  const scalar period,
80  const scalar g,
81  scalar (*celerityPtr)(const AiryCoeffs&)
82 )
83 :
84  depth(depth),
85  amplitude(amplitude),
86  length(calcLength(depth, amplitude, period, g, celerityPtr)),
87  g(g)
88 {}
89 
90 
91 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
92 
93 Foam::scalar Foam::waveModels::AiryCoeffs::k() const
94 {
95  return 2*Foam::constant::mathematical::pi/length;
96 }
97 
98 
100 {
101  return depth*k() > log(great);
102 }
103 
104 
106 {
107  return sqrt(coeffs.g/coeffs.k()*tanh(coeffs.k()*coeffs.depth));
108 }
109 
110 
112 {
113  return celerity(*this);
114 }
115 
116 
118 (
119  const scalar phase,
120  const scalar t,
121  const scalarField& x
122 ) const
123 {
124  return phase + k()*(x - celerity()*t);
125 }
126 
127 
129 (
130  const scalar phase,
131  const scalar t,
132  const scalarField& x
133 ) const
134 {
135  return amplitude*cos(angle(phase, t, x));
136 }
137 
138 
140 (
141  const label i,
142  const scalar phase,
143  const scalar t,
144  const vector2DField& xz
145 ) const
146 {
147  const scalarField x(xz.component(0));
148  const scalarField z(xz.component(1));
149 
150  const scalarField phi(angle(phase, t, x));
151 
152  const scalar kzGreat = log(i*great);
153  const scalarField kz(min(max(k()*z, - kzGreat), kzGreat));
154 
155  if (deep())
156  {
157  return i*exp(kz)*zip(cos(i*phi), sin(i*phi));
158  }
159  else
160  {
161  const scalar kd = k()*depth;
162  const scalarField kdz(max(scalar(0), kd + kz));
163 
164  return i*zip(cosh(i*kdz)*cos(i*phi), sinh(i*kdz)*sin(i*phi))/sinh(kd);
165  }
166 }
167 
168 
170 (
171  const scalar phase,
172  const scalar t,
173  const vector2DField& xz
174 ) const
175 {
176  const scalar ka = k()*amplitude;
177 
178  return celerity()*ka*vi(1, phase, t, xz);
179 }
180 
181 
182 // ************************************************************************* //
label k
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:479
A class for managing temporary objects.
Definition: tmp.H:55
Calculation engine for the Airy wave model and other models that are a correction on top of the Airy ...
Definition: AiryCoeffs.H:52
const scalar depth
Depth [m].
Definition: AiryCoeffs.H:76
bool deep() const
Return whether shallow and intermediate effects are to be omitted.
Definition: AiryCoeffs.C:99
scalar celerity() const
The wave celerity [m/s].
Definition: AiryCoeffs.C:111
tmp< vector2DField > vi(const label i, const scalar phase, const scalar t, const vector2DField &xz) const
Return the non-dimensionalised i-th harmonic of the velocity.
Definition: AiryCoeffs.C:140
const scalar amplitude
Amplitude [m].
Definition: AiryCoeffs.H:79
tmp< scalarField > elevation(const scalar phase, const scalar t, const scalarField &x) const
Get the wave elevation at a given time and local coordinates. Local.
Definition: AiryCoeffs.C:129
tmp< scalarField > angle(const scalar phase, const scalar t, const scalarField &x) const
Angle of the oscillation [rad].
Definition: AiryCoeffs.C:118
tmp< vector2DField > velocity(const scalar phase, const scalar t, const vector2DField &xz) const
Get the wave velocity at a given time and local coordinates. Local.
Definition: AiryCoeffs.C:170
AiryCoeffs(const scalar depth, const scalar amplitude, const scalar length, const scalar g)
Construct from components.
Definition: AiryCoeffs.C:61
const scalar g
Gravitational acceleration [m/s^2].
Definition: AiryCoeffs.H:85
scalar k() const
The angular wavenumber [rad/m].
Definition: AiryCoeffs.C:93
const scalar length
Wavelength [m].
Definition: AiryCoeffs.H:82
dimensionedScalar exp(const dimensionedScalar &ds)
label log2(label i)
Return the log base 2 by successive bit-shifting of the given label.
Definition: label.H:79
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedScalar cosh(const dimensionedScalar &ds)
dimensionedScalar sin(const dimensionedScalar &ds)
dimensionedScalar tanh(const dimensionedScalar &ds)
dimensionedScalar sinh(const dimensionedScalar &ds)
dimensionedScalar log(const dimensionedScalar &ds)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensionedScalar sqrt(const dimensionedScalar &ds)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
tmp< vector2DField > zip(const tmp< scalarField > &x, const tmp< scalarField > &y)
Definition: vector2DField.C:31
dimensionedScalar cos(const dimensionedScalar &ds)