PageRenderTime 32ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFunctions/tabulated6DoFMotion/tabulated6DoFMotion.C

https://gitlab.com/johnvarv/OpenFOAM-3.0.x
C | 174 lines | 110 code | 33 blank | 31 comment | 5 complexity | 67c23dd3348a744d3122f0f665f575b5 MD5 | raw file
  1. /*---------------------------------------------------------------------------*\
  2. ========= |
  3. \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
  4. \\ / O peration |
  5. \\ / A nd | Copyright (C) 2011-2015 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 "tabulated6DoFMotion.H"
  22. #include "addToRunTimeSelectionTable.H"
  23. #include "Tuple2.H"
  24. #include "IFstream.H"
  25. #include "interpolateSplineXY.H"
  26. #include "mathematicalConstants.H"
  27. using namespace Foam::constant::mathematical;
  28. // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
  29. namespace Foam
  30. {
  31. namespace solidBodyMotionFunctions
  32. {
  33. defineTypeNameAndDebug(tabulated6DoFMotion, 0);
  34. addToRunTimeSelectionTable
  35. (
  36. solidBodyMotionFunction,
  37. tabulated6DoFMotion,
  38. dictionary
  39. );
  40. }
  41. }
  42. // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
  43. Foam::solidBodyMotionFunctions::tabulated6DoFMotion::tabulated6DoFMotion
  44. (
  45. const dictionary& SBMFCoeffs,
  46. const Time& runTime
  47. )
  48. :
  49. solidBodyMotionFunction(SBMFCoeffs, runTime)
  50. {
  51. read(SBMFCoeffs);
  52. }
  53. // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
  54. Foam::solidBodyMotionFunctions::tabulated6DoFMotion::~tabulated6DoFMotion()
  55. {}
  56. // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
  57. Foam::septernion
  58. Foam::solidBodyMotionFunctions::tabulated6DoFMotion::transformation() const
  59. {
  60. scalar t = time_.value();
  61. if (t < times_[0])
  62. {
  63. FatalErrorIn
  64. (
  65. "solidBodyMotionFunctions::tabulated6DoFMotion::transformation()"
  66. ) << "current time (" << t
  67. << ") is less than the minimum in the data table ("
  68. << times_[0] << ')'
  69. << exit(FatalError);
  70. }
  71. if (t > times_.last())
  72. {
  73. FatalErrorIn
  74. (
  75. "solidBodyMotionFunctions::tabulated6DoFMotion::transformation()"
  76. ) << "current time (" << t
  77. << ") is greater than the maximum in the data table ("
  78. << times_.last() << ')'
  79. << exit(FatalError);
  80. }
  81. translationRotationVectors TRV = interpolateSplineXY
  82. (
  83. t,
  84. times_,
  85. values_
  86. );
  87. // Convert the rotational motion from deg to rad
  88. TRV[1] *= pi/180.0;
  89. quaternion R(TRV[1].x(), TRV[1].y(), TRV[1].z());
  90. septernion TR(septernion(CofG_ + TRV[0])*R*septernion(-CofG_));
  91. Info<< "solidBodyMotionFunctions::tabulated6DoFMotion::transformation(): "
  92. << "Time = " << t << " transformation: " << TR << endl;
  93. return TR;
  94. }
  95. bool Foam::solidBodyMotionFunctions::tabulated6DoFMotion::read
  96. (
  97. const dictionary& SBMFCoeffs
  98. )
  99. {
  100. solidBodyMotionFunction::read(SBMFCoeffs);
  101. // If the timeDataFileName has changed read the file
  102. fileName newTimeDataFileName
  103. (
  104. fileName(SBMFCoeffs_.lookup("timeDataFileName")).expand()
  105. );
  106. if (newTimeDataFileName != timeDataFileName_)
  107. {
  108. timeDataFileName_ = newTimeDataFileName;
  109. IFstream dataStream(timeDataFileName_);
  110. if (dataStream.good())
  111. {
  112. List<Tuple2<scalar, translationRotationVectors> > timeValues
  113. (
  114. dataStream
  115. );
  116. times_.setSize(timeValues.size());
  117. values_.setSize(timeValues.size());
  118. forAll(timeValues, i)
  119. {
  120. times_[i] = timeValues[i].first();
  121. values_[i] = timeValues[i].second();
  122. }
  123. }
  124. else
  125. {
  126. FatalErrorIn
  127. (
  128. "solidBodyMotionFunctions::tabulated6DoFMotion::read"
  129. "(const dictionary&)"
  130. ) << "Cannot open time data file " << timeDataFileName_
  131. << exit(FatalError);
  132. }
  133. }
  134. SBMFCoeffs_.lookup("CofG") >> CofG_;
  135. return true;
  136. }
  137. // ************************************************************************* //