/src/dynamicMesh/meshMotion/solidBodyMotion/graphVelocity/graphVelocity.C

https://gitlab.com/pasbec/foam-extend-3.2 · C · 317 lines · 246 code · 39 blank · 32 comment · 3 complexity · 85963365c5e8ac532710d36288ec8e61 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 "graphVelocity.H"
  23. #include "addToRunTimeSelectionTable.H"
  24. #include "mathematicalConstants.H"
  25. #include "interpolateXY.H"
  26. #include "IFstream.H"
  27. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  28. namespace Foam
  29. {
  30. namespace solidBodyMotionFunctions
  31. {
  32. defineTypeNameAndDebug(graphVelocity, 0);
  33. addToRunTimeSelectionTable(solidBodyMotionFunction, graphVelocity, dictionary);
  34. }
  35. }
  36. // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
  37. Foam::vector
  38. Foam::solidBodyMotionFunctions::graphVelocity::translationalVelocity() const
  39. {
  40. const scalar t = time_.value() - time_.deltaT().value()/2;
  41. return vector
  42. (
  43. interpolateXY(t, surge_.x(), surge_.y()),
  44. interpolateXY(t, sway_.x(), sway_.y()),
  45. interpolateXY(t, heave_.x(), heave_.y())
  46. );
  47. }
  48. Foam::vector
  49. Foam::solidBodyMotionFunctions::graphVelocity::rotationalVelocity() const
  50. {
  51. const scalar t = time_.value() - time_.deltaT().value()/2;
  52. scalar rollVelocity = interpolateXY(t, roll_.x(), roll_.y());
  53. scalar pitchVelocity = interpolateXY(t, pitch_.x(), pitch_.y());
  54. scalar yawVelocity = interpolateXY(t, yaw_.x(), yaw_.y());
  55. if (inDegrees_)
  56. {
  57. const scalar piBy180 = mathematicalConstant::pi/180.0;
  58. rollVelocity *= piBy180;
  59. pitchVelocity *= piBy180;
  60. yawVelocity *= piBy180;
  61. }
  62. return vector(rollVelocity, pitchVelocity, yawVelocity);
  63. }
  64. Foam::septernion
  65. Foam::solidBodyMotionFunctions::graphVelocity::calcTransformation() const
  66. {
  67. // Integrate velocity to get position
  68. if(localTimeIndex_ != time_.timeIndex())
  69. {
  70. // Set old translation and rotation to the previous state
  71. translationOld_ = translation_;
  72. rotationOld_ = rotation_;
  73. const scalar dt = time_.deltaT().value();
  74. translation_ += translationalVelocity()*dt;
  75. rotation_ += rotationalVelocity()*dt;
  76. localTimeIndex_ = time_.timeIndex();
  77. }
  78. const quaternion R(rotation_.x(), rotation_.y(), rotation_.z());
  79. const septernion TR
  80. (
  81. septernion(origin_ + translation_)*R*septernion(-origin_)
  82. );
  83. return TR;
  84. }
  85. // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
  86. Foam::solidBodyMotionFunctions::graphVelocity::graphVelocity
  87. (
  88. const dictionary& SBMFCoeffs,
  89. const Time& runTime
  90. )
  91. :
  92. solidBodyMotionFunction(SBMFCoeffs, runTime),
  93. translation_(vector::zero),
  94. rotation_(vector::zero),
  95. translationOld_(vector::zero),
  96. rotationOld_(vector::zero),
  97. localTimeIndex_(-1),
  98. surge_
  99. (
  100. "surge",
  101. "t",
  102. "eta1Dot",
  103. IFstream
  104. (
  105. time_.path()/time_.caseConstant()/
  106. word(SBMFCoeffs_.lookup("surge"))
  107. )()
  108. ),
  109. sway_
  110. (
  111. "sway",
  112. "t",
  113. "eta2Dot",
  114. IFstream
  115. (
  116. time_.path()/time_.caseConstant()/
  117. word(SBMFCoeffs_.lookup("sway"))
  118. )()
  119. ),
  120. heave_
  121. (
  122. "heave",
  123. "t",
  124. "eta3Dot",
  125. IFstream
  126. (
  127. time_.path()/time_.caseConstant()/
  128. word(SBMFCoeffs_.lookup("heave"))
  129. )()
  130. ),
  131. roll_
  132. (
  133. "roll",
  134. "t",
  135. "eta4Dot",
  136. IFstream
  137. (
  138. time_.path()/time_.caseConstant()/
  139. word(SBMFCoeffs_.lookup("roll"))
  140. )()
  141. ),
  142. pitch_
  143. (
  144. "pitch",
  145. "t",
  146. "eta5Dot",
  147. IFstream
  148. (
  149. time_.path()/time_.caseConstant()/
  150. word(SBMFCoeffs_.lookup("pitch"))
  151. )()
  152. ),
  153. yaw_
  154. (
  155. "yaw",
  156. "t",
  157. "eta6Dot",
  158. IFstream
  159. (
  160. time_.path()/time_.caseConstant()/
  161. word(SBMFCoeffs_.lookup("yaw"))
  162. )()
  163. )
  164. {
  165. read(SBMFCoeffs);
  166. }
  167. // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
  168. Foam::septernion
  169. Foam::solidBodyMotionFunctions::graphVelocity::transformation() const
  170. {
  171. const septernion TR = calcTransformation();
  172. Info<< "solidBodyMotionFunctions::graphVelocity::transformation(): "
  173. << "Time = " << time_.value() << " transformation: " << TR << endl;
  174. return TR;
  175. }
  176. Foam::septernion
  177. Foam::solidBodyMotionFunctions::graphVelocity::velocity() const
  178. {
  179. const scalar dt = time_.deltaT().value();
  180. const septernion TR = calcTransformation();
  181. const quaternion ROld(rotationOld_.x(), rotationOld_.y(), rotationOld_.z());
  182. const septernion TROld
  183. (
  184. septernion(origin_ + translationOld_)*ROld*septernion(-origin_)
  185. );
  186. return septernion
  187. (
  188. (TR.t() - TROld.t())/dt,
  189. (TR.r()/TROld.r())/dt
  190. );
  191. }
  192. bool Foam::solidBodyMotionFunctions::graphVelocity::read
  193. (
  194. const dictionary& SBMFCoeffs
  195. )
  196. {
  197. solidBodyMotionFunction::read(SBMFCoeffs);
  198. SBMFCoeffs_.lookup("origin") >> origin_;
  199. SBMFCoeffs_.lookup("inDegrees") >> inDegrees_;
  200. word surge = SBMFCoeffs_.lookup("surge");
  201. word sway = SBMFCoeffs_.lookup("sway");
  202. word heave = SBMFCoeffs_.lookup("heave");
  203. word roll = SBMFCoeffs_.lookup("roll");
  204. word pitch = SBMFCoeffs_.lookup("pitch");
  205. word yaw = SBMFCoeffs_.lookup("yaw");
  206. surge_ = graph
  207. (
  208. "surge",
  209. "t",
  210. "eta1Dot",
  211. IFstream
  212. (
  213. time_.path()/time_.caseConstant()/
  214. surge
  215. )()
  216. );
  217. sway_ = graph
  218. (
  219. "sway",
  220. "t",
  221. "eta2Dot",
  222. IFstream
  223. (
  224. time_.path()/time_.caseConstant()/
  225. sway
  226. )()
  227. );
  228. heave_ = graph
  229. (
  230. "heave",
  231. "t",
  232. "eta3Dot",
  233. IFstream
  234. (
  235. time_.path()/time_.caseConstant()/
  236. heave
  237. )()
  238. );
  239. roll_ = graph
  240. (
  241. "roll",
  242. "t",
  243. "eta4Dot",
  244. IFstream
  245. (
  246. time_.path()/time_.caseConstant()/
  247. roll
  248. )()
  249. );
  250. pitch_ = graph
  251. (
  252. "pitch",
  253. "t",
  254. "eta5Dot",
  255. IFstream
  256. (
  257. time_.path()/time_.caseConstant()/
  258. pitch
  259. )()
  260. );
  261. yaw_ = graph
  262. (
  263. "yaw",
  264. "t",
  265. "eta6Dot",
  266. IFstream
  267. (
  268. time_.path()/time_.caseConstant()/
  269. yaw
  270. )()
  271. );
  272. return true;
  273. }
  274. // ************************************************************************* //