AGX Dynamics  2.37.3.2
DynamicsSystem.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 #pragma once
18 
19 #include <agx/agxPhysics_export.h>
20 
21 #include <agx/agx.h>
22 
23 #include <agx/Vec3.h>
24 #include <agx/Component.h>
25 #include <agx/Constraint.h>
26 #include <agx/TimeGovernor.h>
27 #include <agx/SymmetricPair.h>
28 #include <agx/agx_hash_types.h>
29 #include <agx/MergeSplit.h>
30 #include <agx/AutoSleep.h>
31 #include <agx/Task.h>
32 #include <agx/Solver.h>
33 #include <agx/ObserverFrame.h>
34 
35 namespace agxCollide
36 {
37  class Space;
38 }
39 
40 namespace agxSDK
41 {
42  class Simulation;
43 }
44 
45 namespace agx
46 {
51 
52 
53  // forward declarations
55  class DynamicsSystem;
56  class IndexLambdaKernel;
57 
66  {
67  public:
68  static agx::Model* ClassModel();
69 
70  public:
73 
75  DynamicsSystem( agx::Device* device );
76 
81  bool add( agx::RigidBody* rigidBody );
82 
91  bool remove( agx::RigidBody* rigidBody );
92 
97  bool add( agx::ObserverFrame* observerFrame );
98 
104  bool remove( agx::ObserverFrame* observerFrame );
105 
110  bool add( agx::Interaction* interaction );
111 
116  bool remove( agx::Interaction* interaction );
117 
122  bool add( agx::Constraint* constraint );
123 
128  bool remove( agx::Constraint* constraint );
129 
134  RigidBody* getRigidBody( const Name& name );
135 
140  const RigidBody* getRigidBody(const Name& name) const;
141 
146  Constraint* getConstraint( const Name& name);
147 
152  const Constraint* getConstraint( const Name& name ) const;
153 
158  ObserverFrame* getObserverFrame(const Name& name);
159 
164  const ObserverFrame* getObserverFrame(const Name& name) const;
165 
171  agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) ;
172 
178  const agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) const;
179 
185  const agx::Constraint* getConstraint( const agx::Uuid& uuid ) const;
186 
192  agx::Constraint* getConstraint( const agx::Uuid& uuid );
193 
199  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid) const;
200 
206  agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid);
207 
212  void setTimeGovernor( agx::TimeGovernor* tg );
213 
217  agx::TimeGovernor* getTimeGovernor() ;
218 
222  const agx::TimeGovernor* getTimeGovernor() const;
223 
227  void setGeometryContacts( const agxCollide::GeometryContactPtrVector* contacts );
228 
232  const agxCollide::GeometryContactPtrVector* getGeometryContacts() const;
233 
238  agx::MergeSplit* getMergeSplit();
239 
244  const agx::MergeSplit* getMergeSplit() const;
245 
249  void stepForward();
250 
254  agx::Vec3 getLinearMomentum() const;
255 
259  agx::Vec3 getAngularMomentum() const;
260 
264  const agx::RigidBodyRefVector& getRigidBodies() const;
265 
269  agx::RigidBodyRefVector& getRigidBodies();
270 
274  const agx::ConstraintRefSetVector& getConstraints() const;
275 
279  agx::ConstraintRefSetVector& getConstraints();
280 
284  const ObserverFrameRefSetVector& getObserverFrames() const;
285 
289  ObserverFrameRefSetVector& getObserverFrames();
290 
294  agx::RigidBodyPtrSetVector& getEnabledRigidBodies();
295 
299  const agx::RigidBodyPtrSetVector& getEnabledRigidBodies() const;
300 
304  agx::RigidBodyPtrSetVector& getSleepingRigidBodies();
305 
309  const agx::RigidBodyPtrSetVector& getSleepingRigidBodies() const;
310 
314  const agx::InteractionRefSetVector& getInteractions() const;
315 
319  const agx::StrongInteractionRefSetVector& getStrongInteractions() const;
320 
324  agx::AutoSleep* getAutoSleep();
325 
329  const agx::AutoSleep* getAutoSleep() const;
330 
334  agx::Solver* getSolver();
335 
339  const agx::Solver* getSolver() const;
340 
341 
355  void enableSolverDataExtraction(const agx::String& filename, const agx::String& solverDataGroup);
356 
361  void disableSolverDataExtraction();
362 
366  bool getEnableSolverDataExtraction() const;
367 
368 
370 
371 
372  agxData::EntityStorage* getRigidBodyStorage();
373 
375  void _setGravityTask( agx::Task* task );
376 
378  void updateSleepState( const agxCollide::SeparationPairVector& separations, const agxCollide::GeometryContactPtrVector& contacts );
379 
381  agx::TaskGroup* getUpdateTask();
382 
389  agx::Index getInstanceId(const agx::Uuid& uuid) const;
390 
392 
393 
394 
409  void setEnableContactWarmstarting( bool enable );
410 
414  bool getEnableContactWarmstarting() const;
415 
420  agx::IndexLambdaKernel* getIndexLambdaKernel() const;
422 
423  protected:
424 
426  virtual ~DynamicsSystem();
427 
428  private:
429 
430  void updateFrames();
431 
432  void createUpdateTask();
433 
434  void setSimulation(agxSDK::Simulation* simulation);
435 
436  class SolveTask;
437  friend class RigidBody;
438  friend class agxSDK::Simulation;
439 
440  Task* createIntegratePositionsTask();
441  Task* createUpdateFramesTask();
442  Task* createSynchronizeGeometriesTask();
443  Task* createMergedBodyPostIntegrateTask();
444 
445  virtual void setContext(Object* context) override;
446  void updateGravity();
447  void init();
448  void commitRemovedBodies();
449  void reset();
450  void disableBody( RigidBody* body );
451  void enableBody( RigidBody* body );
452 
453  void sleepBody( RigidBody* body );
454  bool wakeBody( RigidBody* body );
455 
456 
458  void mergeSplitPre();
460  void mergeSplitPost();
461  void updateInteractionForces();
462  void updateSleepState();
463 
464  void startUpdateTimer(agx::Task* task);
465  void stopUpdateTimerAndReport(agx::Task* task);
466  void recordPlaybackStatistics();
467 
468  agxData::EntityStorageRef m_rigidBodyStorage;
469  TaskRef m_updateWorldMassAndInertiaTask;
470  TaskRef m_integratePositionsTask;
471  TaskRef m_gravityTask;
472 
473  private:
474  RigidBodyPtrSetVector m_enabledBodies;
475  RigidBodyPtrSetVector m_sleepingBodies;
476  RigidBodyRefSetVector m_removedBodies;
477 
478  RigidBodyRefVector m_rigidBodies;
479 
480 
481  ConstraintRefSetVector m_constraints;
482  InteractionRefSetVector m_interactions;
483  StrongInteractionRefSetVector m_strongInteractions;
484 
485  ObserverFrameRefSetVector m_observerFrames;
486 
487  ref_ptr<TimeGovernor> m_timeGovernor;
488 
489  const agxCollide::GeometryContactPtrVector* m_geometryContacts;
490 
491  int m_garbageCollectionCounter;
492 
493  ref_ptr<MergeSplit> m_mergeSplit;
494  ref_ptr<AutoSleep> m_autoSleep;
495 
496  TaskGroupRef m_updateTask;
497  agxSDK::Simulation* m_simulation;
498  agx::Timer m_updateTimer;
499  agx::Task::ExecutionEvent::CallbackType m_startUpdateTimerCallback;
500  agx::Task::ExecutionEvent::CallbackType m_stopUpdateTimerAndReportCallback;
501 
502  SolverRef m_solver;
503  bool m_useSSE;
504 
505  LambdaKernelRef m_indexLambdaKernel;
506  };
507 
509 
510 
511  //-------------------------------------------------------------------------
512  // inline code
513 
514  inline RigidBodyPtrSetVector& DynamicsSystem::getEnabledRigidBodies()
515  {
516  return m_enabledBodies;
517  }
518 
519  inline const RigidBodyPtrSetVector& DynamicsSystem::getEnabledRigidBodies() const
520  {
521  return m_enabledBodies;
522  }
523 
524  inline RigidBodyPtrSetVector& DynamicsSystem::getSleepingRigidBodies()
525  {
526  return m_sleepingBodies;
527  }
528  inline const RigidBodyPtrSetVector& DynamicsSystem::getSleepingRigidBodies() const
529  {
530  return m_sleepingBodies;
531  }
532 
533  inline void DynamicsSystem::setGeometryContacts( const agxCollide::GeometryContactPtrVector* contacts )
534  {
535  m_geometryContacts = contacts;
536  }
537 
538  inline const agxCollide::GeometryContactPtrVector* DynamicsSystem::getGeometryContacts() const
539  {
540  return m_geometryContacts;
541  }
542 
543  inline Solver* DynamicsSystem::getSolver() { return m_solver; }
544  inline const Solver* DynamicsSystem::getSolver() const { return m_solver; }
545 
546 
547 } //namespace agx
548 
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
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
This namespace consists of a set of classes for handling geometric intersection tests including boole...
#define AGXPHYSICS_EXPORT
The base class for a constraint.
Definition: Constraint.h:88
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:74
ref_ptr< DynamicsSystem > DynamicsSystemRef
The base class for interactions.
Definition: Interaction.h:31
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
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
TaskGroup.
Definition: Task.h:585
agx::SetVector< InteractionRef > InteractionRefSetVector
agx::SetVector< RigidBody * > RigidBodyPtrSetVector
UInt32 Index
Definition: Integer.h:52
virtual void setContext(agx::Object *context)
Callback1< T1 > CallbackType
Definition: Event.h:37
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
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:126
Utility entrance to the task system, simplifying parallelization of algorithms.
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:98
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:37
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
agx::SetVector< ref_ptr< Constraint > > ConstraintRefSetVector
Definition: Constraint.h:55
agx::Object is a refcounted object with a name.
Definition: Object.h:58
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:43