AGX Dynamics 2.41.3.0
Loading...
Searching...
No Matches
DynamicsSystem.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
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
33namespace agxCollide
34{
35 class Space;
36}
37
38namespace agxSDK
39{
40 class Simulation;
41}
42
43namespace agx
44{
49
50
51 // forward declarations
53 class DynamicsSystem;
55
64 {
65 public:
67
68 public:
71
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
145
150 const Constraint* getConstraint( const Name& name ) const;
151
157
162 const ObserverFrame* getObserverFrame(const Name& name) const;
163
170
176 const agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) const;
177
183 const agx::Constraint* getConstraint( const agx::Uuid& uuid ) const;
184
191
198
205
211
216
221
225 void setGeometryContacts( const agxCollide::GeometryContactPtrVector* contacts );
226
230 const agxCollide::GeometryContactPtrVector* getGeometryContacts() const;
231
232
237
242
247
252
257
262
267
272
277
281 agx::RigidBodyPtrSetVector& getEnabledRigidBodies();
282
286 const agx::RigidBodyPtrSetVector& getEnabledRigidBodies() const;
287
292
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
329
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
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
464 inline RigidBodyPtrSetVector& DynamicsSystem::getEnabledRigidBodies()
465 {
466 return m_enabledBodies;
467 }
468
469 inline const RigidBodyPtrSetVector& DynamicsSystem::getEnabledRigidBodies() const
470 {
471 return m_enabledBodies;
472 }
473
474 inline void DynamicsSystem::setGeometryContacts( const agxCollide::GeometryContactPtrVector* contacts )
475 {
476 m_geometryContacts = contacts;
477 }
478
479 inline const agxCollide::GeometryContactPtrVector* DynamicsSystem::getGeometryContacts() const
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
#define AGXPHYSICS_EXPORT
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,...
agx::ConstraintRefSetVector & getConstraints()
agx::RigidBodyRefVector & getRigidBodies()
const agx::StrongInteractionRefSetVector & getStrongInteractions() const
const agx::InteractionRefSetVector & getInteractions() const
void stepForward()
Step the Dynamics system forward using dt calculated from the current TimeGovernor.
const agx::RigidBodyRefVector & getRigidBodies() const
ObserverFrameRefSetVector & getObserverFrames()
const agx::RigidBody * getRigidBody(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a RigidBody with the given uuid.
static agx::Model * ClassModel()
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
agx::Constraint * getConstraint(const agx::Uuid &uuid)
Find and return a pointer to a Constraint with the given uuid.
agx::TimeGovernor * getTimeGovernor()
agx::Vec3 getAngularMomentum() const
Return the total angular momentum in the system.
RigidBody * getRigidBody(const Name &name)
Find (linear search) the first Physical in the system that matches the name.
Constraint * getConstraint(const Name &name)
Find (linear search) the first Constraint object in the system that matches the name.
const agx::ObserverFrame * getObserverFrame(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a ObserverFrame 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.
const ObserverFrameRefSetVector & getObserverFrames() const
agx::RigidBody * getRigidBody(const agx::Uuid &uuid)
Find (linear search) and return a pointer to a RigidBody with the given uuid.
void disableSolverDataExtraction()
Disable solver data extraction.
bool add(agx::Interaction *interaction)
Add an Interaction to the system.
void enableSolverDataExtraction(const agx::String &filename, const agx::String &solverDataGroup)
Enable solver data extraction.
const RigidBody * getRigidBody(const Name &name) const
Find (linear search) the first Physical in the system that matches the name.
bool add(agx::ObserverFrame *observerFrame)
Add a ObserverFrame to the system.
bool add(agx::Constraint *constraint)
Add a constraint from the simulation.
agx::ObserverFrame * getObserverFrame(const agx::Uuid &uuid)
Find and return a pointer to a ObserverFrame with the given uuid.
bool getEnableSolverDataExtraction() const
ObserverFrame * getObserverFrame(const Name &name)
Find (linear search) the first ObserverFrame object in the system that matches the name.
bool remove(agx::Constraint *constraint)
Remove a constraint from the simulation.
bool remove(agx::RigidBody *rigidBody)
Schedule a RigidBody for removal.
bool remove(agx::ObserverFrame *observerFrame)
Schedule a ObserverFrame for removal.
void setTimeGovernor(agx::TimeGovernor *tg)
Replace the current iTimeGovernor with the specified one.
const Constraint * getConstraint(const Name &name) const
Find (linear search) the first Constraint object in the system that matches the name.
DynamicsSystem(agx::Device *device)
Create a DynamicsSystem with a specific device.
bool add(agx::RigidBody *rigidBody)
Add a RigidBody to 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.
DynamicsSystem()
Default constructor.
const agx::ConstraintRefSetVector & getConstraints() const
Utility entrance to the task system, simplifying parallelization of algorithms.
The base class for interactions.
Definition: Interaction.h:33
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:59
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:42
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
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:62
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:42
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Contains classes for low level data storage for AGX.
Definition: Container.h:23
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
agx::SetVector< InteractionRef > InteractionRefSetVector
agx::SetVector< RigidBody * > RigidBodyPtrSetVector
UInt32 Index
Definition: Integer.h:44