Simbody
3.4 (development)
|
00001 #ifndef SimTK_SIMBODY_MULTIBODY_SYSTEM_H_ 00002 #define SimTK_SIMBODY_MULTIBODY_SYSTEM_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * Simbody(tm) * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK biosimulation toolkit originating from * 00008 * Simbios, the NIH National Center for Physics-Based Simulation of * 00009 * Biological Structures at Stanford, funded under the NIH Roadmap for * 00010 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. * 00011 * * 00012 * Portions copyright (c) 2005-12 Stanford University and the Authors. * 00013 * Authors: Michael Sherman * 00014 * Contributors: * 00015 * * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 00017 * not use this file except in compliance with the License. You may obtain a * 00018 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 00019 * * 00020 * Unless required by applicable law or agreed to in writing, software * 00021 * distributed under the License is distributed on an "AS IS" BASIS, * 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00023 * See the License for the specific language governing permissions and * 00024 * limitations under the License. * 00025 * -------------------------------------------------------------------------- */ 00026 00027 #include "SimTKcommon.h" 00028 #include "simbody/internal/common.h" 00029 00030 #include <vector> 00031 00032 namespace SimTK { 00033 00034 class SimbodyMatterSubsystem; 00035 class ForceSubsystem; 00036 class DecorationSubsystem; 00037 class GeneralContactSubsystem; 00038 00039 00048 class SimTK_SIMBODY_EXPORT MultibodySystem : public System { 00049 public: 00050 MultibodySystem(); 00051 explicit MultibodySystem(SimbodyMatterSubsystem& m); 00052 00053 // Steals ownership of the source; returns subsystem ID number. 00054 int addForceSubsystem(ForceSubsystem&); 00055 00056 int setMatterSubsystem(SimbodyMatterSubsystem&); 00057 const SimbodyMatterSubsystem& getMatterSubsystem() const; 00058 SimbodyMatterSubsystem& updMatterSubsystem(); 00059 bool hasMatterSubsystem() const; 00060 00061 int setDecorationSubsystem(DecorationSubsystem&); 00062 const DecorationSubsystem& getDecorationSubsystem() const; 00063 DecorationSubsystem& updDecorationSubsystem(); 00064 bool hasDecorationSubsystem() const; 00065 00066 int setContactSubsystem(GeneralContactSubsystem&); 00067 const GeneralContactSubsystem& getContactSubsystem() const; 00068 GeneralContactSubsystem& updContactSubsystem(); 00069 bool hasContactSubsystem() const; 00070 00071 00074 const Real calcPotentialEnergy(const State&) const; 00077 const Real calcKineticEnergy(const State&) const; 00080 Real calcEnergy(const State& s) const { 00081 return calcPotentialEnergy(s)+calcKineticEnergy(s); 00082 } 00083 00084 // These methods are for use by our constituent subsystems to communicate 00085 // with each other and with the MultibodySystem as a whole. 00086 00087 // These cache entries belong to the global subsystem, which zeroes them at 00088 // the start of the corresponding stage. They are filled in by the force 00089 // subsystems when they are realized to each stage. Forces are cumulative 00090 // from stage to stage, so the Dynamics stage includes everything. That may 00091 // then be accessed by the matter subsystem in Acceleration stage to 00092 // generate the accelerations. 00093 const Vector_<SpatialVec>& getRigidBodyForces(const State&, Stage) const; 00094 const Vector_<Vec3>& getParticleForces (const State&, Stage) const; 00095 const Vector& getMobilityForces (const State&, Stage) const; 00096 00097 // These routines are for use by force subsystems during Dynamics stage. 00098 Vector_<SpatialVec>& updRigidBodyForces(const State&, Stage) const; 00099 Vector_<Vec3>& updParticleForces (const State&, Stage) const; 00100 Vector& updMobilityForces (const State&, Stage) const; 00101 00102 // Private implementation. 00103 SimTK_PIMPL_DOWNCAST(MultibodySystem, System); 00104 class MultibodySystemRep& updRep(); 00105 const MultibodySystemRep& getRep() const; 00106 protected: 00107 explicit MultibodySystem(MultibodySystemRep*); 00108 }; 00109 00110 00111 } // namespace SimTK 00112 00113 #endif // SimTK_SIMBODY_MULTIBODY_SYSTEM_H_