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  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "pointPatchFields.H"
32 #include "Time.H"
33 #include "fvMesh.H"
34 #include "volFields.H"
36 #include "forces.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
47 (
48  const pointPatch& p,
50 )
51 :
53  motion_(db().time()),
54  initialPoints_(p.localPoints()),
55  rhoInf_(1.0),
56  rhoName_("rho"),
57  lookupGravity_(-1),
58  g_(Zero),
59  curTimeIndex_(-1)
60 {}
61 
62 
65 (
66  const pointPatch& p,
68  const dictionary& dict
69 )
70 :
72  motion_(dict, dict, db().time()),
73  rhoInf_(1.0),
74  rhoName_(dict.getOrDefault<word>("rho", "rho")),
75  lookupGravity_(-1),
76  g_(Zero),
77  curTimeIndex_(-1)
78 {
79  if (rhoName_ == "rhoInf")
80  {
81  dict.readEntry("rhoInf", rhoInf_);
82  }
83 
84  if (dict.readIfPresent("g", g_))
85  {
86  lookupGravity_ = -2;
87  }
88 
89  if (!dict.found("value"))
90  {
91  updateCoeffs();
92  }
93 
94  if (dict.found("initialPoints"))
95  {
96  initialPoints_ = vectorField("initialPoints", dict , p.size());
97  }
98  else
99  {
100  initialPoints_ = p.localPoints();
101  }
102 }
103 
104 
107 (
108  const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
109  const pointPatch& p,
110  const DimensionedField<vector, pointMesh>& iF,
111  const pointPatchFieldMapper& mapper
112 )
113 :
114  fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
115  motion_(ptf.motion_),
116  initialPoints_(ptf.initialPoints_, mapper),
117  rhoInf_(ptf.rhoInf_),
118  rhoName_(ptf.rhoName_),
119  lookupGravity_(ptf.lookupGravity_),
120  g_(ptf.g_),
121  curTimeIndex_(-1)
122 {}
123 
124 
127 (
130 )
131 :
133  motion_(ptf.motion_),
134  initialPoints_(ptf.initialPoints_),
135  rhoInf_(ptf.rhoInf_),
136  rhoName_(ptf.rhoName_),
137  lookupGravity_(ptf.lookupGravity_),
138  g_(ptf.g_),
139  curTimeIndex_(-1)
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
146 (
147  const pointPatchFieldMapper& m
148 )
149 {
151 
152  initialPoints_.autoMap(m);
153 }
154 
155 
157 (
158  const pointPatchField<vector>& ptf,
159  const labelList& addr
160 )
161 {
163  refCast<const sixDoFRigidBodyDisplacementPointPatchVectorField>(ptf);
164 
166 
167  initialPoints_.rmap(sDoFptf.initialPoints_, addr);
168 }
169 
170 
172 {
173  if (this->updated())
174  {
175  return;
176  }
177 
178  if (lookupGravity_ < 0)
179  {
180  if (db().time().foundObject<uniformDimensionedVectorField>("g"))
181  {
182  if (lookupGravity_ == -2)
183  {
185  << "Specifying the value of g in this boundary condition "
186  << "when g is available from the database is considered "
187  << "a fatal error to avoid the possibility of inconsistency"
188  << exit(FatalError);
189  }
190  else
191  {
192  lookupGravity_ = 1;
193  }
194  }
195  else
196  {
197  lookupGravity_ = 0;
198  }
199  }
200 
201  const polyMesh& mesh = this->internalField().mesh()();
202  const Time& t = mesh.time();
203  const pointPatch& ptPatch = this->patch();
204 
205  // Store the motion state at the beginning of the time-step
206  bool firstIter = false;
207  if (curTimeIndex_ != t.timeIndex())
208  {
209  motion_.newTime();
210  curTimeIndex_ = t.timeIndex();
211  firstIter = true;
212  }
213 
214  dictionary forcesDict;
215 
216  forcesDict.add("type", functionObjects::forces::typeName);
217  forcesDict.add("patches", wordList(1, ptPatch.name()));
218  forcesDict.add("rhoInf", rhoInf_);
219  forcesDict.add("rho", rhoName_);
220  forcesDict.add("CofR", motion_.centreOfRotation());
221 
222  functionObjects::forces f("forces", db(), forcesDict);
223 
224  f.calcForcesMoment();
225 
226  // Get the forces on the patch faces at the current positions
227 
228  if (lookupGravity_ == 1)
229  {
232 
233  g_ = g.value();
234  }
235 
236  // scalar ramp = min(max((t.value() - 5)/10, 0), 1);
237  scalar ramp = 1.0;
238 
239  motion_.update
240  (
241  firstIter,
242  ramp*(f.forceEff() + motion_.mass()*g_),
243  ramp*(f.momentEff() + motion_.mass()*(motion_.momentArm() ^ g_)),
244  t.deltaTValue(),
245  t.deltaT0Value()
246  );
247 
249  (
250  motion_.transform(initialPoints_) - initialPoints_
251  );
252 
254 }
255 
256 
258 {
260 
261  os.writeEntry("rho", rhoName_);
262 
263  if (rhoName_ == "rhoInf")
264  {
265  os.writeEntry("rhoInf", rhoInf_);
266  }
267 
268  if (lookupGravity_ == 0 || lookupGravity_ == -2)
269  {
270  os.writeEntry("g", g_);
271  }
272 
273  motion_.write(os);
274 
275  initialPoints_.writeEntry("initialPoints", os);
276 
277  writeEntry("value", os);
278 }
279 
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
284 (
286  sixDoFRigidBodyDisplacementPointPatchVectorField
287 );
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 } // End namespace Foam
292 
293 // ************************************************************************* //
volFields.H
Foam::sixDoFRigidBodyMotion::newTime
void newTime()
Definition: sixDoFRigidBodyMotionI.H:272
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:69
Foam::sixDoFRigidBodyMotion::mass
scalar mass() const
Definition: sixDoFRigidBodyMotionI.H:204
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::functionObjects::forces
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:232
Foam::Field::autoMap
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Definition: Field.C:396
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryI.H:80
Foam::Field< vector >::operator
friend Ostream & operator(Ostream &, const Field< Type > &)
Foam::pointPatchField< vector >::db
const objectRegistry & db() const
Definition: pointPatchField.C:103
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:54
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs
virtual void updateCoeffs()
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:164
Foam::pointPatchField< vector >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
Foam::pointPatchField< vector >::patch
const pointPatch & patch() const
Definition: pointPatchField.H:264
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:42
Foam::TimeState::deltaTValue
scalar deltaTValue() const noexcept
Definition: TimeStateI.H:36
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:48
Foam::sixDoFRigidBodyMotion::write
void write(Ostream &) const
Definition: sixDoFRigidBodyMotionIO.C:46
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:58
Foam::TimeState::deltaT0Value
scalar deltaT0Value() const noexcept
Definition: TimeStateI.H:42
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:47
Foam::sixDoFRigidBodyMotion::update
void update(bool firstIter, const vector &fGlobal, const vector &tauGlobal, scalar deltaT, scalar deltaT0)
Definition: sixDoFRigidBodyMotion.C:301
Foam::TimeState::timeIndex
label timeIndex() const noexcept
Definition: TimeStateI.H:30
Foam::fixedValuePointPatchField< vector >
Foam::UniformDimensionedField< vector >
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::autoMap
virtual void autoMap(const pointPatchFieldMapper &)
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:139
Foam::makePointPatchTypeField
makePointPatchTypeField(pointPatchVectorField, solidBodyMotionDisplacementPointPatchVectorField)
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::valuePointPatchField::updateCoeffs
virtual void updateCoeffs()
Definition: valuePointPatchField.C:128
Foam::pointPatchField< vector >::internalField
const DimensionedField< Type, pointMesh > & internalField() const
Definition: pointPatchField.H:271
Foam::pointPatchField::write
virtual void write(Ostream &) const
Definition: pointPatchField.C:110
Foam::uniformDimensionedVectorField
UniformDimensionedField< vector > uniformDimensionedVectorField
Definition: uniformDimensionedFields.H:46
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:295
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:427
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Field::rmap
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
Definition: Field.C:459
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:119
os
OBJstream os(runTime.globalPath()/outputName)
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:26
Foam
Definition: atmBoundaryLayer.C:26
Foam::pointPatch::name
virtual const word & name() const =0
Foam::valuePointPatchField::autoMap
virtual void autoMap(const pointPatchFieldMapper &)
Definition: valuePointPatchField.C:101
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:47
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
Foam::pointPatchField< vector >::updated
bool updated() const
Definition: pointPatchField.H:307
Foam::Field::writeEntry
void writeEntry(const word &keyword, Ostream &os) const
Definition: Field.C:601
Time.H
uniformDimensionedFields.H
FatalErrorInFunction
#define FatalErrorInFunction
Definition: error.H:465
forces.H
sixDoFRigidBodyDisplacementPointPatchVectorField.H
Foam::sixDoFRigidBodyMotion::transform
point transform(const point &initialPoints) const
Definition: sixDoFRigidBodyMotionI.H:294
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
Foam::valuePointPatchField::rmap
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Definition: valuePointPatchField.C:111
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::rmap
virtual void rmap(const pointPatchField< vector > &, const labelList &)
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:150
pointPatchFields.H
Foam::sixDoFRigidBodyMotion::momentArm
vector momentArm() const
Definition: sixDoFRigidBodyMotionI.H:243
Foam::pointPatchVectorField
pointPatchField< vector > pointPatchVectorField
Definition: pointPatchFieldsFwd.H:36
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Definition: dictionary.C:633
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
Foam::sixDoFRigidBodyMotion::centreOfRotation
const point & centreOfRotation() const
Definition: sixDoFRigidBodyMotionI.H:224
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:141
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::write
virtual void write(Ostream &) const
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:250
Foam::objectRegistry::time
const Time & time() const noexcept
Definition: objectRegistry.H:174
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:398
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:50
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::sixDoFRigidBodyDisplacementPointPatchVectorField
sixDoFRigidBodyDisplacementPointPatchVectorField(const pointPatch &, const DimensionedField< vector, pointMesh > &)
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:40