|
[Sponsors] |
DynamicsMeshFv - Rotating motion with prescribed time |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
November 30, 2016, 20:35 |
DynamicsMeshFv - Rotating motion with prescribed time
|
#1 |
Senior Member
|
Hello Guys;
Hope every one is doing great.! Right so I am trying to do this very simple mesh motion where an airfoil will Rotate ( Pitch ) in jumps at prescribed times rather than going through constant motion. I guess what I am trying to say is for example: At time = 0 mesh is at 0 degrees. for time = 1 mesh is at 0 degrees ( no motion until then). At time =1.5 mesh pitchs 5 degree (just once) and then there is no rotation again until next prescribed time. Now I don't mind using omega to integrate this jump rather than manually giving the Pitch angles or Angle of attacks in my case. Code:
Foam::septernion Foam::solidBodyMotionFunctions::rotatingTimeMotion::transformation() const { scalar t = time_.value(); scalarField YY; for (int i = 0; i = 5; i++) { YY[0] = 0; YY[i+1] = YY[i] + 0.01; } Info << "YY " << YY << endl; if (time_.value() == YY[i]) { scalar angle = omega_ -> integrate(0,t); quaternion R(axis_, angle); septernion TR(septernion(origin_)*R*septernion(-origin_)); Info<< "solidBodyMotionFunctions::rotatingTimeMotion::transformation(): " << "Time = " << t << " transformation: " << TR << endl; return TR; } else { scalar angle = 0; quaternion R(axis_, angle); septernion TR(septernion(origin_)*R*septernion(-origin_)); Info<< "solidBodyMotionFunctions::rotatingTimeMotion::transformation(): " << "Time = " << t << " transformation: " << TR << endl; return TR; } } For example let's say prescribed times are 0.01 0.02 0.03 0.04... So what I am really trying to achieve here is: If actual physical time of simulation = YY[i] ( that is either 0.01 or 0.02 or 0.03 or 0.04) then make a single mesh motion. When tested there was no mesh motion from time = 0 to time = 0.01 and it moved just once for time = 0.01. After that there was no more motion at ALL . So I thought that there is no condition for the code to walk along the YY[i] field. Therefore I included; If ( time = YY[i]) then YY[i] = YY[i+1] but this didnt work as well. Is there any way I can compare ( time t to any value in this YY scalarField or array] and if condition is met then exectue this kind of dynamic mesh motion. Sorry about the lengthy ramble. Cheers, thanks |
|
December 6, 2016, 06:18 |
|
#2 |
Senior Member
|
Code:
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. \*---------------------------------------------------------------------------*/ #include "rotatingTimeMotion.H" #include "addToRunTimeSelectionTable.H" #include "Tuple2.H" #include "IFstream.H" #include "interpolateSplineXY.H" #include "mathematicalConstants.H" using namespace Foam::constant::mathematical; // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { namespace solidBodyMotionFunctions { defineTypeNameAndDebug(rotatingTimeMotion, 0); addToRunTimeSelectionTable ( solidBodyMotionFunction, rotatingTimeMotion, dictionary ); } } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::solidBodyMotionFunctions::rotatingTimeMotion::rotatingTimeMotion ( const dictionary& SBMFCoeffs, const Time& runTime ) : solidBodyMotionFunction(SBMFCoeffs, runTime) { read(SBMFCoeffs); } // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * // Foam::solidBodyMotionFunctions::rotatingTimeMotion::~rotatingTimeMotion() {} Foam::septernion Foam::solidBodyMotionFunctions::rotatingTimeMotion::transformation() const { scalar t = time_.value(); for (label i = 0; i <= times_.size(); i++) { // FIRST IF LOOP if ( t <= times_[0]) { vector eulerAngles = amplitude_*sin(omega_*0); eulerAngles *= pi/180.0; quaternion R(eulerAngles.x(), eulerAngles.y(), eulerAngles.z()); septernion TR(septernion(origin_)*R*septernion(-origin_)); Info<< "solidBodyMotionFunctions::rotatingTimeMotion::transformation(): " << "Time = " << t << " transformation: " << TR << endl; return TR; } if ( (t == times_[i])) { vector eulerAngles = amplitude_*sin(omega_*t); eulerAngles *= pi/180.0; quaternion R(eulerAngles.x(), eulerAngles.y(), eulerAngles.z()); septernion TR(septernion(origin_)*R*septernion(-origin_)); Info<< "solidBodyMotionFunctions::rotatingTimeMotion::transformation(): " << "Time = " << t << " transformation: " << TR << endl; return TR; } if (( t > times_[i]) && t < times_[i+1]) { vector eulerAngles = amplitude_*sin(omega_*times_[i]); eulerAngles *= pi/180.0; quaternion R(eulerAngles.x(), eulerAngles.y(), eulerAngles.z()); septernion TR(septernion(origin_)*R*septernion(-origin_)); Info<< "solidBodyMotionFunctions::rotatingTimeMotion::transformation(): " << "Time = " << t << " transformation: " << TR << endl; return TR; } } } bool Foam::solidBodyMotionFunctions::rotatingTimeMotion::read ( const dictionary& SBMFCoeffs ) { solidBodyMotionFunction::read(SBMFCoeffs); fileName newTimeDataFileName ( fileName(SBMFCoeffs_.lookup("timeDataFileName")).expand() ); if (newTimeDataFileName != timeDataFileName_) { timeDataFileName_ = newTimeDataFileName; IFstream dataStream(timeDataFileName_); if (dataStream.good()) { List<scalar> timeValues ( dataStream ); times_.setSize(timeValues.size()); forAll(timeValues, i) { times_[i] = timeValues[i]; } } else { FatalErrorIn ( "solidBodyMotionFunctions::rotatingTimeMotion::read" "(const dictionary&)" ) << "Cannot open time data file " << timeDataFileName_ << exit(FatalError); } } SBMFCoeffs_.lookup("origin") >> origin_; SBMFCoeffs_.lookup("amplitude") >> amplitude_; SBMFCoeffs_.lookup("omega") >> omega_; return true; } // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // ************************************************************************* // Code:
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Class Foam::solidBodyMotionFunctions::rotatingTimeMotion Description SolidBodyMotionFvMesh 6DoF motion function. The rotation is defined by an origin and axis of rotation and an angular speed. SourceFiles rotatingTimeMotion.C \*---------------------------------------------------------------------------*/ #ifndef rotatingTimeMotion_H #define rotatingTimeMotion_H #include "solidBodyMotionFunction.H" #include "primitiveFields.H" #include "point.H" #include "DataEntry.H" #include "autoPtr.H" #include "Vector2D.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { namespace solidBodyMotionFunctions { /*---------------------------------------------------------------------------*\ Class rotatingTimeMotion Declaration \*---------------------------------------------------------------------------*/ class rotatingTimeMotion : public solidBodyMotionFunction { // Private data point origin_; //- Axis vector vector amplitude_; //- Angular velocty (rad/sec) scalar omega_; fileName timeDataFileName_; //- Field of times scalarField times_; // Private Member Functions //- Disallow copy construct rotatingTimeMotion(const rotatingTimeMotion&); //- Disallow default bitwise assignment void operator=(const rotatingTimeMotion&); public: //- Runtime type information TypeName("rotatingTimeMotion"); // Constructors //- Construct from components rotatingTimeMotion ( const dictionary& SBMFCoeffs, const Time& runTime ); //- Construct and return a clone virtual autoPtr<solidBodyMotionFunction> clone() const { return autoPtr<solidBodyMotionFunction> ( new rotatingTimeMotion ( SBMFCoeffs_, time_ ) ); } //- Destructor virtual ~rotatingTimeMotion(); // Member Functions //- Return the solid-body motion transformation septernion virtual septernion transformation() const; //- Update properties from given dictionary virtual bool read(const dictionary& SBMFCoeffs); }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace solidBodyMotionFunctions } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* // Code:
( 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 1.00 ); Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 2.3.0 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "constant"; object dynamicMeshDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dynamicFvMesh solidBodyMotionFvMesh; motionSolverLibs ( "libfvMotionSolvers.so" ); solidBodyMotionFvMeshCoeffs { solidBodyMotionFunction rotatingTimeMotion; rotatingTimeMotionCoeffs { origin (0.06 0 0); amplitude (0 0 -10); omega 14000; // rad/s (8deg/s) timeDataFileName "sj"; } } // ************************************************************************* // Above are C and H files. This automates the whole process of Airfoil in an angle of attack in a prescribed time for those who are interested. It is modified from oscillating rotation motion. It is a dirty code at the moment but does what it needs to do. So any contributions, editions are welcome. Regards Shereez |
|
December 6, 2016, 06:47 |
|
#3 |
Senior Member
Wouter van der Meer
Join Date: May 2009
Location: Elahuizen, Netherlands
Posts: 203
Rep Power: 18 |
hello shereez234,
My knowledge of programming dates from the steam age but than I was learned that comparing two doubles never gives the wanted results so: if ( a == b ) becomes if (abs(a-b)<eps) I think you can replace the for loop by i++ after the moment you had success with the new time so in the if block. This will remove the loop so decrease the execution time. hope this helps Wouter |
|
December 6, 2016, 08:20 |
|
#4 | |
Senior Member
|
Quote:
Thank you for the advice again. |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] Contribution a new utility: refine wall layer mesh based on yPlus field | lakeat | OpenFOAM Community Contributions | 58 | December 23, 2021 03:36 |
[solidMechanics] solidMechanics gear contact in rotation | nlc | OpenFOAM CC Toolkits for Fluid-Structure Interaction | 3 | January 11, 2015 07:41 |
Micro Scale Pore, icoFoam | gooya_kabir | OpenFOAM Running, Solving & CFD | 2 | November 2, 2013 14:58 |
plot over time | fferroni | OpenFOAM Post-Processing | 7 | June 8, 2012 08:56 |
IcoFoam parallel woes | msrinath80 | OpenFOAM Running, Solving & CFD | 9 | July 22, 2007 03:58 |