sixDoFMotion: Adding restraints and constraints to the motion of objects.
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyMotion / sixDoFRigidBodyMotionIO.C
blob68865c69cbab2aa6284a163b1dd9388d13d7a000
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2009-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 "sixDoFRigidBodyMotion.H"
28 #include "IOstreams.H"
30 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
32 void Foam::sixDoFRigidBodyMotion::write(Ostream& os) const
34     motionState_.write(os);
36     os.writeKeyword("initialCentreOfMass")
37         << initialCentreOfMass_ << token::END_STATEMENT << nl;
38     os.writeKeyword("initialOrientation")
39         << initialQ_ << token::END_STATEMENT << nl;
40     os.writeKeyword("momentOfInertia")
41         << momentOfInertia_ << token::END_STATEMENT << nl;
42     os.writeKeyword("mass")
43         << mass_ << token::END_STATEMENT << nl;
44     os.writeKeyword("report")
45         << report_ << token::END_STATEMENT << nl;
47     if (!restraints_.empty())
48     {
49         os  << indent << "restraints" << nl
50             << indent << token::BEGIN_BLOCK << incrIndent << nl;
52         forAll(restraints_, rI)
53         {
54             word restraintType = restraints_[rI].type();
56             os  << indent << restraintNames_[rI] << nl
57                 << indent << token::BEGIN_BLOCK << incrIndent << endl;
59             os.writeKeyword("sixDoFRigidBodyMotionRestraint")
60                 << restraintType << token::END_STATEMENT << nl;
62             os.writeKeyword(word(restraintType + "Coeffs")) << nl;
64             os  << indent << token::BEGIN_BLOCK << nl << incrIndent;
66             restraints_[rI].write(os);
68             os << decrIndent << indent << token::END_BLOCK << nl;
70             os  << decrIndent << indent << token::END_BLOCK << endl;
71         }
73         os  << decrIndent << indent << token::END_BLOCK << nl;
74     }
76     if (!constraints_.empty())
77     {
78         os  << indent << "constraints" << nl
79             << indent << token::BEGIN_BLOCK << incrIndent << nl;
81         os.writeKeyword("maxIterations")
82             << maxConstraintIterations_ << token::END_STATEMENT << nl;
84         forAll(constraints_, rI)
85         {
86             word constraintType = constraints_[rI].type();
88             os  << indent << constraintNames_[rI] << nl
89                 << indent << token::BEGIN_BLOCK << incrIndent << endl;
91             os.writeKeyword("sixDoFRigidBodyMotionConstraint")
92                 << constraintType << token::END_STATEMENT << nl;
94             constraints_[rI].sixDoFRigidBodyMotionConstraint::write(os);
96             os.writeKeyword(word(constraintType + "Coeffs")) << nl;
98             os  << indent << token::BEGIN_BLOCK << nl << incrIndent;
100             constraints_[rI].write(os);
102             os << decrIndent << indent << token::END_BLOCK << nl;
104             os  << decrIndent << indent << token::END_BLOCK << endl;
105         }
107         os  << decrIndent << indent << token::END_BLOCK << nl;
108     }
112 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
114 Foam::Istream& Foam::operator>>(Istream& is, sixDoFRigidBodyMotion& sDoFRBM)
116     is  >> sDoFRBM.motionState_
117         >> sDoFRBM.initialCentreOfMass_
118         >> sDoFRBM.initialQ_
119         >> sDoFRBM.momentOfInertia_
120         >> sDoFRBM.mass_;
122     // Check state of Istream
123     is.check
124     (
125         "Foam::Istream& Foam::operator>>"
126         "(Foam::Istream&, Foam::sixDoFRigidBodyMotion&)"
127     );
129     return is;
133 Foam::Ostream& Foam::operator<<
135     Ostream& os,
136     const sixDoFRigidBodyMotion& sDoFRBM
139     os  << sDoFRBM.motionState()
140         << token::SPACE << sDoFRBM.initialCentreOfMass()
141         << token::SPACE << sDoFRBM.initialQ()
142         << token::SPACE << sDoFRBM.momentOfInertia()
143         << token::SPACE << sDoFRBM.mass();
145     // Check state of Ostream
146     os.check
147     (
148         "Foam::Ostream& Foam::operator<<(Foam::Ostream&, "
149         "const Foam::sixDoFRigidBodyMotion&)"
150     );
152     return os;
156 // ************************************************************************* //