fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / ODE / translationODE / translationODE.C
blob9eea007266c98a0260b29184ff637b6b7e1a8be0
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original authors
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 Class
26     translationODE
28 Description
29     Ordinary differential equation for three degrees of freedom
30     solid body motion
32 Author
33     Hrvoje Jasak
34     Dubravko Matijasevic
36 \*---------------------------------------------------------------------------*/
38 #include "translationODE.H"
39 #include "Time.H"
41 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
43 // namespace Foam
44 // {
45 //     defineTypeNameAndDebug(translationODE, 0);
46 // }
48 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
50 void Foam::translationODE::setCoeffs()
52     // Set ODE coefficients from position and rotation
54     // Linear displacement in relative coordinate system
55     {
56         const vector& xVal = Xrel_.value();
57         coeffs_[0] = xVal.x();
58         coeffs_[1] = xVal.y();
59         coeffs_[2] = xVal.z();
60     }
62     // Linear velocity in relative coordinate system
63     {
64         const vector& uVal = U_.value();
65         coeffs_[3] = uVal.x();
66         coeffs_[4] = uVal.y();
67         coeffs_[5] = uVal.z();
68     }
72 Foam::dimensionedVector Foam::translationODE::A
74     const dimensionedVector& xR,
75     const dimensionedVector& uR
76 ) const
78     return
79     (
80        - (linSpringCoeffs_ & xR)    // spring
81        - (linDampingCoeffs_ & uR)   // damping
82        + force()
83     )/mass_;                        // gravity
87 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
89 // Construct from components
90 Foam::translationODE::translationODE
92     const IOobject& io
95     IOdictionary(io),
96     mass_(lookup("mass")),
97     xEquilibrium_(lookup("equilibriumPosition")),
98     linSpringCoeffs_(lookup("linearSpring")),
99     linDampingCoeffs_(lookup("linearDamping")),
100     Xrel_(lookup("Xrel")),
101     U_(lookup("U")),
102     Uold_(lookup("Uold")),
103     force_(lookup("force")),
104     coeffs_(6, 0.0)
106     setCoeffs();
110 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
112 Foam::translationODE::~translationODE()
116 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
118 void Foam::translationODE::derivatives
120     const scalar x,
121     const scalarField& y,
122     scalarField& dydx
123 ) const
125     // Set the derivatives for displacement
126     dydx[0] = y[3];
127     dydx[1] = y[4];
128     dydx[2] = y[5];
130     dimensionedVector curX("curX", dimLength, vector(y[0], y[1], y[2]));
131     dimensionedVector curU("curU", dimLength/dimTime, vector(y[3], y[4], y[5]));
133     const vector& accel = A(curX, curU).value();
135     dydx[3] = accel.x();
136     dydx[4] = accel.y();
137     dydx[5] = accel.z();
141 void Foam::translationODE::jacobian
143     const scalar x,
144     const scalarField& y,
145     scalarField& dfdx,
146     scalarSquareMatrix& dfdy
147 ) const
149     notImplemented("translationODE::jacobian(...) const");
153 void Foam::translationODE::update(const scalar delta)
155     // Update position
156     vector& Xval = Xrel_.value();
158     Xval.x() = coeffs_[0];
159     Xval.y() = coeffs_[1];
160     Xval.z() = coeffs_[2];
162     // Update velocity
163     Uold_ = U_;
165     vector& Uval = U_.value();
167     Uval.x() = coeffs_[3];
168     Uval.y() = coeffs_[4];
169     Uval.z() = coeffs_[5];
173 bool Foam::translationODE::writeData(Ostream& os) const
175     os << *this;
176     return os.good();
180 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
182 Foam::Ostream& Foam::operator<<(Ostream& os, const translationODE& sds)
184     os.writeKeyword("mass") << sds.mass_ << token::END_STATEMENT << endl;
185     os.writeKeyword("equilibriumPosition") << sds.xEquilibrium_
186         << token::END_STATEMENT << endl;
187     os.writeKeyword("linearSpring") << sds.linSpringCoeffs_
188         << token::END_STATEMENT << endl;
189     os.writeKeyword("linearDamping") << sds.linDampingCoeffs_
190         << token::END_STATEMENT << endl;
192     os.writeKeyword("Xrel") << sds.Xrel() << token::END_STATEMENT << endl;
193     os.writeKeyword("U") << sds.U() << token::END_STATEMENT << endl;
194     os.writeKeyword("Uold") << tab << sds.Uold() << token::END_STATEMENT << nl;
196     os.writeKeyword("force") << sds.force() << token::END_STATEMENT << endl;
198     return os;
202 // ************************************************************************* //