sixDoFRigidBodyDisplacementPointPatchVectorField.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "pointPatchFields.H"
31 #include "Time.H"
32 #include "fvMesh.H"
33 #include "volFields.H"
35 #include "forces.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
46 (
47  const pointPatch& p,
49 )
50 :
52  motion_(db().time()),
53  initialPoints_(p.localPoints()),
54  rhoInf_(1.0),
55  rhoName_("rho"),
56  lookupGravity_(-1),
57  g_(Zero),
58  curTimeIndex_(-1)
59 {}
60 
61 
64 (
65  const pointPatch& p,
67  const dictionary& dict
68 )
69 :
71  motion_(dict, dict, db().time()),
72  rhoInf_(1.0),
73  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
74  lookupGravity_(-1),
75  g_(Zero),
76  curTimeIndex_(-1)
77 {
78  if (rhoName_ == "rhoInf")
79  {
80  dict.readEntry("rhoInf", rhoInf_);
81  }
82 
83  if (dict.readIfPresent("g", g_))
84  {
85  lookupGravity_ = -2;
86  }
87 
88  if (!dict.found("value"))
89  {
90  updateCoeffs();
91  }
92 
93  if (dict.found("initialPoints"))
94  {
95  initialPoints_ = vectorField("initialPoints", dict , p.size());
96  }
97  else
98  {
99  initialPoints_ = p.localPoints();
100  }
101 }
102 
103 
106 (
108  const pointPatch& p,
110  const pointPatchFieldMapper& mapper
111 )
112 :
113  fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
114  motion_(ptf.motion_),
115  initialPoints_(ptf.initialPoints_, mapper),
116  rhoInf_(ptf.rhoInf_),
117  rhoName_(ptf.rhoName_),
118  lookupGravity_(ptf.lookupGravity_),
119  g_(ptf.g_),
120  curTimeIndex_(-1)
121 {}
122 
123 
126 (
129 )
130 :
132  motion_(ptf.motion_),
133  initialPoints_(ptf.initialPoints_),
134  rhoInf_(ptf.rhoInf_),
135  rhoName_(ptf.rhoName_),
136  lookupGravity_(ptf.lookupGravity_),
137  g_(ptf.g_),
138  curTimeIndex_(-1)
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
145 (
146  const pointPatchFieldMapper& m
147 )
148 {
150 
151  initialPoints_.autoMap(m);
152 }
153 
154 
156 (
157  const pointPatchField<vector>& ptf,
158  const labelList& addr
159 )
160 {
162  refCast<const sixDoFRigidBodyDisplacementPointPatchVectorField>(ptf);
163 
165 
166  initialPoints_.rmap(sDoFptf.initialPoints_, addr);
167 }
168 
169 
171 {
172  if (this->updated())
173  {
174  return;
175  }
176 
177  if (lookupGravity_ < 0)
178  {
179  if (db().time().foundObject<uniformDimensionedVectorField>("g"))
180  {
181  if (lookupGravity_ == -2)
182  {
184  << "Specifying the value of g in this boundary condition "
185  << "when g is available from the database is considered "
186  << "a fatal error to avoid the possibility of inconsistency"
187  << exit(FatalError);
188  }
189  else
190  {
191  lookupGravity_ = 1;
192  }
193  }
194  else
195  {
196  lookupGravity_ = 0;
197  }
198  }
199 
200  const polyMesh& mesh = this->internalField().mesh()();
201  const Time& t = mesh.time();
202  const pointPatch& ptPatch = this->patch();
203 
204  // Store the motion state at the beginning of the time-step
205  bool firstIter = false;
206  if (curTimeIndex_ != t.timeIndex())
207  {
208  motion_.newTime();
209  curTimeIndex_ = t.timeIndex();
210  firstIter = true;
211  }
212 
213  dictionary forcesDict;
214 
215  forcesDict.add("type", functionObjects::forces::typeName);
216  forcesDict.add("patches", wordList(1, ptPatch.name()));
217  forcesDict.add("rhoInf", rhoInf_);
218  forcesDict.add("rho", rhoName_);
219  forcesDict.add("CofR", motion_.centreOfRotation());
220 
221  functionObjects::forces f("forces", db(), forcesDict);
222 
223  f.calcForcesMoment();
224 
225  // Get the forces on the patch faces at the current positions
226 
227  if (lookupGravity_ == 1)
228  {
231 
232  g_ = g.value();
233  }
234 
235  // scalar ramp = min(max((t.value() - 5)/10, 0), 1);
236  scalar ramp = 1.0;
237 
238  motion_.update
239  (
240  firstIter,
241  ramp*(f.forceEff() + motion_.mass()*g_),
242  ramp*(f.momentEff() + motion_.mass()*(motion_.momentArm() ^ g_)),
243  t.deltaTValue(),
244  t.deltaT0Value()
245  );
246 
248  (
249  motion_.transform(initialPoints_) - initialPoints_
250  );
251 
253 }
254 
255 
257 {
259 
260  os.writeEntry("rho", rhoName_);
261 
262  if (rhoName_ == "rhoInf")
263  {
264  os.writeEntry("rhoInf", rhoInf_);
265  }
266 
267  if (lookupGravity_ == 0 || lookupGravity_ == -2)
268  {
269  os.writeEntry("g", g_);
270  }
271 
272  motion_.write(os);
273 
274  initialPoints_.writeEntry("initialPoints", os);
275 
276  writeEntry("value", os);
277 }
278 
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
283 (
286 );
287 
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 
290 } // End namespace Foam
291 
292 // ************************************************************************* //
volFields.H
Foam::sixDoFRigidBodyMotion::newTime
void newTime()
Store the motion state at the beginning of the time-step.
Definition: sixDoFRigidBodyMotionI.H:279
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::sixDoFRigidBodyMotion::mass
scalar mass() const
Return the mass.
Definition: sixDoFRigidBodyMotionI.H:211
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::forces
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:236
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionary.C:359
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
Foam::pointPatchField< vector >::db
const objectRegistry & db() const
Return local objectRegistry.
Definition: pointPatchField.C:109
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:58
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.H:1241
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:170
Foam::pointPatchField< vector >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::pointPatchField< vector >::patch
const pointPatch & patch() const
Return patch.
Definition: pointPatchField.H:268
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:48
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::sixDoFRigidBodyMotion::write
void write(Ostream &) const
Write.
Definition: sixDoFRigidBodyMotionIO.C:52
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:51
Foam::sixDoFRigidBodyMotion::update
void update(bool firstIter, const vector &fGlobal, const vector &tauGlobal, scalar deltaT, scalar deltaT0)
Symplectic integration of velocities, orientation and position.
Definition: sixDoFRigidBodyMotion.C:308
Foam::sixDoFRigidBodyMotion::centreOfRotation
const point & centreOfRotation() const
Return the current centre of rotation.
Definition: sixDoFRigidBodyMotionI.H:231
Foam::fixedValuePointPatchField< vector >
Foam::UniformDimensionedField< vector >
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::autoMap
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:145
Foam::makePointPatchTypeField
makePointPatchTypeField(pointPatchVectorField, solidBodyMotionDisplacementPointPatchVectorField)
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::valuePointPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: valuePointPatchField.C:135
Foam::pointPatchField< vector >::internalField
const DimensionedField< vector, pointMesh > & internalField() const
Return dimensioned internal field reference.
Definition: pointPatchField.H:275
Foam::pointPatchField::write
virtual void write(Ostream &) const
Write.
Definition: pointPatchField.C:116
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
fvMesh.H
g
const uniformDimensionedVectorField & g
Definition: createFluidFields.H:24
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointPatch::name
virtual const word & name() const =0
Return name.
Foam::valuePointPatchField::autoMap
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: valuePointPatchField.C:108
Foam::TimeState::deltaT0Value
scalar deltaT0Value() const
Return old time step value.
Definition: TimeStateI.H:48
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::pointPatchField< vector >::updated
bool updated() const
Return true if the boundary condition has already been updated.
Definition: pointPatchField.H:311
Foam::Field::writeEntry
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:631
Time.H
uniformDimensionedFields.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
forces.H
sixDoFRigidBodyDisplacementPointPatchVectorField.H
Foam::sixDoFRigidBodyMotion::transform
point transform(const point &initialPoints) const
Transform the given initial state point by the current motion.
Definition: sixDoFRigidBodyMotionI.H:301
f
labelList f(nPoints)
Foam::TimeState::deltaTValue
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:42
Foam::List< label >
Foam::valuePointPatchField::rmap
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given PointPatchField onto.
Definition: valuePointPatchField.C:118
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::rmap
virtual void rmap(const pointPatchField< vector > &, const labelList &)
Reverse map the given pointPatchField onto this pointPatchField.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:156
pointPatchFields.H
Foam::sixDoFRigidBodyMotion::momentArm
vector momentArm() const
Return the current momentArm.
Definition: sixDoFRigidBodyMotionI.H:250
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:219
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:703
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::TimeState::timeIndex
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:36
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::write
virtual void write(Ostream &) const
Write.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:256
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::sixDoFRigidBodyDisplacementPointPatchVectorField
sixDoFRigidBodyDisplacementPointPatchVectorField(const pointPatch &, const DimensionedField< vector, pointMesh > &)
Construct from patch and internal field.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:46