/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFunctions/SDA/SDA.C

https://github.com/OpenFOAM/OpenFOAM-4.x · C · 133 lines · 72 code · 28 blank · 33 comment · 1 complexity · dd776b124fb49d0c14516332326ef8cc MD5 · raw file

  1. /*---------------------------------------------------------------------------*\
  2. ========= |
  3. \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
  4. \\ / O peration |
  5. \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
  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
  12. the Free Software Foundation, either version 3 of the License, or
  13. (at your 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, see <http://www.gnu.org/licenses/>.
  20. \*---------------------------------------------------------------------------*/
  21. #include "SDA.H"
  22. #include "addToRunTimeSelectionTable.H"
  23. #include "mathematicalConstants.H"
  24. using namespace Foam::constant::mathematical;
  25. // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
  26. namespace Foam
  27. {
  28. namespace solidBodyMotionFunctions
  29. {
  30. defineTypeNameAndDebug(SDA, 0);
  31. addToRunTimeSelectionTable(solidBodyMotionFunction, SDA, dictionary);
  32. }
  33. }
  34. // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
  35. Foam::solidBodyMotionFunctions::SDA::SDA
  36. (
  37. const dictionary& SBMFCoeffs,
  38. const Time& runTime
  39. )
  40. :
  41. solidBodyMotionFunction(SBMFCoeffs, runTime),
  42. CofG_(SBMFCoeffs_.lookup("CofG"))
  43. {
  44. read(SBMFCoeffs);
  45. }
  46. // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
  47. Foam::solidBodyMotionFunctions::SDA::~SDA()
  48. {}
  49. // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
  50. Foam::septernion Foam::solidBodyMotionFunctions::SDA::transformation() const
  51. {
  52. scalar time = time_.value();
  53. scalar Tpi = Tp_ + dTp_*(time/dTi_); // Current roll period [sec]
  54. scalar wr = twoPi/Tpi; // Current Freq [/sec]
  55. // Current Phase for roll [rad]
  56. scalar r = dTp_/dTi_;
  57. scalar u = Tp_ + r*time;
  58. scalar phr = twoPi*((Tp_/u - 1) + log(mag(u)) - log(Tp_))/r;
  59. // Current Phase for Sway [rad]
  60. scalar phs = phr + pi;
  61. // Current Phase for Heave [rad]
  62. scalar phh = phr + piByTwo;
  63. scalar rollA = max(rollAmax_*exp(-sqr(Tpi - Tpn_)/(2*Q_)), rollAmin_);
  64. vector T
  65. (
  66. 0,
  67. swayA_*(sin(wr*time + phs) - sin(phs)),
  68. heaveA_*(sin(wr*time + phh) - sin(phh))
  69. );
  70. quaternion R(quaternion::XYZ, vector(rollA*sin(wr*time + phr), 0, 0));
  71. septernion TR(septernion(-CofG_ - T)*R*septernion(CofG_));
  72. DebugInFunction << "Time = " << time << " transformation: " << TR << endl;
  73. return TR;
  74. }
  75. bool Foam::solidBodyMotionFunctions::SDA::read(const dictionary& SBMFCoeffs)
  76. {
  77. solidBodyMotionFunction::read(SBMFCoeffs);
  78. SBMFCoeffs_.lookup("CofG") >> CofG_;
  79. SBMFCoeffs_.lookup("lamda") >> lamda_;
  80. SBMFCoeffs_.lookup("rollAmax") >> rollAmax_;
  81. SBMFCoeffs_.lookup("rollAmin") >> rollAmin_;
  82. SBMFCoeffs_.lookup("heaveA") >> heaveA_;
  83. SBMFCoeffs_.lookup("swayA") >> swayA_;
  84. SBMFCoeffs_.lookup("Q") >> Q_;
  85. SBMFCoeffs_.lookup("Tp") >> Tp_;
  86. SBMFCoeffs_.lookup("Tpn") >> Tpn_;
  87. SBMFCoeffs_.lookup("dTi") >> dTi_;
  88. SBMFCoeffs_.lookup("dTp") >> dTp_;
  89. // Rescale parameters according to the given scale parameter
  90. if (lamda_ > 1 + SMALL)
  91. {
  92. heaveA_ /= lamda_;
  93. swayA_ /= lamda_;
  94. Tp_ /= sqrt(lamda_);
  95. Tpn_ /= sqrt(lamda_);
  96. dTi_ /= sqrt(lamda_);
  97. dTp_ /= sqrt(lamda_);
  98. }
  99. return true;
  100. }
  101. // ************************************************************************* //