00001 #ifndef SimTK_SIMBODY_MATTER_SUBSYSTEM_H_
00002 #define SimTK_SIMBODY_MATTER_SUBSYSTEM_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "SimTKcommon.h"
00036 #include "simbody/internal/common.h"
00037 #include "simbody/internal/MobilizedBody.h"
00038
00039 #include <cassert>
00040 #include <vector>
00041 #include <iostream>
00042
00043 class SimbodyMatterSubsystemRep;
00044
00045 namespace SimTK {
00046
00047 class MobilizedBody;
00048 class MultibodySystem;
00049 class Constraint;
00050
00124 class SimTK_SIMBODY_EXPORT SimbodyMatterSubsystem : public Subsystem {
00125 public:
00126
00128 SimbodyMatterSubsystem();
00129 explicit SimbodyMatterSubsystem(MultibodySystem&);
00130
00131 class Subtree;
00132 class SubtreeResults;
00133
00134
00135
00136 ~SimbodyMatterSubsystem() {
00137 }
00138 SimbodyMatterSubsystem(const SimbodyMatterSubsystem& ss) : Subsystem(ss) {
00139 }
00140 SimbodyMatterSubsystem& operator=(const SimbodyMatterSubsystem& ss) {
00141 Subsystem::operator=(ss);
00142 return *this;
00143 }
00144
00147 bool getShowDefaultGeometry() const;
00148
00151 void setShowDefaultGeometry(bool show);
00152
00153
00155
00157
00162 Real calcSystemMass(const State& s) const;
00163
00164
00170 Vec3 calcSystemMassCenterLocationInGround(const State& s) const;
00171
00172
00178 MassProperties calcSystemMassPropertiesInGround(const State& s) const;
00179
00185 Inertia calcSystemCentralInertiaInGround(const State& s) const;
00186
00192 Vec3 calcSystemMassCenterVelocityInGround(const State& s) const;
00193
00199 Vec3 calcSystemMassCenterAccelerationInGround(const State& s) const;
00200
00207 SpatialVec calcSystemMomentumAboutGroundOrigin(const State& s) const;
00208
00216 SpatialVec calcSystemCentralMomentum(const State& s) const;
00217
00219
00221
00234 MobilizedBodyIndex adoptMobilizedBody(MobilizedBodyIndex parent,
00235 MobilizedBody& child);
00236
00240 const MobilizedBody& getMobilizedBody(MobilizedBodyIndex) const;
00241
00245 MobilizedBody& updMobilizedBody(MobilizedBodyIndex);
00246
00247
00248
00249
00250
00251
00252
00255 const MobilizedBody::Ground& getGround() const;
00258 MobilizedBody::Ground& updGround();
00261 MobilizedBody::Ground& Ground() {return updGround();}
00262
00273 ConstraintIndex adoptConstraint(Constraint&);
00274
00278 const Constraint& getConstraint(ConstraintIndex) const;
00279
00283 Constraint& updConstraint(ConstraintIndex);
00284
00286
00288
00289
00290
00291
00332 void calcAcceleration(const State&,
00333 const Vector& mobilityForces,
00334 const Vector_<SpatialVec>& bodyForces,
00335 Vector& udot,
00336 Vector_<SpatialVec>& A_GB) const;
00337
00362 void calcDynamicsFromForcesAndMotions(const State&,
00363 const Vector& appliedMobilityForces,
00364 const Vector_<SpatialVec>& appliedBodyForces,
00365 const Vector& udot_p,
00366 Vector& udot,
00367 Vector& lambda_p,
00368 Vector& lambda_r) const;
00369
00378 void calcDynamicsFromForces(const State&,
00379 const Vector& appliedMobilityForces,
00380 const Vector_<SpatialVec>& appliedBodyForces,
00381 Vector& udot,
00382 Vector& lambda_p,
00383 Vector& lambda_r) const;
00384
00399 void calcAccelerationIgnoringConstraints(const State&,
00400 const Vector& mobilityForces,
00401 const Vector_<SpatialVec>& bodyForces,
00402 Vector& udot,
00403 Vector_<SpatialVec>& A_GB) const;
00404
00431 void calcMInverseV(const State&,
00432 const Vector& v,
00433 Vector& MinvV) const;
00434
00454 void calcResidualForce
00455 (const State& state,
00456 const Vector& appliedMobilityForces,
00457 const Vector_<SpatialVec>& appliedBodyForces,
00458 const Vector& knownUdot,
00459 const Vector& knownMultipliers,
00460 Vector& residualMobilityForces) const;
00461
00510 void calcResidualForceIgnoringConstraints
00511 (const State& state,
00512 const Vector& appliedMobilityForces,
00513 const Vector_<SpatialVec>& appliedBodyForces,
00514 const Vector& knownUdot,
00515 Vector& residualMobilityForces) const;
00516
00532 void calcMV(const State&, const Vector& v, Vector& MV) const;
00533
00540 void calcCompositeBodyInertias(const State&,
00541 Vector_<SpatialMat>& R) const;
00542
00566 void calcAccelerationFromUDot(const State& state,
00567 const Vector& knownUDot,
00568 Vector_<SpatialVec>& A_GB) const;
00569
00576 void calcAccConstraintErr(const State&,
00577 const Vector& knownUdot,
00578 Vector& constraintErr) const;
00579
00584 void calcGV(const State&,
00585 const Vector& v,
00586 Vector& Gv) const;
00587
00594 void calcGtV(const State&,
00595 const Vector& v,
00596 Vector& GtV) const;
00597
00598
00611 void calcM(const State&, Matrix& M) const;
00612
00626 void calcMInv(const State&, Matrix& MInv) const;
00627
00638 void calcG(const State&, Matrix& G) const;
00639
00650 void calcGt(const State&, Matrix& Gt) const;
00651
00674 void calcPtV(const State& s, const Vector& v, Vector& PtV) const;
00675
00691 void calcPNInv(const State& state, Matrix& PNInv) const;
00692
00707 void calcP(const State& state, Matrix& P) const;
00708
00710 void calcPt(const State& state, Matrix& Pt) const;
00711
00723 void calcConstraintForcesFromMultipliers
00724 (const State& s, const Vector& multipliers,
00725 Vector_<SpatialVec>& bodyForcesInG,
00726 Vector& mobilityForces) const;
00727
00759 void calcMobilizerReactionForces
00760 (const State& state,
00761 Vector_<SpatialVec>& forcesAtMInG) const;
00762
00764 void calcSpatialKinematicsFromInternal(const State&,
00765 const Vector& v,
00766 Vector_<SpatialVec>& Jv) const;
00767
00769 void calcInternalGradientFromSpatial(const State&,
00770 const Vector_<SpatialVec>& dEdR,
00771 Vector& dEdQ) const;
00772
00774 Real calcKineticEnergy(const State&) const;
00775
00780 void calcTreeEquivalentMobilityForces(const State&,
00781 const Vector_<SpatialVec>& bodyForces,
00782 Vector& mobilityForces) const;
00783
00784
00785
00787 void calcQDot(const State& s,
00788 const Vector& u,
00789 Vector& qdot) const;
00790
00793 void calcQDotDot(const State& s,
00794 const Vector& udot,
00795 Vector& qdotdot) const;
00796
00803 void multiplyByN(const State& s, bool transpose,
00804 const Vector& in, Vector& out) const;
00805
00813 void multiplyByNInv(const State& s, bool transpose,
00814 const Vector& in, Vector& out) const;
00815
00824 void multiplyByNDot(const State& s, bool transpose,
00825 const Vector& in, Vector& out) const;
00826
00827
00828
00837 int getNumBodies() const;
00838
00841 int getNumConstraints() const;
00842
00844 int getNumParticles() const;
00845
00848 int getNumMobilities() const;
00849
00852 int getTotalQAlloc() const;
00853
00856 int getTotalMultAlloc() const;
00857
00864 void setUseEulerAngles(State&, bool) const;
00865 bool getUseEulerAngles (const State&) const;
00866
00867 int getNumQuaternionsInUse(const State&) const;
00868
00869 void setMobilizerIsPrescribed(State&, MobilizedBodyIndex, bool) const;
00870 bool isMobilizerPrescribed (const State&, MobilizedBodyIndex) const;
00871 bool isUsingQuaternion(const State&, MobilizedBodyIndex) const;
00872 QuaternionPoolIndex getQuaternionPoolIndex(const State&, MobilizedBodyIndex) const;
00873 AnglePoolIndex getAnglePoolIndex(const State&, MobilizedBodyIndex) const;
00874 void setConstraintIsDisabled(State&, ConstraintIndex constraint, bool) const;
00875 bool isConstraintDisabled(const State&, ConstraintIndex constraint) const;
00876
00883 void convertToEulerAngles(const State& inputState, State& outputState) const;
00884
00891 void convertToQuaternions(const State& inputState, State& outputState) const;
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904 const Vector_<Vec3>& getAllParticleLocations (const State&) const;
00905 const Vector_<Vec3>& getAllParticleVelocities (const State&) const;
00906
00907 const Vec3& getParticleLocation(const State& s, ParticleIndex p) const {
00908 return getAllParticleLocations(s)[p];
00909 }
00910 const Vec3& getParticleVelocity(const State& s, ParticleIndex p) const {
00911 return getAllParticleVelocities(s)[p];
00912 }
00913
00914 Vector& updAllParticleMasses(State& s) const;
00915
00916 void setAllParticleMasses(State& s, const Vector& masses) const {
00917 updAllParticleMasses(s) = masses;
00918 }
00919
00920
00921
00922
00923
00924
00925 Vector_<Vec3>& updAllParticleLocations(State&) const;
00926 Vector_<Vec3>& updAllParticleVelocities(State&) const;
00927
00928
00929
00930
00931 Vec3& updParticleLocation(State& s, ParticleIndex p) const {
00932 return updAllParticleLocations(s)[p];
00933 }
00934 Vec3& updParticleVelocity(State& s, ParticleIndex p) const {
00935 return updAllParticleVelocities(s)[p];
00936 }
00937
00938 void setParticleLocation(State& s, ParticleIndex p, const Vec3& r) const {
00939 updAllParticleLocations(s)[p] = r;
00940 }
00941 void setParticleVelocity(State& s, ParticleIndex p, const Vec3& v) const {
00942 updAllParticleVelocities(s)[p] = v;
00943 }
00944
00945 void setAllParticleLocations(State& s, const Vector_<Vec3>& r) const {
00946 updAllParticleLocations(s) = r;
00947 }
00948 void setAllParticleVelocities(State& s, const Vector_<Vec3>& v) const {
00949 updAllParticleVelocities(s) = v;
00950 }
00951
00953 const Vector& getAllParticleMasses(const State&) const;
00954
00955 const Vector_<Vec3>& getAllParticleAccelerations(const State&) const;
00956
00957 const Vec3& getParticleAcceleration(const State& s, ParticleIndex p) const {
00958 return getAllParticleAccelerations(s)[p];
00959 }
00960
00961
00962
00971 void realizeCompositeBodyInertias(const State&) const;
00972
00981 void realizeArticulatedBodyInertias(const State&) const;
00982
00983
00984
00985
00993 const SpatialMat& getCompositeBodyInertia(const State&, MobilizedBodyIndex) const;
00994
01003 const SpatialMat& getArticulatedBodyInertia(const State&, MobilizedBodyIndex) const;
01004
01005
01006
01010 void addInStationForce(const State&, MobilizedBodyIndex bodyB, const Vec3& stationOnB,
01011 const Vec3& forceInG, Vector_<SpatialVec>& bodyForcesInG) const;
01012
01015 void addInBodyTorque(const State&, MobilizedBodyIndex, const Vec3& torqueInG,
01016 Vector_<SpatialVec>& bodyForcesInG) const;
01017
01020 void addInMobilityForce(const State&, MobilizedBodyIndex, MobilizerUIndex which, Real f,
01021 Vector& mobilityForces) const;
01022
01023
01024
01030 bool prescribe(State&, Stage) const;
01031
01037 bool projectQConstraints(State& s, Real consAccuracy, const Vector& yWeights,
01038 const Vector& ooTols, Vector& yErrest, System::ProjectOptions) const;
01039
01040
01041
01044 const SpatialVec& getCoriolisAcceleration(const State&, MobilizedBodyIndex) const;
01045
01048 const SpatialVec& getTotalCoriolisAcceleration(const State&, MobilizedBodyIndex) const;
01049
01051 const SpatialVec& getGyroscopicForce(const State&, MobilizedBodyIndex) const;
01052
01057 const SpatialVec& getCentrifugalForces(const State&, MobilizedBodyIndex) const;
01058
01062 const SpatialVec& getTotalCentrifugalForces(const State&, MobilizedBodyIndex) const;
01063
01064
01065
01066
01067
01073 bool projectUConstraints(State& s, Real consAccuracy, const Vector& yWeights,
01074 const Vector& ooTols, Vector& yErrest, System::ProjectOptions) const;
01075
01076
01077
01078
01079
01080 SimTK_PIMPL_DOWNCAST(SimbodyMatterSubsystem, Subsystem);
01081 const SimbodyMatterSubsystemRep& getRep() const;
01082 SimbodyMatterSubsystemRep& updRep();
01083
01084
01085 private:
01086
01087 void multiplyByQMatrix(const State& s, bool transposeMatrix, const Vector& in, Vector& out) const
01088 { multiplyByN(s,transposeMatrix,in,out);}
01089
01090 void multiplyByQMatrixInverse(const State& s, bool transposeMatrix, const Vector& in, Vector& out) const
01091 { multiplyByNInv(s,transposeMatrix,in,out);}
01092
01093 int getNBodies() const {return getNumBodies();}
01094
01095 int getNConstraints() const {return getNumConstraints();}
01096
01097 int getNMobilities() const {return getNumMobilities();}
01098
01099 int getNParticles() const {return getNumParticles();}
01100
01101 };
01102
01103 SimTK_SIMBODY_EXPORT std::ostream&
01104 operator<<(std::ostream&, const SimbodyMatterSubsystem&);
01105
01106
01107 }
01108
01109 #endif // SimTK_SIMBODY_MATTER_SUBSYSTEM_H_