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

fixedLine.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 "fixedLine.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(fixedLine, 0);
00037     addToRunTimeSelectionTable
00038     (
00039         sixDoFRigidBodyMotionConstraint,
00040         fixedLine,
00041         dictionary
00042     );
00043 };
00044 };
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 Foam::sixDoFRigidBodyMotionConstraints::fixedLine::fixedLine
00050 (
00051     const dictionary& sDoFRBMCDict
00052 )
00053 :
00054     sixDoFRigidBodyMotionConstraint(sDoFRBMCDict),
00055     refPt_(),
00056     dir_()
00057 {
00058     read(sDoFRBMCDict);
00059 }
00060 
00061 
00062 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
00063 
00064 Foam::sixDoFRigidBodyMotionConstraints::fixedLine::~fixedLine()
00065 {}
00066 
00067 
00068 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00069 
00070 bool Foam::sixDoFRigidBodyMotionConstraints::fixedLine::constrain
00071 (
00072     const sixDoFRigidBodyMotion& motion,
00073     const vector& existingConstraintForce,
00074     const vector& existingConstraintMoment,
00075     scalar deltaT,
00076     vector& constraintPosition,
00077     vector& constraintForceIncrement,
00078     vector& constraintMomentIncrement
00079 ) const
00080 {
00081     point predictedPosition = motion.predictedPosition
00082     (
00083         refPt_,
00084         existingConstraintForce,
00085         existingConstraintMoment,
00086         deltaT
00087     );
00088 
00089     constraintPosition = motion.currentPosition(refPt_);
00090 
00091     // Info<< "current position " << constraintPosition << nl
00092     //     << "next predictedPosition " << predictedPosition
00093     //     << endl;
00094 
00095     // Vector from reference point to predicted point
00096     vector rC = predictedPosition - refPt_;
00097 
00098     vector error = rC - ((rC) & dir_)*dir_;
00099 
00100     // Info<< "error " << error << endl;
00101 
00102     constraintForceIncrement =
00103         -relaxationFactor_*error*motion.mass()/sqr(deltaT);
00104 
00105     constraintMomentIncrement = vector::zero;
00106 
00107     bool converged(mag(error) < tolerance_);
00108 
00109     if (sixDoFRigidBodyMotionConstraint::debug)
00110     {
00111         Info<< " error " << error
00112             << " force " << constraintForceIncrement
00113             << " moment " << constraintMomentIncrement;
00114 
00115         if (converged)
00116         {
00117             Info<< " converged";
00118         }
00119         else
00120         {
00121             Info<< " not converged";
00122         }
00123 
00124         Info<< endl;
00125     }
00126 
00127     return converged;
00128 }
00129 
00130 
00131 bool Foam::sixDoFRigidBodyMotionConstraints::fixedLine::read
00132 (
00133     const dictionary& sDoFRBMCDict
00134 )
00135 {
00136     sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
00137 
00138     sDoFRBMCCoeffs_.lookup("refPoint") >> refPt_;
00139 
00140     sDoFRBMCCoeffs_.lookup("direction") >> dir_;
00141 
00142     scalar magDir(mag(dir_));
00143 
00144     if (magDir > VSMALL)
00145     {
00146         dir_ /= magDir;
00147     }
00148     else
00149     {
00150         FatalErrorIn
00151         (
00152             "Foam::sixDoFRigidBodyMotionConstraints::fixedLine::read"
00153             "("
00154                 "const dictionary& sDoFRBMCDict"
00155             ")"
00156         )
00157             << "line direction has zero length"
00158             << abort(FatalError);
00159     }
00160 
00161     return true;
00162 }
00163 
00164 
00165 void Foam::sixDoFRigidBodyMotionConstraints::fixedLine::write
00166 (
00167     Ostream& os
00168 ) const
00169 {
00170     os.writeKeyword("refPoint")
00171         << refPt_ << token::END_STATEMENT << nl;
00172 
00173     os.writeKeyword("direction")
00174         << dir_ << token::END_STATEMENT << nl;
00175 }
00176 
00177 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines