1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 "fixedLine.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "sixDoFRigidBodyMotion.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace sixDoFRigidBodyMotionConstraints
36 defineTypeNameAndDebug(fixedLine, 0);
38 addToRunTimeSelectionTable
40 sixDoFRigidBodyMotionConstraint,
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionConstraints::fixedLine::fixedLine
52 const dictionary& sDoFRBMCDict
55 sixDoFRigidBodyMotionConstraint(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,
77 vector& constraintPosition,
78 vector& constraintForceIncrement,
79 vector& constraintMomentIncrement
82 point predictedPosition = motion.predictedPosition
85 existingConstraintForce,
86 existingConstraintMoment,
90 constraintPosition = motion.currentPosition(refPt_);
92 // Info<< "current position " << constraintPosition << nl
93 // << "next predictedPosition " << predictedPosition
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 (sixDoFRigidBodyMotionConstraint::debug)
112 Info<< " error " << error
113 << " force " << constraintForceIncrement
114 << " moment " << constraintMomentIncrement;
122 Info<< " not 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_));
153 "Foam::sixDoFRigidBodyMotionConstraints::fixedLine::read"
155 "const dictionary& sDoFRBMCDict"
158 << "line direction has zero length"
159 << abort(FatalError);
166 void Foam::sixDoFRigidBodyMotionConstraints::fixedLine::write
171 os.writeKeyword("refPoint")
172 << refPt_ << token::END_STATEMENT << nl;
174 os.writeKeyword("direction")
175 << dir_ << token::END_STATEMENT << nl;
178 // ************************************************************************* //