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