FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 
29 #include <OpenFOAM/Time.H>
30 #include <finiteVolume/fvMesh.H>
31 #include <finiteVolume/volFields.H>
33 #include <forces/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 {}
57 
58 
61 (
62  const pointPatch& p,
64  const dictionary& dict
65 )
66 :
68  motion_(dict),
69  rhoInf_(1.0),
70  rhoName_(dict.lookupOrDefault<word>("rhoName", "rho")),
71  lookupGravity_(-1),
72  g_(vector::zero)
73 {
74  if (rhoName_ == "rhoInf")
75  {
76  rhoInf_ = readScalar(dict.lookup("rhoInf"));
77  }
78 
79  if (dict.found("g"))
80  {
81  lookupGravity_ = -2;
82 
83  g_ = dict.lookup("g");
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 {}
119 
120 
123 (
126 )
127 :
129  motion_(ptf.motion_),
130  initialPoints_(ptf.initialPoints_),
131  rhoInf_(ptf.rhoInf_),
132  rhoName_(ptf.rhoName_),
133  lookupGravity_(ptf.lookupGravity_),
134  g_(ptf.g_)
135 {}
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
141 (
142  const pointPatchFieldMapper& m
143 )
144 {
146 
147  initialPoints_.autoMap(m);
148 }
149 
150 
152 (
153  const pointPatchField<vector>& ptf,
154  const labelList& addr
155 )
156 {
158  refCast<const sixDoFRigidBodyDisplacementPointPatchVectorField>(ptf);
159 
161 
162  initialPoints_.rmap(sDoFptf.initialPoints_, addr);
163 }
164 
165 
167 {
168  if (this->updated())
169  {
170  return;
171  }
172 
173  if (lookupGravity_ < 0)
174  {
175  if (db().foundObject<uniformDimensionedVectorField>("g"))
176  {
177  if (lookupGravity_ == -2)
178  {
180  (
181  "void sixDoFRigidBodyDisplacementPointPatchVectorField"
182  "::updateCoeffs()"
183  )
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->dimensionedInternalField().mesh()();
201  const Time& t = mesh.time();
202  const pointPatch& ptPatch = this->patch();
203 
204  // Patch force data is valid for the current positions, so
205  // calculate the forces on the motion object from this data, then
206  // update the positions
207 
208  motion_.updatePosition(t.deltaTValue(), t.deltaT0Value());
209 
210  dictionary forcesDict;
211 
212  forcesDict.add("patches", wordList(1, ptPatch.name()));
213  forcesDict.add("rhoInf", rhoInf_);
214  forcesDict.add("rhoName", rhoName_);
215  forcesDict.add("CofR", motion_.centreOfMass());
216 
217  forces f("forces", db(), forcesDict);
218 
220 
221  // Get the forces on the patch faces at the current positions
222 
223  if (lookupGravity_ == 1)
224  {
227 
228  g_ = g.value();
229  }
230 
231  motion_.updateForce
232  (
233  fm.first().first() + fm.first().second() + g_*motion_.mass(),
234  fm.second().first() + fm.second().second(),
235  t.deltaTValue()
236  );
237 
239  (
240  motion_.currentPosition(initialPoints_) - initialPoints_
241  );
242 
244 }
245 
246 
248 {
250 
251  os.writeKeyword("rhoInf") << rhoInf_ << token::END_STATEMENT << nl;
252 
253  os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl;
254 
255  if (lookupGravity_ == 0 || lookupGravity_ == -2)
256  {
257  os.writeKeyword("g") << g_ << token::END_STATEMENT << nl;
258  }
259 
260  motion_.write(os);
261 
262  initialPoints_.writeEntry("initialPoints", os);
263 
264  writeEntry("value", os);
265 }
266 
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
271 (
274 );
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 } // End namespace Foam
279 
280 // ************************************************************************* //