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 | Copyright (C) 2011-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 
27 #include "pointPatchFields.H"
29 #include "Time.H"
30 #include "fvMesh.H"
31 #include "volFields.H"
33 #include "forces.H"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
44 (
45  const pointPatch& p,
47 )
48 :
50  motion_(),
51  initialPoints_(p.localPoints()),
52  rhoInf_(1.0),
53  rhoName_("rho"),
54  lookupGravity_(-1),
55  g_(vector::zero),
56  curTimeIndex_(-1)
57 {}
58 
59 
62 (
63  const pointPatch& p,
65  const dictionary& dict
66 )
67 :
69  motion_(dict, dict),
70  rhoInf_(1.0),
71  rhoName_(dict.lookupOrDefault<word>("rhoName", "rho")),
72  lookupGravity_(-1),
73  g_(vector::zero),
74  curTimeIndex_(-1)
75 {
76  if (rhoName_ == "rhoInf")
77  {
78  rhoInf_ = readScalar(dict.lookup("rhoInf"));
79  }
80 
81  if (dict.readIfPresent("g", g_))
82  {
83  lookupGravity_ = -2;
84  }
85 
86  if (!dict.found("value"))
87  {
88  updateCoeffs();
89  }
90 
91  if (dict.found("initialPoints"))
92  {
93  initialPoints_ = vectorField("initialPoints", dict , p.size());
94  }
95  else
96  {
97  initialPoints_ = p.localPoints();
98  }
99 }
100 
101 
104 (
106  const pointPatch& p,
108  const pointPatchFieldMapper& mapper
109 )
110 :
111  fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
112  motion_(ptf.motion_),
113  initialPoints_(ptf.initialPoints_, mapper),
114  rhoInf_(ptf.rhoInf_),
115  rhoName_(ptf.rhoName_),
116  lookupGravity_(ptf.lookupGravity_),
117  g_(ptf.g_),
118  curTimeIndex_(-1)
119 {}
120 
121 
124 (
127 )
128 :
130  motion_(ptf.motion_),
131  initialPoints_(ptf.initialPoints_),
132  rhoInf_(ptf.rhoInf_),
133  rhoName_(ptf.rhoName_),
134  lookupGravity_(ptf.lookupGravity_),
135  g_(ptf.g_),
136  curTimeIndex_(-1)
137 {}
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
143 (
144  const pointPatchFieldMapper& m
145 )
146 {
148 
149  initialPoints_.autoMap(m);
150 }
151 
152 
154 (
155  const pointPatchField<vector>& ptf,
156  const labelList& addr
157 )
158 {
160  refCast<const sixDoFRigidBodyDisplacementPointPatchVectorField>(ptf);
161 
163 
164  initialPoints_.rmap(sDoFptf.initialPoints_, addr);
165 }
166 
167 
169 {
170  if (this->updated())
171  {
172  return;
173  }
174 
175  if (lookupGravity_ < 0)
176  {
177  if (db().foundObject<uniformDimensionedVectorField>("g"))
178  {
179  if (lookupGravity_ == -2)
180  {
182  << "Specifying the value of g in this boundary condition "
183  << "when g is available from the database is considered "
184  << "a fatal error to avoid the possibility of inconsistency"
185  << exit(FatalError);
186  }
187  else
188  {
189  lookupGravity_ = 1;
190  }
191  }
192  else
193  {
194  lookupGravity_ = 0;
195  }
196  }
197 
198  const polyMesh& mesh = this->dimensionedInternalField().mesh()();
199  const Time& t = mesh.time();
200  const pointPatch& ptPatch = this->patch();
201 
202  // Store the motion state at the beginning of the time-step
203  bool firstIter = false;
204  if (curTimeIndex_ != t.timeIndex())
205  {
206  motion_.newTime();
207  curTimeIndex_ = t.timeIndex();
208  firstIter = true;
209  }
210 
211  dictionary forcesDict;
212 
213  forcesDict.add("type", forces::typeName);
214  forcesDict.add("patches", wordList(1, ptPatch.name()));
215  forcesDict.add("rhoInf", rhoInf_);
216  forcesDict.add("rhoName", rhoName_);
217  forcesDict.add("CofR", motion_.centreOfRotation());
218 
219  forces f("forces", db(), forcesDict);
220 
221  f.calcForcesMoment();
222 
223  // Get the forces on the patch faces at the current positions
224 
225  if (lookupGravity_ == 1)
226  {
229 
230  g_ = g.value();
231  }
232 
233  // scalar ramp = min(max((t.value() - 5)/10, 0), 1);
234  scalar ramp = 1.0;
235 
237  (
238  firstIter,
239  ramp*(f.forceEff() + motion_.mass()*g_),
240  ramp*(f.momentEff() + motion_.mass()*(motion_.momentArm() ^ g_)),
241  t.deltaTValue(),
242  t.deltaT0Value()
243  );
244 
246  (
248  );
249 
251 }
252 
253 
255 {
257 
258  os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl;
259 
260  if (rhoName_ == "rhoInf")
261  {
262  os.writeKeyword("rhoInf") << rhoInf_ << token::END_STATEMENT << nl;
263  }
264 
265  if (lookupGravity_ == 0 || lookupGravity_ == -2)
266  {
267  os.writeKeyword("g") << g_ << token::END_STATEMENT << nl;
268  }
269 
270  motion_.write(os);
271 
272  initialPoints_.writeEntry("initialPoints", os);
273 
274  writeEntry("value", os);
275 }
276 
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
281 (
284 );
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 } // End namespace Foam
289 
290 // ************************************************************************* //
volFields.H
Foam::sixDoFRigidBodyMotion::newTime
void newTime()
Store the motion state at the beginning of the time-step.
Definition: sixDoFRigidBodyMotionI.H:272
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::sixDoFRigidBodyMotion::mass
scalar mass() const
Return the mass.
Definition: sixDoFRigidBodyMotionI.H:208
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::rhoInf_
scalar rhoInf_
Reference density required by the forces object for.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:63
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::g_
vector g_
Gravity vector to store when not available from the db.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:84
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::motion_
sixDoFRigidBodyMotion motion_
Six dof motion object.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:56
Foam::TimeState::deltaT0Value
scalar deltaT0Value() const
Return old time step value.
Definition: TimeState.H:106
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Definition: dictionaryTemplates.C:33
g
const dimensionedVector & g
Definition: setRegionFluidFields.H:33
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:168
Foam::pointPatchField< vector >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::pointPatchField< vector >::patch
const pointPatch & patch() const
Return patch.
Definition: pointPatchField.H:271
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:46
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:49
Foam::sixDoFRigidBodyMotion::write
void write(Ostream &) const
Write.
Definition: sixDoFRigidBodyMotionIO.C:49
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:54
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:49
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:298
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:143
Foam::makePointPatchTypeField
makePointPatchTypeField(pointPatchVectorField, solidBodyMotionDisplacementPointPatchVectorField)
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::valuePointPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: valuePointPatchField.C:150
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::pointPatchField::write
virtual void write(Ostream &) const
Write.
Definition: pointPatchField.C:119
Foam::TimeState::deltaTValue
scalar deltaTValue() const
Return time step value.
Definition: TimeState.H:100
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
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::pointPatch::name
virtual const word & name() const =0
Return name.
Foam::pointPatchField< vector >::db
const objectRegistry & db() const
Return local objectRegistry.
Definition: pointPatchField.C:112
Foam::valuePointPatchField::autoMap
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: valuePointPatchField.C:123
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::pointPatchField< vector >::updated
bool updated() const
Return true if the boundary condition has already been updated.
Definition: pointPatchField.H:314
Foam::Field::writeEntry
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:700
Foam::forces
This function object calculates the forces and moments by integrating the pressure and skin-friction ...
Definition: forces.H:234
uniformDimensionedFields.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
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:294
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
f
labelList f(nPoints)
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::curTimeIndex_
label curTimeIndex_
Current time index (used for updating)
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:87
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::initialPoints_
pointField initialPoints_
Initial positions of points on the patch.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:59
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::valuePointPatchField::rmap
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given PointPatchField onto.
Definition: valuePointPatchField.C:133
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::rmap
virtual void rmap(const pointPatchField< vector > &, const labelList &)
Reverse map the given pointPatchField onto this pointPatchField.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:154
pointPatchFields.H
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
Foam::sixDoFRigidBodyMotion::momentArm
vector momentArm() const
Definition: sixDoFRigidBodyMotionI.H:247
Foam::pointPatchField< vector >::dimensionedInternalField
const DimensionedField< Type, pointMesh > & dimensionedInternalField() const
Return dimensioned internal field reference.
Definition: pointPatchField.H:278
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::TimeState::timeIndex
label timeIndex() const
Return current time index.
Definition: TimeState.C:73
Foam::sixDoFRigidBodyMotion::centreOfRotation
const point & centreOfRotation() const
Return the current centre of rotation.
Definition: sixDoFRigidBodyMotionI.H:228
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::rhoName_
word rhoName_
Name of density field, optional unless used for an.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:68
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::write
virtual void write(Ostream &) const
Write.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:254
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::lookupGravity_
label lookupGravity_
State of gravity lookup:
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.H:81
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:51
Foam::sixDoFRigidBodyDisplacementPointPatchVectorField::sixDoFRigidBodyDisplacementPointPatchVectorField
sixDoFRigidBodyDisplacementPointPatchVectorField(const pointPatch &, const DimensionedField< vector, pointMesh > &)
Construct from patch and internal field.
Definition: sixDoFRigidBodyDisplacementPointPatchVectorField.C:44