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

OpenFOAM Immersed Boundary Method - forceBased motion class creation

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 3 Post By courant_numero_uno

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 7, 2019, 15:28
Default OpenFOAM Immersed Boundary Method - forceBased motion class creation
  #1
New Member
 
Join Date: Sep 2019
Posts: 17
Rep Power: 6
courant_numero_uno is on a distinguished road
Hello, I am posting this to help anyone out who is encountering the same error I did when following the tutorial for implementing forceBased IBM motion. The useful tutorial is given at: http://www.tfd.chalmers.se/~hani/kur...eirsson/OF.pdf


When I compiled the files using wmake, I got some errors:

Code:
forceBased/forceBased.C: In member function ‘Foam::vector Foam::solidBodyMotionFunctions::forceBased::newPosition() const’:
forceBased/forceBased.C:57:30: error: expected primary-expression before ‘.’ token
     scalar dT = time_.deltaT(.value());
                              ^
forceBased/forceBased.C:70:31: error: ‘g_l’ was not declared in this scope
        Info << "Gravity: " << g_l << endl;
                               ^~~
forceBased/forceBased.C:70:31: note: suggested alternative: ‘g_’
        Info << "Gravity: " << g_l << endl;
                               ^~~
                               g_
forceBased/forceBased.C:72:32: error: ‘imBForces_’ was not declared in this scope
        vector pressureForces = imBForces_.calcForcesMoment().first().first();
                                ^~~~~~~~~~
forceBased/forceBased.C:72:32: note: suggested alternative: ‘forces_H’
        vector pressureForces = imBForces_.calcForcesMoment().first().first();
                                ^~~~~~~~~~
                                forces_H
forceBased/forceBased.C:109:31: error: ‘imBForces_’ was not declared in this scope
       vector pressureForces = imBForces_.calcForcesMoment(.first(.second()));
                               ^~~~~~~~~~
forceBased/forceBased.C:109:31: note: suggested alternative: ‘forces_H’
       vector pressureForces = imBForces_.calcForcesMoment(.first(.second()));
                               ^~~~~~~~~~
                               forces_H
forceBased/forceBased.C:109:59: error: expected primary-expression before ‘.’ token
       vector pressureForces = imBForces_.calcForcesMoment(.first(.second()));
                                                           ^
forceBased/forceBased.C:109:66: error: expected primary-expression before ‘.’ token
       vector pressureForces = imBForces_.calcForcesMoment(.first(.second()));
                                                                  ^
forceBased/forceBased.C:110:58: error: expected primary-expression before ‘.’ token
       vector viscousForces = imBForces_.calcForcesMoment(.first(.second()));
                                                          ^
forceBased/forceBased.C:110:65: error: expected primary-expression before ‘.’ token
       vector viscousForces = imBForces_.calcForcesMoment(.first(.second()));
                                                                 ^
forceBased/forceBased.C:119:49: error: found ‘:’ in nested-name-specifier, expected ‘::’
       vector velocity_ = velocity_+totalForce*dT:
                                                 ^
forceBased/forceBased.C:119:47: error: ‘dT’ is not a class, namespace, or enumeration
       vector velocity_ = velocity_+totalForce*dT:
                                               ^~
forceBased/forceBased.C:123:22: error: ‘newPos’ was not declared in this scope
       oldPosition_ = newPos;
                      ^~~~~~
forceBased/forceBased.C: In constructor ‘Foam::solidBodyMotionFunctions::forceBased::forceBased(const Foam::dictionary&, const Foam::Time&)’:
forceBased/forceBased.C:151:5: error: class ‘Foam::solidBodyMotionFunctions::forceBased’ does not have any field named ‘imBForces_’
     imBForces_("test", time_.lookupObject<objectRegistry>(polyMesh::defaultRegion), SBMFCoeffs_, true)
     ^~~~~~~~~~
forceBased/forceBased.C: In member function ‘virtual Foam::septernion Foam::solidBodyMotionFunctions::forceBased::transformation() const’:
forceBased/forceBased.C:174:4: error: ‘quarternion’ was not declared in this scope
    quarternion::I
    ^~~~~~~~~~~
forceBased/forceBased.C:174:4: note: suggested alternative: ‘quaternion_H’
    quarternion::I
    ^~~~~~~~~~~
    quaternion_H
forceBased/forceBased.C: In member function ‘virtual Foam::septernion Foam::solidBodyMotionFunctions::forceBased::velocity() const’:
forceBased/forceBased.C:187:9: error: ‘quarternion’ has not been declared
         quarternion::I/time_.deltaT().value()
         ^~~~~~~~~~~
forceBased/forceBased.dep:515: recipe for target 'Make/linux64GccDPOpt/forceBased.o' failed

I believe the tutorial forgets to mention that you must declare imBForces_ in the forceBased.H file. There are also some syntax changes to be made to the forceBased.C file. Here is the forceBased.H file:


Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | foam-extend: Open Source CFD
   \\    /   O peration     | Version:     4.0
    \\  /    A nd           | Web:         http://www.foam-extend.org
     \\/     M anipulation  | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
    This file is part of foam-extend.

    foam-extend 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.

    foam-extend 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 foam-extend.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::solidBodyMotionFunctions::forceBased

Description
    Translation motion function with sine law ramping for velocity.

SourceFiles
    forceBased.C

\*---------------------------------------------------------------------------*/

#ifndef forceBased_H
#define forceBased_H

#include "solidBodyMotionFunction.H"
#include "immersedBoundaryForces.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
namespace solidBodyMotionFunctions
{

/*---------------------------------------------------------------------------*\
                          Class forceBased Declaration
\*---------------------------------------------------------------------------*/

class forceBased
:
    public solidBodyMotionFunction
{
    // Private data
        // This has been modified according to http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2016/EliasSiggeirsson/OF.pdf
        
        vector g_;
        scalar still_;
        scalar mass_;
        mutable vector velocity_;
        mutable vector oldPosition_;
        mutable scalar currentTime_;
        immersedBoundaryForces imBForces_;


    // Private Member Functions

        //- Disallow copy construct
        forceBased(const forceBased&);

        //- Disallow default bitwise assignment
        void operator=(const forceBased&);


        //- Position calculations
        vector newPosition() const;
        vector newVelocity() const;


public:

    //- Runtime type information
    TypeName("forceBased");


    // Constructors

        //- Construct from components
        forceBased
        (
            const dictionary& SBMFCoeffs,
            const Time& runTime
        );


    // Destructor

        virtual ~forceBased();


    // Member Functions

        //- Return the solid-body motion transformation septernion
        virtual septernion transformation() const;

        //- Return the solid-body motion velocity
        virtual septernion velocity() const;

        //- Update properties from given dictionary
        virtual bool read(const dictionary& SBMFCoeffs);
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace solidBodyMotionFunctions
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //

And here is the forceBased.C file which worked for me:


Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | foam-extend: Open Source CFD
   \\    /   O peration     | Version:     4.0
    \\  /    A nd           | Web:         http://www.foam-extend.org
     \\/     M anipulation  | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
    This file is part of foam-extend.

    foam-extend 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.

    foam-extend 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 foam-extend.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "forceBased.H"
#include "addToRunTimeSelectionTable.H"
#include "mathematicalConstants.H"

using namespace Foam::mathematicalConstant;

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace solidBodyMotionFunctions
{
    defineTypeNameAndDebug(forceBased, 0);
    addToRunTimeSelectionTable
    (
        solidBodyMotionFunction,
        forceBased,
        dictionary
    );
};
};


// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //

//Theforcebased.Cfile is set to run with a stationary object for the first still_time steps and thenwith a constant velocity of 0.01 for the next still_time steps and then to be set loose.

Foam::vector
Foam::solidBodyMotionFunctions::forceBased::newPosition() const
{
    scalar t = time_.value();
    scalar dT = time_.deltaT().value();
    
    if (t < (still_*dT+currentTime_))
    {
            return oldPosition_;
    }
    
    else if (t < 2*(still_*dT))
    {
        if (t > currentTime_)
            {
                currentTime_ = t;
                vector gravityForce = mass_*g_;
                Info << "Gravity: " << g_ << endl;
                Info << "Gravitational Force: " << gravityForce << endl;
                vector pressureForces = imBForces_.calcForcesMoment().first().first();
                vector viscousForces = imBForces_.calcForcesMoment().first().second();
                vector totalForce = gravityForce + pressureForces + viscousForces;
                
                Info << "Pressure Force: " << pressureForces << endl;
                Info << "Viscous Force: " << viscousForces << endl;
                Info << "Total Force: " << totalForce << endl;
                Info << "Delta t: " << dT << endl;
                Info << "Old position : " << oldPosition_ << endl;
                
                vector velocity(0.01,0,0);
                vector dx = velocity*dT;
                
                Info << "old velocity: " << velocity_ << endl;
                velocity_ = vector(0,0,0);//dx/dT;//velocity_+totalForce/mass_*dT;
                Info << "new velocity: " << velocity_ << endl;
                
                vector newPos=oldPosition_+dx;
                
                Info << "new position: " << newPos << endl;
                Info << "new old position: " << oldPosition_ << endl;
                oldPosition_ = newPos;
                return oldPosition_;
            }
            else
            {
                return oldPosition_;
            }
    }
    
    else
    {
        if (t > currentTime_)
        {
            currentTime_ = t;
            vector gravityForce = mass_*g_;
            Info << "Gravity: " << gravityForce << endl;
            vector pressureForces = imBForces_.calcForcesMoment().first().second();
            vector viscousForces = imBForces_.calcForcesMoment().first().second();
            vector totalForce = gravityForce + pressureForces + viscousForces;
            
            Info << "Force first: " << pressureForces << endl;
            Info << "Force second: " << viscousForces << endl;
            Info << "Total forst pos: " << totalForce << endl;
            Info << "Delta t: " << dT << endl;
            Info << "old position: " << oldPosition_ << endl;
            
            vector velocity_ = velocity_+totalForce*dT;
            
            vector newPos=oldPosition_+velocity_*dT+0.5*totalForce/mass_*pow(dT,2);
            
            oldPosition_ = newPos;
            Info << "new position: " << newPos << endl;
            Info << "old position: " << oldPosition_ << endl;
            Info << "velocity, pos: " << velocity_ << endl;
            oldPosition_ = newPos;
            return oldPosition_;
        }
        else
        {
            return oldPosition_;
        }
    }
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::solidBodyMotionFunctions::forceBased::forceBased
(
    const dictionary& SBMFCoeffs,
    const Time& runTime
)
:
    solidBodyMotionFunction(SBMFCoeffs, runTime),
    g_(0,0,0),
    velocity_(0,0,0),
    oldPosition_(0,0,0),
    currentTime_(0.0),
    imBForces_("test", time_.lookupObject<objectRegistry>(polyMesh::defaultRegion), SBMFCoeffs_, true)

{
    read(SBMFCoeffs);
}


// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //

Foam::solidBodyMotionFunctions::forceBased::~forceBased()
{}


// * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //

Foam::septernion
Foam::solidBodyMotionFunctions::forceBased::transformation() const
{
    septernion TR;
    
        TR = septernion
        (
            newPosition(),
            quaternion::I
        );
    
    return TR;
}


Foam::septernion
Foam::solidBodyMotionFunctions::forceBased::velocity() const
{
    septernion TV
    (
        velocity_,
        quaternion::I/time_.deltaT().value()
    );

    Info<< "solidBodyMotionFunctions::forceBased::transformation(): "
        << "Time = " << time_.value() << " velocity: " << TV << endl;

    return TV;
}


bool Foam::solidBodyMotionFunctions::forceBased::read
(
    const dictionary& SBMFCoeffs
)
{
    solidBodyMotionFunction::read(SBMFCoeffs);

    SBMFCoeffs_.lookup("gravity") >> g_;
    SBMFCoeffs_.lookup("mass") >> mass_;
    SBMFCoeffs_.lookup("stationary") >> still_;

    return true;
}


// ************************************************************************* //
saatt, yulia and IvanLu like this.
courant_numero_uno is offline   Reply With Quote

Old   May 28, 2023, 08:53
Question Problem in parallel running
  #2
New Member
 
Thomas Shi
Join Date: Jan 2018
Posts: 20
Rep Power: 8
ThomasLong is on a distinguished road
Hello! Firstly, thank you very much for your useful thread. According to your guide, I compiled the forceBased files in foam-extend 4.0 with no problem and I tested a case in serial successfully. However, when I tried to run the case in parallel, I got a problem. I stopped the running halfway, but it could not restart from the latest time and I got a mpi error. When I tested the same case in serial, it had no problem like this. Did you meet the same problem like me before?
Attached Images
File Type: jpg 2.jpg (69.7 KB, 6 views)
ThomasLong is offline   Reply With Quote

Old   May 31, 2023, 15:01
Default
  #3
New Member
 
Join Date: Sep 2019
Posts: 17
Rep Power: 6
courant_numero_uno is on a distinguished road
Quote:
Originally Posted by ThomasLong View Post
Hello! Firstly, thank you very much for your useful thread. According to your guide, I compiled the forceBased files in foam-extend 4.0 with no problem and I tested a case in serial successfully. However, when I tried to run the case in parallel, I got a problem. I stopped the running halfway, but it could not restart from the latest time and I got a mpi error. When I tested the same case in serial, it had no problem like this. Did you meet the same problem like me before?

Yes, I have had problems with the IBM in parallel. I believe the issue occurs when the immersed boundary crosses the boundary between two processor domains. To solve this, if you're just doing a straight y-direction VIV, you can partition the domain using "simple", in a manner that the immersed boundary always stays within one domain. This is just my own past experience.
courant_numero_uno is offline   Reply With Quote

Old   June 2, 2023, 12:04
Talking
  #4
New Member
 
Thomas Shi
Join Date: Jan 2018
Posts: 20
Rep Power: 8
ThomasLong is on a distinguished road
Quote:
Originally Posted by courant_numero_uno View Post
Yes, I have had problems with the IBM in parallel. I believe the issue occurs when the immersed boundary crosses the boundary between two processor domains. To solve this, if you're just doing a straight y-direction VIV, you can partition the domain using "simple", in a manner that the immersed boundary always stays within one domain. This is just my own past experience.
I am really appreciative of your reply. Your advice is quite useful. I partitioned the domain using "manual" method with "cellDecomposition" to keep the boundary between two processor domains away from the immersed boundary. And I also found that it always worked well when I ran the calculation in parallel from time 0. So I reconstructed the domain at the latestTime and rename the folder as "0", then it could be run in parallel again.

However, when I took turbulence flow into consideration, a new error occured in immersed boundary condition of "U" file. I googled the error but did not get any solution. Have you ever used turbulence models in IBM? Have you ever met the same boundary condition error before? Your reply will be appreciated!
Attached Images
File Type: jpg 3.jpg (37.0 KB, 5 views)
ThomasLong is offline   Reply With Quote

Reply


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
Radiation in semi-transparent media with surface-to-surface model? mpeppels CFX 11 August 22, 2019 07:30
[ImmersedBoundary] Immersed Boundary Method DoQuocVu OpenFOAM Community Contributions 11 July 13, 2018 09:36
OpenFOAM 4.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 2 October 6, 2017 05:40
Centrifugal fan-reverse flow in outlet lesds to a mass in flow field xiexing CFX 3 March 29, 2017 10:00
Error - Solar absorber - Solar Thermal Radiation MichaelK CFX 12 September 1, 2016 05:15


All times are GMT -4. The time now is 04:39.