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

sphericalAngularSpring.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 "sphericalAngularSpring.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <forces/sixDoFRigidBodyMotion.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 namespace sixDoFRigidBodyMotionRestraints
00035 {
00036     defineTypeNameAndDebug(sphericalAngularSpring, 0);
00037     addToRunTimeSelectionTable
00038     (
00039         sixDoFRigidBodyMotionRestraint,
00040         sphericalAngularSpring,
00041         dictionary
00042     );
00043 };
00044 };
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::
00050 sphericalAngularSpring
00051 (
00052     const dictionary& sDoFRBMRDict
00053 )
00054 :
00055     sixDoFRigidBodyMotionRestraint(sDoFRBMRDict),
00056     refQ_(),
00057     stiffness_(),
00058     damping_()
00059 {
00060     read(sDoFRBMRDict);
00061 }
00062 
00063 
00064 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
00065 
00066 Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::
00067 ~sphericalAngularSpring()
00068 {}
00069 
00070 
00071 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00072 
00073 void
00074 Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::restrain
00075 (
00076     const sixDoFRigidBodyMotion& motion,
00077     vector& restraintPosition,
00078     vector& restraintForce,
00079     vector& restraintMoment
00080 ) const
00081 {
00082     restraintMoment = vector::zero;
00083 
00084     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00085     {
00086         vector axis = vector::zero;
00087 
00088         axis[cmpt] = 1;
00089 
00090         vector refDir = vector::zero;
00091 
00092         refDir[(cmpt + 1) % 3] = 1;
00093 
00094         vector newDir = motion.orientation() & refDir;
00095 
00096         axis = (refQ_ & axis);
00097 
00098         refDir = (refQ_ & refDir);
00099 
00100         newDir -= (axis & newDir)*axis;
00101 
00102         restraintMoment += -stiffness_*(refDir ^ newDir);
00103     }
00104 
00105     restraintMoment += -damping_*motion.omega();
00106 
00107     restraintForce = vector::zero;
00108 
00109     // Not needed to be altered as restraintForce is zero, but set to
00110     // centreOfMass to be sure of no spurious moment
00111     restraintPosition = motion.centreOfMass();
00112 
00113     if (motion.report())
00114     {
00115         Info<< " force " << restraintForce
00116             << " moment " << restraintMoment
00117             << endl;
00118     }
00119 }
00120 
00121 
00122 bool Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::read
00123 (
00124     const dictionary& sDoFRBMRDict
00125 )
00126 {
00127     sixDoFRigidBodyMotionRestraint::read(sDoFRBMRDict);
00128 
00129     refQ_ = sDoFRBMRCoeffs_.lookupOrDefault<tensor>("referenceOrientation", I);
00130 
00131     if (mag(mag(refQ_) - sqrt(3.0)) > 1e-9)
00132     {
00133         FatalErrorIn
00134         (
00135             "Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::"
00136             "read"
00137             "("
00138                 "const dictionary& sDoFRBMRDict"
00139             ")"
00140         )
00141             << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
00142             << "mag(referenceOrientation) - sqrt(3) = "
00143             << mag(refQ_) - sqrt(3.0) << nl
00144             << exit(FatalError);
00145     }
00146 
00147     sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
00148 
00149     sDoFRBMRCoeffs_.lookup("damping") >> damping_;
00150 
00151     return true;
00152 }
00153 
00154 
00155 void Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::write
00156 (
00157     Ostream& os
00158 ) const
00159 {
00160     os.writeKeyword("referenceOrientation")
00161         << refQ_ << token::END_STATEMENT << nl;
00162 
00163     os.writeKeyword("stiffness") << stiffness_ << token::END_STATEMENT << nl;
00164 
00165     os.writeKeyword("damping") << damping_ << token::END_STATEMENT << nl;
00166 }
00167 
00168 
00169 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines