Airy.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-2018 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 "Airy.H"
27 #include "mathematicalConstants.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace waveModels
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
43 
44 Foam::scalar Foam::waveModels::Airy::k() const
45 {
46  return 2*Foam::constant::mathematical::pi/length_;
47 }
48 
49 
51 {
52  return sqrt(g()/k()*tanh(k()*depth()));
53 }
54 
55 
57 (
58  const scalar t,
59  const scalar u,
60  const scalarField& x
61 ) const
62 {
63  return phase_ + k()*(x - (u + celerity())*t);
64 }
65 
66 
68 {
69  return k()*depth() > log(great);
70 }
71 
72 
74 (
75  const label i,
76  const scalar t,
77  const scalar u,
78  const vector2DField& xz
79 ) const
80 {
81  const scalarField x(xz.component(0));
82  const scalarField z(xz.component(1));
83 
84  const scalarField phi(angle(t, u, x));
85  const scalarField kz(- k()*z);
86 
87  if (deep())
88  {
89  return i*exp(- mag(kz))*zip(cos(i*phi), sin(i*phi));
90  }
91  else
92  {
93  const scalar kd = k()*depth();
94  const scalarField kdz(max(scalar(0), kd - mag(kz)));
95  return i*zip(cosh(i*kdz)*cos(i*phi), sinh(i*kdz)*sin(i*phi))/sinh(kd);
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 
103 :
104  waveModel(wave),
105  length_(wave.length_),
106  phase_(wave.phase_),
107  depth_(wave.depth_)
108 {}
109 
110 
112 (
113  const objectRegistry& db,
114  const dictionary& dict
115 )
116 :
117  waveModel(db, dict),
118  length_(readScalar(dict.lookup("length"))),
119  phase_(readScalar(dict.lookup("phase"))),
120  depth_(dict.lookupOrDefault<scalar>("depth", log(2*great)/k()))
121 {}
122 
123 
124 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
125 
127 {}
128 
129 
130 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
131 
133 (
134  const scalar t,
135  const scalar u,
136  const scalarField& x
137 ) const
138 {
139  return amplitude(t)*cos(angle(t, u, x));
140 }
141 
142 
144 (
145  const scalar t,
146  const scalar u,
147  const vector2DField& xz
148 ) const
149 {
150  const scalar ka = k()*amplitude(t);
151 
152  return celerity()*ka*vi(1, t, u, xz);
153 }
154 
155 
157 (
158  const scalar t,
159  const scalar u,
160  const vector2DField& xz
161 ) const
162 {
163  // It is a fluke of the formulation that the time derivative of the velocity
164  // potential equals the x-derivative multiplied by the celerity. This allows
165  // for this shortcut in evaluating the unsteady pressure.
166  return celerity()*velocity(t, u, xz)->component(0);
167 }
168 
169 
171 {
172  waveModel::write(os);
173 
174  os.writeKeyword("length") << length_ << token::END_STATEMENT << nl;
175  os.writeKeyword("phase") << phase_ << token::END_STATEMENT << nl;
176  if (!deep())
177  {
178  os.writeKeyword("depth") << depth_ << token::END_STATEMENT << nl;
179  }
180 }
181 
182 
183 // ************************************************************************* //
tmp< vector2DField > zip(const tmp< scalarField > &x, const tmp< scalarField > &y)
Definition: vector2DField.C:31
dimensionedScalar tanh(const dimensionedScalar &ds)
Airy(const Airy &wave)
Construct a copy.
Definition: Airy.C:102
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
surfaceScalarField & phi
dimensionedScalar log(const dimensionedScalar &ds)
scalar celerity() const
The wave celerity [m/s].
Definition: Airy.C:50
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
defineTypeNameAndDebug(Airy, 0)
dimensionedScalar sqrt(const dimensionedScalar &ds)
First-order wave model.
Definition: Airy.H:58
bool deep() const
Return whether shallow and intermdiate effects are to be omitted.
Definition: Airy.C:67
label k
Boltzmann constant.
Macros for easy insertion into run-time selection tables.
dimensionedScalar cos(const dimensionedScalar &ds)
dimensionedScalar exp(const dimensionedScalar &ds)
Generic base class for waves. Derived classes must implement field functions which return the elevati...
Definition: waveModel.H:55
tmp< scalarField > angle(const scalar t, const scalar u, const scalarField &x) const
Angle of the oscillation [rad].
Definition: Airy.C:57
scalar k() const
The angular wavenumber [rad/m].
Definition: Airy.C:44
addToRunTimeSelectionTable(waveModel, Airy, objectRegistry)
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:68
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:657
waveModel(const waveModel &wave)
Construct a copy.
Definition: waveModel.C:41
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
dimensionedScalar sin(const dimensionedScalar &ds)
static const char nl
Definition: Ostream.H:265
virtual tmp< vector2DField > velocity(const scalar t, const scalar u, const vector2DField &xz) const
Get the wave velocity at a given time, mean velocity and local.
Definition: Airy.C:144
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
tmp< vector2DField > vi(const label i, const scalar t, const scalar u, const vector2DField &xz) const
Return the non-dimensionalised i-th harmonic of the velocity.
Definition: Airy.C:74
virtual tmp< scalarField > pressure(const scalar t, const scalar u, const vector2DField &xz) const
Get the wave pressure at a given time, mean velocity and local.
Definition: Airy.C:157
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
dimensionedScalar sinh(const dimensionedScalar &ds)
scalar amplitude(const scalar t) const
Get the amplitude.
Definition: waveModel.H:122
dimensioned< scalar > mag(const dimensioned< Type > &)
virtual void write(Ostream &os) const
Write.
Definition: Airy.C:170
dimensionedScalar cosh(const dimensionedScalar &ds)
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
const dimensionedVector & g
virtual ~Airy()
Destructor.
Definition: Airy.C:126
virtual void write(Ostream &os) const
Write.
Definition: waveModel.C:73
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576
virtual tmp< scalarField > elevation(const scalar t, const scalar u, const scalarField &x) const
Get the wave elevation at a given time, mean velocity and local.
Definition: Airy.C:133