AGX Dynamics  2.35.0.1
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:
69 
70  public:
73 
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 
159 
164  const ObserverFrame* getObserverFrame(const Name& name) const;
165 
172 
178  const agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) const;
179 
185  const agx::Constraint* getConstraint( const agx::Uuid& uuid ) const;
186 
193 
199  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid) const;
200 
207 
213 
218 
223 
227  void setGeometryContacts( const agxCollide::GeometryContactPtrVector* contacts );
228 
232  const agxCollide::GeometryContactPtrVector* getGeometryContacts() const;
233 
239 
245 
249  void stepForward();
250 
255 
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 
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 
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 
538  inline RigidBodyPtrSetVector& DynamicsSystem::getEnabledRigidBodies()
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 
#define AGXPHYSICS_EXPORT
Class that will investigate bodies to see if they are resting, that is if linear/angular velocity and...
Definition: AutoSleep.h:41
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:39
The base class for a constraint.
Definition: Constraint.h:89
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:58
The complete physical system with bodies, interactions, data layout, time stepper,...
void setGeometryContacts(const agxCollide::GeometryContactPtrVector *contacts)
Set the geometry contacts to resolve.
static agx::Model * ClassModel()
void stepForward()
Step the Dynamics system forward using dt calculated from the current TimeGovernor.
const agx::ObserverFrame * getObserverFrame(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a ObserverFrame with the given uuid.
ObserverFrame * getObserverFrame(const Name &name)
Find (linear search) the first ObserverFrame object in the system that matches the name.
agx::RigidBody * getRigidBody(const agx::Uuid &uuid)
Find (linear search) and return a pointer to a RigidBody with the given uuid.
const agxCollide::GeometryContactPtrVector * getGeometryContacts() const
Get the geometry contacts to be resolved.
agx::RigidBodyPtrSetVector & getEnabledRigidBodies()
agx::Vec3 getAngularMomentum() const
Return the total angular momentum in the system.
const agx::Constraint * getConstraint(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a Constraint with the given uuid.
agx::ObserverFrame * getObserverFrame(const agx::Uuid &uuid)
Find and return a pointer to a ObserverFrame with the given uuid.
agx::Constraint * getConstraint(const agx::Uuid &uuid)
Find and return a pointer to a Constraint with the given uuid.
agx::Vec3 getLinearMomentum() const
Return the total linear momentum in the system.
bool remove(agx::Interaction *interaction)
Remove the specified Interaction from the system.
agx::MergeSplit * getMergeSplit()
RigidBody * getRigidBody(const Name &name)
Find (linear search) the first Physical in the system that matches the name.
agx::TimeGovernor * getTimeGovernor()
const RigidBody * getRigidBody(const Name &name) const
Find (linear search) the first Physical in the system that matches the name.
bool add(agx::Interaction *interaction)
Add an Interaction to the system.
const ObserverFrame * getObserverFrame(const Name &name) const
Find (linear search) the first ObserverFrame object in the system that matches the name.
const agx::TimeGovernor * getTimeGovernor() const
bool add(agx::ObserverFrame *observerFrame)
Add a ObserverFrame to the system.
bool add(agx::Constraint *constraint)
Add a constraint from the simulation.
agx::Solver * getSolver()
const agx::RigidBody * getRigidBody(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a RigidBody with the given uuid.
bool remove(agx::Constraint *constraint)
Remove a constraint from the simulation.
const agx::MergeSplit * getMergeSplit() const
bool remove(agx::RigidBody *rigidBody)
Schedule a RigidBody for removal.
const Constraint * getConstraint(const Name &name) const
Find (linear search) the first Constraint object in the system that matches the name.
bool remove(agx::ObserverFrame *observerFrame)
Schedule a ObserverFrame for removal.
void setTimeGovernor(agx::TimeGovernor *tg)
Replace the current iTimeGovernor with the specified one.
DynamicsSystem(agx::Device *device)
Create a DynamicsSystem with a specific device.
bool add(agx::RigidBody *rigidBody)
Add a RigidBody to the system.
agx::RigidBodyPtrSetVector & getSleepingRigidBodies()
Constraint * getConstraint(const Name &name)
Find (linear search) the first Constraint object in the system that matches the name.
DynamicsSystem()
Default constructor.
Utility entrance to the task system, simplifying parallelization of algorithms.
The base class for interactions.
Definition: Interaction.h:32
Class which will go through contacting/separating bodies and determine if the bodies can be merged (g...
Definition: MergeSplit.h:38
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:41
Representation of a name string.
Definition: Name.h:33
agx::Object is a refcounted object with a name.
Definition: Object.h:60
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:44
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:38
TaskGroup.
Definition: Task.h:586
A representation of a generic task.
Definition: Task.h:58
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:75
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:42
#define AGX_DEPRECATED(since)
Definition: macros.h:89
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
This namespace consists of a set of classes for handling geometric intersection tests including boole...
agx::Vector< agx::Physics::GeometryPairPtr, agxData::BufferProxyAllocator > SeparationPairVector
Definition: Space.h:66
agx::VectorPOD< GeometryContact * > GeometryContactPtrVector
Contains classes for low level data storage for AGX.
Definition: Container.h:23
agx::ref_ptr< EntityStorage > EntityStorageRef
Definition: EntityStorage.h:62
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::SetVector< InteractionRef > StrongInteractionRefSetVector
agx::SetVector< ref_ptr< Constraint > > ConstraintRefSetVector
Definition: Constraint.h:55
double Real
Definition: Real.h:42
agx::SetVector< InteractionRef > InteractionRefSetVector
agx::SetVector< RigidBody * > RigidBodyPtrSetVector
void AGXPHYSICS_EXPORT init()
Initialize agx.
UInt32 Index
Definition: Integer.h:52