/src/dynamicMesh/meshMotion/solidBodyMotion/constantVelocity/constantVelocity.C

https://gitlab.com/pasbec/foam-extend-3.2 · C · 133 lines · 76 code · 26 blank · 31 comment · 0 complexity · 1721dee83da98547d00c6aac38aebf0d MD5 · raw file

  1. /*---------------------------------------------------------------------------*\
  2. ========= |
  3. \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
  4. \\ / O peration |
  5. \\ / A nd | Copyright held by original author
  6. \\/ M anipulation |
  7. -------------------------------------------------------------------------------
  8. License
  9. This file is part of OpenFOAM.
  10. OpenFOAM is free software; you can redistribute it and/or modify it
  11. under the terms of the GNU General Public License as published by the
  12. Free Software Foundation; either version 2 of the License, or (at your
  13. option) any later version.
  14. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
  15. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with OpenFOAM; if not, write to the Free Software Foundation,
  20. Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. \*---------------------------------------------------------------------------*/
  22. #include "constantVelocity.H"
  23. #include "addToRunTimeSelectionTable.H"
  24. #include "mathematicalConstants.H"
  25. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  26. namespace Foam
  27. {
  28. namespace solidBodyMotionFunctions
  29. {
  30. defineTypeNameAndDebug(constantVelocity, 0);
  31. addToRunTimeSelectionTable
  32. (
  33. solidBodyMotionFunction,
  34. constantVelocity,
  35. dictionary
  36. );
  37. }
  38. }
  39. // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
  40. Foam::septernion
  41. Foam::solidBodyMotionFunctions::constantVelocity::calcTransformation
  42. (
  43. const scalar t
  44. ) const
  45. {
  46. const vector translation = transVelocity_*(t - startMotionTime_);
  47. const vector rotation = rotVelocity_*(t - startMotionTime_);
  48. const quaternion R(rotation.x(), rotation.y(), rotation.z());
  49. const septernion TR
  50. (
  51. septernion(origin_ + translation)*R*septernion(-origin_)
  52. );
  53. return TR;
  54. }
  55. // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
  56. Foam::solidBodyMotionFunctions::constantVelocity::constantVelocity
  57. (
  58. const dictionary& SBMFCoeffs,
  59. const Time& runTime
  60. )
  61. :
  62. solidBodyMotionFunction(SBMFCoeffs, runTime)
  63. {
  64. read(SBMFCoeffs);
  65. }
  66. // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
  67. Foam::septernion
  68. Foam::solidBodyMotionFunctions::constantVelocity::transformation() const
  69. {
  70. const scalar t = time_.value();
  71. const septernion TR = calcTransformation(t);
  72. Info<< "solidBodyMotionFunctions::constantVelocity::transformation(): "
  73. << "Time = " << t << " transformation: " << TR << endl;
  74. return TR;
  75. }
  76. Foam::septernion
  77. Foam::solidBodyMotionFunctions::constantVelocity::velocity() const
  78. {
  79. const scalar t = time_.value();
  80. const scalar dt = time_.deltaT().value();
  81. const septernion velocity
  82. (
  83. (calcTransformation(t).t() - calcTransformation(t - dt).t())/dt,
  84. (calcTransformation(t).r()/calcTransformation(t - dt).r())/dt
  85. );
  86. return velocity;
  87. }
  88. bool Foam::solidBodyMotionFunctions::constantVelocity::read
  89. (
  90. const dictionary& SBMFCoeffs
  91. )
  92. {
  93. solidBodyMotionFunction::read(SBMFCoeffs);
  94. SBMFCoeffs_.lookup("origin") >> origin_;
  95. SBMFCoeffs_.lookup("translationalVelocity") >> transVelocity_;
  96. SBMFCoeffs_.lookup("rotationalVelocity") >> rotVelocity_;
  97. SBMFCoeffs_.lookup("startMotionTime") >> startMotionTime_;
  98. SBMFCoeffs_.lookup("inDegrees") >> inDegrees_;
  99. // Convert to radians if necessary
  100. rotVelocity_ *= inDegrees_ ? mathematicalConstant::pi/180.0 : 1;
  101. return true;
  102. }
  103. // ************************************************************************* //