waveSuperposition.H
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 Class
25  Foam::waveSuperposition
26 
27 Description
28  A wrapper around a list of wave models. Superimposes the modelled values of
29  elevation and velocity. The New method looks up or constructs an
30  instance of this class on demand and returns a reference. Properties are
31  read from a waveProperties dictionary in constant.
32 
33 Usage
34  \table
35  Property | Description | Required? | Default
36  origin | origin of the wave coordinate \\
37  system | yes |
38  direction | direction of the wave \\
39  coordinate system | yes |
40  waves | list of wave models to \\
41  superimpose | yes |
42  UMean | velocity of the mean flow | yes |
43  scale | scale factor in the direction | no | None
44  crossScale | scale factor perpendicular to \\
45  the direction | no | None
46  heightAboveWave | use the height above the wave \\
47  as the vertical coordinate | no | false
48  \endtable
49 
50  Example specification:
51  \verbatim
52  origin (0 25 0);
53 
54  direction (1 0 0);
55 
56  waves
57  (
58  Airy
59  {
60  length 40;
61  amplitude 0.5;
62  phase 0;
63  angle 0;
64  }
65  Airy
66  {
67  length 20;
68  amplitude 0.25;
69  phase 1.5708;
70  angle 0;
71  }
72  );
73 
74  UMean (2 0 0);
75 
76  scale table ((100 1) (200 0));
77 
78  crossScale constant 1;
79 
80  heightAboveWave no;
81  \endverbatim
82 
83 SourceFiles
84  waveSuperposition.C
85  waveSuperpositionNew.C
86 
87 \*---------------------------------------------------------------------------*/
88 
89 #ifndef waveSuperposition_H
90 #define waveSuperposition_H
91 
92 #include "waveModel.H"
93 #include "IOdictionary.H"
94 #include "tensor.H"
95 
96 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 
98 namespace Foam
99 {
100 
101 /*---------------------------------------------------------------------------*\
102  Class waveSuperposition Declaration
103 \*---------------------------------------------------------------------------*/
104 
105 class waveSuperposition
106 :
107  public IOdictionary
108 {
109 protected:
110 
111  // Protected Data
112 
113  //- The origin of the wave coordinate system
114  const vector origin_;
115 
116  //- The direction of the wave coordinate system
117  const vector direction_;
118 
119  //- Wave models to superimpose
120  PtrList<waveModel> waveModels_;
121 
122  //- The angle relative to the direction at which the waves propagate
124 
125  //- Mean velocity
126  const autoPtr<Function1<vector>> UMean_;
127 
128  //- Scaling in the local x-direction
129  const autoPtr<Function1<scalar>> scale_;
130 
131  //- Scaling perpendicular to the local x-direction
132  const autoPtr<Function1<scalar>> crossScale_;
133 
134  //- Calculate wave properties using the height above the wave (true) or
135  // the height above the origin (false)?
136  const Switch heightAboveWave_;
137 
138 
139  // Protected Member Functions
140 
141  //- Get the transformation to actual coordinates
142  void transformation
143  (
144  const scalar t,
145  const vectorField& p,
146  tensor& axes,
147  vector& drift,
149  ) const;
150 
151  //- Get the wave elevation relative to the mean at a given time and
152  // local coordinates. Local x is aligned with the direction, and y is
153  // perpendicular to both x and gravity.
155  (
156  const scalar t,
157  const vector2D& drift,
158  const vector2DField& xy
159  ) const;
160 
161  //- Get the wave velocity at a given time and local coordinates. Local
162  // x is aligned with the direction, z with negative gravity, and y is
163  // perpendicular to both.
165  (
166  const scalar t,
167  const vector& drift,
168  const vectorField& xyz
169  ) const;
170 
171  //- Get the scaling factor, calculated from the optional scaling
172  // functions. X and y are the same as for the elevation method.
173  tmp<scalarField> scale(const vector2DField& xy) const;
174 
175 
176 public:
177 
178  //- Runtime type information
179  TypeName("wave");
180 
181 
182  // Declare runtime construction
184  (
185  autoPtr,
188  (const objectRegistry& db),
189  (db)
190  );
191 
192 
193  // Static Data
194 
195  //- The name of the dictionary
196  static const word dictName;
197 
198 
199  // Static Member Functions
200 
201  //- Return a reference to the wave model on the given database,
202  // constructing if it doesn't exist
203  static const waveSuperposition& New(const objectRegistry& db);
204 
205 
206  // Constructors
207 
208  //- Construct from a database
210 
211 
212  //- Destructor
214 
215 
216  // Member Functions
217 
218  //- Return the maximum wave speed for the given time t
219  // used to evaluate the mean velocity
220  scalar maxWaveSpeed(const scalar t) const;
221 
222  //- Get the height above the waves at a given time and global positions
223  virtual tmp<scalarField> height
224  (
225  const scalar t,
226  const vectorField& p
227  ) const;
228 
229  //- Get the liquid velocity at a given time and global positions
231  (
232  const scalar t,
233  const vectorField& p
234  ) const;
235 
236  //- Get the gas velocity at a given time and global positions
237  virtual tmp<vectorField> UGas
238  (
239  const scalar t,
240  const vectorField& p
241  ) const;
242 
243  //- Inherit write from regIOobject
244  using regIOobject::write;
245 
246  //- Write
247  void write(Ostream&) const;
248 };
249 
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 } // End namespace Foam
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 #endif
258 
259 // ************************************************************************* //
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:312
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Registry of regIOobjects.
virtual bool write(const bool write=true) const
Write using setting from DB.
A class for managing temporary objects.
Definition: tmp.H:55
A wrapper around a list of wave models. Superimposes the modelled values of elevation and velocity....
const Switch heightAboveWave_
Calculate wave properties using the height above the wave (true) or.
TypeName("wave")
Runtime type information.
tmp< scalarField > elevation(const scalar t, const vector2D &drift, const vector2DField &xy) const
Get the wave elevation relative to the mean at a given time and.
const autoPtr< Function1< vector > > UMean_
Mean velocity.
const vector origin_
The origin of the wave coordinate system.
virtual tmp< scalarField > height(const scalar t, const vectorField &p) const
Get the height above the waves at a given time and global positions.
virtual tmp< vectorField > ULiquid(const scalar t, const vectorField &p) const
Get the liquid velocity at a given time and global positions.
virtual tmp< vectorField > UGas(const scalar t, const vectorField &p) const
Get the gas velocity at a given time and global positions.
waveSuperposition(const objectRegistry &db)
Construct from a database.
static const word dictName
The name of the dictionary.
tmp< scalarField > scale(const vector2DField &xy) const
Get the scaling factor, calculated from the optional scaling.
void transformation(const scalar t, const vectorField &p, tensor &axes, vector &drift, vectorField &xyz) const
Get the transformation to actual coordinates.
const autoPtr< Function1< scalar > > scale_
Scaling in the local x-direction.
scalarList waveAngles_
The angle relative to the direction at which the waves propagate.
const autoPtr< Function1< scalar > > crossScale_
Scaling perpendicular to the local x-direction.
const vector direction_
The direction of the wave coordinate system.
virtual bool write(const bool write=true) const
Inherit write from regIOobject.
PtrList< waveModel > waveModels_
Wave models to superimpose.
static const waveSuperposition & New(const objectRegistry &db)
Return a reference to the wave model on the given database,.
declareRunTimeSelectionTable(autoPtr, waveSuperposition, objectRegistry,(const objectRegistry &db),(db))
scalar maxWaveSpeed(const scalar t) const
Return the maximum wave speed for the given time t.
tmp< vectorField > velocity(const scalar t, const vector &drift, const vectorField &xyz) const
Get the wave velocity at a given time and local coordinates. Local.
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
volScalarField & p