49void Foam::RBD::rigidBodyModel::initializeRootBody()
64void Foam::RBD::rigidBodyModel::resizeState()
66 Xlambda_.append(spatialTransform());
67 X0_.append(spatialTransform());
85void Foam::RBD::rigidBodyModel::addRestraints
90 if (
dict.found(
"restraints"))
96 restraints_.setSize(restraintDict.size());
98 for (
const entry& dEntry : restraintDict)
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)
193 const keyType& key = dEntry.keyword();
196 if (bodyDict.
found(
"mergeWith"))
232 const label parentID,
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();
305void Foam::RBD::rigidBodyModel::makeComposite(
const label 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);
374 bodyIDs_.insert(sBody.name(), sBodyID);
387 const subBody& mBody = mergedBody(bodyId);
397 os.beginBlock(
"bodies");
400 for (label i=1; i<nBodies(); 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);
void append(const T &val)
Copy append an element to the end of this list.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
void append(autoPtr< T > &ptr)
Move append an element to the end of the list.
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 > X0_
Transform for external forces to the bodies reference frame.
DynamicList< spatialTransform > XT_
Transform from the parent body frame to the joint frame.
const Time & time_
Reference to time database.
label nBodies() const
Return the number of bodies in the model (bodies().size()).
const Time & time() const
Return the time.
label mergedBodyID(const label mergedBodyIndex) const
Return the merged body ID for the given merged body index.
virtual void write(Ostream &) const
Write.
label nDoF_
The number of degrees of freedom of the model.
PtrList< subBody > mergedBodies_
Bodies may be merged into existing bodies, the inertia of which is.
const subBody & mergedBody(label mergedBodyID) const
Return the merged body for the given body ID.
rigidBodyModel(const Time &time)
Null-constructor which adds the single root-body at the origin.
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.
vector g_
Acceleration due to gravity.
PtrList< restraint > restraints_
Motion restraints.
label bodyID(const word &name) const
Return the ID of the body with the given 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.
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.
HashTable< label > bodyIDs_
Lookup-table of the IDs of the bodies.
virtual ~rigidBodyModel()
Destructor.
bool merged(label bodyID) const
Return true if the body with given ID has been merged with a parent.
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.
const spatialTransform & masterXT() const
Return the transform with respect to the master body.
label masterID() const
Return the master body Id.
const word & name() const
Return the body name.
static const SpatialTensor I
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
label size() const noexcept
The number of entries in the list.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
T * release() noexcept
Release ownership and return the pointer.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
T * ptr() noexcept
Same as release().
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
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.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
A keyword and a list of tokens is an 'entry'.
A class for handling keywords in dictionaries.
This specialized rigidBody holds the original body after it has been merged into a master.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const rigidBody &)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Ostream & indent(Ostream &os)
Indent stream.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
static constexpr const zero Zero
Global zero (0).
bool isType(const U &obj)
Check if typeid of the object and Type are identical.
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.