49void Foam::RBD::rigidBodyModel::initializeRootBody()
55 XT_.append(spatialTransform());
64void Foam::RBD::rigidBodyModel::resizeState()
66 Xlambda_.append(spatialTransform());
67 X0_.append(spatialTransform());
85void 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"))
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();
305void 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);
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);
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,...
void append(T *ptr)
Append an element to the end of the list.
virtual bool read()
Re-read model coefficients if they have changed.
Abstract base-class for all rigid-body joints.
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.
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.
virtual void write(Ostream &) const
Write.
label nDoF_
The number of degrees of freedom of the model.
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.
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.
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.
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
Identity matrix for square matrices.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
label size() const noexcept
The number of elements 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(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
T * ptr() noexcept
Same as release().
virtual bool merge() const
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
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
Search for an entry (const access) with the given keyword.
A keyword and a list of tokens is an 'entry'.
virtual bool write()
Write the output fields.
A class for handling keywords in dictionaries.
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.
static constexpr const zero Zero
Global zero (0)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.