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

fixedOrientation.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 "fixedOrientation.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(fixedOrientation, 0);
00037     addToRunTimeSelectionTable
00038     (
00039         sixDoFRigidBodyMotionConstraint,
00040         fixedOrientation,
00041         dictionary
00042     );
00043 };
00044 };
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::fixedOrientation
00050 (
00051     const dictionary& sDoFRBMCDict
00052 )
00053 :
00054     sixDoFRigidBodyMotionConstraint(sDoFRBMCDict)
00055 {
00056     read(sDoFRBMCDict);
00057 }
00058 
00059 
00060 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
00061 
00062 Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::~fixedOrientation()
00063 {}
00064 
00065 
00066 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00067 
00068 bool Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::constrain
00069 (
00070     const sixDoFRigidBodyMotion& motion,
00071     const vector& existingConstraintForce,
00072     const vector& existingConstraintMoment,
00073     scalar deltaT,
00074     vector& constraintPosition,
00075     vector& constraintForceIncrement,
00076     vector& constraintMomentIncrement
00077 ) const
00078 {
00079     constraintMomentIncrement = vector::zero;
00080 
00081     scalar maxTheta = -SMALL;
00082 
00083     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00084     {
00085         vector axis = vector::zero;
00086 
00087         axis[cmpt] = 1;
00088 
00089         vector refDir = vector::zero;
00090 
00091         refDir[(cmpt + 1) % 3] = 1;
00092 
00093         vector predictedDir = motion.predictedOrientation
00094         (
00095             refDir,
00096             existingConstraintMoment,
00097             deltaT
00098         );
00099 
00100         // Removing any axis component from predictedDir
00101         predictedDir -= (axis & predictedDir)*axis;
00102 
00103         scalar theta = GREAT;
00104 
00105         scalar magPredictedDir = mag(predictedDir);
00106 
00107         if (magPredictedDir > VSMALL)
00108         {
00109             predictedDir /= magPredictedDir;
00110 
00111             theta = acos(min(predictedDir & refDir, 1.0));
00112 
00113             // Recalculating axis to give correct sign to angle
00114             axis = (refDir ^ predictedDir);
00115 
00116             scalar magAxis = mag(axis);
00117 
00118             if (magAxis > VSMALL)
00119             {
00120                 axis /= magAxis;
00121             }
00122             else
00123             {
00124                 axis = vector::zero;
00125             }
00126         }
00127 
00128         if (theta > maxTheta)
00129         {
00130             maxTheta = theta;
00131         }
00132 
00133         constraintMomentIncrement +=
00134            -relaxationFactor_
00135            *theta*axis
00136            *motion.momentOfInertia()[cmpt]/sqr(deltaT);
00137     }
00138 
00139     constraintPosition = motion.centreOfMass();
00140 
00141     constraintForceIncrement = vector::zero;
00142 
00143     bool converged(mag(maxTheta) < tolerance_);
00144 
00145     if (sixDoFRigidBodyMotionConstraint::debug)
00146     {
00147         Info<< " max angle " << maxTheta
00148             << " force " << constraintForceIncrement
00149             << " moment " << constraintMomentIncrement;
00150 
00151         if (converged)
00152         {
00153             Info<< " converged";
00154         }
00155         else
00156         {
00157             Info<< " not converged";
00158         }
00159 
00160         Info<< endl;
00161     }
00162 
00163     return converged;
00164 }
00165 
00166 
00167 bool Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::read
00168 (
00169     const dictionary& sDoFRBMCDict
00170 )
00171 {
00172     sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
00173 
00174     return true;
00175 }
00176 
00177 
00178 void Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::write
00179 (
00180     Ostream& os
00181 ) const
00182 {
00183 }
00184 
00185 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines