solitary.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-2021 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 "solitary.H"
27 #include "mathematicalConstants.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace waveModels
35 {
36  defineTypeNameAndDebug(solitary, 0);
37  addToRunTimeSelectionTable(waveModel, solitary, dictionary);
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 Foam::scalar Foam::waveModels::solitary::k() const
45 {
46  return sqrt(0.75*amplitude()/pow3(depth()));
47 }
48 
49 
50 Foam::scalar Foam::waveModels::solitary::alpha() const
51 {
52  return amplitude()/depth();
53 }
54 
55 
56 Foam::scalar Foam::waveModels::solitary::celerity() const
57 {
58  return sqrt(g()*depth()/(1 - alpha()));
59 }
60 
61 
62 Foam::tmp<Foam::scalarField> Foam::waveModels::solitary::parameter
63 (
64  const scalar t,
65  const scalarField& x
66 ) const
67 {
68  return k()*(x - offset() - celerity()*t);
69 }
70 
71 
72 Foam::tmp<Foam::scalarField> Foam::waveModels::solitary::Pi
73 (
74  const scalar t,
75  const scalarField& x
76 ) const
77 {
78  const scalar clip = log(great);
79 
80  return 1/sqr(cosh(max(- clip, min(clip, parameter(t, x)))));
81 }
82 
83 
84 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85 
87 :
88  waveModel(wave),
89  depth_(wave.depth_),
90  amplitude_(wave.amplitude_),
91  offset_(wave.offset_)
92 {}
93 
94 
96 (
97  const dictionary& dict,
98  const scalar g
99 )
100 :
101  waveModel(dict, g),
102  depth_(dict.lookup<scalar>("depth")),
103  amplitude_(dict.lookup<scalar>("amplitude")),
104  offset_(dict.lookup<scalar>("offset"))
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
109 
111 {}
112 
113 
114 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
115 
117 (
118  const scalar t,
119  const scalarField& x
120 ) const
121 {
122  return amplitude()*Pi(t, x);
123 }
124 
125 
127 (
128  const scalar t,
129  const vector2DField& xz
130 ) const
131 {
132  const scalar A = alpha();
133  const scalarField Z(max(scalar(0), 1 + xz.component(1)/depth()));
134  const scalarField P(Pi(t, xz.component(0)));
135 
136  return
137  celerity()
138  *zip
139  (
140  A/4
141  *(
142  (4 + 2*A - 6*A*sqr(Z))*P
143  + (- 7*A + 9*A*sqr(Z))*sqr(P)
144  ),
145  A*Z*depth()*k()*tanh(parameter(t, xz.component(0)))
146  *(
147  (2 + A - A*sqr(Z))*P
148  + (- 7*A + 3*A*sqr(Z))*sqr(P)
149  )
150  );
151 }
152 
153 
155 {
156  waveModel::write(os);
157 
158  writeEntry(os, "offset", offset_);
159  writeEntry(os, "amplitude", amplitude_);
160  writeEntry(os, "depth", depth_);
161 }
162 
163 
164 // ************************************************************************* //
solitary(const solitary &wave)
Construct a copy.
Definition: solitary.C:86
tmp< vector2DField > zip(const tmp< scalarField > &x, const tmp< scalarField > &y)
Definition: vector2DField.C:31
dimensionedScalar tanh(const dimensionedScalar &ds)
scalar depth() const
Get the depth.
Definition: solitary.H:132
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dimensionedScalar log(const dimensionedScalar &ds)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
defineTypeNameAndDebug(Airy, 0)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
volScalarField alpha(IOobject("alpha", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
dimensionedScalar sqrt(const dimensionedScalar &ds)
label k
Boltzmann constant.
Macros for easy insertion into run-time selection tables.
virtual void write(Ostream &os) const
Write.
Definition: solitary.C:154
Generic base class for waves. Derived classes must implement field functions which return the elevati...
Definition: waveModel.H:55
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual tmp< vector2DField > velocity(const scalar t, const vector2DField &xz) const
Get the wave velocity at a given time and local coordinates. Local.
Definition: solitary.C:127
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:455
waveModel(const waveModel &wave)
Construct a copy.
Definition: waveModel.C:39
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
dimensionedScalar pow3(const dimensionedScalar &ds)
addToRunTimeSelectionTable(waveModel, Airy, dictionary)
dimensionedScalar cosh(const dimensionedScalar &ds)
A class for managing temporary objects.
Definition: PtrList.H:53
const dimensionedVector & g
scalar amplitude() const
Get the amplitude.
Definition: solitary.H:138
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.
virtual ~solitary()
Destructor.
Definition: solitary.C:110
virtual void write(Ostream &os) const
Write.
Definition: waveModel.C:63
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864
Solitary wave model.
Definition: solitary.H:59
virtual tmp< scalarField > elevation(const scalar t, const scalarField &x) const
Get the wave elevation at a given time and local coordinates. Local.
Definition: solitary.C:117