sixDoFRigidBodyMotionSolver.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) 2013-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 \*---------------------------------------------------------------------------*/
25 
27 #include "polyMesh.H"
28 #include "pointPatchDist.H"
29 #include "pointConstraints.H"
30 #include "timeIOdictionary.H"
32 #include "forces.H"
33 #include "mathematicalConstants.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(sixDoFRigidBodyMotionSolver, 0);
41 
43  (
44  motionSolver,
45  sixDoFRigidBodyMotionSolver,
46  dictionary
47  );
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const word& name,
56  const polyMesh& mesh,
57  const dictionary& dict
58 )
59 :
60  displacementMotionSolver(name, mesh, dict, typeName),
62  (
63  coeffDict(),
65  (
66  "sixDoFRigidBodyMotionState",
67  mesh.time().timeName(),
68  "uniform",
69  mesh
70  ).headerOk()
72  (
73  IOobject
74  (
75  "sixDoFRigidBodyMotionState",
76  mesh.time().timeName(),
77  "uniform",
78  mesh,
81  false
82  )
83  )
84  : coeffDict()
85  ),
86  patches_(wordReList(coeffDict().lookup("patches"))),
87  patchSet_(mesh.boundaryMesh().patchSet(patches_)),
88  di_(coeffDict().lookup<scalar>("innerDistance")),
89  do_(coeffDict().lookup<scalar>("outerDistance")),
90  test_(coeffDict().lookupOrDefault<Switch>("test", false)),
91  rhoInf_(1.0),
92  rhoName_(coeffDict().lookupOrDefault<word>("rho", "rho")),
93  scale_
94  (
95  IOobject
96  (
97  "motionScale",
98  mesh.time().timeName(),
99  mesh,
100  IOobject::NO_READ,
101  IOobject::NO_WRITE,
102  false
103  ),
104  pointMesh::New(mesh),
106  ),
107  curTimeIndex_(-1)
108 {
109  if (rhoName_ == "rhoInf")
110  {
111  rhoInf_ = coeffDict().lookup<scalar>("rhoInf");
112  }
113 
114  // Calculate scaling factor everywhere
115  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116 
117  {
118  const pointMesh& pMesh = pointMesh::New(mesh);
119 
120  pointPatchDist pDist(pMesh, patchSet_, points0());
121 
122  // Scaling: 1 up to di then linear down to 0 at do away from patches
123  scale_.primitiveFieldRef() =
124  min
125  (
126  max
127  (
128  (do_ - pDist.primitiveField())/(do_ - di_),
129  scalar(0)
130  ),
131  scalar(1)
132  );
133 
134  // Convert the scale function to a cosine
135  scale_.primitiveFieldRef() =
136  min
137  (
138  max
139  (
140  0.5
141  - 0.5
142  *cos(scale_.primitiveField()
144  scalar(0)
145  ),
146  scalar(1)
147  );
148 
149  pointConstraints::New(pMesh).constrain(scale_);
150  scale_.write();
151  }
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 
158 {}
159 
160 
161 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
162 
165 {
166  return points0() + pointDisplacement_.primitiveField();
167 }
168 
169 
171 {
172  const Time& t = mesh().time();
173 
174  if (mesh().nPoints() != points0().size())
175  {
177  << "The number of points in the mesh seems to have changed." << endl
178  << "In constant/polyMesh there are " << points0().size()
179  << " points; in the current mesh there are " << mesh().nPoints()
180  << " points." << exit(FatalError);
181  }
182 
183  // Store the motion state at the beginning of the time-stepbool
184  bool firstIter = false;
185  if (curTimeIndex_ != t.timeIndex())
186  {
187  newTime();
188  curTimeIndex_ = t.timeIndex();
189  firstIter = true;
190  }
191 
193 
194  if (mesh().foundObject<uniformDimensionedVectorField>("g"))
195  {
197  }
198  else if (coeffDict().found("g"))
199  {
200  coeffDict().lookup("g") >> g;
201  }
202 
203  // scalar ramp = min(max((t.value() - 5)/10, 0), 1);
204  scalar ramp = 1.0;
205 
206  if (test_)
207  {
208  update
209  (
210  firstIter,
211  ramp*(mass()*g.value()),
212  ramp*(mass()*(momentArm() ^ g.value())),
213  t.deltaTValue(),
214  t.deltaT0Value()
215  );
216  }
217  else
218  {
219  dictionary forcesDict;
220 
221  forcesDict.add("type", functionObjects::forces::typeName);
222  forcesDict.add("patches", patches_);
223  forcesDict.add("rhoInf", rhoInf_);
224  forcesDict.add("rho", rhoName_);
225  forcesDict.add("CofR", centreOfRotation());
226 
227  functionObjects::forces f("forces", t, forcesDict);
228 
229  f.calcForcesMoment();
230 
231  update
232  (
233  firstIter,
234  ramp*(f.forceEff() + mass()*g.value()),
235  ramp
236  *(
237  f.momentEff()
238  + mass()*(momentArm() ^ g.value())
239  ),
240  t.deltaTValue(),
241  t.deltaT0Value()
242  );
243  }
244 
245  // Update the displacements
246  pointDisplacement_.primitiveFieldRef() =
247  transform(points0(), scale_) - points0();
248 
249  // Displacement has changed. Update boundary conditions
251  (
252  pointDisplacement_.mesh()
253  ).constrainDisplacement(pointDisplacement_);
254 }
255 
256 
258 {
260  (
261  IOobject
262  (
263  "sixDoFRigidBodyMotionState",
264  mesh().time().timeName(),
265  "uniform",
266  mesh(),
269  false
270  )
271  );
272 
273  state().write(dict);
274 
275  return
276  dict.regIOobject::writeObject
277  (
280  mesh().time().writeCompression(),
281  true
282  )
284 }
285 
286 
287 // ************************************************************************* //
Six degree of freedom motion for a rigid body.
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:1025
virtual bool write() const
Write motion state information for restart.
dictionary dict
Virtual base class for displacement motion solver.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Templated form of IOobject providing type information for file reading and header type checking...
Definition: IOobject.H:537
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
virtual vector forceEff() const
Return the total force.
Definition: forces.C:1019
const dimensionSet dimless
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:372
fvMesh & mesh
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1153
virtual bool write() const
Write points0 if the mesh topology changed.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
sixDoFRigidBodyMotionSolver(const word &name, const polyMesh &, const dictionary &dict)
Construct from polyMesh and dictionary.
stressControl lookup("compactNormalStress") >> compactNormalStress
dimensionedScalar cos(const dimensionedScalar &ds)
const dimensionSet dimAcceleration
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
Definition: Time.C:666
scalar deltaT0Value() const
Return old time step value.
Definition: TimeStateI.H:40
A class for handling words, derived from string.
Definition: word.H:59
label nPoints
virtual tmp< pointField > curPoints() const
Return point location obtained from the current motion field.
Calculation of distance to nearest patch for all points.
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:34
const Type & value() const
Return const reference to value.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
word timeName
Definition: getTimeIndex.H:3
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:884
static const zero Zero
Definition: zero.H:97
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
const Time & time() const
Return time.
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
virtual void solve()
Solve for motion.
timeIOdictionary derived from IOdictionary with globalFile set false to enable writing to processor t...
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:28
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
label nPoints() const
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:204
A class for managing temporary objects.
Definition: PtrList.H:53
const dimensionedVector & g
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
void constrain(GeometricField< Type, pointPatchField, pointMesh > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
Namespace for OpenFOAM.
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:483