FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

fixedAxis.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "fixedAxis.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <forces/sixDoFRigidBodyMotion.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 namespace sixDoFRigidBodyMotionConstraints
00035 {
00036     defineTypeNameAndDebug(fixedAxis, 0);
00037     addToRunTimeSelectionTable
00038     (
00039         sixDoFRigidBodyMotionConstraint,
00040         fixedAxis,
00041         dictionary
00042     );
00043 };
00044 };
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::fixedAxis
00050 (
00051     const dictionary& sDoFRBMCDict
00052 )
00053 :
00054     sixDoFRigidBodyMotionConstraint(sDoFRBMCDict),
00055     fixedAxis_()
00056 {
00057     read(sDoFRBMCDict);
00058 }
00059 
00060 
00061 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
00062 
00063 Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::~fixedAxis()
00064 {}
00065 
00066 
00067 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00068 
00069 bool Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::constrain
00070 (
00071     const sixDoFRigidBodyMotion& motion,
00072     const vector& existingConstraintForce,
00073     const vector& existingConstraintMoment,
00074     scalar deltaT,
00075     vector& constraintPosition,
00076     vector& constraintForceIncrement,
00077     vector& constraintMomentIncrement
00078 ) const
00079 {
00080     constraintMomentIncrement = vector::zero;
00081 
00082     vector predictedDir = motion.predictedOrientation
00083     (
00084         fixedAxis_,
00085         existingConstraintMoment,
00086         deltaT
00087     );
00088 
00089     scalar theta = acos(min(predictedDir & fixedAxis_, 1.0));
00090 
00091     vector rotationAxis = fixedAxis_ ^ predictedDir;
00092 
00093     scalar magRotationAxis = mag(rotationAxis);
00094 
00095     if (magRotationAxis > VSMALL)
00096     {
00097         rotationAxis /= magRotationAxis;
00098 
00099         const tensor& Q = motion.orientation();
00100 
00101         // Transform rotationAxis to body local system
00102         rotationAxis = Q.T() & rotationAxis;
00103 
00104         constraintMomentIncrement =
00105            -relaxationFactor_
00106            *(motion.momentOfInertia() & rotationAxis)
00107            *theta/sqr(deltaT);
00108 
00109         // Transform moment increment to global system
00110         constraintMomentIncrement = Q & constraintMomentIncrement;
00111 
00112         // Remove any moment that is around the fixedAxis_
00113         constraintMomentIncrement -=
00114             (constraintMomentIncrement & fixedAxis_)*fixedAxis_;
00115     }
00116 
00117     constraintPosition = motion.centreOfMass();
00118 
00119     constraintForceIncrement = vector::zero;
00120 
00121     bool converged(mag(theta) < tolerance_);
00122 
00123     if (sixDoFRigidBodyMotionConstraint::debug)
00124     {
00125         Info<< " angle " << theta
00126             << " force " << constraintForceIncrement
00127             << " moment " << constraintMomentIncrement;
00128 
00129         if (converged)
00130         {
00131             Info<< " converged";
00132         }
00133         else
00134         {
00135             Info<< " not converged";
00136         }
00137 
00138         Info<< endl;
00139     }
00140 
00141     return converged;
00142 }
00143 
00144 
00145 bool Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::read
00146 (
00147     const dictionary& sDoFRBMCDict
00148 )
00149 {
00150     sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
00151 
00152     sDoFRBMCCoeffs_.lookup("axis") >> fixedAxis_;
00153 
00154     scalar magFixedAxis(mag(fixedAxis_));
00155 
00156     if (magFixedAxis > VSMALL)
00157     {
00158         fixedAxis_ /= magFixedAxis;
00159     }
00160     else
00161     {
00162         FatalErrorIn
00163         (
00164             "Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::read"
00165             "("
00166                 "const dictionary& sDoFRBMCDict"
00167             ")"
00168         )
00169             << "axis has zero length"
00170             << abort(FatalError);
00171     }
00172 
00173     return true;
00174 }
00175 
00176 
00177 void Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::write
00178 (
00179     Ostream& os
00180 ) const
00181 {
00182     os.writeKeyword("axis")
00183         << fixedAxis_ << token::END_STATEMENT << nl;
00184 }
00185 
00186 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines