FreeFOAM The Cross-Platform CFD Toolkit
fixedLine.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 "fixedLine.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sixDoFRigidBodyMotionConstraints
35 {
36  defineTypeNameAndDebug(fixedLine, 0);
38  (
39  sixDoFRigidBodyMotionConstraint,
40  fixedLine,
41  dictionary
42  );
43 };
44 };
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const dictionary& sDoFRBMCDict
52 )
53 :
54  sixDoFRigidBodyMotionConstraint(sDoFRBMCDict),
55  refPt_(),
56  dir_()
57 {
58  read(sDoFRBMCDict);
59 }
60 
61 
62 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
63 
65 {}
66 
67 
68 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
69 
71 (
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
80 {
81  point predictedPosition = motion.predictedPosition
82  (
83  refPt_,
84  existingConstraintForce,
85  existingConstraintMoment,
86  deltaT
87  );
88 
89  constraintPosition = motion.currentPosition(refPt_);
90 
91  // Info<< "current position " << constraintPosition << nl
92  // << "next predictedPosition " << predictedPosition
93  // << endl;
94 
95  // Vector from reference point to predicted point
96  vector rC = predictedPosition - refPt_;
97 
98  vector error = rC - ((rC) & dir_)*dir_;
99 
100  // Info<< "error " << error << endl;
101 
102  constraintForceIncrement =
103  -relaxationFactor_*error*motion.mass()/sqr(deltaT);
104 
105  constraintMomentIncrement = vector::zero;
106 
107  bool converged(mag(error) < tolerance_);
108 
109  if (sixDoFRigidBodyMotionConstraint::debug)
110  {
111  Info<< " error " << error
112  << " force " << constraintForceIncrement
113  << " moment " << constraintMomentIncrement;
114 
115  if (converged)
116  {
117  Info<< " converged";
118  }
119  else
120  {
121  Info<< " not converged";
122  }
123 
124  Info<< endl;
125  }
126 
127  return converged;
128 }
129 
130 
132 (
133  const dictionary& sDoFRBMCDict
134 )
135 {
137 
138  sDoFRBMCCoeffs_.lookup("refPoint") >> refPt_;
139 
140  sDoFRBMCCoeffs_.lookup("direction") >> dir_;
141 
142  scalar magDir(mag(dir_));
143 
144  if (magDir > VSMALL)
145  {
146  dir_ /= magDir;
147  }
148  else
149  {
151  (
152  "Foam::sixDoFRigidBodyMotionConstraints::fixedLine::read"
153  "("
154  "const dictionary& sDoFRBMCDict"
155  ")"
156  )
157  << "line direction has zero length"
158  << abort(FatalError);
159  }
160 
161  return true;
162 }
163 
164 
166 (
167  Ostream& os
168 ) const
169 {
170  os.writeKeyword("refPoint")
171  << refPt_ << token::END_STATEMENT << nl;
172 
173  os.writeKeyword("direction")
174  << dir_ << token::END_STATEMENT << nl;
175 }
176 
177 // ************************ vim: set sw=4 sts=4 et: ************************ //