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 "fixedAxis.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "sixDoFRigidBodyMotion.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace sixDoFRigidBodyMotionConstraints
37 defineTypeNameAndDebug(fixedAxis, 0);
38 addToRunTimeSelectionTable
40 sixDoFRigidBodyMotionConstraint,
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::fixedAxis
52 const dictionary& sDoFRBMCDict
55 sixDoFRigidBodyMotionConstraint(sDoFRBMCDict),
62 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
64 Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::~fixedAxis()
68 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
70 bool Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::constrain
72 const sixDoFRigidBodyMotion& motion,
73 const vector& existingConstraintForce,
74 const vector& existingConstraintMoment,
76 vector& constraintPosition,
77 vector& constraintForceIncrement,
78 vector& constraintMomentIncrement
81 constraintMomentIncrement = vector::zero;
83 vector predictedDir = motion.predictedOrientation
86 existingConstraintMoment,
90 scalar theta = acos(min(predictedDir & fixedAxis_, 1.0));
92 vector rotationAxis = fixedAxis_ ^ predictedDir;
94 scalar magRotationAxis = mag(rotationAxis);
96 if (magRotationAxis > VSMALL)
98 rotationAxis /= magRotationAxis;
100 const tensor& Q = motion.orientation();
102 // Transform rotationAxis to body local system
103 rotationAxis = Q.T() & rotationAxis;
105 constraintMomentIncrement =
107 *(motion.momentOfInertia() & rotationAxis)
110 // Transform moment increment to global system
111 constraintMomentIncrement = Q & constraintMomentIncrement;
113 // Remove any moment that is around the fixedAxis_
114 constraintMomentIncrement -=
115 (constraintMomentIncrement & fixedAxis_)*fixedAxis_;
118 constraintPosition = motion.centreOfMass();
120 constraintForceIncrement = vector::zero;
122 bool converged(mag(theta) < tolerance_);
126 Info<< " angle " << theta
127 << " force " << constraintForceIncrement
128 << " moment " << constraintMomentIncrement;
136 Info<< " not converged";
146 bool Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::read
148 const dictionary& sDoFRBMCDict
151 sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
153 sDoFRBMCCoeffs_.lookup("axis") >> fixedAxis_;
155 scalar magFixedAxis(mag(fixedAxis_));
157 if (magFixedAxis > VSMALL)
159 fixedAxis_ /= magFixedAxis;
165 "Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::read"
167 "const dictionary& sDoFRBMCDict"
170 << "axis has zero length"
171 << abort(FatalError);
178 void Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::write
183 os.writeKeyword("axis")
184 << fixedAxis_ << token::END_STATEMENT << nl;
187 // ************************************************************************* //