rigidBodyMeshMotion: displacementMotionSolver for the mesh-motion of multiple articulated rigid-bodies

The motion of the bodies is integrated using the rigidBodyDynamics
library with joints, restraints and external forces.

The mesh-motion is interpolated using septernion averaging.

This development is sponsored by Carnegie Wave Energy Ltd.
This commit is contained in:
Henry Weller
2016-04-16 16:02:25 +01:00
parent f78d929b3f
commit 69e877a53a
20 changed files with 782 additions and 116 deletions

View File

@ -0,0 +1,3 @@
rigidBodyMeshMotion.C
LIB = $(FOAM_LIBBIN)/librigidBodyMeshMotion

View File

@ -0,0 +1,14 @@
EXE_INC = -ggdb3 -DFULLDEBUG \
-I$(LIB_SRC)/rigidBodyDynamics/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/postProcessing/functionObjects/forces/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude
LIB_LIBS = \
-lrigidBodyDynamics \
-lforces \
-lmeshTools \
-lfileFormats \
-ldynamicMesh

View File

@ -0,0 +1,357 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 "rigidBodyMeshMotion.H"
#include "addToRunTimeSelectionTable.H"
#include "polyMesh.H"
#include "pointPatchDist.H"
#include "pointConstraints.H"
#include "uniformDimensionedFields.H"
#include "forces.H"
#include "mathematicalConstants.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(rigidBodyMeshMotion, 0);
addToRunTimeSelectionTable
(
motionSolver,
rigidBodyMeshMotion,
dictionary
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::rigidBodyMeshMotion::bodyMesh::bodyMesh
(
const polyMesh& mesh,
const word& name,
const label bodyID,
const dictionary& dict
)
:
name_(name),
bodyID_(bodyID),
patches_(wordReList(dict.lookup("patches"))),
patchSet_(mesh.boundaryMesh().patchSet(patches_)),
di_(readScalar(dict.lookup("innerDistance"))),
do_(readScalar(dict.lookup("outerDistance"))),
weight_
(
IOobject
(
name_ + ".motionScale",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
pointMesh::New(mesh),
dimensionedScalar("zero", dimless, 0.0)
)
{}
Foam::rigidBodyMeshMotion::rigidBodyMeshMotion
(
const polyMesh& mesh,
const IOdictionary& dict
)
:
displacementMotionSolver(mesh, dict, typeName),
model_
(
coeffDict(),
IOobject
(
"rigidBodyMotionState",
mesh.time().timeName(),
"uniform",
mesh
).headerOk()
? IOdictionary
(
IOobject
(
"rigidBodyMotionState",
mesh.time().timeName(),
"uniform",
mesh,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
)
)
: coeffDict()
),
test_(coeffDict().lookupOrDefault<Switch>("test", false)),
rhoInf_(1.0),
rhoName_(coeffDict().lookupOrDefault<word>("rhoName", "rho")),
curTimeIndex_(-1)
{
if (rhoName_ == "rhoInf")
{
rhoInf_ = readScalar(coeffDict().lookup("rhoInf"));
}
const dictionary& bodiesDict = coeffDict().subDict("bodies");
forAllConstIter(IDLList<entry>, bodiesDict, iter)
{
const dictionary& bodyDict = iter().dict();
if (bodyDict.found("patches"))
{
bodyMeshes_.append
(
new bodyMesh
(
mesh,
iter().keyword(),
model_.bodyID(iter().keyword()),
bodyDict
)
);
}
}
// Calculate scaling factor everywhere for each meshed body
forAll(bodyMeshes_, bi)
{
const pointMesh& pMesh = pointMesh::New(mesh);
pointPatchDist pDist(pMesh, bodyMeshes_[bi].patchSet_, points0());
pointScalarField& scale = bodyMeshes_[bi].weight_;
// Scaling: 1 up to di then linear down to 0 at do away from patches
scale.internalField() =
min
(
max
(
(bodyMeshes_[bi].do_ - pDist.internalField())
/(bodyMeshes_[bi].do_ - bodyMeshes_[bi].di_),
scalar(0)
),
scalar(1)
);
// Convert the scale function to a cosine
scale.internalField() =
min
(
max
(
0.5
- 0.5
*cos(scale.internalField()
*Foam::constant::mathematical::pi),
scalar(0)
),
scalar(1)
);
pointConstraints::New(pMesh).constrain(scale);
//scale.write();
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::rigidBodyMeshMotion::~rigidBodyMeshMotion()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::tmp<Foam::pointField>
Foam::rigidBodyMeshMotion::curPoints() const
{
return points0() + pointDisplacement_.internalField();
}
void Foam::rigidBodyMeshMotion::solve()
{
const Time& t = mesh().time();
if (mesh().nPoints() != points0().size())
{
FatalErrorInFunction
<< "The number of points in the mesh seems to have changed." << endl
<< "In constant/polyMesh there are " << points0().size()
<< " points; in the current mesh there are " << mesh().nPoints()
<< " points." << exit(FatalError);
}
// Store the motion state at the beginning of the time-step
if (curTimeIndex_ != this->db().time().timeIndex())
{
model_.newTime();
curTimeIndex_ = this->db().time().timeIndex();
}
dimensionedVector g("g", dimAcceleration, vector::zero);
if (db().foundObject<uniformDimensionedVectorField>("g"))
{
g = db().lookupObject<uniformDimensionedVectorField>("g");
}
else if (coeffDict().found("g"))
{
coeffDict().lookup("g") >> g;
}
model_.g() = g.value();
if (test_)
{
label nIter(readLabel(coeffDict().lookup("nIter")));
for (label i=0; i<nIter; i++)
{
model_.solve
(
t.deltaTValue(),
scalarField(model_.nDoF(), Zero),
Field<spatialVector>(model_.nBodies(), Zero)
);
}
}
else
{
Field<spatialVector> fx(model_.nBodies(), Zero);
forAll(bodyMeshes_, bi)
{
const label bodyID = bodyMeshes_[bi].bodyID_;
dictionary forcesDict;
forcesDict.add("type", forces::typeName);
forcesDict.add("patches", bodyMeshes_[bi].patches_);
forcesDict.add("rhoInf", rhoInf_);
forcesDict.add("rhoName", rhoName_);
forcesDict.add("CofR", model_.X0(bodyID).r());
forces f("forces", db(), forcesDict);
f.calcForcesMoment();
fx[bodyID].l() = f.forceEff();
fx[bodyID].w() = f.momentEff();
}
model_.solve
(
t.deltaTValue(),
scalarField(model_.nDoF(), Zero),
fx
);
}
// Update the displacements
if (bodyMeshes_.size() == 1)
{
pointDisplacement_.internalField() = model_.transformPoints
(
bodyMeshes_[0].bodyID_,
bodyMeshes_[0].weight_,
points0()
) - points0();
}
else
{
labelList bodyIDs(bodyMeshes_.size());
List<const scalarField*> weights(bodyMeshes_.size());
forAll(bodyIDs, bi)
{
bodyIDs[bi] = bodyMeshes_[bi].bodyID_;
weights[bi] = &bodyMeshes_[bi].weight_;
}
pointDisplacement_.internalField() =
model_.transformPoints(bodyIDs, weights, points0()) - points0();
}
// Displacement has changed. Update boundary conditions
pointConstraints::New
(
pointDisplacement_.mesh()
).constrainDisplacement(pointDisplacement_);
}
bool Foam::rigidBodyMeshMotion::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
) const
{
IOdictionary dict
(
IOobject
(
"rigidBodyMotionState",
mesh().time().timeName(),
"uniform",
mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
)
);
model_.state().write(dict);
return dict.regIOobject::write();
}
bool Foam::rigidBodyMeshMotion::read()
{
if (displacementMotionSolver::read())
{
model_.read(coeffDict());
return true;
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,184 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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::rigidBodyMeshMotion
Description
Rigid-body mesh motion solver for fvMesh.
Applies septernion interpolation of movement as function of distance to the
object surface.
SourceFiles
rigidBodyMeshMotion.C
\*---------------------------------------------------------------------------*/
#ifndef rigidBodyMeshMotion_H
#define rigidBodyMeshMotion_H
#include "displacementMotionSolver.H"
#include "rigidBodyMotion.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class rigidBodyMeshMotion Declaration
\*---------------------------------------------------------------------------*/
class rigidBodyMeshMotion
:
public displacementMotionSolver
{
//- Class containing the patches and point motion weighting for each body
class bodyMesh
{
//- Name of the body
const word name_;
//- ID of the body in the RBD::rigidBodyMotion
const label bodyID_;
//- List of mesh patches associated with this body
const wordReList patches_;
//- Patches to integrate forces
const labelHashSet patchSet_;
//- Inner morphing distance (limit of solid-body region)
const scalar di_;
//- Outer morphing distance (limit of linear interpolation region)
const scalar do_;
//- Current interpolation weight
// (1 at patches and within di_, 0 at do_ and beyond)
pointScalarField weight_;
public:
friend class rigidBodyMeshMotion;
bodyMesh
(
const polyMesh& mesh,
const word& name,
const label bodyID,
const dictionary& dict
);
};
// Private data
//- Rigid-body model
RBD::rigidBodyMotion model_;
//- List of the bodyMeshes containing the patches and point motion
// weighting for each body
PtrList<bodyMesh> bodyMeshes_;
//- Switch for test-mode in which only the
// gravitational body-force is applied
Switch test_;
//- Reference density required by the forces object for
// incompressible calculations, required if rhoName == rhoInf
scalar rhoInf_;
//- Name of density field, optional unless used for an
// incompressible simulation, when this needs to be specified
// as rhoInf
word rhoName_;
//- Current time index (used for updating)
label curTimeIndex_;
// Private Member Functions
//- Disallow default bitwise copy construct
rigidBodyMeshMotion
(
const rigidBodyMeshMotion&
);
//- Disallow default bitwise assignment
void operator=(const rigidBodyMeshMotion&);
public:
//- Runtime type information
TypeName("rigidBodyMotion");
// Constructors
//- Construct from polyMesh and IOdictionary
rigidBodyMeshMotion
(
const polyMesh&,
const IOdictionary& dict
);
//- Destructor
~rigidBodyMeshMotion();
// Member Functions
//- Return point location obtained from the current motion field
virtual tmp<pointField> curPoints() const;
//- Solve for motion
virtual void solve();
//- Write state using given format, version and compression
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
) const;
//- Read dynamicMeshDict dictionary
virtual bool read();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //