ENH: Adding more useful information to sixDoFRigidBodyMotion restraint
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyMotion / sixDoFRigidBodyMotionConstraint / fixedPlane / fixedPlane.C
blobf30940766e28d7be0070802f4aff2dcd2a654ef6
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 "fixedPlane.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "sixDoFRigidBodyMotion.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35 namespace sixDoFRigidBodyMotionConstraints
37     defineTypeNameAndDebug(fixedPlane, 0);
38     addToRunTimeSelectionTable
39     (
40         sixDoFRigidBodyMotionConstraint,
41         fixedPlane,
42         dictionary
43     );
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionConstraints::fixedPlane::fixedPlane
52     const dictionary& sDoFRBMCDict
55     sixDoFRigidBodyMotionConstraint(sDoFRBMCDict),
56     fixedPlane_(vector::one)
58     read(sDoFRBMCDict);
62 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
64 Foam::sixDoFRigidBodyMotionConstraints::fixedPlane::~fixedPlane()
68 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
70 bool Foam::sixDoFRigidBodyMotionConstraints::fixedPlane::constrain
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
81     const point& refPt = fixedPlane_.refPoint();
83     const vector& n = fixedPlane_.normal();
85     point predictedPosition = motion.predictedPosition
86     (
87         refPt,
88         existingConstraintForce,
89         existingConstraintMoment,
90         deltaT
91     );
93     constraintPosition = motion.currentPosition(refPt);
95     // Info<< "current position " << constraintPosition << nl
96     //     << "next predictedPosition " << predictedPosition
97     //     << endl;
99     vector error = ((predictedPosition - refPt) & n)*n;
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)
111     {
112         Info<< " error " << error
113             << " force " << constraintForceIncrement
114             << " moment " << constraintMomentIncrement;
116         if (converged)
117         {
118             Info<< " converged";
119         }
120         else
121         {
122             Info<< " not converged";
123         }
125         Info<< endl;
126     }
128     return converged;
132 bool Foam::sixDoFRigidBodyMotionConstraints::fixedPlane::read
134     const dictionary& sDoFRBMCDict
137     sixDoFRigidBodyMotionConstraint::read(sDoFRBMCDict);
139     point refPt = sDoFRBMCCoeffs_.lookup("refPoint");
141     vector normal = sDoFRBMCCoeffs_.lookup("normal");
143     fixedPlane_ = plane(refPt, normal);
145     return true;
149 void Foam::sixDoFRigidBodyMotionConstraints::fixedPlane::write
151     Ostream& os
152 ) const
154     os.writeKeyword("refPoint")
155         << fixedPlane_.refPoint() << token::END_STATEMENT << nl;
157     os.writeKeyword("normal")
158         << fixedPlane_.normal() << token::END_STATEMENT << nl;
161 // ************************************************************************* //