49 void Foam::RBD::rigidBodyModel::initializeRootBody()
51 bodies_.append(
new masslessBody(
"root"));
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"))
96 restraints_.setSize(restraintDict.size());
98 for (
const entry& dEntry : restraintDict)
115 restraints_.setSize(i);
124 const label parentID,
131 const rigidBody& body = bodyPtr();
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);
141 lambda_.append(sBody.masterID());
142 XT_.append(XT & sBody.masterXT());
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();
159 unitQuaternions_ = unitQuaternions_ || curJoint.unitQuaternion();
174 initializeRootBody();
187 initializeRootBody();
191 for (
const entry& dEntry : bodiesDict)
196 if (bodyDict.
found(
"mergeWith"))
232 const label parentID,
238 if (isA<joints::composite>(jointPtr()))
246 dynamic_cast<joints::composite*>(jointPtr.
ptr())
266 const label parentID,
272 label parent = parentID;
273 joints::composite& cJoint = cJointPtr();
277 for (label j=0; j<cJoint.size()-1; j++)
292 cJoint.size() == 1 ? XT : spatialTransform(),
293 autoPtr<joint>(cJointPtr.
ptr()),
299 cJoint.setLastJoint();
305 void Foam::RBD::rigidBodyModel::makeComposite(
const label bodyID)
307 if (!isA<compositeBody>(bodies_[bodyID]))
310 autoPtr<rigidBody> bodyPtr = bodies_.
release(bodyID);
324 const label parentID,
334 if (merged(parentID))
336 const subBody& sBody = mergedBody(parentID);
338 makeComposite(sBody.masterID());
345 bodies_[sBody.masterID()].name(),
347 XT & sBody.masterXT()
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);
397 os.beginBlock(
"bodies");
400 for (label i=1; i<nBodies(); i++)
404 if (!isType<jointBody>(bodies_[i]))
406 os.beginBlock(bodies_[i].
name());
408 bodies_[i].write(
os);
410 os.writeEntry(
"parent", bodies_[lambda_[i]].
name());
411 os.writeEntry(
"transform", XT_[i]);
414 << joints_[i] <<
endl;
423 os.beginBlock(mergedBodies_[i].
name());
425 mergedBodies_[i].body().write(
os);
427 os.writeEntry(
"transform", mergedBodies_[i].masterXT());
428 os.writeEntry(
"mergeWith", mergedBodies_[i].masterName());
436 if (!restraints_.empty())
438 os.beginBlock(
"restraints");
444 os.beginBlock(restraints_[ri].
name());
446 restraints_[ri].write(
os);
static autoPtr< rigidBody > New(const word &name, const scalar &m, const vector &c, const symmTensor &Ic)
Select constructed from components.
A class for handling keywords in dictionaries.
Ostream & operator<<(Ostream &, const rigidBody &)
Ostream & indent(Ostream &os)
Indent stream.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
This specialized rigidBody holds the original body after it has been merged into a master...
constexpr char nl
The newline '\n' character (0x0a)
label merge(const label parentID, const spatialTransform &X, autoPtr< rigidBody > bodyPtr)
Merge the given body with transform X into the parent with ID.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static const SpatialTensor I
Identity matrix for square matrices.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
#define forAll(list, i)
Loop across all elements in list.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
PtrList< joint > joints_
Each body it attached with a joint which are held on this list.
PtrList< rigidBody > bodies_
List of the bodies.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A class for handling words, derived from Foam::string.
label nDoF_
The number of degrees of freedom of the model.
bool read(const dictionary &dict)
Read coefficients dictionary and update system parameters,.
rigidBodyModel(const Time &time)
Null-constructor which adds the single root-body at the origin.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
DynamicList< spatialTransform > XT_
Transform from the parent body frame to the joint frame.
void append(const T &val)
Copy append an element to the end of this list.
defineTypeNameAndDebug(cuboid, 0)
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 void write(Ostream &) const
Write.
T * release() noexcept
Release ownership and return the pointer.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
DynamicList< label > lambda_
List of indices of the parent of each body.
OBJstream os(runTime.globalPath()/outputName)
label masterID() const
Return the master body Id.
bool unitQuaternions_
True if any of the joints using quaternions.
T * ptr() noexcept
Same as release().
void append(autoPtr< T > &ptr)
Move append an element to the end of the list.
HashTable< label > bodyIDs_
Lookup-table of the IDs of the bodies.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
virtual ~rigidBodyModel()
Destructor.
static autoPtr< joint > New(joint *jointPtr)
Simple selector to return an autoPtr<joint> of the given joint*.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
label bodyID(const word &name) const
Return the ID of the body with the given name.
spatialTransform X0(const label bodyId) const
Return the current transform to the global frame for the given body.
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.
static autoPtr< restraint > New(const word &name, const dictionary &dict, const rigidBodyModel &model)
Select constructed from the dict dictionary and Time.
A keyword and a list of tokens is an 'entry'.
const spatialTransform & masterXT() const
Return the transform with respect to the master body.
static constexpr const zero Zero
Global zero (0)