ENH: Adding more useful information to sixDoFRigidBodyMotion restraint
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyMotion / sixDoFRigidBodyMotionConstraint / fixedOrientation / fixedOrientation.C
blob40d95484e50e6fe624a5d5c99f7b5bbe6bdcec58
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "fixedOrientation.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "sixDoFRigidBodyMotion.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35 namespace sixDoFRigidBodyMotionConstraints
37     defineTypeNameAndDebug(fixedOrientation, 0);
38     addToRunTimeSelectionTable
39     (
40         sixDoFRigidBodyMotionConstraint,
41         fixedOrientation,
42         dictionary
43     );
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::fixedOrientation
52     const dictionary& sDoFRBMCDict
55     sixDoFRigidBodyMotionConstraint(sDoFRBMCDict)
57     read(sDoFRBMCDict);
61 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
63 Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::~fixedOrientation()
67 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
69 bool Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::constrain
71     const sixDoFRigidBodyMotion& motion,
72     const vector& existingConstraintForce,
73     const vector& existingConstraintMoment,
74     scalar deltaT,
75     vector& constraintPosition,
76     vector& constraintForceIncrement,
77     vector& constraintMomentIncrement
78 ) const
80     constraintMomentIncrement = vector::zero;
82     scalar maxTheta = -SMALL;
84     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
85     {
86         vector axis = vector::zero;
88         axis[cmpt] = 1;
90         vector refDir = vector::zero;
92         refDir[(cmpt + 1) % 3] = 1;
94         vector predictedDir = motion.predictedOrientation
95         (
96             refDir,
97             existingConstraintMoment,
98             deltaT
99         );
101         // Removing any axis component from predictedDir
102         predictedDir -= (axis & predictedDir)*axis;
104         scalar theta = GREAT;
106         scalar magPredictedDir = mag(predictedDir);
108         if (magPredictedDir > VSMALL)
109         {
110             predictedDir /= magPredictedDir;
112             theta = acos(min(predictedDir & refDir, 1.0));
114             // Recalculating axis to give correct sign to angle
115             axis = (refDir ^ predictedDir);
117             scalar magAxis = mag(axis);
119             if (magAxis > VSMALL)
120             {
121                 axis /= magAxis;
122             }
123             else
124             {
125                 axis = vector::zero;
126             }
127         }
129         if (theta > maxTheta)
130         {
131             maxTheta = theta;
132         }
134         constraintMomentIncrement +=
135            -relaxationFactor_
136            *theta*axis
137            *motion.momentOfInertia()[cmpt]/sqr(deltaT);
138     }
140     constraintPosition = motion.centreOfMass();
142     constraintForceIncrement = vector::zero;
144     bool converged(mag(maxTheta) < tolerance_);
146     if (sixDoFRigidBodyMotionConstraint::debug)
147     {
148         Info<< " max angle " << maxTheta
149             << " force " << constraintForceIncrement
150             << " moment " << constraintMomentIncrement;
152         if (converged)
153         {
154             Info<< " converged";
155         }
156         else
157         {
158             Info<< " not converged";
159         }
161         Info<< endl;
162     }
164     return converged;
168 bool Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::read
170     const dictionary& sDoFRBMCDict
173     sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
175     return true;
179 void Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::write
181     Ostream& os
182 ) const
186 // ************************************************************************* //