CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Vary stiffness over time - sixDoFRigidBodyMotion

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By Rodolfo Puraca

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 16, 2018, 17:06
Post Vary stiffness over time - sixDoFRigidBodyMotion
  #1
New Member
 
Rodolfo Puraca
Join Date: Feb 2017
Posts: 2
Rep Power: 0
Rodolfo Puraca is on a distinguished road
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
MylinearSpring.C
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;
}

// ************************************************************************* //
When I compile the code I get this error:
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();
                           ^
It seems that the class MylinearSpring don't have the access to the time.

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
Rodolfo Puraca is offline   Reply With Quote

Old   February 22, 2018, 19:51
Talking The Solution
  #2
New Member
 
Rodolfo Puraca
Join Date: Feb 2017
Posts: 2
Rep Power: 0
Rodolfo Puraca is on a distinguished road
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
)
After that, the function applyRestrains() is called in the function updateAceleration, so I put again the variable deltaT in applyRestraints.
Code:
void Foam::sixDoFRigidBodyMotion::applyRestraints(const scalar deltaT)
Finally, the function restrains() is called, and this function was that I wanted to work.
Code:
void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::restrain
(
    const sixDoFRigidBodyMotion& motion,
    vector& restraintPosition,
    vector& restraintForce,
    vector& restraintMoment,
    const scalar deltaT
) const
One thing bad, is that I needed to do theses modifications in all the classes where this functions appears, that includes the solvers and all restraints.

I attached the library that I modified, to help someone that needs to do something similar.

Regards,
Rodolfo Puraca
Attached Files
File Type: zip MysixDoFRigidBodyMotion.zip (87.9 KB, 23 views)
yujia111 likes this.
Rodolfo Puraca is offline   Reply With Quote

Reply

Tags
restraints, sixdofrigidbodymotion, spring, time

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script for pseudo-parallel usage of reconstructPar kwardle OpenFOAM Post-Processing 39 July 1, 2020 09:13
Elastic or Plastic Deformations in OpenFOAM NickolasPl OpenFOAM Pre-Processing 28 April 2, 2019 18:29
simpleFoam error - "Floating point exception" mbcx4jc2 OpenFOAM Running, Solving & CFD 12 August 4, 2015 02:20
Micro Scale Pore, icoFoam gooya_kabir OpenFOAM Running, Solving & CFD 2 November 2, 2013 13:58
same geometry,structured and unstructured mesh,different behaviour. sharonyue OpenFOAM Running, Solving & CFD 13 January 2, 2013 22:40


All times are GMT -4. The time now is 15:14.