AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Simulation.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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
19#include <agx/config/AGX_USE_WEBSOCKETS.h>
20#include <agxSDK/agxSDK.h>
23#include <agxSDK/EventManager.h>
25#include <agxSDK/Assembly.h>
28
29#include <agx/DynamicsSystem.h>
30#include <agx/TimeStamp.h>
31#include <agx/HashTable.h>
32#include <agx/Component.h>
33#include <agx/GravityField.h>
34#include <agx/Clock.h>
36#include <agxData/Frame.h>
37
39
40#include <agxCollide/Space.h>
41
43
44#ifdef _MSC_VER
45# pragma warning(push)
46# pragma warning( disable : 4290 ) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
47#endif
48
49namespace agx
50{
51 class Interaction;
52 class ParticleSystem;
53 class RigidBody;
54 class MergedBody;
55 class ParticleEmitter;
56 class RigidBodyEmitter;
57 class Journal;
58 class RemoteSolver;
59 class Solver;
60 class ObserverFrame;
61 class StabilityReport;
62
63 class Hinge;
64 class Prismatic;
65 class DistanceJoint;
66 class LockJoint;
67 class BallJoint;
68 class PlaneJoint;
69 class AngularLockJoint;
70 class CylindricalJoint;
71 class UniversalJoint;
72 class PrismaticUniversalJoint;
73}
74
75namespace agxCollide
76{
77 class Geometry;
78}
79
80namespace agxNet
81{
82 class RemoteDebugClient;
83}
84
85namespace agxRender
86{
87 class RenderManager;
88}
89
90namespace agxWire
91{
92 class Wire;
93}
94
95namespace agxModel
96{
97 class SurfaceVelocityConveyorBelt;
98}
99
100namespace agxPlot
101{
102 class System;
103 class DataSeries;
104}
105
106namespace agxSDK
107{
108 class SimulationFrameReader;
109 class SimulationFrameWriter;
110 class EventListener;
111 class SimulationFrameWriter;
112 class GuiEventAdapterImplementation;
113 class PickHandler;
114 class MergeSplitHandler;
115 class TerrainInstance;
116 class EnergyManager;
117
119
126 {
127 public:
134
137
140
143
146
149
151
152 public:
158
159 public:
165
171 bool add( agx::Material* material );
172
177 bool add( agx::ContactMaterial* material );
178
183 bool remove( agx::ContactMaterial* material );
184
188 const agx::Material* getMaterial(const agx::Name& materialName) const;
189
193 agx::Material* getMaterial(const agx::Name& materialName);
194
199
204
209
214 bool remove( agx::Material* material );
215
221 bool add( agxCollide::Geometry* geometry );
222
232 bool remove( agxCollide::Geometry* geometry );
233
241 bool add( agx::RigidBody* body, bool addGeometries = true );
242
251 bool remove( agx::RigidBody* body, bool removeGeometries = true );
252
258 bool add( agx::MergedBody* mergedBody );
259
265 bool remove( agx::MergedBody* mergedBody );
266
272 bool add( agx::Constraint* constraint );
273
279 bool remove( agx::Constraint* constraint );
280
286 bool add( agx::Interaction* interaction );
287
293 bool remove( agx::Interaction* interaction );
294
301 bool add( agxSDK::Assembly* assembly, bool addAllEntries = true );
302
309 bool remove( agxSDK::Assembly* assembly, bool removeAllEntries = true );
310
316 bool add( agx::Component* subComponent );
317
323 bool remove( agx::Component* subComponent );
324
330 bool add(agx::ObserverFrame* observerFrame);
331
337 bool remove(agx::ObserverFrame* observerFrame);
338
345 bool contains( const agx::Component* object ) const;
346
352 bool add( agxControl::Action* action );
353
359 bool remove( agxControl::Action* action );
360
366 bool add( agxControl::Operation* operation );
367
373 bool remove( agxControl::Operation* operation );
374
380 bool add( agx::ParticleSystem* particleSystem );
381
387 bool remove( agx::ParticleSystem* particleSystem);
388
396 bool add( agx::Emitter* emitter, bool addGeometries=true);
397
405 bool remove(agx::Emitter* emitter, bool removeGeometries=true);
406
413
420
425
430
435
440
445
451 bool add( agxSDK::TerrainInstance* terrain );
452
459
467 bool setUniformGravity( const agx::Vec3& g );
468
474
479 void setGravityField( agx::GravityField* gravityField );
480
483
486
493
500
506 const agx::RigidBody* getRigidBody( const agx::Name& name ) const;
507
514
520 const agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) const;
521
528
534 const agx::MergedBody* getMergedBody(const agx::Name& name) const;
535
542
548 const agx::MergedBody* getMergedBody(const agx::Uuid& uuid) const;
549
555 const agx::Constraint* getConstraint( const agx::Uuid& uuid ) const;
556
563
569 const agx::Constraint* getConstraint(const agx::Name& name) const;
570
577
583 const agxSDK::Assembly* getAssembly(const agx::Name& name) const;
584
591
597 const agxSDK::Assembly* getAssembly(const agx::Uuid& uuid) const;
598
605
611 const agx::Emitter* getEmitter(const agx::Uuid& uuid) const;
612
619
625 agx::Emitter* getEmitter(const agx::Name& name) const;
626
633
642 template < typename T >
643 T* getConstraint(const agx::Uuid& uuid);
644
653 template < typename T >
654 const T* getConstraint(const agx::Uuid& uuid) const;
655
664 template < typename T >
665 T* getConstraint( const agx::Name& name );
666
675 template < typename T >
676 const T* getConstraint( const agx::Name& name ) const;
677
678#define GETCONSTRAINT_TYPE(CLASS_NAME, TYPENAME) \
679 CLASS_NAME *get ## TYPENAME(const agx::Name& name); \
680 CLASS_NAME *get ##TYPENAME(const agx::Uuid& uuid);
681
690 GETCONSTRAINT_TYPE(agx::PrismaticUniversalJoint, PrismaticUniversalJoint)
692#undef GETCONSTRAINT_TYPE
693
699 const agxCollide::Geometry* getGeometry(const agx::Name& name ) const;
700
707
713 const agxCollide::Geometry* getGeometry( const agx::Uuid& uuid ) const;
714
721
728
735
742
749
750
756 const agxWire::Wire* getWire(const agx::Name& name) const;
757
764
770 const agxWire::Wire* getWire(const agx::Uuid& uuid) const;
771
778
785
791 const agx::ObserverFrame* getObserver(const agx::Name& name) const;
792
799
805 const agx::ObserverFrame* getObserver(const agx::Uuid& uuid) const;
806
814
816 agx::Real getTimeStep() const;
817
823 bool setTimeStep( agx::Real timeStep );
824
828 agx::Clock* getClock();
829
833 const agx::Clock* getClock() const;
834
839
843 const agx::Journal* getJournal() const;
844
845 #if AGX_USE_WEBSOCKETS()
849 agx::RemoteSolver* getRemoteSolver();
850
854 const agx::RemoteSolver* getRemoteSolver() const;
855 #endif
856
864
868 agx::Real getTimeStamp() const;
869
875
881
885 agxCollide::Space* getSpace();
886
890 const agxCollide::Space* getSpace() const;
891
895 agx::DynamicsSystem* getDynamicsSystem();
896
900 const agx::DynamicsSystem* getDynamicsSystem() const;
901
906
911
916
921
922
929
940 bool addEventListener( agxSDK::EventListener* listener, int priority = EventManager::DEFAULT_PRIORITY );
941
952 bool add( agxSDK::EventListener* listener, int priority = EventManager::DEFAULT_PRIORITY );
953
959 bool remove( agxSDK::EventListener* listener );
960
965 bool triggerEvent( const GuiEvent& e );
966
971
972#ifdef SWIG
974 STEP_LISTENERS = 0x1,
975 CONTACT_LISTENERS = 0x2,
976 GUI_LISTENERS = 0x4,
977 LISTENERS = STEP_LISTENERS | CONTACT_LISTENERS | GUI_LISTENERS,
978 SYSTEM = 0x200,
979 SPACE = 0x400,
980 MATERIALS = 0x800,
981 ASSEMBLIES = 0x1000,
982 PARTICLE_SYSTEMS = 0x2000,
983 CONTACT_DATA = 0x4000,
984 CLEANUP_ALL = LISTENERS | SYSTEM | SPACE | MATERIALS | ASSEMBLIES | PARTICLE_SYSTEMS | CONTACT_DATA
985 };
986#else
992 STEP_LISTENERS = EventManager::STEP_LISTENERS,
993 CONTACT_LISTENERS = EventManager::CONTACT_LISTENERS,
994 GUI_LISTENERS = EventManager::GUI_LISTENERS,
995 LISTENERS = EventManager::LISTENERS,
996 SYSTEM = 0x200,
997 SPACE = 0x400,
998 MATERIALS = 0x800,
999 ASSEMBLIES = 0x1000,
1000 PARTICLE_SYSTEMS = 0x2000,
1001 CONTACT_DATA = 0x4000,
1002 PLOTSYSTEM = 0x8000,
1003 CLEANUP_ALL = LISTENERS | SYSTEM | SPACE | MATERIALS | ASSEMBLIES | PARTICLE_SYSTEMS | CONTACT_DATA | PLOTSYSTEM
1005#endif
1006
1012 READ_NONE = 0x0,
1013 READ_TIMESTEP = 0x1,
1014 READ_TIMESTAMP = 0x2,
1015 READ_GRAVITY = 0x4,
1016 READ_SOLVER = 0x8,
1017 READ_ALL = READ_TIMESTEP + READ_TIMESTAMP + READ_GRAVITY + READ_SOLVER,
1018 READ_DEFAULT = READ_TIMESTEP /* + READ_TIMESTAMP */ + READ_GRAVITY + READ_SOLVER // Not using READ_TIMESTAMP
1020
1028 void cleanup( agx::UInt selection = CLEANUP_ALL, bool fast=false );
1029
1036
1040 agxControl::ActionManager* getActionManager();
1041
1046
1050 agx::Solver* getSolver();
1051
1055 const agx::Solver* getSolver() const;
1056
1060 void setPreIntegratePositions( bool flag );
1061
1066
1073
1080
1081
1087
1093
1099
1104 void setStatisticsPath( const agx::String& path );
1105
1110
1116 void setEnableStatistics( bool enable );
1117
1120
1122 void setEnableStatisticsRendering( bool enable );
1123
1126
1131
1136
1141
1142
1146 void getEventListeners( EventListenerPtrVector& eventListeners ) const;
1147
1152
1157
1162
1163
1168
1173
1178
1183
1188
1193
1200
1207
1213
1219
1220
1226 size_t write( const agx::String& filename ) const;
1227
1234 size_t write( std::ostream& stream, bool binary ) const;
1235
1242 size_t read( const agx::String& filename, agxSDK::Assembly* parent = nullptr, agx::UInt selection = READ_DEFAULT);
1243
1252 size_t read( std::istream& stream, bool isBinary, agxSDK::Assembly* parent = nullptr, agx::UInt selection = READ_DEFAULT);
1253
1259 bool restore(const agx::String& filename, agx::UInt selection = READ_DEFAULT);
1260 bool restore(std::istream& stream, bool isBinary, agx::UInt selection = READ_DEFAULT);
1261
1262
1271
1278
1283 void store( agxStream::OutputArchive& archive ) const;
1284
1292 void restore( agxStream::InputArchive& in, agxSDK::Assembly* parent = nullptr, agx::UInt selection = READ_DEFAULT, bool replaceUsingCache = false );
1293
1301 void setEnableRemoteDebugging( bool flag, agx::Int16 port = -1, bool useCompression = false, bool waitForSynchronization = true );
1302
1307
1313
1318
1328
1333
1340
1345
1352
1357
1362
1367
1372
1383
1388
1393
1398
1403
1408
1409 public:
1410 // Internal, but public methods
1411
1414
1420
1426
1431
1432
1439
1447
1454 void commit( agxSDK::SimulationProxy* simulationProxy );
1455
1461 void handleStabiltyReport( const agx::StabilityReport* stabilityReport );
1462
1464
1467 agx::SolveModel* getSolveModel(const agx::Name& name);
1468
1469 const agx::SolveModelRefVector& getSolveModels() const;
1470
1471 #if AGX_USE_WEBSOCKETS()
1472 void setRemoteSolver(agx::RemoteSolver* remoteSolver);
1473 #endif
1474
1477
1478 static Simulation* load(agx::TiXmlElement* eSimulation, agx::Device* device);
1479
1482
1489
1492
1493 void addSolveModel(agx::SolveModel* model);
1494 void removeSolveModel(agx::SolveModel* model);
1495 void loadSolveModels(const agx::String& path, bool clear = false);
1496
1497 // For LUA only
1498 agx::Constraint1DOF* getConstraint1DOF(const agx::Name& name) { return this->getConstraint<agx::Constraint1DOF>(name); }
1499 agx::Constraint2DOF* getConstraint2DOF(const agx::Name& name) { return this->getConstraint<agx::Constraint2DOF>(name); }
1500
1505
1511
1516
1522
1525
1529 void dumpTaskTimers(const agx::String& filePath = "BufferAllocations.xml");
1530
1534 void dumpMemoryUsage(const agx::String& filePath = "TaskTimers.xml");
1535
1536
1538 bool allowCreateParticles() const;
1539
1541 void readStoragePermutations(agxStream::InputArchive& in, bool clearStorages = false);
1543
1544 void writeStatisticsFiles(const agx::String& directoryPath = "Statistics", bool taskProfile = true, bool threadTimeline = true, const agx::Vector<agx::String>& timelineFormats = agx::Vector<agx::String>(), bool bufferAllocations = true);
1545
1547
1548 protected:
1550 friend class GuiEventAdapterImplementation;
1554
1556 virtual ~Simulation();
1557
1558 private:
1559 void addListener(EventListener *listener);
1560 void removeListener(EventListener *listener);
1561 bool hasListener(EventListener *listener);
1562
1563 private:
1565 void init();
1566
1568 void initConfiguration();
1569
1571 void updateStatisticsEnable();
1572
1573 void setEnableComputeAllConstraintForces(bool flag);
1574 bool getEnableComputeAllConstraintForces() const;
1575
1577 void resetGraphStatistics();
1578
1580 agx::Vec4 getSubsystemColor(agx::RigidBody* body);
1581
1583 void setupStatisticsLogging();
1584
1585 void updateConstraintForceData();
1586
1587 void createUpdateTask();
1588
1589 void generateContactMaterials();
1590 void preCollide();
1591 void prepareContacts();
1592 void triggerParticleContactSensors();
1593 void triggerPreStepEvents();
1594 void triggerPostStepEvents();
1595 void triggerLastStepEvents();
1596 void terrainPostUpdate();
1597 void stepSystem();
1598 void resetDirtyMaterials();
1599 void updateRemoteDebugger();
1600 void recordStatistics();
1601 void recordPlaybackStatistics();
1602 void recordParticleCount();
1603 void recordWarmStartingData();
1604 void printStatistics();
1605 void updateClock();
1606
1607
1608 void pruneContacts();
1609 void contactPointReduction();
1610 void updateSleepState();
1611 void triggerPreCollideStepEvent();
1612 void triggerSeparationContactEventListeners();
1613 void triggerContactEventListeners();
1614 void assignContactMaterials();
1615 void dumpThreadLogs(agx::Task *);
1616
1617 void applyPreIntegrationSettings();
1618
1619 private:
1620 friend class agx::Solver;
1621 void registerParticleSystemPointers();
1622 void unregisterParticleSystemPointers();
1623 void removeParticleSolverObjects( agx::ParticleSystem* particleSystem );
1624
1625 private:
1626
1627 class StatisticsWriter;
1628
1629 friend class agx::Journal;
1631 #if AGX_USE_WEBSOCKETS()
1632 friend class agx::RemoteSolver;
1633 #endif
1634
1635 void setJournal(agx::Journal* journal);
1636 void setHasJournal(bool flag);
1637 void preStoreSynchronization();
1638
1639 StatisticsEntries m_statisticsEntry;
1640 StatisticsWriter* m_statWriter;
1641
1643
1644 AssemblyHash m_assemblies;
1645
1646 agxCollide::SpaceRef m_space;
1647 agx::DynamicsSystemRef m_system;
1648
1649 agx::ref_ptr<agx::Referenced> m_plotSystem;
1650 agx::ref_ptr<agx::Referenced> m_timeDataSeries;
1651
1652 agx::ComponentRef m_header;
1653 bool m_stepToStarted;
1654
1655 EventManagerRef m_eventManager;
1656 MaterialManagerRef m_materialManager;
1657
1658 agxControl::ActionManagerRef m_actionManager;
1659 agx::TaskRef m_actionManagerTask;
1660
1661 agx::observer_ptr< Referenced > m_pickHandler;
1662
1663 SimulationSerializerRef m_serializationListener;
1664
1665 agx::ParticleSystemRefVector m_particleSystems;
1666 agx::TaskGroupRef m_updateEmitters;
1667 agxData::EntityStorageRef m_emitterStorage;
1668
1669 agx::ref_ptr<agx::Referenced> m_controlledServer;
1670 agx::ref_ptr<agx::Referenced> m_debugServer;
1671 agx::UInt8 m_contactReductionBinResolution;
1672 agx::UInt m_contactReductionThreshold;
1673 agx::ComponentRefVector m_subComponents;
1674 agx::Real m_remoteDebuggerTimeStep;
1675 agx::TimeStamp m_remoteDebuggerTimeStamp;
1676 agx::TaskGroupRef m_updateTask;
1677 agx::TaskRefVector m_preIntegrateTasks;
1678 bool m_preIntegrate;
1679 bool m_fastCleanup;
1680 bool m_allowCreateParticles;
1681
1682 agx::Timer m_stepTimer;
1683 agx::Timer m_updateRenderManagerTimer;
1684 agx::ClockRef m_clock;
1685 agx::TaskRef m_renderTask;
1686 agx::GravityFieldRef m_gravityField;
1687
1688 agx::SolveModelTable m_solveModelTable;
1689 agx::SolveModelRefVector m_solveModels;
1690
1691 agx::ref_ptr<agx::Referenced> m_renderManager;
1692 agx::Thread* m_mainWorkThread;
1693 agxData::FrameRef m_journalLastWrittenFrame;
1694 agx::UInt32 m_journalAgxArchiveIdCounter;
1695
1696 void* m_journal;
1697 bool m_hasJournal;
1698 void* m_remoteSolver;
1699
1700 agxData::EntityStorageRef m_constraintForcesStorage;
1701 bool m_enableComputeAllConstraintForces;
1702 bool m_inDestructor;
1703 SimulationProxyRef m_simulationProxy;
1704 agx::ParticleContactSensorRefVector m_particleContactSensors;
1705
1707 ParticleContactSensorTable m_particleContactSensorTable;
1708
1710 RestoreListenerHash m_restoreListeners;
1711 agxSDK::SimulationStatisticsListenerRef m_simulationStatisticsListener;
1712 agx::Real m_profilingFrequency;
1713
1715 StabilityReportContainer m_stabilityReports;
1716
1719 MergedBodiesContainer m_mergedBodies;
1720
1722 MergeSplitHandlerPointer m_mergeSplitHandler;
1723
1726 LinkedStructureContainer m_linkedStructures;
1727
1730 TerrainInstanceContainer m_terrains;
1731
1732 bool m_disableGeometryAutoAdd;
1733 agxSDK::SimulationParameterRefVector m_simulationParameters;
1734
1735
1736 agx::RangeJobVector m_postSolveConstraintForceJobs;
1737 agx::ParallelTaskRef m_postSolveConstraintForceTask;
1738
1739 agx::ref_ptr<agx::Referenced> m_energyManager;
1740 };
1741
1742 /* Implementation */
1744 {
1745 return m_clock->getTime();
1746 }
1747
1749 {
1750 return m_space.get();
1751 }
1752
1754 {
1755 return m_space.get();
1756 }
1757
1759 {
1760 return m_system.get();
1761 }
1762
1767
1769 {
1770 if (m_system) return m_system->getTimeGovernor()->getTimeStep();
1771 else return 0;
1772 }
1773
1775 {
1776 return m_clock;
1777 }
1778
1780 {
1781 return m_clock;
1782 }
1783
1785 {
1786 return m_allowCreateParticles;
1787 }
1788
1789 AGX_FORCE_INLINE const agx::SolveModelRefVector& Simulation::getSolveModels() const
1790 {
1791 return m_solveModels;
1792 }
1793
1794 template< typename T >
1796 {
1797 return dynamic_cast< T* >( this->getConstraint( uuid ) );
1798 }
1799
1800 template< typename T >
1801 const T* Simulation::getConstraint( const agx::Uuid& uuid ) const
1802 {
1803 return dynamic_cast< const T* >( this->getConstraint( uuid ) );
1804 }
1805
1806 template< typename T >
1808 {
1809 return dynamic_cast< T* >( this->getConstraint( name ) );
1810 }
1811
1812 template< typename T >
1813 const T* Simulation::getConstraint( const agx::Name& name ) const
1814 {
1815 return dynamic_cast< const T* >( this->getConstraint( name ) );
1816 }
1817} // namespace agxSDK
1818
1819#ifdef _MSC_VER
1820# pragma warning(pop) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow). Restored.
1821#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define GETCONSTRAINT_TYPE(CLASS_NAME, TYPENAME)
Definition Simulation.h:678
#define AGXPHYSICS_EXPORT
The geometry representation used by the collision detection engine.
Definition Geometry.h:92
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition Space.h:82
Data storage for a collection of entity instances of a specified EntityModel.
Class for receiving serialized agxSDK::Simulation:s from remote host.
Class that encapsulates data to be plotted, including methods for accessing the data,...
Definition DataSeries.h:45
System that manages the plotting system.
Definition System.h:39
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc.
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition Assembly.h:68
Keeps track of the energy flow in the system.
An EventListener can be associated to a Simulation and triggered upon various events.
Class for storing an Event which will be executed later inside Simulation.
Definition GuiEvent.h:28
Simulation unique manager that handles logics around and parameters in contact materials given two ag...
Base class for a merge split algorithm handling a set of merged bodies.
Interface class used by internal objects running in parallel.
class for serializing a simulation into a series for files on disk <filename>_0001....
This class will collect statistics and sizes of a simulation.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
void readStoragePermutations(agxStream::InputArchive &in, bool clearStorages=false)
agx::Constraint1DOF * getConstraint1DOF(const agx::Name &name)
agx::Journal * getJournal()
MaterialEvent addMaterialEvent
Definition Simulation.h:144
const agx::ObserverFrame * getObserverFrame(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a ObserverFrame with the given uuid.
bool add(agx::RigidBody *body, bool addGeometries=true)
agx::ObserverFrame * getObserver(const agx::Uuid &uuid)
Find (linear search) and return a pointer to a ObserverFrame with the given uuid.
const agx::RigidBody * getRigidBody(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a RigidBody with the given uuid.
bool addEventListener(agxSDK::EventListener *listener, int priority=EventManager::DEFAULT_PRIORITY)
Add an event listener The listener will get a call to its addNotification method if adding was succes...
bool remove(agx::MergedBody *mergedBody)
Removes the merged body from this simulation.
void loadSolveModels(const agx::String &path, bool clear=false)
agxSDK::EventListener * getEventListener(const agx::Name &name)
Find and return the first matching named event listener.
bool getEnableStatistics() const
bool add(agx::ParticleContactSensor *sensor)
Add a particle contact sensor to the Simulation.
bool contains(const agx::Component *object) const
Is the object contained in the simulation?
agxSDK::Assembly * getAssembly(const agx::Name &name)
Find (linear search) and return named Assembly.
const agx::Material * getMaterial(const agx::Name &materialName) const
agx::Event2< Simulation *, agxCollide::Geometry * > GeometryEvent
Definition Simulation.h:128
void setEnableSimulationStatisticsListener(bool flag)
Enable/disable the listener that collects all statistics data from the simulation.
const agxSDK::PickHandler * getPickHandler() const
bool remove(agxStream::Serializable *object)
Remove an object as a serializable object.
bool remove(agx::ContactMaterial *material)
Remove an explicit contact material from the set of existing ContactMaterials.
void setStatisticsPath(const agx::String &path)
Specify the path to a file where the statistics information will be written when enabled.
agxSDK::SimulationParameter * getParameter(const agx::Name &name)
agx::Constraint * getConstraint(const agx::Uuid &uuid)
Find and return a pointer to a Constraint with the given uuid.
bool setTimeStep(agx::Real timeStep)
Sets the time step determined by the TimeGovernor in the DynamicsSystem.
agx::Constraint * getConstraint(const agx::Name &name)
Find (linear search) and return named Constraint.
bool add(agx::Material *material)
Add a material to the simulation.
agx::Clock * getClock()
agx::Emitter * getEmitter(const agx::Uuid &uuid)
Find (linear search) and return an emitter matching the given uuid.
const agx::ObserverFrame * getObserverFrame(const agx::Name &name) const
Find (linear search) the first ObserverFrame object in the system that matches the name.
void setPickHandler(agxSDK::PickHandler *pickHandler)
Assign interface for pick handler.
agx::ConstraintRefSetVector & getConstraints()
bool remove(agx::Interaction *interaction)
Remove an Interaction from the Simulation.
void updateActionManager()
Internal method.
const agxCollide::GeometryRefVector & getGeometries() const
agx::UInt getContactReductionThreshold() const
bool removeRestoreListener(agxStream::RestoreListener *listener)
Remove an existing listener in a simulation.
agxRender::RenderManager * getRenderManager()
const agx::RigidBody * getRigidBody(const agx::Name &name) const
Find (linear search) and return named RigidBody.
void setEnableStatisticsRendering(bool enable)
void sendSimulation()
Send the simulation to the remote debugger (if enabled)
bool remove(agxSDK::EventListener *listener)
Remove a Event listener.
agx::RigidBodyRefVector & getRigidBodies()
const agxSDK::SimulationParameterRefVector & getParameters() const
const MaterialManager * getMaterialManager() const
const agx::ConstraintRefSetVector & getConstraints() const
const AssemblyHash & getAssemblies() const
agx::ParticleSystem * getParticleSystem() const
bool remove(agx::Component *subComponent)
Remove a sub component from Simulation.
void setContactReductionBinResolution(agx::UInt8 binResolution)
Specify the bin resolution used when evaluating contacts for reduction between body-body contacts.
RigidBodyEvent addRigidBodyEvent
Definition Simulation.h:138
agx::Event2< Simulation *, agx::Constraint * > ConstraintEvent
Definition Simulation.h:130
bool add(agxControl::Operation *operation)
Register an operation to this simulation.
const agx::RigidBodyRefVector & getRigidBodies() const
void getEventListeners(EventListenerPtrVector &eventListeners) const
Get a vector containing all the registered event listeners.
agx::ParticleEmitterRefVector getParticleEmitters()
agx::ObserverFrame * getObserver(const agx::Name &name)
Find (linear search) and return named ObserverFrame.
void clearContactData()
Clears contact data in the simulation.
void addSolveModel(agx::SolveModel *model)
bool removeEventListener(agxSDK::EventListener *listener)
Remove the specified listener.
const SimulationSerializer * getSerializer() const
const agx::MergedBody * getMergedBody(const agx::Name &name) const
Find (linear search) and return named MergedBody.
bool add(agx::Constraint *constraint)
Add a constraint to the simulation.
agx::ObserverFrameRefSetVector & getObserverFrames()
const agx::ParticleSystemRefVector & getParticleSystems() const
agx::RigidBodyPtrSetVector & getEnabledRigidBodies()
bool add(agxSDK::TerrainInstance *terrain)
Add terrain (agxTerrain::Terrain) instance to this simulation.
JournalAttachEvent journalAttachedEvent
Definition Simulation.h:150
bool add(agx::ContactMaterial *material)
Add an explicit contact material to the simulation.
agxSDK::TerrainInstance * getTerrain(agx::UInt i) const
void stepForward()
Take one step forward in the simulation.
static Simulation * load(agx::TiXmlElement *eSimulation, agx::Device *device)
agx::Emitter * getEmitter(const agx::Name &name) const
Find (linear search) and return an emitter matching the given name.
bool restore(const agx::String &filename, agx::UInt selection=READ_DEFAULT)
Restore state from a serialized scene file.
bool add(agxSDK::EventListener *listener, int priority=EventManager::DEFAULT_PRIORITY)
Add an event listener The listener will get a call to its addNotification method if adding was succes...
size_t write(std::ostream &stream, bool binary) const
Serialize the simulation to the specified file.
bool add(agxSDK::SimulationParameter *parameter)
Add a parameter to the simulation configuration interface.
agx::SolveModel * getSolveModel(const agx::Name &name)
const agx::SolveModelRefVector & getSolveModels() const
void commit(agxSDK::SimulationProxy *simulationProxy)
Internal method.
ReadSelectionMask
Enum for specifying some additional, part of a simulation that can be restored from a serialization.
agxSDK::PickHandler * getPickHandler()
agxWire::Wire * getWire(const agx::Uuid &uuid)
Find (linear search) and return the first wire matching the uuid.
bool add(agx::ParticleSystem *particleSystem)
Add a particle system to the simulation.
bool remove(agx::RigidBody *body, bool removeGeometries=true)
Remove a body from the Simulation, the body will be disabled!
agx::ObserverFrame * getObserverFrame(const agx::Uuid &uuid)
Find and return a pointer to a ObserverFrame with the given uuid.
void store(agxStream::OutputArchive &archive) const
Save this simulation to the output archive.
bool remove(agxSDK::TerrainInstance *terrain)
Remove terrain (agxTerrain::Terrain) instance from this simulation.
const agx::ObserverFrameRefSetVector & getObserverFrames() const
Simulation()
Default constructor This constructor CAN Throw a std::runtime_exception if configuration file is brok...
agx::Material * getMaterial(const agx::Name &materialName)
size_t read(const agx::String &filename, agxSDK::Assembly *parent=nullptr, agx::UInt selection=READ_DEFAULT)
Read serialized simulation from the specified file and append to this simulation.
agxSDK::Assembly * getAssembly(const agx::Uuid &uuid)
Find (linear search) and return an Assembly matching the given uuid.
void setTimeStamp(agx::TimeStamp t)
Set the timestamp for the simulation (and the DynamicsSystem)
void setEnableRemoteDebugging(bool flag, agx::Int16 port=-1, bool useCompression=false, bool waitForSynchronization=true)
Enable/Disable remote debugging.
void setStatisticsInterval(agx::Real interval)
const agxRender::RenderManager * getRenderManager() const
agx::Event2< Simulation *, agx::Journal * > JournalAttachEvent
Definition Simulation.h:133
agx::EmitterRefVector getEmitters()
agxSDK::EnergyManager * getEnergyManager() const
return the energy manager of the system.
agx::UInt getNumTerrains() const
agx::Real getTimeStep() const
agx::Real getProfilingFrequency() const
agx::Real getRemoteDebuggingTimeStep() const
bool remove(agxSDK::SimulationParameter *parameter)
Remove a parameter from the simulation configuration interface.
const agx::Journal * getJournal() const
RigidBodyEvent removeRigidBodyEvent
Definition Simulation.h:139
MaterialManager * getMaterialManager()
void setPlotSystem(agxPlot::System *plotSystem)
Replace the current PlotSystem with plotSystem.
bool remove(agx::ObserverFrame *observerFrame)
Remove a ObserverFrame to the Simulation.
bool remove(agx::ParticleSystem *particleSystem)
Remove a particle system from the simulation.
void setActionManagerTimeStamp(const agx::TimeStamp &time)
Truncating an AGX simulation does not reset the timestamp in the action manager.
agxSDK::EventListener * getEventListener(const agx::Uuid &uuid)
Find (linear search) and return the first event listener matching the uuid.
bool add(agxCollide::Geometry *geometry)
bool restore(std::istream &stream, bool isBinary, agx::UInt selection=READ_DEFAULT)
void setGravityField(agx::GravityField *gravityField)
Set the GravityField model used in gravity calculations.
agx::Event2< Simulation *, agx::Material * > MaterialEvent
Definition Simulation.h:131
agx::MergedBody * getMergedBody(const agx::Uuid &uuid)
Find (linear search) and return a pointer to a MergedBody with the given uuid.
const agx::Constraint * getConstraint(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a Constraint with the given uuid.
void restore(agxStream::InputArchive &in, agxSDK::Assembly *parent=nullptr, agx::UInt selection=READ_DEFAULT, bool replaceUsingCache=false)
Read data from the input archive and add to the simulation.
void resetTaskTimers()
Reset profiling timers.
agxPlot::DataSeries * getTimeDataSeries() const
A data series that contains all time stamps of the simulation.
GeometryEvent addGeometryEvent
Definition Simulation.h:135
bool setUniformGravity(const agx::Vec3 &g)
Set the uniform gravity.
bool getEnableRemoteDebugging() const
size_t read(std::istream &stream, bool isBinary, agxSDK::Assembly *parent=nullptr, agx::UInt selection=READ_DEFAULT)
Read serialized simulation from the specified stream.
void dumpMemoryUsage(const agx::String &filePath="TaskTimers.xml")
Print current agxData buffer allocations to a file.
const agx::GravityField * getGravityField() const
const agxWire::Wire * getWire(const agx::Uuid &uuid) const
Find (linear search) and return the first wire matching the uuid.
agxControl::ActionManager * getActionManager()
Gets the action manager.
bool remove(agxControl::Action *action)
Remove an action from this simulation.
agx::Event2< Simulation *, agx::RigidBody * > RigidBodyEvent
Definition Simulation.h:129
agxCollide::Geometry * getGeometry(const agx::Uuid &uuid)
Find (linear search) and return a geometry matching the given uuid.
virtual ~Simulation()
Destructor.
void setSpace(agxCollide::Space *space)
Replace the current Collision space with space.
void removeSolveModel(agx::SolveModel *model)
agxPlot::System * getPlotSystem() const
agxCollide::Geometry * getGeometry(const agx::Name &name)
Find (linear search) and return named collision Geometry.
CleanupSelectionMask
Specification of what should be cleaned up from a simulation during a call to the cleanup() method.
Definition Simulation.h:991
bool remove(agx::ParticleContactSensor *sensor)
Remove a particle contact sensor from the system.
void writeStatisticsFiles(const agx::String &directoryPath="Statistics", bool taskProfile=true, bool threadTimeline=true, const agx::Vector< agx::String > &timelineFormats=agx::Vector< agx::String >(), bool bufferAllocations=true)
void cleanup(agx::UInt selection=CLEANUP_ALL, bool fast=false)
This method will remove/cleanup selected parts of the simulation.
const agxSDK::Assembly * getAssembly(const agx::Uuid &uuid) const
Find (linear search) and return an Assembly matching the given uuid.
agx::MergedBody * getMergedBody(agx::UInt i) const
ConstraintEvent removeConstraintEvent
Definition Simulation.h:142
agx::Component * getHeader()
agx::Solver * getSolver()
bool add(agx::MergedBody *mergedBody)
Add a merged body to this simulation.
const agx::ObserverFrame * getObserver(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a ObserverFrame with the given uuid.
void setPreIntegratePositions(bool flag)
Set true to integrate positions at the start of the timestep rather than at the end.
bool remove(agxCollide::Geometry *geometry)
Remove geometry from collision space.
const agxCollide::Geometry * getGeometry(const agx::Uuid &uuid) const
Find (linear search) and return a geometry matching the given uuid.
bool allowCreateParticles() const
const agx::ObserverFrame * getObserver(const agx::Name &name) const
Find (linear search) and return named ObserverFrame.
agx::Vec3 getUniformGravity() const
If the current gravity field is not a uniform one (for example PointGravityField),...
void handleStabiltyReport(const agx::StabilityReport *stabilityReport)
Internal method.
void setDynamicsSystem(agx::DynamicsSystem *system)
Replace the current DynamicsSystem with system.
static agx::Model * ClassModel()
Internal method.
agx::GravityField * getGravityField()
agx::Real getTimeStamp() const
bool add(agxControl::Action *action)
Register an action to this simulation.
void dumpTaskTimers(const agx::String &filePath="BufferAllocations.xml")
Print current task performance timers to a file.
void setMainWorkThread(agx::Thread *thread)
Specify which is the main working thread for the Simulation.
bool add(agx::ObserverFrame *observerFrame)
Add a ObserverFrame to the Simulation.
bool triggerEvent(const GuiEvent &e)
Execute a GuiEvent.
const agxSDK::EventListener * getEventListener(const agx::Name &name) const
Find and return the first matching named event listener.
bool getEnableStatisticsRendering() const
void updateStatisticsRenderData()
Make an explicit call to RenderManager::update() to update the statistics rendering information.
void garbageCollect()
Use with caution!
bool add(agx::Component *subComponent)
Add a sub component to the Simulation.
agx::Material * getMaterial(const agx::Uuid &uuid)
agxSDK::MergeSplitHandler * getMergeSplitHandler() const
Merge split handler is an object that enables performance boosts by merging rigid bodies together whi...
size_t write(const agx::String &filename) const
Serialize the simulation to the specified file.
agx::DynamicsSystem * getDynamicsSystem()
const agx::MergedBody * getMergedBody(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a MergedBody with the given uuid.
bool remove(agx::Emitter *emitter, bool removeGeometries=true)
Remove an emitter from the system.
Simulation(agx::Device *device)
Special constructor which will associate the Simulation to a specified device.
const agx::Solver * getSolver() const
agx::RigidBody * getRigidBody(const agx::Name &name)
Find (linear search) and return named RigidBody.
ContactMaterialEvent removeContactMaterialEvent
Definition Simulation.h:148
const agx::Constraint * getConstraint(const agx::Name &name) const
Find (linear search) and return named Constraint.
void setEnableStatistics(bool enable)
Enable/disable statistics logging to disk.
bool remove(agx::Constraint *constraint)
Remove a constraint from the simulation.
bool remove(agxSDK::Assembly *assembly, bool removeAllEntries=true)
Remove an assembly from the simulation.
const agxCollide::Geometry * getGeometry(const agx::Name &name) const
Find (linear search) and return named collision Geometry.
bool remove(agxControl::Operation *operation)
Remove an operation from this simulation.
agxCollide::Space * getSpace()
const agx::Emitter * getEmitter(const agx::Uuid &uuid) const
Find (linear search) and return an emitter matching the given uuid.
bool breakStepTo()
Break an initiated stepTo() after the current simulation step.
void setRemoteDebuggingTimeStep(agx::Real timeStep)
Sets the time step for remote debugging.
agx::ObserverFrame * getObserverFrame(const agx::Name &name)
Find (linear search) the first ObserverFrame object in the system that matches the name.
GeometryEvent removeGeometryEvent
Definition Simulation.h:136
SimulationStatisticsListener * getSimulationStatisticsListener()
agx::ParticleSystemRefVector & getParticleSystems()
bool add(agx::Interaction *interaction)
Add an Interaction to the Simulation.
void updateRenderManager()
Make an explicit call to RenderManager::update() to update the debug rendering information.
bool addRestoreListener(agxStream::RestoreListener *listener)
Add a restore listener to the Simulation.
const agxSDK::EventListener * getEventListener(const agx::Uuid &uuid) const
Find (linear search) and return the first event listener matching the uuid.
ConstraintEvent addConstraintEvent
Definition Simulation.h:141
void setContactReductionThreshold(agx::UInt threshold)
Specify the minimum number of contacts between two bodies required to execute contact reduction.
void setProfilingFrequency(agx::Real frequency)
Specify the frequency for performance profiling.
ContactMaterialEvent addContactMaterialEvent
Definition Simulation.h:147
void writeStoragePermutations(agxStream::OutputArchive &archive) const
const agxWire::Wire * getWire(const agx::Name &name) const
Find and return the first matching named wire.
bool getPreIntegratePositions() const
agx::TimeStamp stepTo(agx::TimeStamp t)
Step the simulation forward 1 or more time steps in time until we get to the time t.
agx::RigidBody * getRigidBody(const agx::Uuid &uuid)
Find (linear search) and return a pointer to a RigidBody with the given uuid.
agx::UInt getNumMergedBodies() const
agx::Constraint2DOF * getConstraint2DOF(const agx::Name &name)
agxWire::Wire * getWire(const agx::Name &name)
Find and return the first matching named wire.
MaterialEvent removeMaterialEvent
Definition Simulation.h:145
const agxSDK::Assembly * getAssembly(const agx::Name &name) const
Find (linear search) and return named Assembly.
bool remove(agx::Material *material)
Remove a specified material from the simulation.
bool add(agx::Emitter *emitter, bool addGeometries=true)
Add an emitter to the Simulation.
agxData::EntityStorage * getEmitterStorage()
bool add(agxStream::Serializable *object)
Add an object as a serializable object.
agx::UInt8 getContactReductionBinResolution() const
agx::Emitter * getEmitter(const agx::Name &name)
Find (linear search) and return an emitter matching the given name.
const agx::RigidBodyPtrSetVector & getEnabledRigidBodies() const
agx::TaskGroup * getUpdateTask()
agxSDK::SimulationProxy * getSimulationProxy() const
Internal method.
SimulationSerializer * getSerializer()
static agxSDK::SimulationProxyRef createDefaultProxy(agxSDK::Simulation *simulation)
Creates new simulation proxy of default type.
bool add(agxSDK::Assembly *assembly, bool addAllEntries=true)
Add an assembly to the simulation including all its parts.
agx::MergedBody * getMergedBody(const agx::Name &name)
Find (linear search) and return named MergedBody.
agx::Event2< Simulation *, agx::ContactMaterial * > ContactMaterialEvent
Definition Simulation.h:132
const SimulationStatisticsListener * getSimulationStatisticsListener() const
void setSerializer(SimulationSerializer *serializer)
Replace the current SimulationSerializer with a new instance.
agxTerrain::Terrain instance in a simulation, receiving step and contact callbacks in a controllable ...
Class for reading a binary stream of serialized data.
Class for writing serialized data in binary format to a stream.
Class for listening to the restore of Serializable objects.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Interface and placeholder of controllers/helpers for wires.
Definition Wire.h:62
Constraint that removes 3 DOF (rotational degrees of freedom) between two bodies, or one body and the...
Constraint that removes the three translation DOF between two bodies (or one and the world).
Definition BallJoint.h:48
Clock class keeps representation of virtual/simulated time.
Definition Clock.h:38
agx::Real getTime() const
A component is an object containing other objects, enabling hierarchical structuring.
Definition Component.h:39
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition Constraint.h:674
Specialization for constraints that have two degree of freedom such as Cylindrical.
Definition Constraint.h:762
The base class for a constraint.
Definition Constraint.h:89
This class store the combine material properties between two agx::Material's.
Definition Material.h:516
A cylindrical joint is similar to a prismatic joint but with an extra degree of freedom free (rotatio...
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition Device.h:58
This joint will preserve the initial distance between a body and a point in world coordinate or betwe...
The complete physical system with bodies, interactions, data layout, time stepper,...
Spawns new bodys inside a given volume.
Definition Emitter.h:45
An event with two arguments.
Definition Event.h:122
The class GravityField is responsible for calculating and applying a gravity force on a set of bodies...
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition HashVector.h:41
The hinge constraint between two rigid bodies or one rigid body and the world.
Definition Hinge.h:104
The base class for interactions.
Definition Interaction.h:32
Inheritance with partial specialization due to bug with ref_ptr containers.
Constraint that removes all 6 DOF between two bodies, or one body and the world.
Definition LockJoint.h:31
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition Material.h:376
Structure holding several "normal" rigid bodies.
Definition MergedBody.h:56
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
With this class you can attach an ObserverFrame object relative to a RigidBody.
This class is for detecting and handling particle collisions with geometries in the simulation.
A basic particle system that contains all the storages and buffers required for basic operation and a...
A Prismatic Universal Joint has two translational dof's constrained.
A prismatic joint keeps a fixed relative orientation between the attached bodies but allows them to s...
Definition Prismatic.h:67
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
TaskGroup.
Definition Task.h:586
A representation of a generic task.
Definition Task.h:58
agx::Thread is a representation of an OS specific implementation of a computational thread.
Definition Thread.h:199
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition Timer.h:75
A Universal Joint has one fixed relative point, the 3 translational dof's, and one constrained axis (...
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition Uuid.h:42
A class holding 4 dimensional vectors and providing basic arithmetic.
Templated vector class.
Definition agx/Vector.h:53
T * get() const
Definition ref_ptr.h:256
#define CALLABLE
Definition macros.h:72
#define AGX_FORCE_INLINE
Definition macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition FlowUnit.h:37
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition MacUtil.h:23
Namespace contains functionality related to plotting.
Namespace containing classes for handling debug rendering of collision geometries,...
Definition Constraint.h:36
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
agx::HashVector< agxSDK::Assembly *, agxSDK::AssemblyRef > AssemblyHash
Definition Simulation.h:118
Implements a Wire model with adaptive resolution.
Definition MergedBody.h:40
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition Integer.h:32
uint64_t UInt
Definition Integer.h:27
double Real
Definition Real.h:42
uint8_t UInt8
Definition Integer.h:30
agx::Real TimeStamp
Definition TimeStamp.h:26
int16_t Int16
Definition Integer.h:36