sixDoFRigidBodyControl.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) 2018-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 "sixDoFRigidBodyControl.H"
27 #include "Time.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
36  defineTypeNameAndDebug(sixDoFRigidBodyControl, 0);
37 
39  (
40  functionObject,
41  sixDoFRigidBodyControl,
42  dictionary
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  const word& name,
53  const Time& runTime,
54  const dictionary& dict
55 )
56 :
57  sixDoFRigidBodyState(name, runTime, dict),
58  time_(runTime),
59  meanVelocity_(Zero),
60  meanAngularVelocity_(Zero)
61 {
62  read(dict);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
69 {}
70 
71 
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 
75 {
77 
78  dict.lookup("window") >> w_;
79  dict.lookup("convergedVelocity") >> convergedVelocity_;
80  dict.lookup("convergedAngularVelocity") >> convergedAngularVelocity_;
81 
82  resetName(typeName);
83 
84  return true;
85 }
86 
87 
89 {
90  if (time_.timeIndex() <= time_.startTimeIndex() + 1)
91  {
92  meanVelocity_ = cmptMag(velocity());
93  meanAngularVelocity_ = cmptMag(angularVelocity());
94  }
95  else
96  {
97  const scalar dt = time_.deltaTValue();
98  const scalar beta = min(dt/w_, 1);
99 
100  meanVelocity_ = (1 - beta)*meanVelocity_ + beta*cmptMag(velocity());
101 
102  meanAngularVelocity_ =
103  (1 - beta)*meanAngularVelocity_ + beta*cmptMag(angularVelocity());
104  }
105 
106  if
107  (
108  time_.value() - time_.startTime().value() > w_
109  && meanVelocity_ < convergedVelocity_
110  && meanAngularVelocity_ < convergedAngularVelocity_
111  )
112  {
113  time_.stopAt(Time::stopAtControl::writeNow);
114  }
115 
116  return true;
117 }
118 
119 
120 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
set endTime to stop immediately w/ writing
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
virtual bool read(const dictionary &)
Read the sixDoFRigidBodyState data.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
virtual bool read(const dictionary &)
Read the sixDoFRigidBodyControl data.
static const zero Zero
Definition: zero.H:97
sixDoFRigidBodyControl(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
defineTypeNameAndDebug(Qdot, 0)
virtual bool execute()
Execute, currently does nothing.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844