sixDoFMotion: Adding restraints and constraints to the motion of objects.
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyMotion / sixDoFRigidBodyMotionConstraint / fixedPoint / fixedPoint.C
blob692289851c381235074cbf035d3fd77ee0deebeb
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 "fixedPoint.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "sixDoFRigidBodyMotion.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35 namespace sixDoFRigidBodyMotionConstraints
37     defineTypeNameAndDebug(fixedPoint, 0);
38     addToRunTimeSelectionTable
39     (
40         sixDoFRigidBodyMotionConstraint,
41         fixedPoint,
42         dictionary
43     );
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::fixedPoint
52     const dictionary& sDoFRBMCDict
55     sixDoFRigidBodyMotionConstraint(sDoFRBMCDict),
56     fixedPoint_()
58     read(sDoFRBMCDict);
62 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
64 Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::~fixedPoint()
68 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
70 bool Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::constrain
72     const sixDoFRigidBodyMotion& motion,
73     const vector& existingConstraintForce,
74     const vector& existingConstraintMoment,
75     scalar deltaT,
76     vector& constraintPosition,
77     vector& constraintForceIncrement,
78     vector& constraintMomentIncrement
79 ) const
81     point predictedPosition = motion.predictedPosition
82     (
83         fixedPoint_,
84         existingConstraintForce,
85         existingConstraintMoment,
86         deltaT
87     );
89     constraintPosition = motion.currentPosition(fixedPoint_);
91     // Info<< "current position " << constraintPosition << nl
92     //     << "next predictedPosition " << predictedPosition
93     //     << endl;
95     vector error = predictedPosition - fixedPoint_;
97     // Info<< "error " << error << endl;
99     // Correction force derived from Lagrange multiplier:
100     //     G = -lambda*grad(sigma)
101     // where
102     //     sigma = mag(error) = 0
103     // so
104     //     grad(sigma) = error/mag(error)
105     // Solving for lambda using the SHAKE methodology gives
106     //     lambda = mass*mag(error)/sqr(deltaT)
107     // This is only strictly applicable (i.e. will converge in one
108     // iteration) to constraints at the centre of mass.  Everything
109     // else will need to iterate, and may need under-relaxed to be
110     // stable.
112     constraintForceIncrement =
113         -relaxationFactor_*error*motion.mass()/sqr(deltaT);
115     constraintMomentIncrement = vector::zero;
117     bool converged(mag(error) < tolerance_);
119     if (motion.report())
120     {
121         Info<< " error " << error
122             << " force " << constraintForceIncrement
123             << " moment " << constraintMomentIncrement;
125         if (converged)
126         {
127             Info<< " converged";
128         }
129         else
130         {
131             Info<< " not converged";
132         }
134         Info<< endl;
135     }
137     return converged;
141 bool Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::read
143     const dictionary& sDoFRBMCDict
146     sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
148     sDoFRBMCCoeffs_.lookup("fixedPoint") >> fixedPoint_;
150     return true;
154 void Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::write
156     Ostream& os
157 ) const
159     os.writeKeyword("fixedPoint")
160         << fixedPoint_ << token::END_STATEMENT << nl;
163 // ************************************************************************* //