sixDoFRigidBodyMotionSolver.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 | Copyright (C) 2013-2015 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 
28 #include "polyMesh.H"
29 #include "pointPatchDist.H"
30 #include "pointConstraints.H"
32 #include "forces.H"
33 #include "mathematicalConstants.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(sixDoFRigidBodyMotionSolver, 0);
40 
42  (
43  motionSolver,
44  sixDoFRigidBodyMotionSolver,
45  dictionary
46  );
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  const polyMesh& mesh,
55  const IOdictionary& dict
56 )
57 :
59  motion_
60  (
61  coeffDict(),
62  IOobject
63  (
64  "sixDoFRigidBodyMotionState",
65  mesh.time().timeName(),
66  "uniform",
67  mesh
68  ).headerOk()
69  ? IOdictionary
70  (
71  IOobject
72  (
73  "sixDoFRigidBodyMotionState",
74  mesh.time().timeName(),
75  "uniform",
76  mesh,
77  IOobject::READ_IF_PRESENT,
78  IOobject::NO_WRITE,
79  false
80  )
81  )
82  : coeffDict()
83  ),
84  patches_(wordReList(coeffDict().lookup("patches"))),
85  patchSet_(mesh.boundaryMesh().patchSet(patches_)),
86  di_(readScalar(coeffDict().lookup("innerDistance"))),
87  do_(readScalar(coeffDict().lookup("outerDistance"))),
88  test_(coeffDict().lookupOrDefault<Switch>("test", false)),
89  rhoInf_(1.0),
90  rhoName_(coeffDict().lookupOrDefault<word>("rhoName", "rho")),
91  scale_
92  (
93  IOobject
94  (
95  "motionScale",
96  mesh.time().timeName(),
97  mesh,
98  IOobject::NO_READ,
99  IOobject::NO_WRITE,
100  false
101  ),
103  dimensionedScalar("zero", dimless, 0.0)
104  ),
105  curTimeIndex_(-1)
106 {
107  if (rhoName_ == "rhoInf")
108  {
109  rhoInf_ = readScalar(coeffDict().lookup("rhoInf"));
110  }
111 
112  // Calculate scaling factor everywhere
113  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114 
115  {
116  const pointMesh& pMesh = pointMesh::New(mesh);
117 
118  pointPatchDist pDist(pMesh, patchSet_, points0());
119 
120  // Scaling: 1 up to di then linear down to 0 at do away from patches
121  scale_.internalField() =
122  min
123  (
124  max
125  (
126  (do_ - pDist.internalField())/(do_ - di_),
127  scalar(0)
128  ),
129  scalar(1)
130  );
131 
132  // Convert the scale function to a cosine
133  scale_.internalField() =
134  min
135  (
136  max
137  (
138  0.5
139  - 0.5
140  *cos(scale_.internalField()
142  scalar(0)
143  ),
144  scalar(1)
145  );
146 
147  pointConstraints::New(pMesh).constrain(scale_);
148  scale_.write();
149  }
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
154 
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
163 {
164  return points0() + pointDisplacement_.internalField();
165 }
166 
167 
169 {
170  const Time& t = mesh().time();
171 
172  if (mesh().nPoints() != points0().size())
173  {
175  << "The number of points in the mesh seems to have changed." << endl
176  << "In constant/polyMesh there are " << points0().size()
177  << " points; in the current mesh there are " << mesh().nPoints()
178  << " points." << exit(FatalError);
179  }
180 
181  // Store the motion state at the beginning of the time-stepbool
182  bool firstIter = false;
183  if (curTimeIndex_ != this->db().time().timeIndex())
184  {
185  motion_.newTime();
186  curTimeIndex_ = this->db().time().timeIndex();
187  firstIter = true;
188  }
189 
191 
192  if (db().foundObject<uniformDimensionedVectorField>("g"))
193  {
194  g = db().lookupObject<uniformDimensionedVectorField>("g");
195  }
196  else if (coeffDict().found("g"))
197  {
198  coeffDict().lookup("g") >> g;
199  }
200 
201  // scalar ramp = min(max((this->db().time().value() - 5)/10, 0), 1);
202  scalar ramp = 1.0;
203 
204  if (test_)
205  {
206  motion_.update
207  (
208  firstIter,
209  ramp*(motion_.mass()*g.value()),
210  ramp*(motion_.mass()*(motion_.momentArm() ^ g.value())),
211  t.deltaTValue(),
212  t.deltaT0Value()
213  );
214  }
215  else
216  {
217  dictionary forcesDict;
218 
219  forcesDict.add("type", forces::typeName);
220  forcesDict.add("patches", patches_);
221  forcesDict.add("rhoInf", rhoInf_);
222  forcesDict.add("rhoName", rhoName_);
223  forcesDict.add("CofR", motion_.centreOfRotation());
224 
225  forces f("forces", db(), forcesDict);
226 
227  f.calcForcesMoment();
228 
229  motion_.update
230  (
231  firstIter,
232  ramp*(f.forceEff() + motion_.mass()*g.value()),
233  ramp
234  *(
235  f.momentEff()
236  + motion_.mass()*(motion_.momentArm() ^ g.value())
237  ),
238  t.deltaTValue(),
239  t.deltaT0Value()
240  );
241  }
242 
243  // Update the displacements
244  pointDisplacement_.internalField() =
245  motion_.transform(points0(), scale_) - points0();
246 
247  // Displacement has changed. Update boundary conditions
249  (
250  pointDisplacement_.mesh()
251  ).constrainDisplacement(pointDisplacement_);
252 }
253 
254 
256 (
260 ) const
261 {
263  (
264  IOobject
265  (
266  "sixDoFRigidBodyMotionState",
267  mesh().time().timeName(),
268  "uniform",
269  mesh(),
272  false
273  )
274  );
275 
276  motion_.state().write(dict);
277  return dict.regIOobject::write();
278 }
279 
280 
282 {
284  {
285  motion_.read(coeffDict());
286 
287  return true;
288  }
289  else
290  {
291  return false;
292  }
293 }
294 
295 
296 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
mathematicalConstants.H
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
sixDoFRigidBodyMotionSolver.H
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::IOstream::compressionType
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
Foam::TimeState::deltaT0Value
scalar deltaT0Value() const
Return old time step value.
Definition: TimeState.H:106
Foam::wordReList
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
g
const dimensionedVector & g
Definition: setRegionFluidFields.H:33
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:261
Foam::pointConstraints::constrainDisplacement
void constrainDisplacement(pointVectorField &displacement, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints),.
Definition: pointConstraints.C:369
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::MeshObject< pointMesh, UpdateableMeshObject, pointConstraints >::New
static const pointConstraints & New(const pointMesh &mesh)
Definition: MeshObject.C:44
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::sixDoFRigidBodyMotionSolver::solve
virtual void solve()
Solve for motion.
Definition: sixDoFRigidBodyMotionSolver.C:168
Foam::IOobject::headerOk
bool headerOk()
Read and check header info.
Definition: IOobject.C:439
Foam::IOstream::versionNumber
Version number type.
Definition: IOstream.H:96
Foam::primitiveMesh::nPoints
label nPoints() const
Definition: primitiveMeshI.H:35
Foam::UniformDimensionedField< vector >
Foam::sixDoFRigidBodyMotionSolver::curPoints
virtual tmp< pointField > curPoints() const
Return point location obtained from the current motion field.
Definition: sixDoFRigidBodyMotionSolver.C:162
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
pointConstraints.H
Foam::GeometricField::internalField
InternalField & internalField()
Return internal field.
Definition: GeometricField.C:724
Foam::TimeState::deltaTValue
scalar deltaTValue() const
Return time step value.
Definition: TimeState.H:100
Foam::motionSolver::read
virtual bool read()
Read dynamicMeshDict dictionary.
Definition: motionSolver.C:189
timeIndex
label timeIndex
Definition: getTimeIndex.H:4
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::displacementMotionSolver
Virtual base class for displacement motion solver.
Definition: displacementMotionSolver.H:55
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
pointPatchDist.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
readScalar
#define readScalar
Definition: doubleScalar.C:38
Foam::dimAcceleration
const dimensionSet dimAcceleration
Foam::forces
This function object calculates the forces and moments by integrating the pressure and skin-friction ...
Definition: forces.H:234
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::pointPatchDist
Calculation of distance to nearest patch for all points.
Definition: pointPatchDist.H:50
uniformDimensionedFields.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
forces.H
Foam::sixDoFRigidBodyMotionSolver::~sixDoFRigidBodyMotionSolver
~sixDoFRigidBodyMotionSolver()
Destructor.
Definition: sixDoFRigidBodyMotionSolver.C:155
f
labelList f(nPoints)
Foam::sixDoFRigidBodyMotionSolver::sixDoFRigidBodyMotionSolver
sixDoFRigidBodyMotionSolver(const sixDoFRigidBodyMotionSolver &)
Disallow default bitwise copy construct.
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::constant::mathematical::pi
const scalar pi(M_PI)
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::sixDoFRigidBodyMotionSolver::read
virtual bool read()
Read dynamicMeshDict dictionary.
Definition: sixDoFRigidBodyMotionSolver.C:281
Foam::sixDoFRigidBodyMotionSolver::writeObject
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write state using given format, version and compression.
Definition: sixDoFRigidBodyMotionSolver.C:256
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729
lookup
stressControl lookup("compactNormalStress") >> compactNormalStress
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:256
Foam::IOstream::streamFormat
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86