46 void Foam::RBD::rigidBodyModel::initialiseRootBody()
48 bodies_.append(
new masslessBody(
"root"));
52 XT_.append(spatialTransform());
61 void Foam::RBD::rigidBodyModel::resizeState()
63 Xlambda_.append(spatialTransform());
64 X0_.append(spatialTransform());
82 void Foam::RBD::rigidBodyModel::addRestraints
84 const dictionary&
dict
87 if (
dict.found(
"restraints"))
89 const dictionary& restraintDict =
dict.subDict(
"restraints");
93 restraints_.setSize(restraintDict.size());
112 restraints_.setSize(i);
121 const label parentID,
129 bodies_.append(bodyPtr);
130 const label bodyID = nBodies()-1;
131 bodyIndices_.insert(body.
name(), bodyID);
135 if (merged(parentID))
137 const subBody& sBody = mergedBody(parentID);
143 lambda_.append(parentID);
148 const joint& prevJoint = joints_[joints_.size() - 1];
149 joints_.append(jointPtr);
150 joint& curJoint = joints_[joints_.size() - 1];
151 curJoint.index() = joints_.size() - 1;
152 curJoint.qIndex() = prevJoint.qIndex() + prevJoint.
nDoF();
155 nDoF_ += curJoint.
nDoF();
170 initialiseRootBody();
178 initialiseRootBody();
186 if (bodyDict.
found(
"mergeWith"))
191 bodyDict.
lookup(
"transform"),
200 bodyDict.
lookup(
"transform"),
222 const label parentID,
228 if (isA<joints::composite>(jointPtr()))
256 const label parentID,
262 label parent = parentID;
289 cJoint.setLastJoint();
295 void Foam::RBD::rigidBodyModel::makeComposite(
const label bodyID)
297 if (!isA<compositeBody>(bodies_[bodyID]))
314 const label parentID,
324 if (merged(parentID))
326 const subBody& sBody = mergedBody(parentID);
343 makeComposite(parentID);
350 bodies_[parentID].
name(),
357 const subBody& sBody = sBodyPtr();
358 mergedBodies_.append(sBodyPtr);
363 const label sBodyID = mergedBodyID(mergedBodies_.size() - 1);
364 bodyIndices_.insert(sBody.
name(), sBodyID);
377 const subBody& mBody = mergedBody(bodyId);
392 for (
label i=1; i<nBodies(); i++)
394 if (!isType<jointBody>(bodies_[i]))
396 names[j++] = bodies_[i].name();
412 for (
label i=1; i<nBodies(); i++)
416 if (!isType<jointBody>(bodies_[i]))
421 bodies_[i].
write(os);
437 mergedBodies_[i].body().
write(os);
439 writeEntry(os,
"transform", mergedBodies_[i].masterXT());
441 writeEntry(os,
"mergeWith", mergedBodies_[i].masterName());
449 if (!restraints_.empty())
456 word restraintType = restraints_[ri].type();
461 restraints_[ri].
write(os);
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Template class for intrusive linked lists.
virtual const fileName & name() const
Return the name of the stream.
void setSize(const label)
Reset size of List.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual Ostream & write(const char)=0
Write character.
void append(T *)
Append an element at the end of the list.
This specialised rigidBody holds the original body after it has been merged into a parent.
Abstract base-class for all rigid-body joints.
static autoPtr< joint > New(joint *jointPtr)
Simple selector to return an autoPtr<joint> of the given joint*.
label nDoF() const
Return the number of degrees of freedom in this joint.
virtual bool unitQuaternion() const
Return true if this joint describes rotation using a quaternion.
Prismatic joint for translation along the specified arbitrary axis.
static autoPtr< restraint > New(const word &name, const dictionary &dict, const rigidBodyModel &model)
Select constructed from the dict dictionary and Time.
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints.
DynamicList< spatialTransform > XT_
Transform from the parent body frame to the joint frame.
rigidBodyModel()
Null-constructor which adds the single root-body at the origin.
wordList movingBodyNames() const
Return the names of the moving bodies.
virtual void write(Ostream &) const
Write.
label nDoF_
The number of degrees of freedom of the model.
HashTable< label, word > bodyIndices_
Lookup-table of the IDs of the bodies.
PtrList< rigidBody > bodies_
List of the bodies.
label merge(const label parentID, const spatialTransform &X, autoPtr< rigidBody > bodyPtr)
Merge the given body with transform X into the parent with ID.
bool read(const dictionary &dict)
Read coefficients dictionary and update system parameters,.
bool unitQuaternions_
True if any of the joints using quaternions.
virtual label join(const label parentID, const spatialTransform &XT, autoPtr< joint > jointPtr, autoPtr< rigidBody > bodyPtr)
Join the given body to the parent with ID parentID via the given.
label bodyIndex(const word &name) const
Return the ID of the body with the given name.
PtrList< joint > joints_
Each body it attached with a joint which are held on this list.
virtual label join_(const label parentID, const spatialTransform &XT, autoPtr< joint > jointPtr, autoPtr< rigidBody > bodyPtr)
Join the given body to the parent with ID parentID via the given.
virtual ~rigidBodyModel()
Destructor.
spatialTransform X0(const label bodyId) const
Return the current transform to the global frame for the given body.
DynamicList< label > lambda_
List of indices of the parent of each body.
static autoPtr< rigidBody > New(const word &name, const scalar &m, const vector &c, const symmTensor &Ic)
Select constructed from components.
const word & name() const
Return name.
This specialised rigidBody holds the original body after it has been merged into a master.
const spatialTransform & masterXT() const
Return the transform with respect to the master body.
const word & name() const
Return the body name.
label masterIndex() const
Return the master body Id.
static const SpatialTensor I
Identity matrix for square matrices.
label size() const
Return the number of elements in the UPtrList.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
T * ptr()
Return object pointer for reuse.
void set(T *)
Set pointer to that given.
A list of keyword definitions, which are a keyword followed by any number of values (e....
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
A class for handling words, derived from string.
defineTypeNameAndDebug(cuboid, 0)
Ostream & operator<<(Ostream &, const rigidBody &)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Ostream & indent(Ostream &os)
Indent stream.