sixDoFMotion: Adding restraints and constraints to the motion of objects.
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyMotion / sixDoFRigidBodyMotionConstraint / fixedLine / fixedLine.C
blob1bd544eae56c6b3d30537f521f7eee67f45754c6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "fixedLine.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "sixDoFRigidBodyMotion.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35 namespace sixDoFRigidBodyMotionConstraints
37     defineTypeNameAndDebug(fixedLine, 0);
38     addToRunTimeSelectionTable
39     (
40         sixDoFRigidBodyMotionConstraint,
41         fixedLine,
42         dictionary
43     );
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionConstraints::fixedLine::fixedLine
52     const dictionary& sDoFRBMCDict
55     sixDoFRigidBodyMotionConstraint(sDoFRBMCDict),
56     refPt_(),
57     dir_()
59     read(sDoFRBMCDict);
63 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
65 Foam::sixDoFRigidBodyMotionConstraints::fixedLine::~fixedLine()
69 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
71 bool Foam::sixDoFRigidBodyMotionConstraints::fixedLine::constrain
73     const sixDoFRigidBodyMotion& motion,
74     const vector& existingConstraintForce,
75     const vector& existingConstraintMoment,
76     scalar deltaT,
77     vector& constraintPosition,
78     vector& constraintForceIncrement,
79     vector& constraintMomentIncrement
80 ) const
82     point predictedPosition = motion.predictedPosition
83     (
84         refPt_,
85         existingConstraintForce,
86         existingConstraintMoment,
87         deltaT
88     );
90     constraintPosition = motion.currentPosition(refPt_);
92     // Info<< "current position " << constraintPosition << nl
93     //     << "next predictedPosition " << predictedPosition
94     //     << endl;
96     // Vector from reference point to predicted point
97     vector rC = predictedPosition - refPt_;
99     vector error = rC - ((rC) & dir_)*dir_;
101     // Info<< "error " << error << endl;
103     constraintForceIncrement =
104         -relaxationFactor_*error*motion.mass()/sqr(deltaT);
106     constraintMomentIncrement = vector::zero;
108     bool converged(mag(error) < tolerance_);
110     if (motion.report())
111     {
112         Info<< " error " << error
113             << " force " << constraintForceIncrement
114             << " moment " << constraintMomentIncrement;
116         if (converged)
117         {
118             Info<< " converged";
119         }
120         else
121         {
122             Info<< " not converged";
123         }
125         Info<< endl;
126     }
128     return converged;
132 bool Foam::sixDoFRigidBodyMotionConstraints::fixedLine::read
134     const dictionary& sDoFRBMCDict
137     sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
139     sDoFRBMCCoeffs_.lookup("refPoint") >> refPt_;
141     sDoFRBMCCoeffs_.lookup("direction") >> dir_;
143     scalar magDir(mag(dir_));
145     if (magDir > VSMALL)
146     {
147         dir_ /= magDir;
148     }
149     else
150     {
151         FatalErrorIn
152         (
153             "Foam::sixDoFRigidBodyMotionConstraints::fixedLine::read"
154             "("
155                 "const dictionary& sDoFRBMCDict"
156             ")"
157         )
158             << "line direction has zero length"
159             << abort(FatalError);
160     }
162     return true;
166 void Foam::sixDoFRigidBodyMotionConstraints::fixedLine::write
168     Ostream& os
169 ) const
171     os.writeKeyword("refPoint")
172         << refPt_ << token::END_STATEMENT << nl;
174     os.writeKeyword("direction")
175         << dir_ << token::END_STATEMENT << nl;
178 // ************************************************************************* //