AGXDynamics  2.31.1.0
DynamicsSystem.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_DYNAMICS_SYSTEM_H
18 #define AGX_DYNAMICS_SYSTEM_H
19 
20 #include <agx/agxPhysics_export.h>
21 
22 #include <agx/agx.h>
23 
24 #include <agx/Vec3.h>
25 #include <agx/Component.h>
26 #include <agx/Constraint.h>
27 #include <agx/TimeGovernor.h>
28 #include <agx/SymmetricPair.h>
29 #include <agx/agx_hash_types.h>
30 #include <agx/MergeSplit.h>
31 #include <agx/AutoSleep.h>
32 #include <agx/Task.h>
33 #include <agx/Solver.h>
34 #include <agx/ObserverFrame.h>
35 
36 namespace agxCollide
37 {
38  class Space;
39 }
40 
41 namespace agxSDK
42 {
43  class Simulation;
44 }
45 
46 namespace agx
47 {
54 
55 
56  // forward declarations
58  class DynamicsSystem;
59  class IndexLambdaKernel;
60 
69  {
70  public:
71  static agx::Model* ClassModel();
72 
73  public:
76 
78  DynamicsSystem( agx::Device* device );
79 
84  bool add( agx::RigidBody* rigidBody );
85 
94  bool remove( agx::RigidBody* rigidBody );
95 
100  bool add( agx::ObserverFrame* observerFrame );
101 
107  bool remove( agx::ObserverFrame* observerFrame );
108 
113  bool add( agx::Interaction* interaction );
114 
119  bool remove( agx::Interaction* interaction );
120 
125  bool add( agx::Constraint* constraint );
126 
131  bool remove( agx::Constraint* constraint );
132 
137  RigidBody* getRigidBody( const Name& name );
138 
143  const RigidBody* getRigidBody(const Name& name) const;
144 
149  Constraint* getConstraint( const Name& name);
150 
155  const Constraint* getConstraint( const Name& name ) const;
156 
161  ObserverFrame* getObserverFrame(const Name& name);
162 
167  const ObserverFrame* getObserverFrame(const Name& name) const;
168 
174  agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) ;
175 
181  const agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) const;
182 
188  const agx::Constraint* getConstraint( const agx::Uuid& uuid ) const;
189 
195  agx::Constraint* getConstraint( const agx::Uuid& uuid );
196 
202  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid) const;
203 
209  agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid);
210 
215  void setTimeGovernor( agx::TimeGovernor* tg );
216 
220  agx::TimeGovernor* getTimeGovernor() ;
221 
225  const agx::TimeGovernor* getTimeGovernor() const;
226 
230  void setGeometryContacts( const agxCollide::GeometryContactPtrVector* contacts );
231 
235  const agxCollide::GeometryContactPtrVector* getGeometryContacts() const;
236 
241  agx::MergeSplit* getMergeSplit();
242 
247  const agx::MergeSplit* getMergeSplit() const;
248 
252  void stepForward();
253 
257  agx::Vec3 getLinearMomentum() const;
258 
262  agx::Vec3 getAngularMomentum() const;
263 
267  AGX_DEPRECATED( 2.29.0.0 )
268  agx::Real getPotentialEnergy() const;
269 
273  AGX_DEPRECATED( 2.29.0.0 )
274  agx::Real getTranslationalEnergy() const;
275 
279  AGX_DEPRECATED( 2.29.0.0 )
280  agx::Real getRotationalEnergy() const;
281 
285  AGX_DEPRECATED( 2.29.0.0 )
286  agx::Real getTotalEnergy() const;
287 
291  const agx::RigidBodyRefVector& getRigidBodies() const;
292 
296  agx::RigidBodyRefVector& getRigidBodies();
297 
301  const agx::ConstraintRefSetVector& getConstraints() const;
302 
306  agx::ConstraintRefSetVector& getConstraints();
307 
311  const ObserverFrameRefSetVector& getObserverFrames() const;
312 
316  ObserverFrameRefSetVector& getObserverFrames();
317 
321  agx::RigidBodyPtrSetVector& getEnabledRigidBodies();
322 
326  const agx::RigidBodyPtrSetVector& getEnabledRigidBodies() const;
327 
331  agx::RigidBodyPtrSetVector& getSleepingRigidBodies();
332 
336  const agx::RigidBodyPtrSetVector& getSleepingRigidBodies() const;
337 
341  const agx::InteractionRefSetVector& getInteractions() const;
342 
346  const agx::StrongInteractionRefSetVector& getStrongInteractions() const;
347 
351  agx::AutoSleep* getAutoSleep();
352 
356  const agx::AutoSleep* getAutoSleep() const;
357 
361  agx::Solver* getSolver();
362 
366  const agx::Solver* getSolver() const;
367 
368 
382  void enableSolverDataExtraction(const agx::String& filename, const agx::String& solverDataGroup);
383 
388  void disableSolverDataExtraction();
389 
393  bool getEnableSolverDataExtraction() const;
394 
395 
397 
398 
399  agxData::EntityStorage* getRigidBodyStorage();
400 
402  void _setGravityTask( agx::Task* task );
403 
405  void updateSleepState( const agxCollide::SeparationPairVector& separations, const agxCollide::GeometryContactPtrVector& contacts );
406 
408  agx::TaskGroup* getUpdateTask();
409 
416  agx::Index getInstanceId(const agx::Uuid& uuid) const;
417 
419 
420 
421 
436  void setEnableContactWarmstarting( bool enable );
437 
441  bool getEnableContactWarmstarting() const;
442 
447  agx::IndexLambdaKernel* getIndexLambdaKernel() const;
449 
450  protected:
451 
453  virtual ~DynamicsSystem();
454 
455  private:
456 
457  void updateFrames();
458 
459  void createUpdateTask();
460 
461  void setSimulation(agxSDK::Simulation* simulation);
462 
463  class SolveTask;
464  friend class RigidBody;
465  friend class agxSDK::Simulation;
466 
467  Task* createIntegratePositionsTask();
468  Task* createUpdateFramesTask();
469  Task* createSynchronizeGeometriesTask();
470  Task* createMergedBodyPostIntegrateTask();
471 
472  virtual void setContext(Object* context) override;
473  void updateGravity();
474  void init();
475  void commitRemovedBodies();
476  void reset();
477  void disableBody( RigidBody* body );
478  void enableBody( RigidBody* body );
479 
480  void sleepBody( RigidBody* body );
481  bool wakeBody( RigidBody* body );
482 
483 
485  void mergeSplitPre();
487  void mergeSplitPost();
488  void updateInteractionForces();
489  void updateSleepState();
490 
491  void startUpdateTimer(agx::Task* task);
492  void stopUpdateTimerAndReport(agx::Task* task);
493  void recordPlaybackStatistics();
494 
495  agxData::EntityStorageRef m_rigidBodyStorage;
496  TaskRef m_updateWorldMassAndInertiaTask;
497  TaskRef m_integratePositionsTask;
498  TaskRef m_gravityTask;
499 
500  private:
501  RigidBodyPtrSetVector m_enabledBodies;
502  RigidBodyPtrSetVector m_sleepingBodies;
503  RigidBodyRefSetVector m_removedBodies;
504 
505  RigidBodyRefVector m_rigidBodies;
506 
507 
508  ConstraintRefSetVector m_constraints;
509  InteractionRefSetVector m_interactions;
510  StrongInteractionRefSetVector m_strongInteractions;
511 
512  ObserverFrameRefSetVector m_observerFrames;
513 
514  ref_ptr<TimeGovernor> m_timeGovernor;
515 
516  const agxCollide::GeometryContactPtrVector* m_geometryContacts;
517 
518  int m_garbageCollectionCounter;
519 
520  ref_ptr<MergeSplit> m_mergeSplit;
521  ref_ptr<AutoSleep> m_autoSleep;
522 
523  TaskGroupRef m_updateTask;
524  agxSDK::Simulation* m_simulation;
525  agx::Timer m_updateTimer;
526  agx::Task::ExecutionEvent::CallbackType m_startUpdateTimerCallback;
527  agx::Task::ExecutionEvent::CallbackType m_stopUpdateTimerAndReportCallback;
528 
529  SolverRef m_solver;
530  bool m_useSSE;
531 
532  LambdaKernelRef m_indexLambdaKernel;
533  };
534 
536 
537 
538  //-------------------------------------------------------------------------
539  // inline code
540 
541  inline RigidBodyPtrSetVector& DynamicsSystem::getEnabledRigidBodies()
542  {
543  return m_enabledBodies;
544  }
545 
546  inline const RigidBodyPtrSetVector& DynamicsSystem::getEnabledRigidBodies() const
547  {
548  return m_enabledBodies;
549  }
550 
551  inline RigidBodyPtrSetVector& DynamicsSystem::getSleepingRigidBodies()
552  {
553  return m_sleepingBodies;
554  }
555  inline const RigidBodyPtrSetVector& DynamicsSystem::getSleepingRigidBodies() const
556  {
557  return m_sleepingBodies;
558  }
559 
560  inline void DynamicsSystem::setGeometryContacts( const agxCollide::GeometryContactPtrVector* contacts )
561  {
562  m_geometryContacts = contacts;
563  }
564 
565  inline const agxCollide::GeometryContactPtrVector* DynamicsSystem::getGeometryContacts() const
566  {
567  return m_geometryContacts;
568  }
569 
570  inline Solver* DynamicsSystem::getSolver() { return m_solver; }
571  inline const Solver* DynamicsSystem::getSolver() const { return m_solver; }
572 
573 
574 } //namespace agx
575 
576 #endif
void AGXPHYSICS_EXPORT init()
Initialize agx.
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
agxCollide namespace consists of a set of classes for handling geometric intersection tests including...
#define AGXPHYSICS_EXPORT
The base class for a constraint.
Definition: Constraint.h:86
A representation of a generic task.
Definition: Task.h:57
Representation of a name string.
Definition: Name.h:32
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:73
agx::SetVector< RigidBodyRef > RigidBodyRefSetVector
agx::SetVector< InteractionRef > InteractionRefSetVector
ref_ptr< DynamicsSystem > DynamicsSystemRef
The base class for interactions.
Definition: Interaction.h:30
Class which will go through contacting/separating bodies and determine if the bodies can be merged (g...
Definition: MergeSplit.h:37
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
Namespace agx contains the dynamics/math part of the AGX Dynamics API.
TaskGroup.
Definition: Task.h:585
agx::SetVector< RigidBody * > RigidBodyPtrSetVector
UInt32 Index
Definition: Integer.h:52
virtual void setContext(agx::Object *context)
Callback1< T1 > CallbackType
Definition: Event.h:37
agx::SetVector< ObserverFrameRef > ObserverFrameRefSetVector
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
agx::SetVector< ConstraintRef > ConstraintRefSetVector
The complete physical system with bodies, interactions, data layout, time stepper, and solver.
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:41
Class that will investigate bodies to see if they are resting, that is if linear/angular velocity and...
Definition: AutoSleep.h:40
agx::SetVector< InteractionRef > StrongInteractionRefSetVector
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
Utility entrance to the task system, simplifying parallelization of algorithms.
double Real
Definition: Real.h:42
#define AGX_DEPRECATED(since)
Definition: Object.h:94
An agx::Device is an abstract representation of a device on which data can be stored and processed...
Definition: Device.h:57
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:102
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:101
agx::Object is a refcounted object with a name.
Definition: Object.h:59
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:42