Go to the documentation of this file.
48 void Foam::RBD::rigidBodyModel::initializeRootBody()
54 XT_.append(spatialTransform());
63 void Foam::RBD::rigidBodyModel::resizeState()
65 Xlambda_.append(spatialTransform());
66 X0_.append(spatialTransform());
84 void Foam::RBD::rigidBodyModel::addRestraints
86 const dictionary&
dict
89 if (
dict.found(
"restraints"))
91 const dictionary& restraintDict =
dict.subDict(
"restraints");
95 restraints_.setSize(restraintDict.size());
97 for (
const entry& dEntry : restraintDict)
114 restraints_.setSize(i);
123 const label parentID,
131 bodies_.append(bodyPtr);
132 const label bodyID = nBodies()-1;
133 bodyIDs_.insert(body.
name(), bodyID);
137 if (merged(parentID))
139 const subBody& sBody = mergedBody(parentID);
145 lambda_.append(parentID);
150 const joint& prevJoint = joints_[joints_.size() - 1];
151 joints_.append(jointPtr);
152 joint& curJoint = joints_[joints_.size() - 1];
153 curJoint.index() = joints_.size() - 1;
154 curJoint.qIndex() = prevJoint.qIndex() + prevJoint.
nDoF();
157 nDoF_ += curJoint.
nDoF();
173 initializeRootBody();
186 initializeRootBody();
190 for (
const entry& dEntry : bodiesDict)
192 const keyType& key = dEntry.keyword();
195 if (bodyDict.
found(
"mergeWith"))
199 bodyID(bodyDict.
get<
word>(
"mergeWith")),
200 bodyDict.
lookup(
"transform"),
208 bodyID(bodyDict.
get<
word>(
"parent")),
209 bodyDict.
lookup(
"transform"),
231 const label parentID,
237 if (isA<joints::composite>(jointPtr()))
265 const label parentID,
271 label parent = parentID;
276 for (
label j=0; j<cJoint.size()-1; j++)
298 cJoint.setLastJoint();
304 void Foam::RBD::rigidBodyModel::makeComposite(
const label bodyID)
306 if (!isA<compositeBody>(bodies_[bodyID]))
323 const label parentID,
333 if (merged(parentID))
335 const subBody& sBody = mergedBody(parentID);
352 makeComposite(parentID);
359 bodies_[parentID].
name(),
366 const subBody& sBody = sBodyPtr();
367 mergedBodies_.append(sBodyPtr);
370 bodies_[sBody.
masterID()].merge(sBody);
372 const label sBodyID = mergedBodyID(mergedBodies_.size() - 1);
373 bodyIDs_.insert(sBody.
name(), sBodyID);
386 const subBody& mBody = mergedBody(bodyId);
399 for (
label i=1; i<nBodies(); i++)
403 if (!isType<jointBody>(bodies_[i]))
407 bodies_[i].
write(os);
413 << joints_[i] <<
endl;
424 mergedBodies_[i].body().
write(os);
426 os.
writeEntry(
"transform", mergedBodies_[i].masterXT());
427 os.
writeEntry(
"mergeWith", mergedBodies_[i].masterName());
435 if (!restraints_.empty())
445 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.
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.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
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.
void append(T *ptr)
Append an element to the end of the list.
static const SpatialTensor I
Identity matrix for square matrices.
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
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.