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-2024 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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 Foam::scalar Foam::waveModels::Airy::readLength
44 (
45  const dictionary& dict,
46  const scalar depth,
47  const scalar amplitude,
48  const scalar g,
49  scalar (*celerityPtr)(const AiryCoeffs&)
50 )
51 {
52  const bool haveLength = dict.found("length");
53  const bool havePeriod = dict.found("period");
54 
55  if (haveLength == havePeriod)
56  {
58  << "Exactly one of either length or period must be specified"
59  << exit(FatalIOError);
60  }
61 
62  if (haveLength)
63  {
64  return dict.lookup<scalar>("length");
65  }
66  else
67  {
68  return
69  AiryCoeffs
70  (
71  depth,
72  amplitude,
73  dict.lookup<scalar>("period"),
74  g,
75  celerityPtr
76  ).length;
77  }
78 }
79 
80 
81 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
82 
83 Foam::scalar Foam::waveModels::Airy::celerity(const AiryCoeffs& coeffs)
84 {
85  return coeffs.celerity();
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 :
93  waveModel(wave),
94  depth_(wave.depth_),
95  amplitude_(wave.amplitude_, false),
96  length_(wave.length_),
97  phase_(wave.phase_)
98 {}
99 
100 
102 (
103  const dictionary& dict,
104  const scalar g,
105  const word& modelName,
106  scalar (*celerityPtr)(const AiryCoeffs&)
107 )
108 :
109  waveModel(dict, g),
110  depth_(dict.lookupOrDefault<scalar>("depth", great)),
111  amplitude_(Function1<scalar>::New("amplitude", dimTime, dimLength, dict)),
112  length_(readLength(dict, depth_, amplitude(), g, celerityPtr)),
113  phase_(dict.lookup<scalar>("phase"))
114 {
115  const scalar c = celerityPtr(coeffs());
116 
117  Info<< waveModel::typeName << ": " << modelName
118  << ": period = " << length_/c
119  << ", length = " << length_ << endl;;
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
124 
126 {}
127 
128 
129 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
130 
132 {
133  return celerity(coeffs());
134 }
135 
136 
138 (
139  const scalar t,
140  const scalarField& x
141 ) const
142 {
143  return amplitude(t)*cos(coeffs().angle(phase_, t, x));
144 }
145 
146 
148 (
149  const scalar t,
150  const vector2DField& xz
151 ) const
152 {
153  const scalar ka = coeffs().k()*amplitude(t);
154 
155  return Airy::celerity()*ka*coeffs().vi(1, phase_, t, xz);
156 }
157 
158 
160 {
161  waveModel::write(os);
162 
163  if (!coeffs().deep())
164  {
165  writeEntry(os, "depth", depth_);
166  }
167  writeEntry(os, amplitude_());
168  writeEntry(os, "length", length_);
169  writeEntry(os, "phase", phase_);
170 }
171 
172 
173 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Run-time selectable general function of one variable.
Definition: Function1.H:125
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for managing temporary objects.
Definition: tmp.H:55
Generic base class for waves. Derived classes must implement field functions which return the elevati...
Definition: waveModel.H:56
scalar g() const
Get the value of gravity.
Definition: waveModel.H:117
virtual void write(Ostream &os) const
Write.
Definition: waveModel.C:59
Calculation engine for the Airy wave model and other models that are a correction on top of the Airy ...
Definition: AiryCoeffs.H:52
static scalar celerity(const AiryCoeffs &coeffs)
The wave celerity [m/s].
Definition: AiryCoeffs.C:105
First-order wave model.
Definition: Airy.H:116
scalar amplitude() const
Get the amplitude at steady state.
Definition: AiryI.H:59
virtual scalar celerity() const
The wave celerity [m/s].
Definition: Airy.C:131
virtual ~Airy()
Destructor.
Definition: Airy.C:125
AiryCoeffs coeffs() const
Return the wave coefficients at steady state.
Definition: AiryI.H:39
virtual tmp< scalarField > elevation(const scalar t, const scalarField &x) const
Get the wave elevation at a given time and local coordinates. Local.
Definition: Airy.C:138
virtual void write(Ostream &os) const
Write.
Definition: Airy.C:159
virtual tmp< vector2DField > velocity(const scalar t, const vector2DField &xz) const
Get the wave velocity at a given time and local coordinates. Local.
Definition: Airy.C:148
scalar depth() const
Get the depth.
Definition: AiryI.H:47
Airy(const Airy &wave)
Construct a copy.
Definition: Airy.C:91
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
const dimensionedScalar c
Speed of light in a vacuum.
label wave(const fvMesh &mesh, const List< labelPair > &changedPatchAndFaces, const label nCorrections, GeometricField< scalar, PatchField, GeoMesh > &distance, TrackingData &td, GeometricField< DataType, PatchField, GeoMesh > &... data)
Wave distance (and maybe additional) data from faces. If nCorrections is.
defineTypeNameAndDebug(Airy, 0)
addToRunTimeSelectionTable(waveModel, Airy, dictionary)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
const dimensionSet dimLength
const dimensionSet dimTime
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
IOerror FatalIOError
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict