/src/dynamicMesh/meshMotion/solidBodyMotion/translation/translation.C

https://gitlab.com/pasbec/foam-extend-3.2 · C · 173 lines · 104 code · 31 blank · 38 comment · 3 complexity · f75e1f58db7f4051bd743b80807d08b5 MD5 · raw file

  1. /*---------------------------------------------------------------------------*\
  2. ========= |
  3. \\ / F ield | foam-extend: Open Source CFD
  4. \\ / O peration | Version: 3.2
  5. \\ / A nd | Web: http://www.foam-extend.org
  6. \\/ M anipulation | For copyright notice see file Copyright
  7. -------------------------------------------------------------------------------
  8. License
  9. This file is part of foam-extend.
  10. foam-extend 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 3 of the License, or (at your
  13. option) any later version.
  14. foam-extend is distributed in the hope that it will be useful, but
  15. WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
  20. \*---------------------------------------------------------------------------*/
  21. #include "translation.H"
  22. #include "addToRunTimeSelectionTable.H"
  23. #include "mathematicalConstants.H"
  24. using namespace Foam::mathematicalConstant;
  25. // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
  26. namespace Foam
  27. {
  28. namespace solidBodyMotionFunctions
  29. {
  30. defineTypeNameAndDebug(translation, 0);
  31. addToRunTimeSelectionTable
  32. (
  33. solidBodyMotionFunction,
  34. translation,
  35. dictionary
  36. );
  37. };
  38. };
  39. // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
  40. Foam::scalar
  41. Foam::solidBodyMotionFunctions::translation::rampFactor() const
  42. {
  43. const scalar t = time_.value();
  44. if (t < rampTime_)
  45. {
  46. // Ramping region
  47. return sin(pi/(2*rampTime_)*t);
  48. }
  49. else
  50. {
  51. // Past ramping region
  52. return 1;
  53. }
  54. }
  55. // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
  56. Foam::solidBodyMotionFunctions::translation::translation
  57. (
  58. const dictionary& SBMFCoeffs,
  59. const Time& runTime
  60. )
  61. :
  62. solidBodyMotionFunction(SBMFCoeffs, runTime),
  63. velocity_(SBMFCoeffs_.lookup("velocity")),
  64. rampTime_(readScalar(SBMFCoeffs_.lookup("rampTime")))
  65. {
  66. if (rampTime_ < 0)
  67. {
  68. FatalIOErrorIn
  69. (
  70. "solidBodyMotionFunctions::translation::translation",
  71. SBMFCoeffs_
  72. ) << "Negative rampTime not allowed."
  73. << abort(FatalIOError);
  74. }
  75. }
  76. // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
  77. Foam::solidBodyMotionFunctions::translation::~translation()
  78. {}
  79. // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
  80. Foam::septernion
  81. Foam::solidBodyMotionFunctions::translation::transformation() const
  82. {
  83. const scalar t = time_.value();
  84. septernion TR;
  85. if (t < rampTime_)
  86. {
  87. // Ramping region
  88. // Account for ramping using analytical integration from ramped velocity
  89. // distribution in this region
  90. TR = septernion
  91. (
  92. velocity_*2*rampTime_/pi*(1 - cos(pi/(2*rampTime_)*t)),
  93. quaternion::I
  94. );
  95. }
  96. else
  97. {
  98. // Past ramping region
  99. TR = septernion
  100. (
  101. velocity_*
  102. (
  103. // Displacement during the ramping region
  104. 2*rampTime_/pi
  105. // Displacement during constant velocity after ramping region
  106. + (t - rampTime_)
  107. ),
  108. quaternion::I
  109. );
  110. }
  111. Info<< "solidBodyMotionFunctions::translation::transformation(): "
  112. << "Time = " << t << " velocity = " << rampFactor()*velocity_
  113. << " transformation = " << TR
  114. << endl;
  115. return TR;
  116. }
  117. Foam::septernion
  118. Foam::solidBodyMotionFunctions::translation::velocity() const
  119. {
  120. septernion TV
  121. (
  122. rampFactor()*velocity_,
  123. quaternion::I/time_.deltaT().value()
  124. );
  125. Info<< "solidBodyMotionFunctions::translation::transformation(): "
  126. << "Time = " << time_.value() << " velocity: " << TV << endl;
  127. return TV;
  128. }
  129. bool Foam::solidBodyMotionFunctions::translation::read
  130. (
  131. const dictionary& SBMFCoeffs
  132. )
  133. {
  134. solidBodyMotionFunction::read(SBMFCoeffs);
  135. rampTime_ = readScalar(SBMFCoeffs_.lookup("rampTime"));
  136. return true;
  137. }
  138. // ************************************************************************* //