|
[Sponsors] |
Vary stiffness over time - sixDoFRigidBodyMotion |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 16, 2018, 18:06 |
Vary stiffness over time - sixDoFRigidBodyMotion
|
#1 |
New Member
Rodolfo Puraca
Join Date: Feb 2017
Posts: 2
Rep Power: 0 |
Hi all,
I have been trying to modify the LinearSpring restraint in the sixDoFRigidBodyMotion libary. I am trying to make the spring vary its stiffness over time, using a expression like this: variable_stiffness(time) = stiffness + (percentage*stiffness*sin(frequency*time)) Where the inputs stiffness, percentage and frequency will come from dynamicMeshDict. My code for the spring class: MylinearSpring.H Code:
#ifndef linearSpring_H #define linearSpring_H #include "sixDoFRigidBodyMotionRestraint.H" #include "point.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { namespace sixDoFRigidBodyMotionRestraints { /*---------------------------------------------------------------------------*\ Class linearSpring Declaration \*---------------------------------------------------------------------------*/ class linearSpring : public sixDoFRigidBodyMotionRestraint { // Private data //- Anchor point, where the spring is attached to an immovable // object point anchor_; //- Reference point of attachment to the solid body point refAttachmentPt_; //- Spring stiffness coefficient (N/m) scalar stiffness_; //- Damping coefficient (Ns/m) scalar damping_; //- Rest length - length of spring when no forces are applied to it scalar restLength_; //- Percentage scalar porcentagem_; //- Frequência (rad/s) scalar freq_; public: //- Runtime type information TypeName("linearSpring"); // Constructors //- Construct from components linearSpring ( const word& name, //const Time& runTime, const dictionary& sDoFRBMRDict ); //- Construct and return a clone virtual autoPtr<sixDoFRigidBodyMotionRestraint> clone() const { return autoPtr<sixDoFRigidBodyMotionRestraint> ( new linearSpring(*this) ); } //- Destructor virtual ~linearSpring(); // Member Functions //- Calculate the restraint position, force and moment. // Global reference frame vectors. virtual void restrain ( const sixDoFRigidBodyMotion& motion, vector& restraintPosition, vector& restraintForce, vector& restraintMoment ) const; //- Update properties from given dictionary virtual bool read(const dictionary& sDoFRBMRCoeff); //- Write virtual void write(Ostream&) const; }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace solidBodyMotionFunctions } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif Code:
#include "MylinearSpring.H" #include "addToRunTimeSelectionTable.H" #include "sixDoFRigidBodyMotion.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { namespace sixDoFRigidBodyMotionRestraints { defineTypeNameAndDebug(linearSpring, 0); addToRunTimeSelectionTable ( sixDoFRigidBodyMotionRestraint, linearSpring, dictionary ); } } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::sixDoFRigidBodyMotionRestraints::linearSpring::linearSpring ( const word& name, //const Time& runTime, const dictionary& sDoFRBMRDict ) : sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict), anchor_(), refAttachmentPt_(), stiffness_(), damping_(), restLength_(), porcentagem_(), freq_() { read(sDoFRBMRDict); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::sixDoFRigidBodyMotionRestraints::linearSpring::~linearSpring() {} // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::restrain ( const sixDoFRigidBodyMotion& motion, vector& restraintPosition, vector& restraintForce, vector& restraintMoment ) const { restraintPosition = motion.transform(refAttachmentPt_); vector r = restraintPosition - anchor_; scalar magR = mag(r); r /= (magR + VSMALL); vector v = motion.velocity(restraintPosition); scalar current_time = runTime.time().value(); scalar variable_stiffness = (stiffness_+(porcentagem_*stiffness_*sin(freq_*current_time))); Info<< "Variable Spring Value= " << variable_stiffness << endl; restraintForce = -variable_stiffness*(magR - restLength_)*r - damping_*(r & v)*r; restraintMoment = Zero; if (motion.report()) { Info<< " attachmentPt - anchor " << r*magR << " spring length " << magR << " force " << restraintForce << endl; } } bool Foam::sixDoFRigidBodyMotionRestraints::linearSpring::read ( const dictionary& sDoFRBMRDict ) { sixDoFRigidBodyMotionRestraint::read(sDoFRBMRDict); sDoFRBMRCoeffs_.lookup("anchor") >> anchor_; sDoFRBMRCoeffs_.lookup("refAttachmentPt") >> refAttachmentPt_; sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_; sDoFRBMRCoeffs_.lookup("damping") >> damping_; sDoFRBMRCoeffs_.lookup("restLength") >> restLength_; return true; } void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::write ( Ostream& os ) const { os.writeKeyword("anchor") << anchor_ << token::END_STATEMENT << nl; os.writeKeyword("refAttachmentPt") << refAttachmentPt_ << token::END_STATEMENT << nl; os.writeKeyword("stiffness") << stiffness_ << token::END_STATEMENT << nl; os.writeKeyword("damping") << damping_ << token::END_STATEMENT << nl; os.writeKeyword("restLength") << restLength_ << token::END_STATEMENT << nl; } // ************************************************************************* // Code:
In member function ‘virtual void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::restrain(const Foam::sixDoFRigidBodyMotion&, Foam::vector&, Foam::vector&, Foam::vector&) const’: sixDoFRigidBodyMotion/restraints/linearSpring/MylinearSpring.C:95:27: error: ‘runTime’ was not declared in this scope scalar current_time = runTime.time().value(); ^ From the similars topics that I found in the forum, I think that I have to edit the sixDoFRigidBodyMotion.C and sixDoFRigidBodyMotion.H to make new functions to get the time, but I was not sucessful implementing theses solutions. Topic #6 Access the Time object in sixDoFRigidBodyMotionRestraints Topic #6 Check current time Topic #2 How to access to the solid body motion state from a custom interDyMFoam.C ? If anyone knows how to implement theses solutions or helps me to implement I would be very grateful. Thanks, Rodolfo Puraca |
|
February 22, 2018, 20:51 |
The Solution
|
#2 |
New Member
Rodolfo Puraca
Join Date: Feb 2017
Posts: 2
Rep Power: 0 |
Hi all,
I am posting the solution that I have encountered. I don't know if is the best solution, but works The version of OpenFoam that I am using is 5.0. After digging in the code a little more, I found a variable named deltaT in the function solve on the Sympletic class (sympletic.C / sympletic.H). The function solve calls the function updateAceleration located in the class sixDoFRigidMotion. What I did, was put the variable deltaT in the function updateAceleration. Code:
void Foam::sixDoFRigidBodyMotion::updateAcceleration ( const vector& fGlobal, const vector& tauGlobal, const scalar deltaT ) Code:
void Foam::sixDoFRigidBodyMotion::applyRestraints(const scalar deltaT) Code:
void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::restrain ( const sixDoFRigidBodyMotion& motion, vector& restraintPosition, vector& restraintForce, vector& restraintMoment, const scalar deltaT ) const I attached the library that I modified, to help someone that needs to do something similar. Regards, Rodolfo Puraca |
|
Tags |
restraints, sixdofrigidbodymotion, spring, time |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
bash script for pseudo-parallel usage of reconstructPar | kwardle | OpenFOAM Post-Processing | 42 | May 8, 2024 00:17 |
Elastic or Plastic Deformations in OpenFOAM | NickolasPl | OpenFOAM Pre-Processing | 36 | September 23, 2023 09:22 |
simpleFoam error - "Floating point exception" | mbcx4jc2 | OpenFOAM Running, Solving & CFD | 12 | August 4, 2015 03:20 |
Micro Scale Pore, icoFoam | gooya_kabir | OpenFOAM Running, Solving & CFD | 2 | November 2, 2013 14:58 |
same geometry,structured and unstructured mesh,different behaviour. | sharonyue | OpenFOAM Running, Solving & CFD | 13 | January 2, 2013 23:40 |