Simbody
|
This force element represents a uniform gravitational field applied to a set of bodies. More...
#include <Force_Gravity.h>
Public Member Functions | |
Construction | |
Methods in this section refer both to constructors, and to methods that can be used to set or change contruction (Topology-stage) parameters; these specify the values assigned by default to the corresponding Instance-stage state variables. Note:
| |
Gravity (GeneralForceSubsystem &forces, const SimbodyMatterSubsystem &matter, const Vec3 &gravity) | |
Create a Gravity force element within a particular force subsystem and affecting all the bodies of a particular matter subsystem, by specifying only a gravity vector, that is, the product of the gravity magnitude and the "down" direction vector. | |
Gravity (GeneralForceSubsystem &forces, const SimbodyMatterSubsystem &matter, const UnitVec3 &down, Real g, Real zeroHeight=0) | |
Create a Gravity force element within a particular force subsystem and affecting all the bodies of a particular matter subsystem, providing gravity magnitude and direction separately. | |
Gravity & | setDefaultGravityVector (const Vec3 &gravity) |
Set the default value for the gravity vector, that is, the direction and magnitude with which gravity will act (must not be zero). | |
Gravity & | setDefaultDownDirection (const UnitVec3 &down) |
Set the default "down" direction d, that is, the direction along which gravity will act. | |
Gravity & | setDefaultDownDirection (const Vec3 &down) |
Convenience overload that takes the down direction as a Vec3 and normalizes it (throwing away the magnitude) to create the required unit vector for the down direction. | |
Gravity & | setDefaultMagnitude (Real g) |
Set the default magnitude of gravity (a nonegative scalar). | |
Gravity & | setDefaultZeroHeight (Real zeroHeight) |
Set the default zero height (a signed scalar), for use in potential energy calculation. | |
Vec3 | getDefaultGravityVector () const |
Return the default gravity vector being used for this Gravity force element, calculated from the default magnitude and direction. | |
const UnitVec3 & | getDefaultDownDirection () const |
Return the default down direction (a unit vector) for this Gravity force element. | |
Real | getDefaultMagnitude () const |
Return the default gravity magnitude g (a nonnegative scalar). | |
Real | getDefaultZeroHeight () const |
Return the default zero height used in the calculation of graviational potential energy. | |
Instance Parameters | |
These refer to the Instance-stage state variables that determine the actual values to be used to calculate gravitational forces and energy from a given State object. If these are not set explicitly, the default values are set to those provided in the constructor or via the correponding setDefault...() methods. Note:
| |
const Gravity & | setGravityVector (State &state, const Vec3 &gravity) const |
Set the gravity vector v, that is, the magnitude and direction with which gravitational forces will act, overriding the default magnitude and direction that are stored in this Gravity force element. | |
const Gravity & | setDownDirection (State &state, const UnitVec3 &down) const |
Set the "down" direction d (a unit vector), that is, the direction along which gravitational forces will act. | |
const Gravity & | setDownDirection (State &state, const Vec3 &down) const |
Convenience overload that takes the down direction as a Vec3 and normalizes it (throwing away the magnitude) to create the required unit vector. | |
const Gravity & | setMagnitude (State &state, Real g) const |
Set the gravity magnitude g (a nonnegative scalar) in this state, overriding the default gravity magnitude that is stored in this Gravity force element. | |
const Gravity & | setZeroHeight (State &state, Real hz) const |
Set the potential energy zero height hz (a scalar) in this state, overriding the default zero height that is stored in this Gravity force element. | |
Vec3 | getGravityVector (const State &state) const |
Get the gravity vector v that will be used for computations done with this state. | |
const UnitVec3 & | getDownDirection (const State &state) const |
Get the gravity "down" direction d (a unit vector) that is currently set in this state. | |
Real | getMagnitude (const State &state) const |
Get the gravity magnitude g (a nonnegative scalar) that is currently set in this state. | |
Real | getZeroHeight (const State &state) const |
Get the zero height hz that is currently set in this state for use in calculating gravitational potential energy. | |
Energy and Forces | |
These methods return the gravitational potential energy and the forces being applied by this Gravity element in the configuration contained in the supplied State. These are evaluated during force calculation and available at no computational cost afterwards, although the first call after a position or instance-variable change will initiate computation if forces haven't already been computed. | |
Real | getPotentialEnergy (const State &state) const |
Obtain the gravitational potential energy contained in this Gravity force element in the given configuration. | |
const SpatialVec & | getBodyForce (const State &state, MobilizedBodyIndex mobod) const |
Obtain the gravitational force currently being applied by this Gravity force element to the given mobilized body. |
This force element represents a uniform gravitational field applied to a set of bodies.
This can be used instead of the more limited Force::UniformGravity class if you want more control.
Force::Gravity is given a magnitude g in units of acceleration, and a "down" direction (unit vector) d, expressed in the Ground frame. For example, in SI units "standard gravity" g at the Earth's surface is defined to be exactly g=9.80665 m/s^2. If gravity acts in Ground's -Y direction, then its direction vector is d=[0,-1,0]; together this yields a gravity vector v=g*d=[0,-9.80665,0]. Gravity affects all the bodies and particles in the given SimbodyMatterSubsystem (except for Ground).
SimTK::Force::Gravity::Gravity | ( | GeneralForceSubsystem & | forces, |
const SimbodyMatterSubsystem & | matter, | ||
const Vec3 & | gravity | ||
) |
Create a Gravity force element within a particular force subsystem and affecting all the bodies of a particular matter subsystem, by specifying only a gravity vector, that is, the product of the gravity magnitude and the "down" direction vector.
[in,out] | forces | The subsystem to which this force should be added. |
[in] | matter | The subsystem containing the bodies that will be affected. |
[in] | gravity | The default gravity vector v, interpreted as v=g*d where g=|gravity| is a positive scalar and d is the "down" direction unit vector d=gravity/g. This value is used to calculate g and d separately so must not be zero length. If you want to create a Gravity force element with default magnitude zero, use the other constructor which allows magnitude and direction to be provided separately. |
This constructor sets the default zero height hz to zero (for use in calculating gravitational potential energy). If you want a different default value, use the more general constructor or the setDefaultZeroHeight() method.
SimTK::Force::Gravity::Gravity | ( | GeneralForceSubsystem & | forces, |
const SimbodyMatterSubsystem & | matter, | ||
const UnitVec3 & | down, | ||
Real | g, | ||
Real | zeroHeight = 0 |
||
) |
Create a Gravity force element within a particular force subsystem and affecting all the bodies of a particular matter subsystem, providing gravity magnitude and direction separately.
[in,out] | forces | The subsystem to which this force should be added. |
[in] | matter | The subsystem containing the bodies that will be affected. |
[in] | down | The default gravity direction vector d (i.e., the "down" direction), expressed in the Ground frame. This is a unit vector; if you provide an ordinary Vec3 it will be normalized before use and its magnitude ignored. Gravity will be directed along this direction unless explicitly changed within a particular State via the setDirection() or setGravityVector() methods. |
[in] | g | The default magnitude g to be used for gravity, given as a nonnegative scalar with units of acceleration. The gravity vector is calculated as v=g*d where d is the current direction vector, typically the default direction as given by the direction argument to this constructor. Gravity will have the magnitude given here unless explicitly changed within a particular State. |
[in] | zeroHeight | This is an optional specification of the default value for the height up the gravity vector that is considered to be "zero" for purposes of calculating the gravitational potential energy. The default is zeroHeight == 0, i.e., a body's potential energy is defined to be zero when the height of its mass center is the same as the height of the Ground origin. The zero height will have the value specified here unless explicitly changed within a particular State use the setZeroHeight() method. |
Set the default value for the gravity vector, that is, the direction and magnitude with which gravity will act (must not be zero).
From the given vector we extract separately the magnitude g and "down" direction d (a unit vector) so the supplied vector cannot be zero. If you want the default magnitude to be zero, use setDefaultMagnitude() and setDefaultDownDirection() methods to provide them separately instead of combining them as is required by this method.
[in] | gravity | A vector giving the magnitude and direction with which gravity will act on the bodies. Must not be zero. |
Set the default "down" direction d, that is, the direction along which gravity will act.
[in] | down | A unit vector giving the direction along which gravity will act ("down"). If you pass an ordinary Vec3, it will be normalized before use and its length will be ignored. Do not pass a zero-length Vec3, however. |
Convenience overload that takes the down direction as a Vec3 and normalizes it (throwing away the magnitude) to create the required unit vector for the down direction.
It is an error if the supplied Vec3 has zero length.
Gravity& SimTK::Force::Gravity::setDefaultMagnitude | ( | Real | g | ) |
Set the default magnitude of gravity (a nonegative scalar).
This will be combined with the default direction unit vector d to calculate the gravity vector v = g*d that is used to generate body forces mb*v where mb is the mass of body b and the force is applied to b's mass center.
[in] | g | The magnitude of the uniform gravitational field, given as a nonnegative scalar in units of acceleration. If this is zero no forces will be applied by this element. |
Gravity& SimTK::Force::Gravity::setDefaultZeroHeight | ( | Real | zeroHeight | ) |
Set the default zero height (a signed scalar), for use in potential energy calculation.
See the Gravity class comments for how this is used.
[in] | zeroHeight | The height that is considered to be "zero" for purposes of potential energy calculation. An affected body whose mass center is at this height will have zero gravitational potential energy. |
Vec3 SimTK::Force::Gravity::getDefaultGravityVector | ( | ) | const |
Return the default gravity vector being used for this Gravity force element, calculated from the default magnitude and direction.
const UnitVec3& SimTK::Force::Gravity::getDefaultDownDirection | ( | ) | const |
Return the default down direction (a unit vector) for this Gravity force element.
Real SimTK::Force::Gravity::getDefaultMagnitude | ( | ) | const |
Return the default gravity magnitude g (a nonnegative scalar).
Real SimTK::Force::Gravity::getDefaultZeroHeight | ( | ) | const |
Return the default zero height used in the calculation of graviational potential energy.
const Gravity& SimTK::Force::Gravity::setGravityVector | ( | State & | state, |
const Vec3 & | gravity | ||
) | const |
Set the gravity vector v, that is, the magnitude and direction with which gravitational forces will act, overriding the default magnitude and direction that are stored in this Gravity force element.
This is used to calculate the magnitude and direction separately, so must not be zero.
[in,out] | state | The State object that is modified by this method. |
[in] | gravity | The gravity vector including both the magnitude and direction. Must not be zero. |
const Gravity& SimTK::Force::Gravity::setDownDirection | ( | State & | state, |
const UnitVec3 & | down | ||
) | const |
Set the "down" direction d (a unit vector), that is, the direction along which gravitational forces will act.
Magnitude can be changed independently with setMagnitude().
[in,out] | state | The State object that is modified by this method. |
[in] | down | A unit vector giving the "down" direction along which gravity will act. |
const Gravity& SimTK::Force::Gravity::setDownDirection | ( | State & | state, |
const Vec3 & | down | ||
) | const [inline] |
Convenience overload that takes the down direction as a Vec3 and normalizes it (throwing away the magnitude) to create the required unit vector.
It is an error if the supplied Vec3 has zero length.
Set the gravity magnitude g (a nonnegative scalar) in this state, overriding the default gravity magnitude that is stored in this Gravity force element.
[in,out] | state | The State object that is modified by this method. |
[in] | g | The magnitude of the uniform gravitational field. |
Set the potential energy zero height hz (a scalar) in this state, overriding the default zero height that is stored in this Gravity force element.
[in,out] | state | The State object that is modified by this method. |
[in] | hz | The height at which potential energy is considered to be zero. |
Get the gravity vector v that will be used for computations done with this state.
This is calculated as v=g*d from the current values of the magnitude g and direction d Instance variables in the state.
[in] | state | The state containing the gravity Instance variables used to calculate the gravity vector. |
Get the gravity "down" direction d (a unit vector) that is currently set in this state.
[in] | state | The state containing the gravity direction Instance variable whose value is returned. |
Real SimTK::Force::Gravity::getMagnitude | ( | const State & | state | ) | const |
Get the gravity magnitude g (a nonnegative scalar) that is currently set in this state.
[in] | state | The state containing the gravity magnitude Instance variable whose value is returned. |
Real SimTK::Force::Gravity::getZeroHeight | ( | const State & | state | ) | const |
Get the zero height hz that is currently set in this state for use in calculating gravitational potential energy.
See the class documentation for information about hz is used.
[in] | state | The state containing the zero height Instance variable whose value is returned. |
Real SimTK::Force::Gravity::getPotentialEnergy | ( | const State & | state | ) | const |
Obtain the gravitational potential energy contained in this Gravity force element in the given configuration.
Note that gravitational potential energy is m*g*h for each body where the height h is measured from an arbitrary zero height. By default the zero height is defined to be height of the Ground origin but that can be changed arbitrarily.
[in] | state | The State from whose cache the potential energy is retrieved. |
const SpatialVec& SimTK::Force::Gravity::getBodyForce | ( | const State & | state, |
MobilizedBodyIndex | mobod | ||
) | const |
Obtain the gravitational force currently being applied by this Gravity force element to the given mobilized body.
[in] | state | The State from whose cache the force is retrieved. |
[in] | mobod | The index of the mobilized body whose force is wanted. |