FreeFOAM The Cross-Platform CFD Toolkit
fixedAxis.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 
26 #include "fixedAxis.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sixDoFRigidBodyMotionConstraints
35 {
38  (
40  fixedAxis,
42  );
43 };
44 };
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const dictionary& sDoFRBMCDict
52 )
53 :
54  sixDoFRigidBodyMotionConstraint(sDoFRBMCDict),
55  fixedAxis_()
56 {
57  read(sDoFRBMCDict);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
62 
64 {}
65 
66 
67 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
68 
70 (
71  const sixDoFRigidBodyMotion& motion,
72  const vector& existingConstraintForce,
73  const vector& existingConstraintMoment,
74  scalar deltaT,
75  vector& constraintPosition,
76  vector& constraintForceIncrement,
77  vector& constraintMomentIncrement
78 ) const
79 {
80  constraintMomentIncrement = vector::zero;
81 
82  vector predictedDir = motion.predictedOrientation
83  (
84  fixedAxis_,
85  existingConstraintMoment,
86  deltaT
87  );
88 
89  scalar theta = acos(min(predictedDir & fixedAxis_, 1.0));
90 
91  vector rotationAxis = fixedAxis_ ^ predictedDir;
92 
93  scalar magRotationAxis = mag(rotationAxis);
94 
95  if (magRotationAxis > VSMALL)
96  {
97  rotationAxis /= magRotationAxis;
98 
99  const tensor& Q = motion.orientation();
100 
101  // Transform rotationAxis to body local system
102  rotationAxis = Q.T() & rotationAxis;
103 
104  constraintMomentIncrement =
105  -relaxationFactor_
106  *(motion.momentOfInertia() & rotationAxis)
107  *theta/sqr(deltaT);
108 
109  // Transform moment increment to global system
110  constraintMomentIncrement = Q & constraintMomentIncrement;
111 
112  // Remove any moment that is around the fixedAxis_
113  constraintMomentIncrement -=
114  (constraintMomentIncrement & fixedAxis_)*fixedAxis_;
115  }
116 
117  constraintPosition = motion.centreOfMass();
118 
119  constraintForceIncrement = vector::zero;
120 
121  bool converged(mag(theta) < tolerance_);
122 
123  if (sixDoFRigidBodyMotionConstraint::debug)
124  {
125  Info<< " angle " << theta
126  << " force " << constraintForceIncrement
127  << " moment " << constraintMomentIncrement;
128 
129  if (converged)
130  {
131  Info<< " converged";
132  }
133  else
134  {
135  Info<< " not converged";
136  }
137 
138  Info<< endl;
139  }
140 
141  return converged;
142 }
143 
144 
146 (
147  const dictionary& sDoFRBMCDict
148 )
149 {
151 
152  sDoFRBMCCoeffs_.lookup("axis") >> fixedAxis_;
153 
154  scalar magFixedAxis(mag(fixedAxis_));
155 
156  if (magFixedAxis > VSMALL)
157  {
158  fixedAxis_ /= magFixedAxis;
159  }
160  else
161  {
163  (
164  "Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::read"
165  "("
166  "const dictionary& sDoFRBMCDict"
167  ")"
168  )
169  << "axis has zero length"
170  << abort(FatalError);
171  }
172 
173  return true;
174 }
175 
176 
178 (
179  Ostream& os
180 ) const
181 {
182  os.writeKeyword("axis")
183  << fixedAxis_ << token::END_STATEMENT << nl;
184 }
185 
186 // ************************ vim: set sw=4 sts=4 et: ************************ //