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" 223 os.writeEntry(
"referenceOrientation", refQ_);
224 os.writeEntry(
"axis", axis_);
225 omegaSet_->writeData(
os);
dimensionedScalar sign(const dimensionedScalar &ds)
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
dimensionedScalar acos(const dimensionedScalar &ds)
addToRunTimeSelectionTable(restraint, externalForce, dictionary)
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
defineTypeNameAndDebug(externalForce, 0)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual ~prescribedRotation()
Destructor.
Base class for defining restraints for rigid-body dynamics.
constexpr char nl
The newline '\n' character (0x0a)
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Macros for easy insertion into run-time selection tables.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Holds the motion state of rigid-body model.
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
static const Identity< scalar > I
prescribedRotation(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from components.
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
A class for handling words, derived from Foam::string.
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
virtual void write(Ostream &) const
Write.
virtual void restrain(scalarField &tau, Field< spatialVector > &fx, const rigidBodyModelState &state) const
Accumulate the retraint internal joint forces into the tau field and.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
messageStream Info
Information stream (stdout output on master, null elsewhere)
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints...
virtual void write(Ostream &) const =0
Write.
Tensor of scalars, i.e. Tensor<scalar>.
static constexpr const zero Zero
Global zero (0)