1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "fixedPoint.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "sixDoFRigidBodyMotion.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace sixDoFRigidBodyMotionConstraints
36 defineTypeNameAndDebug(fixedPoint, 0);
38 addToRunTimeSelectionTable
40 sixDoFRigidBodyMotionConstraint,
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::fixedPoint
52 const dictionary& sDoFRBMCDict
55 sixDoFRigidBodyMotionConstraint(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,
76 vector& constraintPosition,
77 vector& constraintForceIncrement,
78 vector& constraintMomentIncrement
81 point predictedPosition = motion.predictedPosition
84 existingConstraintForce,
85 existingConstraintMoment,
89 constraintPosition = motion.currentPosition(fixedPoint_);
91 // Info<< "current position " << constraintPosition << nl
92 // << "next predictedPosition " << predictedPosition
95 vector error = predictedPosition - fixedPoint_;
97 // Info<< "error " << error << endl;
99 // Correction force derived from Lagrange multiplier:
100 // G = -lambda*grad(sigma)
102 // sigma = mag(error) = 0
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
112 constraintForceIncrement =
113 -relaxationFactor_*error*motion.mass()/sqr(deltaT);
115 constraintMomentIncrement = vector::zero;
117 bool converged(mag(error) < tolerance_);
119 if (sixDoFRigidBodyMotionConstraint::debug)
121 Info<< " error " << error
122 << " force " << constraintForceIncrement
123 << " moment " << constraintMomentIncrement;
131 Info<< " not converged";
141 bool Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::read
143 const dictionary& sDoFRBMCDict
146 sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
148 sDoFRBMCCoeffs_.lookup("fixedPoint") >> fixedPoint_;
154 void Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::write
159 os.writeKeyword("fixedPoint")
160 << fixedPoint_ << token::END_STATEMENT << nl;
163 // ************************************************************************* //