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

linearSpring.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 "linearSpring.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(linearSpring, 0);
00037     addToRunTimeSelectionTable
00038     (
00039         sixDoFRigidBodyMotionRestraint,
00040         linearSpring,
00041         dictionary
00042     );
00043 };
00044 };
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 Foam::sixDoFRigidBodyMotionRestraints::linearSpring::linearSpring
00050 (
00051     const dictionary& sDoFRBMRDict
00052 )
00053 :
00054     sixDoFRigidBodyMotionRestraint(sDoFRBMRDict),
00055     anchor_(),
00056     refAttachmentPt_(),
00057     stiffness_(),
00058     damping_(),
00059     restLength_()
00060 {
00061     read(sDoFRBMRDict);
00062 }
00063 
00064 
00065 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
00066 
00067 Foam::sixDoFRigidBodyMotionRestraints::linearSpring::~linearSpring()
00068 {}
00069 
00070 
00071 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00072 
00073 void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::restrain
00074 (
00075     const sixDoFRigidBodyMotion& motion,
00076     vector& restraintPosition,
00077     vector& restraintForce,
00078     vector& restraintMoment
00079 ) const
00080 {
00081     restraintPosition = motion.currentPosition(refAttachmentPt_);
00082 
00083     vector r = restraintPosition - anchor_;
00084 
00085     scalar magR = mag(r);
00086 
00087     // r is now the r unit vector
00088     r /= (magR + VSMALL);
00089 
00090     vector v = motion.currentVelocity(restraintPosition);
00091 
00092     restraintForce = -stiffness_*(magR - restLength_)*r - damping_*(r & v)*r;
00093 
00094     restraintMoment = vector::zero;
00095 
00096     if (motion.report())
00097     {
00098         Info<< " attachmentPt - anchor " << r*magR
00099             << " spring length " << magR
00100             << " force " << restraintForce
00101             << " moment " << restraintMoment
00102             << endl;
00103     }
00104 }
00105 
00106 
00107 bool Foam::sixDoFRigidBodyMotionRestraints::linearSpring::read
00108 (
00109     const dictionary& sDoFRBMRDict
00110 )
00111 {
00112     sixDoFRigidBodyMotionRestraint::read(sDoFRBMRDict);
00113 
00114     sDoFRBMRCoeffs_.lookup("anchor") >> anchor_;
00115 
00116     sDoFRBMRCoeffs_.lookup("refAttachmentPt") >> refAttachmentPt_;
00117 
00118     sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
00119 
00120     sDoFRBMRCoeffs_.lookup("damping") >> damping_;
00121 
00122     sDoFRBMRCoeffs_.lookup("restLength") >> restLength_;
00123 
00124     return true;
00125 }
00126 
00127 
00128 void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::write
00129 (
00130     Ostream& os
00131 ) const
00132 {
00133     os.writeKeyword("anchor")
00134         << anchor_ << token::END_STATEMENT << nl;
00135 
00136     os.writeKeyword("refAttachmentPt")
00137         << refAttachmentPt_ << token::END_STATEMENT << nl;
00138 
00139     os.writeKeyword("stiffness")
00140         << stiffness_ << token::END_STATEMENT << nl;
00141 
00142     os.writeKeyword("damping")
00143         << damping_ << token::END_STATEMENT << nl;
00144 
00145     os.writeKeyword("restLength")
00146         << restLength_ << token::END_STATEMENT << nl;
00147 }
00148 
00149 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines