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-2024 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 {
37 
39  (
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  w_ = dict.lookup<scalar>("window", dimTime);
79 
80  convergedVelocity_ =
81  dict.lookup<vector>("convergedVelocity", dimVelocity);
82  convergedAngularVelocity_ =
83  dict.lookup<vector>("convergedAngularVelocity", angularVelocityUnits());
84 
85  resetName(typeName);
86 
87  return true;
88 }
89 
90 
92 {
93  if (time_.timeIndex() <= time_.startTimeIndex() + 1)
94  {
95  meanVelocity_ = cmptMag(velocity());
96  meanAngularVelocity_ = cmptMag(angularVelocity());
97  }
98  else
99  {
100  const scalar dt = time_.deltaTValue();
101  const scalar beta = min(dt/w_, 1);
102 
103  meanVelocity_ = (1 - beta)*meanVelocity_ + beta*cmptMag(velocity());
104 
105  meanAngularVelocity_ =
106  (1 - beta)*meanAngularVelocity_ + beta*cmptMag(angularVelocity());
107  }
108 
109  if
110  (
111  time_.value() - time_.startTime().value() > w_
112  && meanVelocity_ < convergedVelocity_
113  && meanAngularVelocity_ < convergedAngularVelocity_
114  )
115  {
116  time_.stopAt(Time::stopAtControl::writeNow);
117  }
118 
119  return true;
120 }
121 
122 
123 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
@ writeNow
set endTime to stop immediately w/ writing
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
Convergence control based on the 6-DoF motion state.
sixDoFRigidBodyControl(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual bool execute()
Execute, currently does nothing.
virtual bool read(const dictionary &)
Read the sixDoFRigidBodyControl data.
virtual bool read(const dictionary &)
Read the sixDoFRigidBodyState data.
A class for handling words, derived from string.
Definition: word.H:62
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
const dimensionSet dimTime
dimensionSet cmptMag(const dimensionSet &)
Definition: dimensionSet.C:296
const dimensionSet dimVelocity
dictionary dict