60 const rigidBodyModel& model
91 vector oldDir = refQ_ & refDir;
92 vector newDir = model_.X0(bodyID_).E() & refDir;
94 if (
mag(oldDir & axis_) > 0.95 ||
mag(newDir & axis_) > 0.95)
98 oldDir = refQ_ & refDir;
99 newDir = model_.X0(bodyID_).E() & refDir;
103 oldDir -= (axis_ & oldDir)*axis_;
104 oldDir /= (
mag(oldDir) + VSMALL);
106 newDir -= (axis_ & newDir)*axis_;
107 newDir /= (
mag(newDir) + VSMALL);
109 scalar theta =
mag(
acos(
min(oldDir & newDir, 1.0)));
112 vector a = (oldDir ^ newDir);
115 a = (a & axis_)*axis_;
117 scalar magA =
mag(a);
129 vector omega = model_.v(model_.master(bodyID_)).w();
131 scalar Inertia =
mag(model_.I(model_.master(bodyID_)).Ic());
136 vector error = omegaSet_->value(model_.time().value()) - omega;
137 vector integral = integral0_ + error;
138 vector derivative = (error - error0_);
140 vector moment = ((p_*error + i_*integral + d_*derivative)&a)*a;
141 moment *= Inertia/model_.time().deltaTValue();
143 moment = relax_*moment + (1- relax_)*oldMom_;
148 <<
" omega " << omega <<
endl
149 <<
" wanted " << omegaSet_->value(model_.time().value()) <<
endl
150 <<
" moment " << moment <<
endl
151 <<
" oldDir " << oldDir <<
endl
152 <<
" newDir " << newDir <<
endl
153 <<
" inertia " << Inertia <<
endl
154 <<
" error " << error <<
endl
155 <<
" integral " << integral <<
endl
156 <<
" derivative " << derivative <<
endl
157 <<
" refDir " << refDir
166 integral0_ = integral;
177 refQ_ = coeffs_.getOrDefault<
tensor>(
"referenceOrientation",
I);
182 <<
"referenceOrientation " << refQ_ <<
" is not a rotation tensor. "
183 <<
"mag(referenceOrientation) - sqrt(3) = "
188 coeffs_.readEntry(
"axis", axis_);
190 const scalar magAxis(
mag(axis_));
192 coeffs_.readEntry(
"relax", relax_);
194 coeffs_.readEntry(
"p", p_);
195 coeffs_.readEntry(
"i", i_);
196 coeffs_.readEntry(
"d", d_);
198 if (magAxis > VSMALL)
205 <<
"axis has zero length"
210 omegaSet_.reset(Function1<vector>::New(
"omega",
coeffs_, &
model_.time()));
223 os.writeEntry(
"referenceOrientation", refQ_);
224 os.writeEntry(
"axis", axis_);
225 omegaSet_->writeData(
os);
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors).
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Base class for defining restraints for rigid-body dynamics.
label bodyID_
ID of the body the restraint is applied to.
restraint(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from the dict dictionary and Time.
const word & name() const
Return the name.
label bodyIndex_
Index of the body the force is applied to.
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
dictionary coeffs_
Restraint model specific coefficient dictionary.
virtual void write(Ostream &) const =0
Write.
const rigidBodyModel & model_
Reference to the model.
Restraint setting angular velocity of the rigid body. Developed from the linear axial angular spring ...
virtual void write(Ostream &) const
Write.
prescribedRotation(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from components.
virtual ~prescribedRotation()
Destructor.
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
virtual void restrain(scalarField &tau, Field< spatialVector > &fx, const rigidBodyModelState &state) const
Accumulate the retraint internal joint forces into the tau field and.
Holds the motion state of rigid-body model.
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Class to handle errors and exceptions in a simple, consistent stream-based manner.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
Namespace for rigid-body dynamics restraints.
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
dimensionedScalar sign(const dimensionedScalar &ds)
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
messageStream Info
Information stream (stdout output on master, null elsewhere).
static const Identity< scalar > I
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensionedScalar acos(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a).