diff --git a/src/ODE/Make/files b/src/ODE/Make/files index 3650dbb93..602890f76 100644 --- a/src/ODE/Make/files +++ b/src/ODE/Make/files @@ -21,6 +21,7 @@ $(sixDOF)/constraints/rotationalConstraints/constantAngularAcceleration/constant $(sixDOF)/constraints/translationalConstraints/translationalConstraint/translationalConstraint.C $(sixDOF)/constraints/translationalConstraints/constantTranslationalAcceleration/constantTranslationalAcceleration.C +$(sixDOF)/constraints/translationalConstraints/periodicOscillation/periodicOscillation.C $(sixDOF)/sixDOFODE/sixDOFODE.C $(sixDOF)/sixDOFODE/newSixDOFODE.C diff --git a/src/ODE/sixDOF/constraints/rotationalConstraints/constantAngularAcceleration/constantAngularAcceleration.C b/src/ODE/sixDOF/constraints/rotationalConstraints/constantAngularAcceleration/constantAngularAcceleration.C index 2dc6c302f..ad61b3a2b 100644 --- a/src/ODE/sixDOF/constraints/rotationalConstraints/constantAngularAcceleration/constantAngularAcceleration.C +++ b/src/ODE/sixDOF/constraints/rotationalConstraints/constantAngularAcceleration/constantAngularAcceleration.C @@ -51,7 +51,26 @@ Foam::constantAngularAcceleration::constantAngularAcceleration dir_(dict.lookup("constraintDirection")), alpha_(readScalar(dict.lookup("angularAcceleration"))), inGlobal_(dict.lookup("inGlobalCoordinateSystem")) -{} +{ + // Rescale direction + if (mag(dir_) < SMALL) + { + FatalErrorIn + ( + "Foam::constantTranslationalAcceleration::" + "constantTranslationalAcceleration" + "\n(" + "\n const word& name," + "\n const dictionary& dict" + "\n)" + ) << "Zero direction specified. This is not allowed." + << exit(FatalError); + } + else + { + dir_ /= mag(dir_); + } +} Foam::autoPtr diff --git a/src/ODE/sixDOF/constraints/rotationalConstraints/constantAngularAcceleration/constantAngularAcceleration.H b/src/ODE/sixDOF/constraints/rotationalConstraints/constantAngularAcceleration/constantAngularAcceleration.H index 342f49f24..3513ac57f 100644 --- a/src/ODE/sixDOF/constraints/rotationalConstraints/constantAngularAcceleration/constantAngularAcceleration.H +++ b/src/ODE/sixDOF/constraints/rotationalConstraints/constantAngularAcceleration/constantAngularAcceleration.H @@ -59,7 +59,7 @@ class constantAngularAcceleration // Private data //- Direction of the constraint (unit vector) - const vector dir_; + vector dir_; //- Constant value of angular acceleration const scalar alpha_; diff --git a/src/ODE/sixDOF/constraints/translationalConstraints/constantTranslationalAcceleration/constantTranslationalAcceleration.C b/src/ODE/sixDOF/constraints/translationalConstraints/constantTranslationalAcceleration/constantTranslationalAcceleration.C index d8d1ac3b2..041b01e52 100644 --- a/src/ODE/sixDOF/constraints/translationalConstraints/constantTranslationalAcceleration/constantTranslationalAcceleration.C +++ b/src/ODE/sixDOF/constraints/translationalConstraints/constantTranslationalAcceleration/constantTranslationalAcceleration.C @@ -50,7 +50,26 @@ Foam::constantTranslationalAcceleration::constantTranslationalAcceleration translationalConstraint(name, dict), dir_(dict.lookup("constraintDirection")), a_(readScalar(dict.lookup("translationalAcceleration"))) -{} +{ + // Rescale direction + if (mag(dir_) < SMALL) + { + FatalErrorIn + ( + "Foam::constantTranslationalAcceleration::" + "constantTranslationalAcceleration" + "\n(" + "\n const word& name," + "\n const dictionary& dict" + "\n)" + ) << "Zero direction specified. This is not allowed." + << exit(FatalError); + } + else + { + dir_ /= mag(dir_); + } +} Foam::autoPtr diff --git a/src/ODE/sixDOF/constraints/translationalConstraints/constantTranslationalAcceleration/constantTranslationalAcceleration.H b/src/ODE/sixDOF/constraints/translationalConstraints/constantTranslationalAcceleration/constantTranslationalAcceleration.H index ae8ecdf51..906d3a861 100644 --- a/src/ODE/sixDOF/constraints/translationalConstraints/constantTranslationalAcceleration/constantTranslationalAcceleration.H +++ b/src/ODE/sixDOF/constraints/translationalConstraints/constantTranslationalAcceleration/constantTranslationalAcceleration.H @@ -59,7 +59,7 @@ class constantTranslationalAcceleration // Private data //- Direction of the constraint (unit vector) - const vector dir_; + vector dir_; //- Constant value of the translational acceleration const scalar a_; diff --git a/src/ODE/sixDOF/constraints/translationalConstraints/periodicOscillation/periodicOscillation.C b/src/ODE/sixDOF/constraints/translationalConstraints/periodicOscillation/periodicOscillation.C new file mode 100644 index 000000000..ed5a3adb1 --- /dev/null +++ b/src/ODE/sixDOF/constraints/translationalConstraints/periodicOscillation/periodicOscillation.C @@ -0,0 +1,136 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + foam-extend is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "periodicOscillation.H" +#include "addToRunTimeSelectionTable.H" +#include "mathematicalConstants.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(periodicOscillation, 0); + addToRunTimeSelectionTable + ( + translationalConstraint, + periodicOscillation, + word + ); +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::periodicOscillation::periodicOscillation +( + const word& name, + const dictionary& dict +) +: + translationalConstraint(name, dict), + dir_(dict.lookup("direction")), + a_(readScalar(dict.lookup("motionAmplitude"))), + period_(readScalar(dict.lookup("period"))), + omega_(mathematicalConstant::twoPi/period_), + phi_(readScalar(dict.lookup("phaseShift"))*mathematicalConstant::pi/180.0) +{ + // Rescale direction + if (mag(dir_) < SMALL) + { + FatalErrorIn + ( + "Foam::periodicOscillation::periodicOscillation" + "\n(" + "\n const word& name," + "\n const dictionary& dict" + "\n)" + ) << "Zero direction specified. This is not allowed." + << exit(FatalError); + } + else + { + dir_ /= mag(dir_); + } +} + + +Foam::autoPtr +Foam::periodicOscillation::clone() const +{ + return autoPtr + ( + new periodicOscillation(*this) + ); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::periodicOscillation::~periodicOscillation() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::vector Foam::periodicOscillation::matrixContribution +( + const scalar, + const tensor&, + const vector&, + const vector& +) const +{ + return dir_; +} + + +Foam::scalar Foam::periodicOscillation::sourceContribution +( + const scalar t, + const tensor&, + const vector&, + const vector& +) const +{ + return -a_*sqr(omega_)*(sin(omega_*t + phi_)); +} + + +void Foam::periodicOscillation::write(Ostream& os) const +{ + os.writeKeyword("type") << tab << type() + << token::END_STATEMENT << nl << nl; + + os.writeKeyword("direction") << tab << dir_ + << token::END_STATEMENT << nl; + os.writeKeyword("motionAmplitude") << tab << a_ + << token::END_STATEMENT << nl; + os.writeKeyword("period") << tab << period_ + << token::END_STATEMENT << nl; + os.writeKeyword("phaseShift") << tab + << phi_*180.0/mathematicalConstant::pi << token::END_STATEMENT << endl; +} + + +// ************************************************************************* // diff --git a/src/ODE/sixDOF/constraints/translationalConstraints/periodicOscillation/periodicOscillation.H b/src/ODE/sixDOF/constraints/translationalConstraints/periodicOscillation/periodicOscillation.H new file mode 100644 index 000000000..98cd72b17 --- /dev/null +++ b/src/ODE/sixDOF/constraints/translationalConstraints/periodicOscillation/periodicOscillation.H @@ -0,0 +1,144 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + foam-extend is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with foam-extend. If not, see . + +Class + Foam::periodicOscillation + +Description + Periodic translational motion given by: + + g(vDot, t) = vDot + a*omega^2*sin(omega*t + phi) = 0, + + where a is the amplitude of oscillation, omega radial frequency and phi is + the phase shift. + +Author + Viktor Pandza, FSB Zagreb. All rights reserved. + Vuko Vukcevic, FSB Zagreb. All rights reserved. + +SourceFiles + periodicOscillation.C + +\*---------------------------------------------------------------------------*/ + +#ifndef periodicOscillation_H +#define periodicOscillation_H + +#include "translationalConstraint.H" +#include "OFstream.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class periodicOscillation Declaration +\*---------------------------------------------------------------------------*/ + +class periodicOscillation +: + public translationalConstraint +{ + // Private data + + //- Direction + vector dir_; + + //- Amplitude of the motion + const scalar a_; + + //- Period of the motion + const scalar period_; + + //- Radian frequency of the motion + const scalar omega_; + + //- Phase shift (in degrees) + const scalar phi_; + + +public: + + //- Runtime type information + TypeName("periodicOscillation"); + + + // Constructors + + //- Construct from dictionary + periodicOscillation + ( + const word& name, + const dictionary& dict + ); + + //- Construct and return a clone + virtual autoPtr clone() const; + + + // Destructor + + virtual ~periodicOscillation(); + + + // Member Functions + + // Constraint specific functions + + //- Return matrix contribution defined by constraint, f(t) + virtual vector matrixContribution + ( + const scalar, + const tensor&, + const vector&, + const vector& + ) const; + + //- Return source contribution defined by constraint, a(t) + virtual scalar sourceContribution + ( + const scalar t, + const tensor&, + const vector&, + const vector& + ) const; + + + + // I-O Functions + + //- Virtual write function + virtual void write(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //