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-2025 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 "pointDist.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 {
41 
43  (
47  );
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const word& name,
56  const polyMesh& mesh,
57  const dictionary& dict
58 )
59 :
62  (
63  dict,
65  (
66  "sixDoFRigidBodyMotionState",
67  mesh.time().name(),
68  "uniform",
69  mesh
70  ).headerOk()
72  (
73  IOobject
74  (
75  "sixDoFRigidBodyMotionState",
76  mesh.time().name(),
77  "uniform",
78  mesh,
79  IOobject::READ_IF_PRESENT,
80  IOobject::NO_WRITE,
81  false
82  )
83  )
84  : dict
85  ),
86  patches_(wordReList(dict.lookup("patches"))),
87  patchSet_(mesh.boundaryMesh().patchSet(patches_)),
88  di_(dict.lookup<scalar>("innerDistance")),
89  do_(dict.lookup<scalar>("outerDistance")),
90  test_(dict.lookupOrDefault<Switch>("test", false)),
91  rhoInf_(1.0),
92  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
93  g_("g", dimAcceleration, dict, vector::zero),
94  scale_
95  (
96  IOobject
97  (
98  "motionScale",
99  mesh.time().name(),
100  mesh,
101  IOobject::NO_READ,
102  IOobject::NO_WRITE,
103  false
104  ),
105  pointMesh::New(mesh),
107  ),
108  curTimeIndex_(-1)
109 {
110  if (rhoName_ == "rhoInf")
111  {
112  rhoInf_ = dict.lookup<scalar>("rhoInf");
113  }
114 
115  // Calculate scaling factor everywhere
116  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117 
118  {
119  const pointMesh& pMesh = pointMesh::New(mesh);
120 
121  pointDist pDist(pMesh, patchSet_, points0(), do_);
122 
123  // Scaling: 1 up to di then linear down to 0 at do away from patches
124  scale_.primitiveFieldRef() =
125  min
126  (
127  max
128  (
129  (do_ - pDist.primitiveField())/(do_ - di_),
130  scalar(0)
131  ),
132  scalar(1)
133  );
134 
135  // Convert the scale function to a cosine
136  scale_.primitiveFieldRef() =
137  min
138  (
139  max
140  (
141  0.5
142  - 0.5
143  *cos(scale_.primitiveField()
145  scalar(0)
146  ),
147  scalar(1)
148  );
149 
150  pointConstraints::New(pMesh).constrain(scale_);
151  scale_.write();
152  }
153 }
154 
155 
156 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
157 
159 {}
160 
161 
162 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
163 
166 {
167  return points0() + pointDisplacement_.primitiveField();
168 }
169 
170 
172 {
173  const Time& t = mesh().time();
174 
175  if (mesh().nPoints() != points0().size())
176  {
178  << "The number of points in the mesh seems to have changed." << endl
179  << "In constant/polyMesh there are " << points0().size()
180  << " points; in the current mesh there are " << mesh().nPoints()
181  << " points." << exit(FatalError);
182  }
183 
184  // Store the motion state at the beginning of the time-stepbool
185  bool firstIter = false;
186  if (curTimeIndex_ != t.timeIndex())
187  {
188  newTime();
189  curTimeIndex_ = t.timeIndex();
190  firstIter = true;
191  }
192 
193  dimensionedVector g(g_);
194 
195  if (mesh().foundObject<uniformDimensionedVectorField>("g"))
196  {
198  }
199 
200  // scalar ramp = min(max((t.value() - 5)/10, 0), 1);
201  scalar ramp = 1.0;
202 
203  if (test_)
204  {
205  update
206  (
207  firstIter,
208  ramp*(mass()*g.value()),
209  ramp*(mass()*(momentArm() ^ g.value())),
210  t.deltaTValue(),
211  t.deltaT0Value()
212  );
213  }
214  else
215  {
217  (
218  functionObjects::forces::typeName,
219  t,
221  (
222  "type", functionObjects::forces::typeName,
223  "patches", patches_,
224  "rhoInf", rhoInf_,
225  "rho", rhoName_,
226  "CofR", centreOfRotation()
227  )
228  );
229 
230  f.calcForcesMoments();
231 
232  update
233  (
234  firstIter,
235  ramp*(f.forceEff() + mass()*g.value()),
236  ramp
237  *(
238  f.momentEff()
239  + mass()*(momentArm() ^ g.value())
240  ),
241  t.deltaTValue(),
242  t.deltaT0Value()
243  );
244  }
245 
246  // Update the displacements
247  pointDisplacement_.primitiveFieldRef() =
248  transform(points0(), scale_) - points0();
249 
250  // Displacement has changed. Update boundary conditions
252  (
253  pointDisplacement_.mesh()
254  ).constrainDisplacement(pointDisplacement_);
255 }
256 
257 
259 {
261  (
262  IOobject
263  (
264  "sixDoFRigidBodyMotionState",
265  mesh().time().name(),
266  "uniform",
267  mesh(),
270  false
271  )
272  );
273 
274  state().write(dict);
275 
276  return
277  dict.regIOobject::writeObject
278  (
281  mesh().time().writeCompression(),
282  true
283  )
285 }
286 
287 
288 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
static pointMesh & New(const word &name, const polyMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
Internal::FieldType & primitiveFieldRef()
Return a reference to the primitive field.
const Internal::FieldType & primitiveField() const
Return a const-reference to the primitive field.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
scalar deltaT0Value() const
Return old time step value.
Definition: TimeStateI.H:40
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:28
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:34
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
static std::tuple< const Entries &... > entries(const Entries &...)
Construct an entries tuple from which to make a dictionary.
const Type & value() const
Return const reference to value.
Virtual base class for displacement motion solver.
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:188
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:420
Virtual base class for mesh motion solver.
Definition: motionSolver.H:57
const polyMesh & mesh() const
Return reference to mesh.
Definition: motionSolver.H:133
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
void constrain(PointField< Type > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
void constrainDisplacement(pointVectorField &displacement, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints),.
Calculates the distance to the specified sets of patch and pointZone points or for all points.
Definition: pointDist.H:54
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:53
virtual bool write() const
Write points0 if the mesh topology changed.
pointField & points0()
Return reference to the reference field.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
label nPoints() const
virtual bool write(const bool write=true) const
Write using setting from DB.
6-DoF solid-body mesh motion solver for an fvMesh.
virtual tmp< pointField > curPoints() const
Return point location obtained from the current motion field.
sixDoFRigidBodyMotionSolver(const word &name, const polyMesh &, const dictionary &dict)
Construct from polyMesh and dictionary.
virtual bool write() const
Write motion state information for restart.
virtual void solve()
Solve for motion.
Six degree of freedom motion for a rigid body.
timeIOdictionary derived from IOdictionary with globalFile set false to enable writing to processor t...
A class for managing temporary objects.
Definition: tmp.H:55
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:530
A class for handling words, derived from string.
Definition: word.H:62
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label nPoints
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
const dimensionSet dimless
const dimensionSet dimAcceleration
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:501
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
dimensionedScalar cos(const dimensionedScalar &ds)
labelList f(nPoints)
dictionary dict