Commit 04e4e1a7 authored by Henry Weller's avatar Henry Weller
Browse files

rigidBodyMeshMotion: displacementMotionSolver for the mesh-motion of multiple...

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.
parent 831e429d
......@@ -104,4 +104,7 @@ extrudePatchMesh/extrudePatchMesh.C
polyMeshFilter/polyMeshFilterSettings.C
polyMeshFilter/polyMeshFilter.C
pointPatchDist/externalPointEdgePoint.C
pointPatchDist/pointPatchDist.C
LIB = $(FOAM_LIBBIN)/libdynamicMesh
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
......@@ -34,7 +34,8 @@ Foam::RBD::rigidBodyModelState::rigidBodyModelState
:
q_(model.nDoF(), Zero),
qDot_(model.nDoF(), Zero),
qDdot_(model.nDoF(), Zero)
qDdot_(model.nDoF(), Zero),
deltaT_(0)
{}
......@@ -46,7 +47,8 @@ Foam::RBD::rigidBodyModelState::rigidBodyModelState
:
q_(dict.lookupOrDefault("q", scalarField(model.nDoF(), Zero))),
qDot_(dict.lookupOrDefault("qDot", scalarField(model.nDoF(), Zero))),
qDdot_(dict.lookupOrDefault("qDdot", scalarField(model.nDoF(), Zero)))
qDdot_(dict.lookupOrDefault("qDdot", scalarField(model.nDoF(), Zero))),
deltaT_(dict.lookupOrDefault<scalar>("deltaT", 0))
{}
......
......@@ -76,6 +76,9 @@ class rigidBodyModelState
//- Joint acceleration
scalarField qDdot_;
//- The time-step used to integrate to this state
scalar deltaT_;
public:
......@@ -107,6 +110,9 @@ public:
//- Return access to the joint acceleration
inline const scalarField& qDdot() const;
//- Return access to the time-step
inline scalar deltaT() const;
// Edit
......@@ -121,6 +127,9 @@ public:
//- Return access to the joint acceleration
inline scalarField& qDdot();
//- Return access to the time-step
inline scalar& deltaT();
//- Write to dictionary
void write(dictionary& dict) const;
......
......@@ -43,6 +43,12 @@ inline const Foam::scalarField& Foam::RBD::rigidBodyModelState::qDdot() const
}
inline Foam::scalar Foam::RBD::rigidBodyModelState::deltaT() const
{
return deltaT_;
}
inline Foam::scalarField& Foam::RBD::rigidBodyModelState::q()
{
return q_;
......@@ -61,4 +67,10 @@ inline Foam::scalarField& Foam::RBD::rigidBodyModelState::qDdot()
}
inline Foam::scalar& Foam::RBD::rigidBodyModelState::deltaT()
{
return deltaT_;
}
// ************************************************************************* //
......@@ -33,6 +33,7 @@ void Foam::RBD::rigidBodyModelState::write(dictionary& dict) const
dict.add("q", q_);
dict.add("qDot", qDot_);
dict.add("qDdot", qDdot_);
dict.add("deltaT", deltaT_);
}
......@@ -41,6 +42,7 @@ void Foam::RBD::rigidBodyModelState::write(Ostream& os) const
os.writeKeyword("q") << q_ << token::END_STATEMENT << nl;
os.writeKeyword("qDot") << qDot_ << token::END_STATEMENT << nl;
os.writeKeyword("qDdot") << qDdot_ << token::END_STATEMENT << nl;
os.writeKeyword("deltaT") << deltaT_ << token::END_STATEMENT << nl;
}
......@@ -54,7 +56,8 @@ Foam::Istream& Foam::RBD::operator>>
{
is >> state.q_
>> state.qDot_
>> state.qDdot_;
>> state.qDdot_
>> state.deltaT_;
// Check state of Istream
is.check
......@@ -75,7 +78,8 @@ Foam::Ostream& Foam::RBD::operator<<
{
os << token::SPACE << state.q_
<< token::SPACE << state.qDot_
<< token::SPACE << state.qDdot_;
<< token::SPACE << state.qDdot_
<< token::SPACE << state.deltaT_;
// Check state of Ostream
os.check
......
......@@ -25,6 +25,20 @@ License
#include "rigidBodyMotion.H"
#include "rigidBodySolver.H"
#include "septernion.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::RBD::rigidBodyMotion::initialize()
{
// Calculate the initial body-state
forwardDynamicsCorrection(rigidBodyModelState(*this));
X00_ = X0_;
// Update the body-state to correspond to the current joint-state
forwardDynamicsCorrection(motionState_);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -39,7 +53,6 @@ Foam::RBD::rigidBodyMotion::rigidBodyMotion()
solver_(NULL)
{}
Foam::RBD::rigidBodyMotion::rigidBodyMotion
(
const dictionary& dict
......@@ -48,11 +61,14 @@ Foam::RBD::rigidBodyMotion::rigidBodyMotion
rigidBodyModel(dict),
motionState_(*this),
motionState0_(motionState_),
X00_(X0_.size()),
aRelax_(dict.lookupOrDefault<scalar>("accelerationRelaxation", 1.0)),
aDamp_(dict.lookupOrDefault<scalar>("accelerationDamping", 1.0)),
report_(dict.lookupOrDefault<Switch>("report", false)),
solver_(rigidBodySolver::New(*this, dict.subDict("solver")))
{}
{
initialize();
}
Foam::RBD::rigidBodyMotion::rigidBodyMotion
......@@ -64,11 +80,14 @@ Foam::RBD::rigidBodyMotion::rigidBodyMotion
rigidBodyModel(dict),
motionState_(*this, stateDict),
motionState0_(motionState_),
X00_(X0_.size()),
aRelax_(dict.lookupOrDefault<scalar>("accelerationRelaxation", 1.0)),
aDamp_(dict.lookupOrDefault<scalar>("accelerationDamping", 1.0)),
report_(dict.lookupOrDefault<Switch>("report", false)),
solver_(rigidBodySolver::New(*this, dict.subDict("solver")))
{}
{
initialize();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
......@@ -79,6 +98,23 @@ Foam::RBD::rigidBodyMotion::~rigidBodyMotion()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::spatialTransform Foam::RBD::rigidBodyMotion::X00
(
const label bodyId
) const
{
if (merged(bodyId))
{
const subBody& mBody = mergedBody(bodyId);
return mBody.masterXT() & X00_[mBody.masterID()];
}
else
{
return X00_[bodyId];
}
}
void Foam::RBD::rigidBodyMotion::solve
(
scalar deltaT,
......@@ -86,7 +122,12 @@ void Foam::RBD::rigidBodyMotion::solve
const Field<spatialVector>& fx
)
{
deltaT_ = deltaT;
motionState_.deltaT() = deltaT;
if (motionState0_.deltaT() < SMALL)
{
motionState0_.deltaT() = deltaT;
}
if (Pstream::master())
{
......@@ -115,64 +156,108 @@ void Foam::RBD::rigidBodyMotion::status() const
*/
}
/*
Foam::tmp<Foam::pointField> Foam::RBD::rigidBodyMotion::transform
Foam::tmp<Foam::pointField> Foam::RBD::rigidBodyMotion::transformPoints
(
const label bodyID,
const scalarField& weight,
const pointField& initialPoints
) const
{
return
(
centreOfRotation()
+ (Q() & initialQ_.T() & (initialPoints - initialCentreOfRotation_))
);
}
// Calculate the transform from the initial state in the global frame
// to the current state in the global frame
spatialTransform X(X0(bodyID).inv() & X00(bodyID));
Foam::tmp<Foam::pointField> Foam::RBD::rigidBodyMotion::transform
(
const pointField& initialPoints,
const scalarField& scale
) const
{
// Calculate the transformation septerion from the initial state
septernion s
(
centreOfRotation() - initialCentreOfRotation(),
quaternion(Q() & initialQ().T())
);
// Calculate the septernion equivalent of the transformation for 'slerp'
// interpolation
septernion s(X);
tmp<pointField> tpoints(new pointField(initialPoints));
pointField& points = tpoints.ref();
forAll(points, pointi)
forAll(points, i)
{
// Move non-stationary points
if (scale[pointi] > SMALL)
if (weight[i] > SMALL)
{
// Use solid-body motion where scale = 1
if (scale[pointi] > 1 - SMALL)
// Use solid-body motion where weight = 1
if (weight[i] > 1 - SMALL)
{
points[pointi] = transform(initialPoints[pointi]);
points[i] = X.transformPoint(initialPoints[i]);
}
// Slerp septernion interpolation
else
{
septernion ss(slerp(septernion::I, s, scale[pointi]));
points[pointi] =
initialCentreOfRotation()
+ ss.transform
(
initialPoints[pointi]
- initialCentreOfRotation()
);
points[i] =
slerp(septernion::I, s, weight[i])
.transformPoint(initialPoints[i]);
}
}
}
return tpoints;
}
*/
Foam::tmp<Foam::pointField> Foam::RBD::rigidBodyMotion::transformPoints
(
const labelList& bodyIDs,
const List<const scalarField*>& weights,
const pointField& initialPoints
) const
{
List<septernion> ss(bodyIDs.size() + 1);
ss[bodyIDs.size()] = septernion::I;
forAll(bodyIDs, bi)
{
const label bodyID = bodyIDs[bi];
// Calculate the transform from the initial state in the global frame
// to the current state in the global frame
spatialTransform X(X0(bodyID).inv() & X00(bodyID));
// Calculate the septernion equivalent of the transformation
ss[bi] = septernion(X);
}
tmp<pointField> tpoints(new pointField(initialPoints));
pointField& points = tpoints.ref();
List<scalar> w(ss.size());
forAll(points, i)
{
// Sum (1 - wi) and find the maximum wi
scalar sum1mw = 0;
scalar maxw = 0;
forAll(bodyIDs, bi)
{
w[bi] = (*(weights[bi]))[i];
sum1mw += 1 - w[bi];
maxw = max(maxw, w[bi]);
}
// Calculate the limiter for (1 - wi) to ensure the sum(wi) = maxw
scalar lambda = (w.size() - 1 - maxw)/sum1mw;
// Limit (1 - wi) and sum the resulting wi
scalar sumw = 0;
forAll(bodyIDs, bi)
{
w[bi] = 1 - lambda*(1 - w[bi]);
sumw += w[bi];
}
// Calculate the weight for the stationary far-field
w[bodyIDs.size()] = 1 - sumw;
points[i] = average(ss, w).transformPoint(initialPoints[i]);
}
return tpoints;
}
// ************************************************************************* //
......@@ -79,11 +79,8 @@ class rigidBodyMotion
//- Motion state data object for previous time-step
rigidBodyModelState motionState0_;
//- The current time-step
scalar deltaT_;
//- The previous time-step
scalar deltaT0_;
//- Initial transform for external forces to the bodies reference frame
List<spatialTransform> X00_;
//- Acceleration relaxation coefficient
scalar aRelax_;
......@@ -98,9 +95,17 @@ class rigidBodyMotion
autoPtr<rigidBodySolver> solver_;
//- Construct as copy
// Private Member Functions
//- Initialize the body-state
void initialize();
//- Disallow copy construct
rigidBodyMotion(const rigidBodyMotion&);
//- Disallow default bitwise assignment
void operator=(const rigidBodyMotion&);
public:
......@@ -140,6 +145,10 @@ public:
//- Return the motion state for modification
inline rigidBodyModelState& state();
//- Return the initial transform to the global frame for the
// given body
spatialTransform X00(const label bodyId) const;
// Edit
......@@ -164,23 +173,26 @@ public:
// Transformations
/*
//- Transform the given initial state point by the current motion
// state
inline point transform(const point& initialPoints) const;
//- Transform the given initial state pointField by the current
// motion state
tmp<pointField> transform(const pointField& initialPoints) const;
//- Transform the given initial pointField of the specified body
// to correspond to the current motion state scaled using
// 'slerp' interpolation
tmp<pointField> transformPoints
(
const label bodyID,
const scalarField& weight,
const pointField& initialPoints
) const;
//- Transform the given initial state pointField by the current
// motion state scaled by the given scale
tmp<pointField> transform
//- Transform the given initial pointField of the specified body
// to correspond to the current motion state scaled using
// 'slerp' interpolation
tmp<pointField> transformPoints
(
const pointField& initialPoints,
const scalarField& scale
const labelList& bodyIDs,
const List<const scalarField*>& weights,
const pointField& initialPoints
) const;
*/
//- Write
void write(Ostream&) const;
......
......@@ -48,23 +48,7 @@ Foam::RBD::rigidBodyMotion::state()
inline void Foam::RBD::rigidBodyMotion::newTime()
{
motionState0_ = motionState_;
deltaT0_ = deltaT_;
}
/*
inline Foam::point Foam::RBD::rigidBodyMotion::transform
(
const point& initialPoint
) const
{
return
(
centreOfRotation()
+ (Q() & initialQ_.T() & (initialPoint - initialCentreOfRotation_))
);
}
*/
// ************************************************************************* //
......@@ -62,15 +62,6 @@ protected:
//- Return the motion state
inline rigidBodyModelState& state();
//- Return the previous motion state
inline const rigidBodyModelState& state0() const;
//- Return the current time-step
inline scalar deltaT() const;
//- Return the previous time-step
inline scalar deltaT0() const;
//- Return the current joint position and orientation
inline scalarField& q();
......@@ -82,6 +73,12 @@ protected:
//- Return the current joint acceleration
inline scalarField& qDdot();
//- Return the current time-step
inline scalar deltaT() const;
//- Return the previous motion state
inline const rigidBodyModelState& state0() const;
//- Return the current joint position and orientation
inline const scalarField& q0() const;
......@@ -94,6 +91,9 @@ protected:
//- Return the current joint acceleration
inline const scalarField& qDdot0() const;
//- Return the previous time-step
inline scalar deltaT0() const;
//- Acceleration damping coefficient (for steady-state simulations)
inline scalar aDamp() const;
......
......@@ -31,43 +31,36 @@ inline Foam::RBD::rigidBodyModelState& Foam::RBD::rigidBodySolver::state()
}
inline const Foam::RBD::rigidBodyModelState&
Foam::RBD::rigidBodySolver::state0() const
{
return model_.motionState0_;
}
inline Foam::scalar Foam::RBD::rigidBodySolver::deltaT() const
inline Foam::scalarField& Foam::RBD::rigidBodySolver::q()
{
return model_.deltaT_;
return state().q();
}
inline Foam::scalar Foam::RBD::rigidBodySolver::deltaT0() const
inline Foam::scalarField& Foam::RBD::rigidBodySolver::qDot()
{
return model_.deltaT0_;
return state().qDot();
}
inline Foam::scalarField& Foam::RBD::rigidBodySolver::q()
inline Foam::scalarField& Foam::RBD::rigidBodySolver::qDdot()
{
return state().q();
return state().qDdot();
}
inline Foam::scalarField& Foam::RBD::rigidBodySolver::qDot()
inline Foam::scalar Foam::RBD::rigidBodySolver::deltaT() const
{
return state().qDot();
return model_.motionState_.deltaT();
}
inline Foam::scalarField& Foam::RBD::rigidBodySolver::qDdot()
inline const Foam::RBD::rigidBodyModelState&
Foam::RBD::rigidBodySolver::