BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyMotion / sixDoFRigidBodyMotionRestraint / linearSpring / linearSpring.C
blob1b96b1d5d30c31b530c20ee084264f0cc723a74c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
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
19     for more details.
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 "linearSpring.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "sixDoFRigidBodyMotion.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34 namespace sixDoFRigidBodyMotionRestraints
36     defineTypeNameAndDebug(linearSpring, 0);
38     addToRunTimeSelectionTable
39     (
40         sixDoFRigidBodyMotionRestraint,
41         linearSpring,
42         dictionary
43     );
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionRestraints::linearSpring::linearSpring
52     const dictionary& sDoFRBMRDict
55     sixDoFRigidBodyMotionRestraint(sDoFRBMRDict),
56     anchor_(),
57     refAttachmentPt_(),
58     stiffness_(),
59     damping_(),
60     restLength_()
62     read(sDoFRBMRDict);
66 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
68 Foam::sixDoFRigidBodyMotionRestraints::linearSpring::~linearSpring()
72 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
74 void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::restrain
76     const sixDoFRigidBodyMotion& motion,
77     vector& restraintPosition,
78     vector& restraintForce,
79     vector& restraintMoment
80 ) const
82     restraintPosition = motion.currentPosition(refAttachmentPt_);
84     vector r = restraintPosition - anchor_;
86     scalar magR = mag(r);
88     // r is now the r unit vector
89     r /= (magR + VSMALL);
91     vector v = motion.currentVelocity(restraintPosition);
93     restraintForce = -stiffness_*(magR - restLength_)*r - damping_*(r & v)*r;
95     restraintMoment = vector::zero;
97     if (motion.report())
98     {
99         Info<< " attachmentPt - anchor " << r*magR
100             << " spring length " << magR
101             << " force " << restraintForce
102             << " moment " << restraintMoment
103             << endl;
104     }
108 bool Foam::sixDoFRigidBodyMotionRestraints::linearSpring::read
110     const dictionary& sDoFRBMRDict
113     sixDoFRigidBodyMotionRestraint::read(sDoFRBMRDict);
115     sDoFRBMRCoeffs_.lookup("anchor") >> anchor_;
117     sDoFRBMRCoeffs_.lookup("refAttachmentPt") >> refAttachmentPt_;
119     sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
121     sDoFRBMRCoeffs_.lookup("damping") >> damping_;
123     sDoFRBMRCoeffs_.lookup("restLength") >> restLength_;
125     return true;
129 void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::write
131     Ostream& os
132 ) const
134     os.writeKeyword("anchor")
135         << anchor_ << token::END_STATEMENT << nl;
137     os.writeKeyword("refAttachmentPt")
138         << refAttachmentPt_ << token::END_STATEMENT << nl;
140     os.writeKeyword("stiffness")
141         << stiffness_ << token::END_STATEMENT << nl;
143     os.writeKeyword("damping")
144         << damping_ << token::END_STATEMENT << nl;
146     os.writeKeyword("restLength")
147         << restLength_ << token::END_STATEMENT << nl;
150 // ************************************************************************* //