sixDoFMotion: Adding restraints and constraints to the motion of objects.
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyMotion / sixDoFRigidBodyMotionConstraint / fixedAxis / fixedAxis.C
blob5d9d4800d93eb445106e755bb63b79b8ac5ad8d8
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 * * * * * * * * * * * * * //
33 namespace Foam
35 namespace sixDoFRigidBodyMotionConstraints
37     defineTypeNameAndDebug(fixedAxis, 0);
38     addToRunTimeSelectionTable
39     (
40         sixDoFRigidBodyMotionConstraint,
41         fixedAxis,
42         dictionary
43     );
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::fixedAxis
52     const dictionary& sDoFRBMCDict
55     sixDoFRigidBodyMotionConstraint(sDoFRBMCDict),
56     fixedAxis_()
58     read(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,
75     scalar deltaT,
76     vector& constraintPosition,
77     vector& constraintForceIncrement,
78     vector& constraintMomentIncrement
79 ) const
81     constraintMomentIncrement = vector::zero;
83     vector predictedDir = motion.predictedOrientation
84     (
85         fixedAxis_,
86         existingConstraintMoment,
87         deltaT
88     );
90     scalar theta = acos(min(predictedDir & fixedAxis_, 1.0));
92     vector rotationAxis = fixedAxis_ ^ predictedDir;
94     scalar magRotationAxis = mag(rotationAxis);
96     if (magRotationAxis > VSMALL)
97     {
98         rotationAxis /= magRotationAxis;
100         const tensor& Q = motion.orientation();
102         // Transform rotationAxis to body local system
103         rotationAxis = Q.T() & rotationAxis;
105         constraintMomentIncrement =
106            -relaxationFactor_
107            *(motion.momentOfInertia() & rotationAxis)
108            *theta/sqr(deltaT);
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_;
116     }
118     constraintPosition = motion.centreOfMass();
120     constraintForceIncrement = vector::zero;
122     bool converged(mag(theta) < tolerance_);
124     if (motion.report())
125     {
126         Info<< " angle " << theta
127             << " force " << constraintForceIncrement
128             << " moment " << constraintMomentIncrement;
130         if (converged)
131         {
132             Info<< " converged";
133         }
134         else
135         {
136             Info<< " not converged";
137         }
139         Info<< endl;
140     }
142     return 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)
158     {
159         fixedAxis_ /= magFixedAxis;
160     }
161     else
162     {
163         FatalErrorIn
164         (
165             "Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::read"
166             "("
167                 "const dictionary& sDoFRBMCDict"
168             ")"
169         )
170             << "axis has zero length"
171             << abort(FatalError);
172     }
174     return true;
178 void Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::write
180     Ostream& os
181 ) const
183     os.writeKeyword("axis")
184         << fixedAxis_ << token::END_STATEMENT << nl;
187 // ************************************************************************* //