AGX Dynamics  2.38.0.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/Task.h>
30 #include <agx/Solver.h>
31 #include <agx/ObserverFrame.h>
32 
33 namespace agxCollide
34 {
35  class Space;
36 }
37 
38 namespace agxSDK
39 {
40  class Simulation;
41 }
42 
43 namespace agx
44 {
49 
50 
51  // forward declarations
53  class DynamicsSystem;
54  class IndexLambdaKernel;
55 
64  {
65  public:
66  static agx::Model* ClassModel();
67 
68  public:
71 
73  DynamicsSystem( agx::Device* device );
74 
79  bool add( agx::RigidBody* rigidBody );
80 
89  bool remove( agx::RigidBody* rigidBody );
90 
95  bool add( agx::ObserverFrame* observerFrame );
96 
102  bool remove( agx::ObserverFrame* observerFrame );
103 
108  bool add( agx::Interaction* interaction );
109 
114  bool remove( agx::Interaction* interaction );
115 
120  bool add( agx::Constraint* constraint );
121 
126  bool remove( agx::Constraint* constraint );
127 
132  RigidBody* getRigidBody( const Name& name );
133 
138  const RigidBody* getRigidBody(const Name& name) const;
139 
144  Constraint* getConstraint( const Name& name);
145 
150  const Constraint* getConstraint( const Name& name ) const;
151 
156  ObserverFrame* getObserverFrame(const Name& name);
157 
162  const ObserverFrame* getObserverFrame(const Name& name) const;
163 
169  agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) ;
170 
176  const agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) const;
177 
183  const agx::Constraint* getConstraint( const agx::Uuid& uuid ) const;
184 
190  agx::Constraint* getConstraint( const agx::Uuid& uuid );
191 
197  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid) const;
198 
204  agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid);
205 
210  void setTimeGovernor( agx::TimeGovernor* tg );
211 
215  agx::TimeGovernor* getTimeGovernor() ;
216 
220  const agx::TimeGovernor* getTimeGovernor() const;
221 
225  void setGeometryContacts( const agxCollide::GeometryContactPtrVector* contacts );
226 
230  const agxCollide::GeometryContactPtrVector* getGeometryContacts() const;
231 
232 
236  void stepForward();
237 
241  agx::Vec3 getLinearMomentum() const;
242 
246  agx::Vec3 getAngularMomentum() const;
247 
251  const agx::RigidBodyRefVector& getRigidBodies() const;
252 
256  agx::RigidBodyRefVector& getRigidBodies();
257 
261  const agx::ConstraintRefSetVector& getConstraints() const;
262 
266  agx::ConstraintRefSetVector& getConstraints();
267 
271  const ObserverFrameRefSetVector& getObserverFrames() const;
272 
276  ObserverFrameRefSetVector& getObserverFrames();
277 
281  agx::RigidBodyPtrSetVector& getEnabledRigidBodies();
282 
286  const agx::RigidBodyPtrSetVector& getEnabledRigidBodies() const;
287 
291  const agx::InteractionRefSetVector& getInteractions() const;
292 
296  const agx::StrongInteractionRefSetVector& getStrongInteractions() const;
297 
301  agx::Solver* getSolver();
302 
306  const agx::Solver* getSolver() const;
307 
308 
322  void enableSolverDataExtraction(const agx::String& filename, const agx::String& solverDataGroup);
323 
328  void disableSolverDataExtraction();
329 
333  bool getEnableSolverDataExtraction() const;
334 
335 
337 
338 
339  agxData::EntityStorage* getRigidBodyStorage();
340 
342  void _setGravityTask( agx::Task* task );
343 
345  agx::TaskGroup* getUpdateTask();
346 
353  agx::Index getInstanceId(const agx::Uuid& uuid) const;
354 
356 
357 
358 
373  void setEnableContactWarmstarting( bool enable );
374 
378  bool getEnableContactWarmstarting() const;
379 
384  agx::IndexLambdaKernel* getIndexLambdaKernel() const;
386 
387  protected:
388 
390  virtual ~DynamicsSystem();
391 
392  private:
393 
394  void updateFrames();
395 
396  void createUpdateTask();
397 
398  void setSimulation(agxSDK::Simulation* simulation);
399 
400  class SolveTask;
401  friend class RigidBody;
402  friend class agxSDK::Simulation;
403 
404  Task* createIntegratePositionsTask();
405  Task* createUpdateFramesTask();
406  Task* createSynchronizeGeometriesTask();
407  Task* createMergedBodyPostIntegrateTask();
408 
409  virtual void setContext(Object* context) override;
410  void updateGravity();
411  void init();
412  void commitRemovedBodies();
413  void reset();
414  void disableBody( RigidBody* body );
415  void enableBody( RigidBody* body );
416 
417  void updateInteractionForces();
418 
419  void startUpdateTimer(agx::Task* task);
420  void stopUpdateTimerAndReport(agx::Task* task);
421  void recordPlaybackStatistics();
422 
423  agxData::EntityStorageRef m_rigidBodyStorage;
424  TaskRef m_updateWorldMassAndInertiaTask;
425  TaskRef m_integratePositionsTask;
426  TaskRef m_gravityTask;
427 
428  private:
429  RigidBodyPtrSetVector m_enabledBodies;
430  RigidBodyRefSetVector m_removedBodies;
431 
432  RigidBodyRefVector m_rigidBodies;
433 
434  ConstraintRefSetVector m_constraints;
435  InteractionRefSetVector m_interactions;
436  StrongInteractionRefSetVector m_strongInteractions;
437 
438  ObserverFrameRefSetVector m_observerFrames;
439 
440  ref_ptr<TimeGovernor> m_timeGovernor;
441 
442  const agxCollide::GeometryContactPtrVector* m_geometryContacts;
443 
444  int m_garbageCollectionCounter;
445 
446  TaskGroupRef m_updateTask;
447  agxSDK::Simulation* m_simulation;
448  agx::Timer m_updateTimer;
449  agx::Task::ExecutionEvent::CallbackType m_startUpdateTimerCallback;
450  agx::Task::ExecutionEvent::CallbackType m_stopUpdateTimerAndReportCallback;
451 
452  SolverRef m_solver;
453  bool m_useSSE;
454 
455  LambdaKernelRef m_indexLambdaKernel;
456  };
457 
459 
460 
461  //-------------------------------------------------------------------------
462  // inline code
463 
465  {
466  return m_enabledBodies;
467  }
468 
470  {
471  return m_enabledBodies;
472  }
473 
475  {
476  m_geometryContacts = contacts;
477  }
478 
480  {
481  return m_geometryContacts;
482  }
483 
484  inline Solver* DynamicsSystem::getSolver() { return m_solver; }
485  inline const Solver* DynamicsSystem::getSolver() const { return m_solver; }
486 
487 
488 } //namespace agx
489 
agxPhysics_export.h
agx::Vector< RigidBodyRef >
agx::DynamicsSystem::getEnabledRigidBodies
agx::RigidBodyPtrSetVector & getEnabledRigidBodies()
Definition: DynamicsSystem.h:464
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
Task.h
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agx::DynamicsSystem::setGeometryContacts
void setGeometryContacts(const agxCollide::GeometryContactPtrVector *contacts)
Set the geometry contacts to resolve.
Definition: DynamicsSystem.h:474
Constraint.h
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agx::ConstraintImplementation
Definition: ConstraintImplementation.h:100
agxData::EntityStorage
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
agx::VectorPOD< GeometryContact * >
agx::RigidBodyPtrSetVector
agx::SetVector< RigidBody * > RigidBodyPtrSetVector
Definition: DynamicsSystem.h:48
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:41
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:125
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:46
agx::DynamicsSystem::getSolver
agx::Solver * getSolver()
Definition: DynamicsSystem.h:484
agx::Index
UInt32 Index
Definition: Integer.h:44
Component.h
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:58
agx::Component
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
agx::ConstraintRefSetVector
agx::SetVector< ref_ptr< Constraint > > ConstraintRefSetVector
Definition: Constraint.h:55
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:458
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 Dynamics API including thread resources and must be executed before using the AGX API.
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:63
agx::DynamicsSystem::getGeometryContacts
const agxCollide::GeometryContactPtrVector * getGeometryContacts() const
Get the geometry contacts to be resolved.
Definition: DynamicsSystem.h:479
agx::StrongInteractionRefSetVector
agx::SetVector< InteractionRef > StrongInteractionRefSetVector
Definition: DynamicsSystem.h:47