Simbody

Force.h

Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_FORCE_H_
00002 #define SimTK_SIMBODY_FORCE_H_
00003 /* -------------------------------------------------------------------------- *
00004  *                      SimTK Core: SimTK Simbody(tm)                         *
00005  * -------------------------------------------------------------------------- *
00006  * This is part of the SimTK Core biosimulation toolkit originating from      *
00007  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00008  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00009  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
00010  *                                                                            *
00011  * Portions copyright (c) 2008-10 Stanford University and the Authors.        *
00012  * Authors: Peter Eastman                                                     *
00013  * Contributors: Michael Sherman                                              *
00014  *                                                                            *
00015  * Permission is hereby granted, free of charge, to any person obtaining a    *
00016  * copy of this software and associated documentation files (the "Software"), *
00017  * to deal in the Software without restriction, including without limitation  *
00018  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00019  * and/or sell copies of the Software, and to permit persons to whom the      *
00020  * Software is furnished to do so, subject to the following conditions:       *
00021  *                                                                            *
00022  * The above copyright notice and this permission notice shall be included in *
00023  * all copies or substantial portions of the Software.                        *
00024  *                                                                            *
00025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00026  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00027  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00028  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00029  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00030  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00031  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
00032  * -------------------------------------------------------------------------- */
00033 
00034 #include "SimTKcommon.h"
00035 #include "simbody/internal/common.h"
00036 #include "simbody/internal/GeneralForceSubsystem.h"
00037 
00038 namespace SimTK {
00039 
00040 class SimbodyMatterSubsystem;
00041 class GeneralForceSubsystem;
00042 class MobilizedBody;
00043 class Force;
00044 class ForceImpl;
00045 
00046 // We only want the template instantiation to occur once. This symbol is defined
00047 // in the SimTK core compilation unit that defines the Force class but should 
00048 // not be defined any other time.
00049 #ifndef SimTK_SIMBODY_DEFINING_FORCE
00050     extern template class PIMPLHandle<Force, ForceImpl, true>;
00051 #endif
00052 
00057 class SimTK_SIMBODY_EXPORT Force : public PIMPLHandle<Force, ForceImpl, true> {
00058 public:
00069     void disable(State&) const;
00073     void enable(State&) const;
00077     bool isDisabled(const State&) const;
00083     void setDisabledByDefault(bool shouldBeDisabled);
00087     bool isDisabledByDefault() const;
00135     void calcForceContribution(const State&          state,
00136                                Vector_<SpatialVec>&  bodyForces,
00137                                Vector_<Vec3>&        particleForces,
00138                                Vector&               mobilityForces) const;
00150     Real calcPotentialEnergyContribution(const State& state) const;
00159     Force() {}
00163     operator ForceIndex() const {return getForceIndex();}
00167     const GeneralForceSubsystem& getForceSubsystem() const;
00171     ForceIndex getForceIndex() const;
00174     class TwoPointLinearSpring;
00175     class TwoPointLinearDamper;
00176     class TwoPointConstantForce;
00177     class MobilityLinearSpring;
00178     class MobilityLinearDamper;
00179     class MobilityConstantForce;
00180     class LinearBushing;
00181     class ConstantForce;
00182     class ConstantTorque;
00183     class GlobalDamper;
00184     class Thermostat;
00185     class UniformGravity;
00186     class Gravity;
00187     class Custom;
00188     
00189     class TwoPointLinearSpringImpl;
00190     class TwoPointLinearDamperImpl;
00191     class TwoPointConstantForceImpl;
00192     class MobilityLinearSpringImpl;
00193     class MobilityLinearDamperImpl;
00194     class MobilityConstantForceImpl;
00195     class LinearBushingImpl;
00196     class ConstantForceImpl;
00197     class ConstantTorqueImpl;
00198     class GlobalDamperImpl;
00199     class ThermostatImpl;
00200     class UniformGravityImpl;
00201     class GravityImpl;
00202     class CustomImpl;
00203 
00204 protected:
00207     explicit Force(ForceImpl* r) : HandleBase(r) { }
00208 };
00209 
00210 
00222 class SimTK_SIMBODY_EXPORT Force::TwoPointLinearSpring : public Force {
00223 public:
00235     TwoPointLinearSpring(GeneralForceSubsystem& forces, const MobilizedBody& body1, const Vec3& station1, const MobilizedBody& body2, const Vec3& station2, Real k, Real x0);
00236     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(TwoPointLinearSpring, TwoPointLinearSpringImpl, Force);
00237 };
00238 
00251 class SimTK_SIMBODY_EXPORT Force::TwoPointLinearDamper: public Force {
00252 public:
00263     TwoPointLinearDamper(GeneralForceSubsystem& forces, const MobilizedBody& body1, const Vec3& station1, const MobilizedBody& body2, const Vec3& station2, Real damping);
00264     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(TwoPointLinearDamper, TwoPointLinearDamperImpl, Force);
00265 };
00266 
00278 class SimTK_SIMBODY_EXPORT Force::TwoPointConstantForce: public Force {
00279 public:
00290     TwoPointConstantForce(GeneralForceSubsystem& forces, const MobilizedBody& body1, const Vec3& station1, const MobilizedBody& body2, const Vec3& station2, Real force);
00291     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(TwoPointConstantForce, TwoPointConstantForceImpl, Force);
00292 };
00293 
00305 class SimTK_SIMBODY_EXPORT Force::MobilityLinearSpring : public Force {
00306 public:
00316     MobilityLinearSpring(GeneralForceSubsystem& forces, const MobilizedBody& body, int coordinate, Real k, Real q0);
00317     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(MobilityLinearSpring, MobilityLinearSpringImpl, Force);
00318 };
00319 
00330 class SimTK_SIMBODY_EXPORT Force::MobilityLinearDamper : public Force {
00331 public:
00340     MobilityLinearDamper(GeneralForceSubsystem& forces, const MobilizedBody& body, int coordinate, Real damping);
00341     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(MobilityLinearDamper, MobilityLinearDamperImpl, Force);
00342 };
00343 
00354 class SimTK_SIMBODY_EXPORT Force::MobilityConstantForce : public Force {
00355 public:
00364     MobilityConstantForce(GeneralForceSubsystem& forces, const MobilizedBody& body, int coordinate, Real force);
00365     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(MobilityConstantForce, MobilityConstantForceImpl, Force);
00366 };
00367 
00375 class SimTK_SIMBODY_EXPORT Force::ConstantForce: public Force {
00376 public:
00377     ConstantForce(GeneralForceSubsystem& forces, const MobilizedBody& body, const Vec3& station, const Vec3& force);
00378     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(ConstantForce, ConstantForceImpl, Force);
00379 };
00380 
00388 class SimTK_SIMBODY_EXPORT Force::ConstantTorque: public Force {
00389 public:
00390     ConstantTorque(GeneralForceSubsystem& forces, const MobilizedBody& body, const Vec3& torque);
00391     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(ConstantTorque, ConstantTorqueImpl, Force);
00392 };
00393 
00408 class SimTK_SIMBODY_EXPORT Force::GlobalDamper : public Force {
00409 public:
00410     GlobalDamper(GeneralForceSubsystem& forces, const SimbodyMatterSubsystem& matter, Real damping);
00411     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(GlobalDamper, GlobalDamperImpl, Force);
00412 };
00413 
00420 class SimTK_SIMBODY_EXPORT Force::UniformGravity : public Force {
00421 public:
00422     UniformGravity(GeneralForceSubsystem& forces, const SimbodyMatterSubsystem& matter, const Vec3& g, Real zeroHeight=0);
00423     Vec3 getGravity() const;
00424     void setGravity(const Vec3& g);
00425     Real getZeroHeight() const;
00426     void setZeroHeight(Real height);
00427     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(UniformGravity, UniformGravityImpl, Force);
00428 };
00429 
00459 class SimTK_SIMBODY_EXPORT Force::Custom : public Force {
00460 public:
00461     class Implementation;
00470     Custom(GeneralForceSubsystem& forces, Implementation* implementation);
00471     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(Custom, CustomImpl, Force);
00472 protected:
00473     const Implementation& getImplementation() const;
00474     Implementation& updImplementation();
00475 };
00476 
00477 class SimTK_SIMBODY_EXPORT Force::Custom::Implementation {
00478 public:
00479     virtual ~Implementation() { }
00491     virtual void calcForce(const State& state, Vector_<SpatialVec>& bodyForces, Vector_<Vec3>& particleForces, Vector& mobilityForces) const = 0;
00497     virtual Real calcPotentialEnergy(const State& state) const = 0;
00503     virtual bool dependsOnlyOnPositions() const {
00504         return false;
00505     }
00510     virtual void realizeTopology(State& state) const {
00511     }
00512     virtual void realizeModel(State& state) const {
00513     }
00514     virtual void realizeInstance(const State& state) const {
00515     }
00516     virtual void realizeTime(const State& state) const {
00517     }
00518     virtual void realizePosition(const State& state) const {
00519     }
00520     virtual void realizeVelocity(const State& state) const {
00521     }
00522     virtual void realizeDynamics(const State& state) const {
00523     }
00524     virtual void realizeAcceleration(const State& state) const {
00525     }
00526     virtual void realizeReport(const State& state) const {
00527     }
00529 };
00530 
00531 } // namespace SimTK
00532 
00533 #endif // SimTK_SIMBODY_FORCE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines