oscillatingLinearMotion.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace solidBodyMotionFunctions
37 {
38  defineTypeNameAndDebug(oscillatingLinearMotion, 0);
40  (
41  solidBodyMotionFunction,
42  oscillatingLinearMotion,
43  dictionary
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 Foam::solidBodyMotionFunctions::oscillatingLinearMotion::oscillatingLinearMotion
52 (
53  const dictionary& SBMFCoeffs,
54  const Time& runTime
55 )
56 :
57  solidBodyMotionFunction(SBMFCoeffs, runTime),
58  omegaPtr_(Function1<scalar>::New("omega", SBMFCoeffs_, &runTime)),
59  phaseShiftPtr_
60  (
61  Function1<scalar>::NewIfPresent
62  (
63  "phaseShift",
64  SBMFCoeffs_,
65  word::null,
66  &runTime
67  )
68  ),
69  amplitudePtr_(Function1<vector>::New("amplitude", SBMFCoeffs_, &runTime)),
70  verticalShiftPtr_
71  (
72  Function1<vector>::NewIfPresent
73  (
74  "verticalShift",
75  SBMFCoeffs_,
76  word::null,
77  &runTime
78  )
79  )
80 {
81  read(SBMFCoeffs);
82 }
83 
84 
85 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
86 
88 Foam::solidBodyMotionFunctions::oscillatingLinearMotion::transformation() const
89 {
90  const scalar t = time_.value();
91 
92  const vector amplitude(amplitudePtr_->value(t));
93  const scalar omega = omegaPtr_->value(t);
94 
95  scalar phaseShift = 0;
96  if (phaseShiftPtr_)
97  {
98  phaseShift = phaseShiftPtr_->value(t);
99  }
100 
101  vector verticalShift(Zero);
102  if (verticalShiftPtr_)
103  {
104  verticalShift = verticalShiftPtr_->value(t);
105  }
106 
107  const vector displacement
108  (
109  amplitude*sin(omega*(t + phaseShift)) + verticalShift
110  );
111 
112  quaternion R(1);
113  septernion TR(septernion(-displacement)*R);
114 
115  DebugInFunction << "Time = " << t << " transformation: " << TR << endl;
116 
117  return TR;
118 }
119 
120 
122 (
123  const dictionary& SBMFCoeffs
124 )
125 {
126  if (!solidBodyMotionFunction::read(SBMFCoeffs))
127  {
128  return false;
129  }
130 
131  omegaPtr_.reset
132  (
133  Function1<scalar>::New("omega", SBMFCoeffs_, &time_)
134  );
135 
136  phaseShiftPtr_.reset
137  (
139  (
140  "phaseShift",
141  SBMFCoeffs_,
142  word::null,
143  &time_
144  )
145  );
146 
147  amplitudePtr_.reset
148  (
149  Function1<vector>::New("amplitude", SBMFCoeffs_, &time_)
150  );
151 
152  verticalShiftPtr_.reset
153  (
155  (
156  "verticalShift",
157  SBMFCoeffs_,
158  word::null,
159  &time_
160  )
161  );
162 
163  return true;
164 }
165 
166 
167 // ************************************************************************* //
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:62
Macros for easy insertion into run-time selection tables.
defineTypeNameAndDebug(axisRotationMotion, 0)
#define DebugInFunction
Report an information message using Foam::Info.
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
static const word null
An empty word.
Definition: word.H:84
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Definition: multiMotion.C:76
Vector< scalar > vector
Definition: vector.H:57
dimensionedScalar sin(const dimensionedScalar &ds)
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
static autoPtr< Function1< scalar > > NewIfPresent(const word &entryName, const dictionary &dict, const word &redirectType, const objectRegistry *obrPtr=nullptr)
An optional selector, with fallback redirection.
Definition: Function1New.C:209
#define R(A, B, C, D, E, F, K, M)
addToRunTimeSelectionTable(solidBodyMotionFunction, axisRotationMotion, dictionary)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:133