FreeFOAM The Cross-Platform CFD Toolkit
sphericalAngularSpring.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "sphericalAngularSpring.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sixDoFRigidBodyMotionRestraints
35 {
36  defineTypeNameAndDebug(sphericalAngularSpring, 0);
38  (
39  sixDoFRigidBodyMotionRestraint,
40  sphericalAngularSpring,
41  dictionary
42  );
43 };
44 };
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
51 (
52  const dictionary& sDoFRBMRDict
53 )
54 :
55  sixDoFRigidBodyMotionRestraint(sDoFRBMRDict),
56  refQ_(),
57  stiffness_(),
58  damping_()
59 {
60  read(sDoFRBMRDict);
61 }
62 
63 
64 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
65 
68 {}
69 
70 
71 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
72 
73 void
75 (
76  const sixDoFRigidBodyMotion& motion,
77  vector& restraintPosition,
78  vector& restraintForce,
79  vector& restraintMoment
80 ) const
81 {
82  restraintMoment = vector::zero;
83 
84  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
85  {
86  vector axis = vector::zero;
87 
88  axis[cmpt] = 1;
89 
90  vector refDir = vector::zero;
91 
92  refDir[(cmpt + 1) % 3] = 1;
93 
94  vector newDir = motion.orientation() & refDir;
95 
96  axis = (refQ_ & axis);
97 
98  refDir = (refQ_ & refDir);
99 
100  newDir -= (axis & newDir)*axis;
101 
102  restraintMoment += -stiffness_*(refDir ^ newDir);
103  }
104 
105  restraintMoment += -damping_*motion.omega();
106 
107  restraintForce = vector::zero;
108 
109  // Not needed to be altered as restraintForce is zero, but set to
110  // centreOfMass to be sure of no spurious moment
111  restraintPosition = motion.centreOfMass();
112 
113  if (motion.report())
114  {
115  Info<< " force " << restraintForce
116  << " moment " << restraintMoment
117  << endl;
118  }
119 }
120 
121 
123 (
124  const dictionary& sDoFRBMRDict
125 )
126 {
128 
129  refQ_ = sDoFRBMRCoeffs_.lookupOrDefault<tensor>("referenceOrientation", I);
130 
131  if (mag(mag(refQ_) - sqrt(3.0)) > 1e-9)
132  {
134  (
135  "Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::"
136  "read"
137  "("
138  "const dictionary& sDoFRBMRDict"
139  ")"
140  )
141  << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
142  << "mag(referenceOrientation) - sqrt(3) = "
143  << mag(refQ_) - sqrt(3.0) << nl
144  << exit(FatalError);
145  }
146 
147  sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
148 
149  sDoFRBMRCoeffs_.lookup("damping") >> damping_;
150 
151  return true;
152 }
153 
154 
156 (
157  Ostream& os
158 ) const
159 {
160  os.writeKeyword("referenceOrientation")
161  << refQ_ << token::END_STATEMENT << nl;
162 
163  os.writeKeyword("stiffness") << stiffness_ << token::END_STATEMENT << nl;
164 
165  os.writeKeyword("damping") << damping_ << token::END_STATEMENT << nl;
166 }
167 
168 
169 // ************************ vim: set sw=4 sts=4 et: ************************ //