AGXDynamics  2.35.0.3
DynamicsSystem.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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  AGX_DEPRECATED( 2.29.0.0 )
265  agx::Real getPotentialEnergy() const;
266 
270  AGX_DEPRECATED( 2.29.0.0 )
271  agx::Real getTranslationalEnergy() const;
272 
276  AGX_DEPRECATED( 2.29.0.0 )
277  agx::Real getRotationalEnergy() const;
278 
282  AGX_DEPRECATED( 2.29.0.0 )
283  agx::Real getTotalEnergy() const;
284 
288  const agx::RigidBodyRefVector& getRigidBodies() const;
289 
293  agx::RigidBodyRefVector& getRigidBodies();
294 
298  const agx::ConstraintRefSetVector& getConstraints() const;
299 
303  agx::ConstraintRefSetVector& getConstraints();
304 
308  const ObserverFrameRefSetVector& getObserverFrames() const;
309 
313  ObserverFrameRefSetVector& getObserverFrames();
314 
318  agx::RigidBodyPtrSetVector& getEnabledRigidBodies();
319 
323  const agx::RigidBodyPtrSetVector& getEnabledRigidBodies() const;
324 
328  agx::RigidBodyPtrSetVector& getSleepingRigidBodies();
329 
333  const agx::RigidBodyPtrSetVector& getSleepingRigidBodies() const;
334 
338  const agx::InteractionRefSetVector& getInteractions() const;
339 
343  const agx::StrongInteractionRefSetVector& getStrongInteractions() const;
344 
348  agx::AutoSleep* getAutoSleep();
349 
353  const agx::AutoSleep* getAutoSleep() const;
354 
358  agx::Solver* getSolver();
359 
363  const agx::Solver* getSolver() const;
364 
365 
379  void enableSolverDataExtraction(const agx::String& filename, const agx::String& solverDataGroup);
380 
385  void disableSolverDataExtraction();
386 
390  bool getEnableSolverDataExtraction() const;
391 
392 
394 
395 
396  agxData::EntityStorage* getRigidBodyStorage();
397 
399  void _setGravityTask( agx::Task* task );
400 
402  void updateSleepState( const agxCollide::SeparationPairVector& separations, const agxCollide::GeometryContactPtrVector& contacts );
403 
405  agx::TaskGroup* getUpdateTask();
406 
413  agx::Index getInstanceId(const agx::Uuid& uuid) const;
414 
416 
417 
418 
433  void setEnableContactWarmstarting( bool enable );
434 
438  bool getEnableContactWarmstarting() const;
439 
444  agx::IndexLambdaKernel* getIndexLambdaKernel() const;
446 
447  protected:
448 
450  virtual ~DynamicsSystem();
451 
452  private:
453 
454  void updateFrames();
455 
456  void createUpdateTask();
457 
458  void setSimulation(agxSDK::Simulation* simulation);
459 
460  class SolveTask;
461  friend class RigidBody;
462  friend class agxSDK::Simulation;
463 
464  Task* createIntegratePositionsTask();
465  Task* createUpdateFramesTask();
466  Task* createSynchronizeGeometriesTask();
467  Task* createMergedBodyPostIntegrateTask();
468 
469  virtual void setContext(Object* context) override;
470  void updateGravity();
471  void init();
472  void commitRemovedBodies();
473  void reset();
474  void disableBody( RigidBody* body );
475  void enableBody( RigidBody* body );
476 
477  void sleepBody( RigidBody* body );
478  bool wakeBody( RigidBody* body );
479 
480 
482  void mergeSplitPre();
484  void mergeSplitPost();
485  void updateInteractionForces();
486  void updateSleepState();
487 
488  void startUpdateTimer(agx::Task* task);
489  void stopUpdateTimerAndReport(agx::Task* task);
490  void recordPlaybackStatistics();
491 
492  agxData::EntityStorageRef m_rigidBodyStorage;
493  TaskRef m_updateWorldMassAndInertiaTask;
494  TaskRef m_integratePositionsTask;
495  TaskRef m_gravityTask;
496 
497  private:
498  RigidBodyPtrSetVector m_enabledBodies;
499  RigidBodyPtrSetVector m_sleepingBodies;
500  RigidBodyRefSetVector m_removedBodies;
501 
502  RigidBodyRefVector m_rigidBodies;
503 
504 
505  ConstraintRefSetVector m_constraints;
506  InteractionRefSetVector m_interactions;
507  StrongInteractionRefSetVector m_strongInteractions;
508 
509  ObserverFrameRefSetVector m_observerFrames;
510 
511  ref_ptr<TimeGovernor> m_timeGovernor;
512 
513  const agxCollide::GeometryContactPtrVector* m_geometryContacts;
514 
515  int m_garbageCollectionCounter;
516 
517  ref_ptr<MergeSplit> m_mergeSplit;
518  ref_ptr<AutoSleep> m_autoSleep;
519 
520  TaskGroupRef m_updateTask;
521  agxSDK::Simulation* m_simulation;
522  agx::Timer m_updateTimer;
523  agx::Task::ExecutionEvent::CallbackType m_startUpdateTimerCallback;
524  agx::Task::ExecutionEvent::CallbackType m_stopUpdateTimerAndReportCallback;
525 
526  SolverRef m_solver;
527  bool m_useSSE;
528 
529  LambdaKernelRef m_indexLambdaKernel;
530  };
531 
533 
534 
535  //-------------------------------------------------------------------------
536  // inline code
537 
539  {
540  return m_enabledBodies;
541  }
542 
544  {
545  return m_enabledBodies;
546  }
547 
549  {
550  return m_sleepingBodies;
551  }
553  {
554  return m_sleepingBodies;
555  }
556 
558  {
559  m_geometryContacts = contacts;
560  }
561 
563  {
564  return m_geometryContacts;
565  }
566 
567  inline Solver* DynamicsSystem::getSolver() { return m_solver; }
568  inline const Solver* DynamicsSystem::getSolver() const { return m_solver; }
569 
570 
571 } //namespace agx
572 
agxPhysics_export.h
agx::Real
double Real
Definition: Real.h:42
agx::DynamicsSystem::getSleepingRigidBodies
agx::RigidBodyPtrSetVector & getSleepingRigidBodies()
Definition: DynamicsSystem.h:548
agx::Vector< RigidBodyRef >
agx::DynamicsSystem::getEnabledRigidBodies
agx::RigidBodyPtrSetVector & getEnabledRigidBodies()
Definition: DynamicsSystem.h:538
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Task.h
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agx::ConstraintRefSetVector
agx::SetVector< ref_ptr< Constraint > > ConstraintRefSetVector
Definition: Constraint.h:55
agx::DynamicsSystem::setGeometryContacts
void setGeometryContacts(const agxCollide::GeometryContactPtrVector *contacts)
Set the geometry contacts to resolve.
Definition: DynamicsSystem.h:557
Constraint.h
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agx::ConstraintImplementation
Definition: ConstraintImplementation.h:100
MergeSplit.h
agxData::EntityStorage
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
AGX_DEPRECATED
#define AGX_DEPRECATED(since)
Definition: macros.h:89
agx::VectorPOD< GeometryContact * >
agx::RigidBodyPtrSetVector
agx::SetVector< RigidBody * > RigidBodyPtrSetVector
Definition: DynamicsSystem.h:50
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::Model
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
Solver.h
agx::Task
A representation of a generic task.
Definition: Task.h:57
agx::ObserverFrame
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:43
Vec3.h
agx::ref_ptr< EntityStorage >
SymmetricPair.h
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agx::SetVector
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:37
agx::InteractionRefSetVector
agx::SetVector< InteractionRef > InteractionRefSetVector
Definition: DynamicsSystem.h:48
agx::DynamicsSystem::getSolver
agx::Solver * getSolver()
Definition: DynamicsSystem.h:567
agx::Index
UInt32 Index
Definition: Integer.h:52
Component.h
agx::MergeSplit
Class which will go through contacting/separating bodies and determine if the bodies can be merged (g...
Definition: MergeSplit.h:37
agx_hash_types.h
agx::TaskGroup
TaskGroup.
Definition: Task.h:585
agx::Name
Representation of a name string.
Definition: Name.h:32
agx::Object
agx::Object is a refcounted object with a name.
Definition: Object.h:59
agx::Component
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
agx.h
agx::Callback1
Templated callback with one argument.
Definition: Callback.h:100
agx::IndexLambdaKernel
Utility entrance to the task system, simplifying parallelization of algorithms.
Definition: IndexLambdaKernel.h:58
agx::Interaction
The base class for interactions.
Definition: Interaction.h:31
agx::Object::setContext
virtual void setContext(agx::Object *context)
agx::Timer
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:74
agxCollide
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Definition: ContactForceFilterParticipant.h:22
agx::TimeGovernor
Definition: TimeGovernor.h:30
agx::Constraint
The base class for a constraint.
Definition: Constraint.h:88
ObserverFrame.h
agx::Device
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:57
agx::DynamicsSystemRef
ref_ptr< DynamicsSystem > DynamicsSystemRef
Definition: DynamicsSystem.h:532
agx::AgXString< std::string >
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agx::init
void AGXPHYSICS_EXPORT init()
Initialize agx.
TimeGovernor.h
agx::Vec3T< Real >
agx::Uuid
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:41
agx::DynamicsSystem
The complete physical system with bodies, interactions, data layout, time stepper,...
Definition: DynamicsSystem.h:65
AutoSleep.h
agx::DynamicsSystem::getGeometryContacts
const agxCollide::GeometryContactPtrVector * getGeometryContacts() const
Get the geometry contacts to be resolved.
Definition: DynamicsSystem.h:562
agx::AutoSleep
Class that will investigate bodies to see if they are resting, that is if linear/angular velocity and...
Definition: AutoSleep.h:40
agx::StrongInteractionRefSetVector
agx::SetVector< InteractionRef > StrongInteractionRefSetVector
Definition: DynamicsSystem.h:49