File size: 4,547 Bytes
5a600cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2017-2023 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "AiryCoeffs.H"
#include "mathematicalConstants.H"

// * * * * * * * * * * * Private Static Member Functions * * * * * * * * * * //

Foam::scalar Foam::waveModels::AiryCoeffs::calcLength
(
    const scalar depth,
    const scalar amplitude,
    const scalar period,
    const scalar g,
    scalar (*celerityPtr)(const AiryCoeffs&)
)
{
    scalar length0 = 0;
    scalar length1 = 1.5*g*sqr(period)/(2*constant::mathematical::pi);

    // Bisect down to round off error to find the wave length
    for (label i = 0; i < ceil(std::log2(1/small)); ++ i)
    {
        const scalar length = (length0 + length1)/2;

        const scalar t =
            length/celerityPtr(AiryCoeffs(depth, amplitude, length, g));

        (t < period ? length0 : length1) = length;
    }

    return (length0 + length1)/2;
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::waveModels::AiryCoeffs::AiryCoeffs
(
    const scalar depth,
    const scalar amplitude,
    const scalar length,
    const scalar g
)
:
    depth(depth),
    amplitude(amplitude),
    length(length),
    g(g)
{}


Foam::waveModels::AiryCoeffs::AiryCoeffs
(
    const scalar depth,
    const scalar amplitude,
    const scalar period,
    const scalar g,
    scalar (*celerityPtr)(const AiryCoeffs&)
)
:
    depth(depth),
    amplitude(amplitude),
    length(calcLength(depth, amplitude, period, g, celerityPtr)),
    g(g)
{}


// * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //

Foam::scalar Foam::waveModels::AiryCoeffs::k() const
{
    return 2*Foam::constant::mathematical::pi/length;
}


bool Foam::waveModels::AiryCoeffs::deep() const
{
    return depth*k() > log(great);
}


Foam::scalar Foam::waveModels::AiryCoeffs::celerity(const AiryCoeffs& coeffs)
{
    return sqrt(coeffs.g/coeffs.k()*tanh(coeffs.k()*coeffs.depth));
}


Foam::scalar Foam::waveModels::AiryCoeffs::celerity() const
{
    return celerity(*this);
}


Foam::tmp<Foam::scalarField> Foam::waveModels::AiryCoeffs::angle
(
    const scalar phase,
    const scalar t,
    const scalarField& x
) const
{
    return phase + k()*(x - celerity()*t);
}


Foam::tmp<Foam::scalarField> Foam::waveModels::AiryCoeffs::elevation
(
    const scalar phase,
    const scalar t,
    const scalarField& x
) const
{
    return amplitude*cos(angle(phase, t, x));
}


Foam::tmp<Foam::vector2DField> Foam::waveModels::AiryCoeffs::vi
(
    const label i,
    const scalar phase,
    const scalar t,
    const vector2DField& xz
) const
{
    const scalarField x(xz.component(0));
    const scalarField z(xz.component(1));

    const scalarField phi(angle(phase, t, x));

    const scalar kzGreat = log(i*great);
    const scalarField kz(min(max(k()*z, - kzGreat), kzGreat));

    if (deep())
    {
        return i*exp(kz)*zip(cos(i*phi), sin(i*phi));
    }
    else
    {
        const scalar kd = k()*depth;
        const scalarField kdz(max(scalar(0), kd + kz));

        return i*zip(cosh(i*kdz)*cos(i*phi), sinh(i*kdz)*sin(i*phi))/sinh(kd);
    }
}


Foam::tmp<Foam::vector2DField> Foam::waveModels::AiryCoeffs::velocity
(
    const scalar phase,
    const scalar t,
    const vector2DField& xz
) const
{
    const scalar ka = k()*amplitude;

    return celerity()*ka*vi(1, phase, t, xz);
}


// ************************************************************************* //