Skip to content
Permalink
Browse files

sixDoFRigidBodyControl: functionObject to stop the run when the body …

…motion converges

Description
    Convergence control based on the 6-DoF motion state.

    The body linear and angular velocities are averaged over a specified time
    window and compared to specified velocity convergence criteria and the run
    stopped after writing the current time results, if the criteria are met.

    Example of function object specification:
    \verbatim
    sixDoFRigidBodyControl
    {
        type           sixDoFRigidBodyControl;
        libs           ("libsixDoFRigidBodyState.so");

        angleFormat    degrees;

        window                      1;
        convergedVelocity           (1e-2 1e-2 1e-2);
        convergedAngularVelocity    (5 5 5);
    }
    \endverbatim

    Note the units of the \c convergedAngularVelocity are specified by the \c
    angleFormat entry.

Usage
    \table
    Property     | Description                       | Required | Default value
    type         | Type name: sixDoFRigidBodyControl | yes      |
    angleFormat  | Degrees or radians                | no       | radian
    window       | Averaging window                  | yes      |
    convergedVelocity | Linear velocity convergence criterion         | yes |
    convergedAngularVelocity | Angular velocity convergence criterion | yes |
    \endtable
  • Loading branch information...
Henry Weller
Henry Weller committed Jul 30, 2018
1 parent 34f0cae commit b4a00c12ca4d8db76997191c78ea99c81a2993f4
@@ -1,3 +1,4 @@
sixDoFRigidBodyState.C
sixDoFRigidBodyState/sixDoFRigidBodyState.C
sixDoFRigidBodyControl/sixDoFRigidBodyControl.C

LIB = $(FOAM_LIBBIN)/libsixDoFRigidBodyState
@@ -0,0 +1,119 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2018 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 "sixDoFRigidBodyControl.H"
#include "Time.H"
#include "addToRunTimeSelectionTable.H"

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

namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(sixDoFRigidBodyControl, 0);

addToRunTimeSelectionTable
(
functionObject,
sixDoFRigidBodyControl,
dictionary
);
}
}


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

Foam::functionObjects::sixDoFRigidBodyControl::sixDoFRigidBodyControl
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
sixDoFRigidBodyState(name, runTime, dict),
time_(runTime),
meanVelocity_(Zero),
meanAngularVelocity_(Zero)
{
read(dict);
resetName(typeName);
}


// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

Foam::functionObjects::sixDoFRigidBodyControl::~sixDoFRigidBodyControl()
{}


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

bool Foam::functionObjects::sixDoFRigidBodyControl::read(const dictionary& dict)
{
sixDoFRigidBodyState::read(dict);

dict.lookup("window") >> w_;
dict.lookup("convergedVelocity") >> convergedVelocity_;
dict.lookup("convergedAngularVelocity") >> convergedAngularVelocity_;

return true;
}


bool Foam::functionObjects::sixDoFRigidBodyControl::execute()
{
if (time_.timeIndex() <= time_.startTimeIndex() + 1)
{
meanVelocity_ = cmptMag(velocity());
meanAngularVelocity_ = cmptMag(angularVelocity());
}
else
{
const scalar dt = time_.deltaTValue();
const scalar beta = min(dt/w_, 1);

meanVelocity_ = (1 - beta)*meanVelocity_ + beta*cmptMag(velocity());

meanAngularVelocity_ =
(1 - beta)*meanAngularVelocity_ + beta*cmptMag(angularVelocity());
}

if
(
time_.value() - time_.startTime().value() > w_
&& meanVelocity_ < convergedVelocity_
&& meanAngularVelocity_ < convergedAngularVelocity_
)
{
time_.stopAt(Time::saWriteNow);
}

return true;
}


// ************************************************************************* //
@@ -0,0 +1,155 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2018 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::functionObjects::sixDoFRigidBodyControl
Description
Convergence control based on the 6-DoF motion state.
The body linear and angular velocities are averaged over a specified time
window and compared to specified velocity convergence criteria and the run
stopped after writing the current time results, if the criteria are met.
Example of function object specification:
\verbatim
sixDoFRigidBodyControl
{
type sixDoFRigidBodyControl;
libs ("libsixDoFRigidBodyState.so");
angleFormat degrees;
window 1;
convergedVelocity (1e-2 1e-2 1e-2);
convergedAngularVelocity (5 5 5);
}
\endverbatim
Note the units of the \c convergedAngularVelocity are specified by the \c
angleFormat entry.
Usage
\table
Property | Description | Required | Default value
type | Type name: sixDoFRigidBodyControl | yes |
angleFormat | Degrees or radians | no | radian
window | Averaging window | yes |
convergedVelocity | Linear velocity convergence criterion | yes |
convergedAngularVelocity | Angular velocity convergence criterion | yes |
\endtable
See also
Foam::functionObjects::sixDoFRigidBodyState
SourceFiles
sixDoFRigidBodyControl.C
\*---------------------------------------------------------------------------*/

#ifndef sixDoFRigidBodyControl_H
#define sixDoFRigidBodyControl_H

#include "sixDoFRigidBodyState.H"

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

namespace Foam
{
namespace functionObjects
{

/*---------------------------------------------------------------------------*\
Class sixDoFRigidBodyControl Declaration
\*---------------------------------------------------------------------------*/

class sixDoFRigidBodyControl
:
public sixDoFRigidBodyState
{
// Private data

//- Reference to the Time
const Time& time_;

scalar w_;

vector convergedVelocity_;

vector convergedAngularVelocity_;

vector meanVelocity_;

vector meanAngularVelocity_;


// Private Member Functions

//- Disallow default bitwise copy construct
sixDoFRigidBodyControl(const sixDoFRigidBodyControl&);

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


public:

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


// Constructors

//- Construct from Time and dictionary
sixDoFRigidBodyControl
(
const word& name,
const Time& runTime,
const dictionary& dict
);


//- Destructor
virtual ~sixDoFRigidBodyControl();


// Member Functions

//- Read the sixDoFRigidBodyControl data
virtual bool read(const dictionary&);

//- Execute, currently does nothing
virtual bool execute();
};


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

} // End namespace functionObjects
} // End namespace Foam

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

#endif

// ************************************************************************* //
@@ -104,19 +104,49 @@ bool Foam::functionObjects::sixDoFRigidBodyState::execute()
}


const Foam::sixDoFRigidBodyMotion&
Foam::functionObjects::sixDoFRigidBodyState::motion() const
{
const dynamicMotionSolverFvMesh& mesh =
refCast<const dynamicMotionSolverFvMesh>(obr_);

const sixDoFRigidBodyMotionSolver& motionSolver_ =
refCast<const sixDoFRigidBodyMotionSolver>(mesh.motion());

return motionSolver_.motion();
}


Foam::vector
Foam::functionObjects::sixDoFRigidBodyState::velocity() const
{
return motion().v();
}


Foam::vector
Foam::functionObjects::sixDoFRigidBodyState::angularVelocity() const
{
vector angularVelocity(motion().omega());

if (angleFormat_ == "degrees")
{
angularVelocity.x() = radToDeg(angularVelocity.x());
angularVelocity.y() = radToDeg(angularVelocity.y());
angularVelocity.z() = radToDeg(angularVelocity.z());
}

return angularVelocity;
}


bool Foam::functionObjects::sixDoFRigidBodyState::write()
{
logFiles::write();

if (Pstream::master())
{
const dynamicMotionSolverFvMesh& mesh =
refCast<const dynamicMotionSolverFvMesh>(obr_);

const sixDoFRigidBodyMotionSolver& motionSolver_ =
refCast<const sixDoFRigidBodyMotionSolver>(mesh.motion());

const sixDoFRigidBodyMotion& motion = motionSolver_.motion();
const sixDoFRigidBodyMotion& motion = this->motion();

vector rotationAngle
(
@@ -57,12 +57,15 @@ SourceFiles
#define sixDoFRigidBodyState_H

#include "fvMeshFunctionObject.H"
#include "vector.H"
#include "logFiles.H"

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

namespace Foam
{
class sixDoFRigidBodyMotion;

namespace functionObjects
{

@@ -82,6 +85,8 @@ class sixDoFRigidBodyState

// Private Member Functions

const sixDoFRigidBodyMotion& motion() const;

//- Disallow default bitwise copy construct
sixDoFRigidBodyState(const sixDoFRigidBodyState&);

@@ -120,6 +125,10 @@ public:

// Member Functions

vector velocity() const;

vector angularVelocity() const;

//- Read the sixDoFRigidBodyState data
virtual bool read(const dictionary&);

0 comments on commit b4a00c1

Please sign in to comment.
You can’t perform that action at this time.