1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original authors
7 -------------------------------------------------------------------------------
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
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
29 Ordinary differential equation for three degrees of freedom
36 \*---------------------------------------------------------------------------*/
38 #include "translationODE.H"
41 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
45 // defineTypeNameAndDebug(translationODE, 0);
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 void Foam::translationODE::setCoeffs()
52 // Set ODE coefficients from position and rotation
54 // Linear displacement in relative coordinate system
56 const vector& xVal = Xrel_.value();
57 coeffs_[0] = xVal.x();
58 coeffs_[1] = xVal.y();
59 coeffs_[2] = xVal.z();
62 // Linear velocity in relative coordinate system
64 const vector& uVal = U_.value();
65 coeffs_[3] = uVal.x();
66 coeffs_[4] = uVal.y();
67 coeffs_[5] = uVal.z();
72 Foam::dimensionedVector Foam::translationODE::A
74 const dimensionedVector& xR,
75 const dimensionedVector& uR
80 - (linSpringCoeffs_ & xR) // spring
81 - (linDampingCoeffs_ & uR) // damping
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
89 // Construct from components
90 Foam::translationODE::translationODE
96 mass_(lookup("mass")),
97 xEquilibrium_(lookup("equilibriumPosition")),
98 linSpringCoeffs_(lookup("linearSpring")),
99 linDampingCoeffs_(lookup("linearDamping")),
100 Xrel_(lookup("Xrel")),
102 Uold_(lookup("Uold")),
103 force_(lookup("force")),
110 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
112 Foam::translationODE::~translationODE()
116 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 void Foam::translationODE::derivatives
121 const scalarField& y,
125 // Set the derivatives for displacement
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();
141 void Foam::translationODE::jacobian
144 const scalarField& y,
146 scalarSquareMatrix& dfdy
149 notImplemented("translationODE::jacobian(...) const");
153 void Foam::translationODE::update(const scalar delta)
156 vector& Xval = Xrel_.value();
158 Xval.x() = coeffs_[0];
159 Xval.y() = coeffs_[1];
160 Xval.z() = coeffs_[2];
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
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;
202 // ************************************************************************* //