Program Listing for File BodyBase.h#
↰ Return to documentation for file (include/Karana/SOADyn/BodyBase.h)
/*
* Copyright (c) 2024-2026 Karana Dynamics Pty Ltd. All rights reserved.
*
* NOTICE TO USER:
*
* This source code and/or documentation (the "Licensed Materials") is
* the confidential and proprietary information of Karana Dynamics Inc.
* Use of these Licensed Materials is governed by the terms and conditions
* of a separate software license agreement between Karana Dynamics and the
* Licensee ("License Agreement"). Unless expressly permitted under that
* agreement, any reproduction, modification, distribution, or disclosure
* of the Licensed Materials, in whole or in part, to any third party
* without the prior written consent of Karana Dynamics is strictly prohibited.
*
* THE LICENSED MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
* KARANA DYNAMICS DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, AND
* FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL KARANA DYNAMICS BE LIABLE FOR ANY DAMAGES WHATSOEVER,
* INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS, DATA, OR USE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, WHETHER IN CONTRACT, TORT,
* OR OTHERWISE ARISING OUT OF OR IN CONNECTION WITH THE LICENSED MATERIALS.
*
* U.S. Government End Users: The Licensed Materials are a "commercial item"
* as defined at 48 C.F.R. 2.101, and are provided to the U.S. Government
* only as a commercial end item under the terms of this license.
*
* Any use of the Licensed Materials in individual or commercial software must
* include, in the user documentation and internal source code comments,
* this Notice, Disclaimer, and U.S. Government Use Provision.
*/
/**
* @file
* @brief Contains the declarations for the BodyBase class.
*/
#pragma once
#include "Karana/SOADyn/CoordBase.h"
namespace Karana::Dynamics {
namespace kc = Karana::Core;
namespace km = Karana::Math;
class SubTree;
class HingeOnode;
class Multibody;
class HingeBase;
class PhysicalBody;
class CompoundBody;
/**
* @class BodyBase
* @brief Represents the abstract base class for bodies
*
* This class is the base class for bodies from which physical and
* compound body classes are derived. The coordinates associated
* with this class as those from deformation coordinates.
*/
// class BodyBase : public CoordBase_T<> {
class BodyBase : public CoordBase {
/* for access to data cache setup methods */
friend class SubTree;
public:
/**
* @brief Return the Multibody system that the body belongs to
*
* @return the parent Multibody instance
*/
const kc::ks_ptr<Multibody> &multibody() const;
/**
* @brief Return flag indicating whether this is a CompoundBody
*
* @return true is the body is a CompoundBody
*/
bool isCompoundBody() const { return _is_compound_body; }
/**
* @brief BodyBase destructor.
*/
virtual ~BodyBase();
/**
* @brief Return the PhysicalBody inboard parent body for the body.
*
* For a PhysicalBody this is simply the inboard body connected
* to it via a PhysicalHinge. For a CompoundBody, this is the
* single PhysicalBody to which the base pnodes in the CompoundBody are
* connected to.
*
* @return the parent PhysicalBody body instance
*/
virtual const kc::ks_ptr<PhysicalBody> &physicalParentBody() const = 0;
/**
* @brief Return the parent hinge for the body.
*
* For a PhysicalBody, parent hinge is a PhysicalHinge, while
* for a CompoundBody the parent hinge is a CompoundHinge
*
* @return The parent HingeBase instance
*/
virtual kc::ks_ptr<HingeBase> parentHinge() const = 0;
/**
* @brief Return true is this body is the Multibody's virtual root body
*
* The default return value if false, since only physical bodies
* can possibly be the virtual root body.
*
* @return true if this is the virtual root body
*/
virtual bool isRootBody() const { return false; }
protected:
/**
* @brief Return the SubTree that owns the body
*
* Return the parent SubTree that created this body and has it in
* its usage tracking map. Physical bodies are always owned by the
* Multibody tree. Compound bodies are owned by non-multibody
* subtrees.
*
* @return the parent SubTree instance
*/
kc::ks_ptr<SubTree> _parentSubtree() const { return _parent_subtree; }
/**
* @brief BodyBase constructor.
* @param nm instance name
* @param id instance id
* @param parent_subtree the subtree the body belongs to
*/
BodyBase(std::string_view nm, kc::id_t id, kc::ks_ptr<SubTree> parent_subtree);
protected:
/**
* @brief Set up cache dependencies with a child body
*
* @param child_body the child body
*/
virtual void _setupChildBodyCacheDependencies(kc::ks_ptr<BodyBase> child_body) = 0;
/**
* @brief Set up cache dependencies with a PhysicalBody child body
*
* @param child_body the PhysicalBody child body
* @param skip_scatter if true, skip dependencies for the scatter phase
*/
virtual void _setupChildPhysicalBodyCacheDependencies(const PhysicalBody &child_body,
bool skip_scatter) = 0;
/**
* @brief Set up cache dependencies with a CompoundBody child body
*
* @param child_body the CompoundBody child body
*/
virtual void
_setupChildCompoundBodyCacheDependencies(kc::ks_ptr<CompoundBody> child_body) = 0;
/**
* @brief Set up cache dependencies for a base body
*/
virtual void _setupBaseBodyCacheDependencies() = 0;
/**
* @brief Tear down cache dependencies with a child body
*
* @param child_body the child body
*/
virtual void _teardownChildBodyCacheDependencies(kc::ks_ptr<BodyBase> child_body) = 0;
/**
* @brief Tear down cache dependencies with a PhysicalBody child body
*
* @param child_body the PhysicalBody child body
* @param skip_scatter if true, skip dependencies for the scatter phase
*/
virtual void _teardownChildPhysicalBodyCacheDependencies(const PhysicalBody &child_body,
bool skip_scatter) = 0;
/**
* @brief Tear down cache dependencies with a CompoundBody child body
*
* @param child_body the CompoundBody child body
*/
virtual void
_teardownChildCompoundBodyCacheDependencies(kc::ks_ptr<CompoundBody> child_body) = 0;
/**
* @brief Tear down cache dependencies for a base body
*/
virtual void _teardownBaseBodyCacheDependencies() = 0;
km::Mat getATBIMatPsi() const override { return km::Mat(); };
km::Mat getATBID() const override;
km::Mat getATBIDinv() const override;
km::Mat getATBIG() const override { return km::Mat(); };
km::Mat getATBITauper() const override { return km::Mat(); };
km::Mat getUpsilonMatrix() override { return km::Mat(); };
km::Mat _oframe2pframePsi() const override { return km::Mat(); };
km::Mat _oframe2pframePhi() const override { return km::Mat(); };
km::Mat _pframe2otherPhi(const kf::Frame & /*other*/) const override { return km::Mat(); };
protected:
km::Mat _jacobian(const kf::FrameToFrame &f2f) const override;
km::Mat _jacobianDot(const kf::FrameToFrame &f2f) const override;
protected:
/** The parent SubTree that created this body and has it in its
usage tracking map. Physical bodies are always owned by the
multibody tree. Compound bodies are owned by non-multibody
subtrees. */
kc::ks_ptr<SubTree> _parent_subtree = nullptr; ///< parent subtree
/** whether or not this body is a compound body. We could check whether the
* parent SubGraph is the multibody tree or not, but storing as a flag and
* accessing it is faster than doing the comparison each time. */
bool _is_compound_body = false;
/** List of child body HingeOnode onodes to use for gather data cache
callbacks for this body. The contents of this list are set
by the algorithmic SubTree this body belongs to.
*/
kc::RegistryList<HingeOnode> _algorithmic_gather_child_onodes;
/** List of child compound bodies to use for gather data cache
callbacks for this body. The contents of this list are set
by the algorithmic SubTree this body belongs to.
*/
kc::RegistryList<CompoundBody> _algorithmic_gather_child_cbs;
};
} // namespace Karana::Dynamics