1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "fixedOrientation.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "sixDoFRigidBodyMotion.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace sixDoFRigidBodyMotionConstraints
37 defineTypeNameAndDebug(fixedOrientation, 0);
38 addToRunTimeSelectionTable
40 sixDoFRigidBodyMotionConstraint,
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::fixedOrientation
52 const dictionary& sDoFRBMCDict
55 sixDoFRigidBodyMotionConstraint(sDoFRBMCDict)
61 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
63 Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::~fixedOrientation()
67 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
69 bool Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::constrain
71 const sixDoFRigidBodyMotion& motion,
72 const vector& existingConstraintForce,
73 const vector& existingConstraintMoment,
75 vector& constraintPosition,
76 vector& constraintForceIncrement,
77 vector& constraintMomentIncrement
80 constraintMomentIncrement = vector::zero;
82 scalar maxTheta = -SMALL;
84 for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
86 vector axis = vector::zero;
90 vector refDir = vector::zero;
92 refDir[(cmpt + 1) % 3] = 1;
94 vector predictedDir = motion.predictedOrientation
97 existingConstraintMoment,
101 // Removing any axis component from predictedDir
102 predictedDir -= (axis & predictedDir)*axis;
104 scalar theta = GREAT;
106 scalar magPredictedDir = mag(predictedDir);
108 if (magPredictedDir > VSMALL)
110 predictedDir /= magPredictedDir;
112 theta = acos(min(predictedDir & refDir, 1.0));
114 // Recalculating axis to give correct sign to angle
115 axis = (refDir ^ predictedDir);
117 scalar magAxis = mag(axis);
119 if (magAxis > VSMALL)
129 if (theta > maxTheta)
134 constraintMomentIncrement +=
137 *motion.momentOfInertia()[cmpt]/sqr(deltaT);
140 constraintPosition = motion.centreOfMass();
142 constraintForceIncrement = vector::zero;
144 bool converged(mag(maxTheta) < tolerance_);
148 Info<< " max angle " << maxTheta
149 << " force " << constraintForceIncrement
150 << " moment " << constraintMomentIncrement;
158 Info<< " not converged";
168 bool Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::read
170 const dictionary& sDoFRBMCDict
173 sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
179 void Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::write
186 // ************************************************************************* //