Go to the documentation of this file.
49 void Foam::RBD::rigidBodyModel::initializeRootBody()
55 XT_.append(spatialTransform());
64 void Foam::RBD::rigidBodyModel::resizeState()
66 Xlambda_.append(spatialTransform());
67 X0_.append(spatialTransform());
85 void Foam::RBD::rigidBodyModel::addRestraints
87 const dictionary&
dict
90 if (
dict.found(
"restraints"))
92 const dictionary& restraintDict =
dict.subDict(
"restraints");
96 restraints_.setSize(restraintDict.size());
98 for (
const entry& dEntry : restraintDict)
115 restraints_.setSize(i);
124 const label parentID,
132 bodies_.append(bodyPtr);
133 const label bodyID = nBodies()-1;
134 bodyIDs_.insert(body.
name(), bodyID);
138 if (merged(parentID))
140 const subBody& sBody = mergedBody(parentID);
146 lambda_.append(parentID);
151 const joint& prevJoint = joints_[joints_.size() - 1];
152 joints_.append(jointPtr);
153 joint& curJoint = joints_[joints_.size() - 1];
154 curJoint.index() = joints_.size() - 1;
155 curJoint.qIndex() = prevJoint.qIndex() + prevJoint.
nDoF();
158 nDoF_ += curJoint.
nDoF();
174 initializeRootBody();
187 initializeRootBody();
191 for (
const entry& dEntry : bodiesDict)
193 const keyType& key = dEntry.keyword();
196 if (bodyDict.
found(
"mergeWith"))
200 bodyID(bodyDict.
get<
word>(
"mergeWith")),
209 bodyID(bodyDict.
get<
word>(
"parent")),
232 const label parentID,
238 if (isA<joints::composite>(jointPtr()))
266 const label parentID,
272 label parent = parentID;
277 for (label j=0; j<cJoint.size()-1; j++)
299 cJoint.setLastJoint();
305 void Foam::RBD::rigidBodyModel::makeComposite(
const label bodyID)
307 if (!isA<compositeBody>(bodies_[bodyID]))
324 const label parentID,
334 if (merged(parentID))
336 const subBody& sBody = mergedBody(parentID);
353 makeComposite(parentID);
360 bodies_[parentID].
name(),
367 const subBody& sBody = sBodyPtr();
368 mergedBodies_.append(sBodyPtr);
371 bodies_[sBody.
masterID()].merge(sBody);
373 const label sBodyID = mergedBodyID(mergedBodies_.size() - 1);
374 bodyIDs_.insert(sBody.
name(), sBodyID);
387 const subBody& mBody = mergedBody(bodyId);
400 for (label i=1; i<nBodies(); i++)
404 if (!isType<jointBody>(bodies_[i]))
408 bodies_[i].
write(os);
414 << joints_[i] <<
endl;
425 mergedBodies_[i].body().
write(os);
427 os.
writeEntry(
"transform", mergedBodies_[i].masterXT());
428 os.
writeEntry(
"mergeWith", mergedBodies_[i].masterName());
436 if (!restraints_.empty())
446 restraints_[ri].
write(os);
A keyword and a list of tokens is an 'entry'.
virtual ~rigidBodyModel()
Destructor.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
static autoPtr< joint > New(joint *jointPtr)
Simple selector to return an autoPtr<joint> of the given joint*.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
label nDoF() const
Return the number of degrees of freedom in this joint.
A class for handling words, derived from Foam::string.
spatialTransform X0(const label bodyId) const
Return the current transform to the global frame for the given body.
static constexpr const zero Zero
Global zero (0)
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Prismatic joint for translation along the specified arbitrary axis.
bool read(const char *buf, int32_t &val)
Same as readInt32.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
PtrList< rigidBody > bodies_
List of the bodies.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
label masterID() const
Return the master body Id.
rigidBodyModel(const Time &time)
Null-constructor which adds the single root-body at the origin.
Ostream & operator<<(Ostream &, const rigidBody &)
#define forAll(list, i)
Loop across all elements in list.
A class for handling keywords in dictionaries.
DynamicList< label > lambda_
List of indices of the parent of each body.
word name(const complex &c)
Return string representation of complex.
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
T * release() noexcept
Return pointer to the managed object and release ownership.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
bool unitQuaternions_
True if any of the joints using quaternions.
T * ptr() noexcept
Same as release().
void append(T *ptr)
Append an element to the end of the list.
static const SpatialTensor I
Identity matrix for square matrices.
defineTypeNameAndDebug(cuboid, 0)
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints.
virtual Ostream & endBlock()
Write end block group.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
PtrList< joint > joints_
Each body it attached with a joint which are held on this list.
Ostream & indent(Ostream &os)
Indent stream.
label nDoF_
The number of degrees of freedom of the model.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
const word & name() const
Return name.
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 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.
bool read(const dictionary &dict)
Read coefficients dictionary and update system parameters,.
virtual void write(Ostream &) const
Write.
DynamicList< spatialTransform > XT_
Transform from the parent body frame to the joint frame.
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Abstract base-class for all rigid-body joints.
const spatialTransform & masterXT() const
Return the transform with respect to the master body.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
static autoPtr< restraint > New(const word &name, const dictionary &dict, const rigidBodyModel &model)
Select constructed from the dict dictionary and Time.
virtual bool unitQuaternion() const
Return true if this joint describes rotation using a quaternion.
HashTable< label > bodyIDs_
Lookup-table of the IDs of the bodies.
const word & name() const
Return the body name.
static autoPtr< rigidBody > New(const word &name, const scalar &m, const vector &c, const symmTensor &Ic)
Select constructed from components.
label merge(const label parentID, const spatialTransform &X, autoPtr< rigidBody > bodyPtr)
Merge the given body with transform X into the parent with ID.