AGX Dynamics  2.37.2.0
Simulation.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/config/AGX_USE_WEBSOCKETS.h>
20 #include <agxSDK/agxSDK.h>
21 #include <agxSDK/SimulationProxy.h>
23 #include <agxSDK/EventManager.h>
24 #include <agxSDK/MaterialManager.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 
49 namespace agx
50 {
51  class Interaction;
52  class ParticleSystem;
53  class RigidBody;
54  class MergeSplit;
55  class MergedBody;
56  class ParticleEmitter;
57  class RigidBodyEmitter;
58  class Journal;
59  class RemoteSolver;
60  class Solver;
61  class ObserverFrame;
62  class StabilityReport;
63 
64  class Hinge;
65  class Prismatic;
66  class DistanceJoint;
67  class LockJoint;
68  class BallJoint;
69  class PlaneJoint;
70  class AngularLockJoint;
71  class CylindricalJoint;
72  class UniversalJoint;
73  class PrismaticUniversalJoint;
74 }
75 
76 namespace agxCollide
77 {
78  class Geometry;
79 }
80 
81 namespace agxNet
82 {
83  class RemoteDebugClient;
84 }
85 
86 namespace agxRender
87 {
88  class RenderManager;
89 }
90 
91 namespace agxWire
92 {
93  class Wire;
94 }
95 
96 namespace agxModel
97 {
98  class SurfaceVelocityConveyorBelt;
99 }
100 
101 namespace agxPlot
102 {
103  class System;
104  class DataSeries;
105 }
106 
107 namespace agxSDK
108 {
109  class SimulationFrameReader;
110  class SimulationFrameWriter;
111  class EventListener;
112  class SimulationFrameWriter;
113  class GuiEventAdapterImplementation;
114  class PickHandler;
115  class MergeSplitHandler;
116  class TerrainInstance;
118 
120 
127  {
128  public:
135 
136  GeometryEvent addGeometryEvent;
137  GeometryEvent removeGeometryEvent;
138 
139  RigidBodyEvent addRigidBodyEvent;
140  RigidBodyEvent removeRigidBodyEvent;
141 
142  ConstraintEvent addConstraintEvent;
143  ConstraintEvent removeConstraintEvent;
144 
145  MaterialEvent addMaterialEvent;
146  MaterialEvent removeMaterialEvent;
147 
148  ContactMaterialEvent addContactMaterialEvent;
149  ContactMaterialEvent removeContactMaterialEvent;
150 
151  JournalAttachEvent journalAttachedEvent;
152 
153  public:
158  static agxSDK::SimulationProxyRef createDefaultProxy( agxSDK::Simulation* simulation );
159 
160  public:
165  Simulation();
166 
172  bool add( agx::Material* material );
173 
178  bool add( agx::ContactMaterial* material );
179 
184  bool remove( agx::ContactMaterial* material );
185 
189  const agx::Material* getMaterial(const agx::Name& materialName) const;
190 
194  agx::Material* getMaterial(const agx::Name& materialName);
195 
199  agx::Material* getMaterial(const agx::Uuid& uuid);
200 
204  MaterialManager* getMaterialManager();
205 
209  const MaterialManager* getMaterialManager() const;
210 
215  bool remove( agx::Material* material );
216 
222  bool add( agxCollide::Geometry* geometry );
223 
233  bool remove( agxCollide::Geometry* geometry );
234 
242  bool add( agx::RigidBody* body, bool addGeometries = true );
243 
252  bool remove( agx::RigidBody* body, bool removeGeometries = true );
253 
259  bool add( agx::MergedBody* mergedBody );
260 
266  bool remove( agx::MergedBody* mergedBody );
267 
273  bool add( agx::Constraint* constraint );
274 
280  bool remove( agx::Constraint* constraint );
281 
287  bool add( agx::Interaction* interaction );
288 
294  bool remove( agx::Interaction* interaction );
295 
302  bool add( agxSDK::Assembly* assembly, bool addAllEntries = true );
303 
310  bool remove( agxSDK::Assembly* assembly, bool removeAllEntries = true );
311 
317  bool add( agx::Component* subComponent );
318 
324  bool remove( agx::Component* subComponent );
325 
331  bool add(agx::ObserverFrame* observerFrame);
332 
338  bool remove(agx::ObserverFrame* observerFrame);
339 
346  bool contains( const agx::Component* object ) const;
347 
353  bool add( agxControl::Action* action );
354 
360  bool remove( agxControl::Action* action );
361 
367  bool add( agxControl::Operation* operation );
368 
374  bool remove( agxControl::Operation* operation );
375 
381  bool add( agx::ParticleSystem* particleSystem );
382 
388  bool remove( agx::ParticleSystem* particleSystem);
389 
397  bool add( agx::Emitter* emitter, bool addGeometries=true);
398 
406  bool remove(agx::Emitter* emitter, bool removeGeometries=true);
407 
413  bool add( agx::ParticleContactSensor* sensor );
414 
420  bool remove( agx::ParticleContactSensor* sensor );
421 
425  agx::ParticleEmitterRefVector getParticleEmitters();
426 
430  agx::EmitterRefVector getEmitters();
431 
435  agx::ParticleSystemRefVector& getParticleSystems();
436 
440  const agx::ParticleSystemRefVector& getParticleSystems() const;
441 
445  agx::ParticleSystem* getParticleSystem() const;
446 
452  bool add( agxSDK::TerrainInstance* terrain );
453 
459  bool remove( agxSDK::TerrainInstance* terrain );
460 
468  bool setUniformGravity( const agx::Vec3& g );
469 
474  agx::Vec3 getUniformGravity() const;
475 
480  void setGravityField( agx::GravityField* gravityField );
481 
483  agx::GravityField* getGravityField();
484 
486  const agx::GravityField* getGravityField() const;
487 
493  void setMainWorkThread(agx::Thread* thread);
494 
500  agx::RigidBody* getRigidBody( const agx::Name& name );
501 
507  const agx::RigidBody* getRigidBody( const agx::Name& name ) const;
508 
514  agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) ;
515 
521  const agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) const;
522 
528  agx::MergedBody* getMergedBody(const agx::Name& name);
529 
535  const agx::MergedBody* getMergedBody(const agx::Name& name) const;
536 
542  agx::MergedBody* getMergedBody(const agx::Uuid& uuid);
543 
549  const agx::MergedBody* getMergedBody(const agx::Uuid& uuid) const;
550 
556  const agx::Constraint* getConstraint( const agx::Uuid& uuid ) const;
557 
563  agx::Constraint* getConstraint( const agx::Uuid& uuid );
564 
570  const agx::Constraint* getConstraint(const agx::Name& name) const;
571 
577  agx::Constraint* getConstraint(const agx::Name& name);
578 
584  const agxSDK::Assembly* getAssembly(const agx::Name& name) const;
585 
591  agxSDK::Assembly* getAssembly(const agx::Name& name);
592 
598  const agxSDK::Assembly* getAssembly(const agx::Uuid& uuid) const;
599 
605  agxSDK::Assembly* getAssembly(const agx::Uuid& uuid);
606 
612  const agx::Emitter* getEmitter(const agx::Uuid& uuid) const;
613 
619  agx::Emitter* getEmitter(const agx::Uuid& uuid);
620 
626  agx::Emitter* getEmitter(const agx::Name& name) const;
627 
633  agx::Emitter* getEmitter(const agx::Name& name);
634 
643  template < typename T >
644  T* getConstraint(const agx::Uuid& uuid);
645 
654  template < typename T >
655  const T* getConstraint(const agx::Uuid& uuid) const;
656 
665  template < typename T >
666  T* getConstraint( const agx::Name& name );
667 
676  template < typename T >
677  const T* getConstraint( const agx::Name& name ) const;
678 
679 #define GETCONSTRAINT_TYPE(CLASS_NAME, TYPENAME) \
680  CLASS_NAME *get ## TYPENAME(const agx::Name& name); \
681  CLASS_NAME *get ##TYPENAME(const agx::Uuid& uuid);
682 
683  GETCONSTRAINT_TYPE(agx::AngularLockJoint, AngularLockJoint)
685  GETCONSTRAINT_TYPE(agx::CylindricalJoint, CylindricalJoint)
686  GETCONSTRAINT_TYPE(agx::DistanceJoint, DistanceJoint)
691  GETCONSTRAINT_TYPE(agx::PrismaticUniversalJoint, PrismaticUniversalJoint)
692  GETCONSTRAINT_TYPE(agx::UniversalJoint, UniversalJoint)
693 #undef GETCONSTRAINT_TYPE
694 
700  const agxCollide::Geometry* getGeometry(const agx::Name& name ) const;
701 
707  agxCollide::Geometry* getGeometry(const agx::Name& name );
708 
714  const agxCollide::Geometry* getGeometry( const agx::Uuid& uuid ) const;
715 
721  agxCollide::Geometry* getGeometry( const agx::Uuid& uuid );
722 
728  const agxSDK::EventListener* getEventListener(const agx::Name& name ) const;
729 
735  agxSDK::EventListener* getEventListener(const agx::Name& name );
736 
742  const agxSDK::EventListener* getEventListener(const agx::Uuid& uuid) const;
743 
749  agxSDK::EventListener* getEventListener(const agx::Uuid& uuid);
750 
751 
757  const agxWire::Wire* getWire(const agx::Name& name) const;
758 
764  agxWire::Wire* getWire(const agx::Name& name);
765 
771  const agxWire::Wire* getWire(const agx::Uuid& uuid) const;
772 
778  agxWire::Wire* getWire(const agx::Uuid& uuid);
779 
785  agx::ObserverFrame* getObserver(const agx::Name& name);
786 
792  const agx::ObserverFrame* getObserver(const agx::Name& name) const;
793 
799  agx::ObserverFrame* getObserver(const agx::Uuid& uuid);
800 
806  const agx::ObserverFrame* getObserver(const agx::Uuid& uuid) const;
807 
814  agx::TimeStamp stepTo( agx::TimeStamp t );
815 
817  agx::Real getTimeStep() const;
818 
824  bool setTimeStep( agx::Real timeStep );
825 
829  agx::Clock* getClock();
830 
834  const agx::Clock* getClock() const;
835 
839  agx::Journal* getJournal();
840 
844  const agx::Journal* getJournal() const;
845 
846  #if AGX_USE_WEBSOCKETS()
847 
850  agx::RemoteSolver* getRemoteSolver();
851 
855  const agx::RemoteSolver* getRemoteSolver() const;
856  #endif
857 
864  bool breakStepTo();
865 
869  agx::Real getTimeStamp() const;
870 
875  void setTimeStamp( agx::TimeStamp t );
876 
881  void stepForward();
882 
886  agxCollide::Space* getSpace();
887 
891  const agxCollide::Space* getSpace() const;
892 
896  agx::DynamicsSystem* getDynamicsSystem();
897 
901  const agx::DynamicsSystem* getDynamicsSystem() const;
902 
906  agxPlot::System* getPlotSystem() const;
907 
911  void setPlotSystem(agxPlot::System* plotSystem);
912 
916  void setSpace( agxCollide::Space* space );
917 
921  void setDynamicsSystem( agx::DynamicsSystem* system );
922 
923 
929  bool removeEventListener( agxSDK::EventListener* listener );
930 
941  bool addEventListener( agxSDK::EventListener* listener, int priority = EventManager::DEFAULT_PRIORITY );
942 
953  bool add( agxSDK::EventListener* listener, int priority = EventManager::DEFAULT_PRIORITY );
954 
960  bool remove( agxSDK::EventListener* listener );
961 
966  bool triggerEvent( const GuiEvent& e );
967 
971  agxPlot::DataSeries* getTimeDataSeries() const;
972 
973 #ifdef SWIG
974  enum CleanupSelectionMask {
975  STEP_LISTENERS = 0x1,
976  CONTACT_LISTENERS = 0x2,
977  GUI_LISTENERS = 0x4,
978  LISTENERS = STEP_LISTENERS | CONTACT_LISTENERS | GUI_LISTENERS,
979  SYSTEM = 0x200,
980  SPACE = 0x400,
981  MATERIALS = 0x800,
982  ASSEMBLIES = 0x1000,
983  PARTICLE_SYSTEMS = 0x2000,
984  CONTACT_DATA = 0x4000,
985  CLEANUP_ALL = LISTENERS | SYSTEM | SPACE | MATERIALS | ASSEMBLIES | PARTICLE_SYSTEMS | CONTACT_DATA
986  };
987 #else
988 
993  STEP_LISTENERS = EventManager::STEP_LISTENERS,
994  CONTACT_LISTENERS = EventManager::CONTACT_LISTENERS,
995  GUI_LISTENERS = EventManager::GUI_LISTENERS,
996  LISTENERS = EventManager::LISTENERS,
997  SYSTEM = 0x200,
998  SPACE = 0x400,
999  MATERIALS = 0x800,
1000  ASSEMBLIES = 0x1000,
1001  PARTICLE_SYSTEMS = 0x2000,
1002  CONTACT_DATA = 0x4000,
1003  PLOTSYSTEM = 0x8000,
1004  CLEANUP_ALL = LISTENERS | SYSTEM | SPACE | MATERIALS | ASSEMBLIES | PARTICLE_SYSTEMS | CONTACT_DATA | PLOTSYSTEM
1005  };
1006 #endif
1007 
1013  READ_NONE = 0x0,
1014  READ_TIMESTEP = 0x1,
1015  READ_TIMESTAMP = 0x2,
1016  READ_GRAVITY = 0x4,
1017  READ_SOLVER = 0x8,
1018  READ_ALL = READ_TIMESTEP + READ_TIMESTAMP + READ_GRAVITY + READ_SOLVER,
1019  READ_DEFAULT = READ_TIMESTEP /* + READ_TIMESTAMP */ + READ_GRAVITY + READ_SOLVER // Not using READ_TIMESTAMP
1020  };
1021 
1029  void cleanup( agx::UInt selection = CLEANUP_ALL, bool fast=false );
1030 
1036  void setActionManagerTimeStamp(const agx::TimeStamp& time);
1037 
1041  agxControl::ActionManager* getActionManager();
1042 
1046  void clearContactData();
1047 
1051  agx::Solver* getSolver();
1052 
1056  const agx::Solver* getSolver() const;
1057 
1061  void setPreIntegratePositions( bool flag );
1062 
1066  bool getPreIntegratePositions() const;
1067 
1073  bool add( agxStream::Serializable* object );
1074 
1080  bool remove( agxStream::Serializable* object );
1081 
1082 
1087  agxSDK::PickHandler* getPickHandler();
1088 
1093  const agxSDK::PickHandler* getPickHandler() const;
1094 
1099  void setPickHandler( agxSDK::PickHandler* pickHandler );
1100 
1105  void setStatisticsPath( const agx::String& path );
1106 
1110  void setStatisticsInterval( agx::Real interval );
1111 
1117  void setEnableStatistics( bool enable );
1118 
1120  bool getEnableStatistics() const;
1121 
1123  void setEnableStatisticsRendering( bool enable );
1124 
1126  bool getEnableStatisticsRendering() const;
1127 
1131  void setProfilingFrequency(agx::Real frequency);
1132 
1136  agx::Real getProfilingFrequency() const;
1137 
1141  const AssemblyHash& getAssemblies() const;
1142 
1143 
1147  void getEventListeners( EventListenerPtrVector& eventListeners ) const;
1148 
1152  const agxCollide::GeometryRefVector& getGeometries() const;
1153 
1157  const agx::RigidBodyRefVector& getRigidBodies() const;
1158 
1162  agx::RigidBodyRefVector& getRigidBodies();
1163 
1164 
1168  const agx::ConstraintRefSetVector& getConstraints() const;
1169 
1173  agx::ConstraintRefSetVector& getConstraints();
1174 
1178  const agx::ObserverFrameRefSetVector& getObserverFrames() const;
1179 
1183  agx::ObserverFrameRefSetVector& getObserverFrames();
1184 
1188  agx::RigidBodyPtrSetVector& getEnabledRigidBodies();
1189 
1193  const agx::RigidBodyPtrSetVector& getEnabledRigidBodies() const;
1194 
1200  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid) const;
1201 
1207  agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid);
1208 
1213  agx::ObserverFrame* getObserverFrame(const agx::Name& name);
1214 
1219  const agx::ObserverFrame* getObserverFrame(const agx::Name& name) const;
1220 
1221 
1227  size_t write( const agx::String& filename ) const;
1228 
1235  size_t write( std::ostream& stream, bool binary ) const;
1236 
1243  size_t read( const agx::String& filename, agxSDK::Assembly* parent = nullptr, agx::UInt selection = READ_DEFAULT);
1244 
1253  size_t read( std::istream& stream, bool isBinary, agxSDK::Assembly* parent = nullptr, agx::UInt selection = READ_DEFAULT);
1254 
1260  bool restore(const agx::String& filename, agx::UInt selection = READ_DEFAULT);
1261  bool restore(std::istream& stream, bool isBinary, agx::UInt selection = READ_DEFAULT);
1262 
1263 
1271  bool addRestoreListener( agxStream::RestoreListener *listener );
1272 
1278  bool removeRestoreListener( agxStream::RestoreListener *listener );
1279 
1284  void store( agxStream::OutputArchive& archive ) const;
1285 
1293  void restore( agxStream::InputArchive& in, agxSDK::Assembly* parent = nullptr, agx::UInt selection = READ_DEFAULT, bool replaceUsingCache = false );
1294 
1302  void setEnableRemoteDebugging( bool flag, agx::Int16 port = -1, bool useCompression = false, bool waitForSynchronization = true );
1303 
1307  bool getEnableRemoteDebugging() const;
1308 
1313  void setRemoteDebuggingTimeStep( agx::Real timeStep );
1314 
1318  agx::Real getRemoteDebuggingTimeStep() const;
1319 
1328  void setContactReductionBinResolution( agx::UInt8 binResolution );
1329 
1333  agx::UInt8 getContactReductionBinResolution() const;
1334 
1340  void setContactReductionThreshold(agx::UInt threshold);
1341 
1345  agx::UInt getContactReductionThreshold() const;
1346 
1350  agx::MergeSplit* getMergeSplit();
1351 
1355  const agx::MergeSplit* getMergeSplit() const;
1356 
1362  agxSDK::MergeSplitHandler* getMergeSplitHandler() const;
1363 
1367  agxRender::RenderManager* getRenderManager();
1368 
1372  const agxRender::RenderManager* getRenderManager() const;
1373 
1377  void updateRenderManager();
1378 
1382  void updateStatisticsRenderData();
1383 
1393  void garbageCollect();
1394 
1398  bool add(agxSDK::SimulationParameter *parameter);
1399 
1403  bool remove(agxSDK::SimulationParameter *parameter);
1404 
1408  const agxSDK::SimulationParameterRefVector& getParameters() const;
1409 
1413  agxSDK::SimulationParameter *getParameter(const agx::Name& name);
1414 
1418  agxSDK::EnergyManager* getEnergyManager() const;
1419 
1420  public:
1421  // Internal, but public methods
1422 
1424  void sendSimulation();
1425 
1430  SimulationSerializer* getSerializer();
1431 
1436  const SimulationSerializer* getSerializer() const;
1437 
1441  void setSerializer( SimulationSerializer* serializer);
1442 
1443 
1449  void updateActionManager();
1450 
1457  agxSDK::SimulationProxy* getSimulationProxy() const;
1458 
1465  void commit( agxSDK::SimulationProxy* simulationProxy );
1466 
1472  void handleStabiltyReport( const agx::StabilityReport* stabilityReport );
1473 
1474  agx::TaskGroup* getUpdateTask();
1475 
1476  void renderComponents();
1477  void createRenderTask();
1478  agx::SolveModel* getSolveModel(const agx::Name& name);
1479 
1480  const agx::SolveModelRefVector& getSolveModels() const;
1481 
1482  #if AGX_USE_WEBSOCKETS()
1483  void setRemoteSolver(agx::RemoteSolver* remoteSolver);
1484  #endif
1485 
1487  Simulation( agx::Device* device );
1488 
1489  static Simulation* load(agx::TiXmlElement* eSimulation, agx::Device* device);
1490 
1492  static agx::Model* ClassModel();
1493 
1499  void setEnableSimulationStatisticsListener( bool flag );
1500 
1501  SimulationStatisticsListener* getSimulationStatisticsListener();
1502  const SimulationStatisticsListener* getSimulationStatisticsListener() const;
1503 
1504  void addSolveModel(agx::SolveModel* model);
1505  void removeSolveModel(agx::SolveModel* model);
1506  void loadSolveModels(const agx::String& path, bool clear = false);
1507 
1508  bool getUseComplexImpactStage() const;
1509  void setUseComplexImpactStage(bool flag);
1510 
1511  // For LUA only
1512  agx::Constraint1DOF* getConstraint1DOF(const agx::Name& name) { return this->getConstraint<agx::Constraint1DOF>(name); }
1513  agx::Constraint2DOF* getConstraint2DOF(const agx::Name& name) { return this->getConstraint<agx::Constraint2DOF>(name); }
1514 
1518  agx::UInt getNumMergedBodies() const;
1519 
1524  agx::MergedBody* getMergedBody( agx::UInt i ) const;
1525 
1529  agx::UInt getNumTerrains() const;
1530 
1535  agxSDK::TerrainInstance* getTerrain( agx::UInt i ) const;
1536 
1538  void resetTaskTimers();
1539 
1543  void dumpTaskTimers(const agx::String& filePath = "BufferAllocations.xml");
1544 
1548  void dumpMemoryUsage(const agx::String& filePath = "TaskTimers.xml");
1549 
1550 
1552  bool allowCreateParticles() const;
1553 
1554  agx::Component *getHeader();
1555  void readStoragePermutations(agxStream::InputArchive& in, bool clearStorages = false);
1556  void writeStoragePermutations(agxStream::OutputArchive& archive) const;
1557 
1558  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);
1559 
1560  agxData::EntityStorage* getEmitterStorage();
1561 
1562  protected:
1564  friend class GuiEventAdapterImplementation;
1565  friend class agx::DynamicsSystem;
1568 
1570  virtual ~Simulation();
1571 
1572  private:
1573  void addListener(EventListener *listener);
1574  void removeListener(EventListener *listener);
1575  bool hasListener(EventListener *listener);
1576 
1577  private:
1579  void init();
1580 
1582  void initConfiguration();
1583 
1585  void updateStatisticsEnable();
1586 
1587  void setEnableComputeAllConstraintForces(bool flag);
1588  bool getEnableComputeAllConstraintForces() const;
1589 
1591  void resetGraphStatistics();
1592 
1594  agx::Vec4 getSubsystemColor(agx::RigidBody* body);
1595 
1597  void setupStatisticsLogging();
1598 
1599  void updateConstraintForceData();
1600 
1601  void createUpdateTask();
1602 
1603  void generateContactMaterials();
1604  void preCollide();
1605  void prepareContacts();
1606  void triggerParticleContactSensors();
1607  void triggerPreStepEvents();
1608  void triggerPostStepEvents();
1609  void triggerLastStepEvents();
1610  void terrainPostUpdate();
1611  void stepSystem();
1612  void resetDirtyMaterials();
1613  void updateRemoteDebugger();
1614  void recordStatistics();
1615  void recordPlaybackStatistics();
1616  void recordParticleCount();
1617  void recordWarmStartingData();
1618  void printStatistics();
1619  void updateClock();
1620 
1621 
1622  void pruneContacts();
1623  void contactPointReduction();
1624  void updateSleepState();
1625  void triggerPreCollideStepEvent();
1626  void triggerSeparationContactEventListeners();
1627  void triggerContactEventListeners();
1628  void assignContactMaterials();
1629  void dumpThreadLogs(agx::Task *);
1630 
1631  void applyPreIntegrationSettings();
1632 
1633  private:
1634  friend class agx::Solver;
1635  void registerParticleSystemPointers();
1636  void unregisterParticleSystemPointers();
1637  void removeParticleSolverObjects( agx::ParticleSystem* particleSystem );
1638 
1639  private:
1640 
1641  class StatisticsWriter;
1642 
1643  friend class agx::Journal;
1645  #if AGX_USE_WEBSOCKETS()
1646  friend class agx::RemoteSolver;
1647  #endif
1648 
1649  void setJournal(agx::Journal* journal);
1650  void setHasJournal(bool flag);
1651  void preStoreSynchronization();
1652 
1653  StatisticsEntries m_statisticsEntry;
1654  StatisticsWriter* m_statWriter;
1655 
1657 
1658  AssemblyHash m_assemblies;
1659 
1660  agxCollide::SpaceRef m_space;
1661  agx::DynamicsSystemRef m_system;
1662 
1663  agx::ref_ptr<agx::Referenced> m_plotSystem;
1664  agx::ref_ptr<agx::Referenced> m_timeDataSeries;
1665 
1666  agx::ComponentRef m_header;
1667  bool m_stepToStarted;
1668 
1669  EventManagerRef m_eventManager;
1670  MaterialManagerRef m_materialManager;
1671 
1672  agxControl::ActionManagerRef m_actionManager;
1673  agx::TaskRef m_actionManagerTask;
1674 
1675  agx::observer_ptr< Referenced > m_pickHandler;
1676 
1677  SimulationSerializerRef m_serializationListener;
1678 
1679  agx::ParticleSystemRefVector m_particleSystems;
1680  agx::TaskGroupRef m_updateEmitters;
1681  agxData::EntityStorageRef m_emitterStorage;
1682 
1683  agx::ref_ptr<agx::Referenced> m_controlledServer;
1684  agx::ref_ptr<agx::Referenced> m_debugServer;
1685  agx::UInt8 m_contactReductionBinResolution;
1686  agx::UInt m_contactReductionThreshold;
1687  agx::ComponentRefVector m_subComponents;
1688  agx::Real m_remoteDebuggerTimeStep;
1689  agx::TimeStamp m_remoteDebuggerTimeStamp;
1690  agx::TaskGroupRef m_updateTask;
1691  agx::TaskRefVector m_preIntegrateTasks;
1692  bool m_preIntegrate;
1693  bool m_fastCleanup;
1694  bool m_allowCreateParticles;
1695 
1696  agx::Timer m_stepTimer;
1697  agx::Timer m_updateRenderManagerTimer;
1698  agx::ClockRef m_clock;
1699  agx::TaskRef m_renderTask;
1700  agx::GravityFieldRef m_gravityField;
1701 
1702  agx::SolveModelTable m_solveModelTable;
1703  agx::SolveModelRefVector m_solveModels;
1704 
1705  agx::ref_ptr<agx::Referenced> m_renderManager;
1706  agx::Thread* m_mainWorkThread;
1707  agxData::FrameRef m_journalLastWrittenFrame;
1708  agx::UInt32 m_journalAgxArchiveIdCounter;
1709 
1710  void* m_journal;
1711  bool m_hasJournal;
1712  void* m_remoteSolver;
1713 
1714  agxData::EntityStorageRef m_constraintForcesStorage;
1715  bool m_enableComputeAllConstraintForces;
1716  bool m_inDestructor;
1717  SimulationProxyRef m_simulationProxy;
1718  agx::ParticleContactSensorRefVector m_particleContactSensors;
1719 
1721  ParticleContactSensorTable m_particleContactSensorTable;
1722 
1724  RestoreListenerHash m_restoreListeners;
1725  agxSDK::SimulationStatisticsListenerRef m_simulationStatisticsListener;
1726  agx::Real m_profilingFrequency;
1727  agxData::ValueRefT<bool> m_useComplexImpactStage;
1728 
1730  StabilityReportContainer m_stabilityReports;
1731 
1734  MergedBodiesContainer m_mergedBodies;
1735 
1737  MergeSplitHandlerPointer m_mergeSplitHandler;
1738 
1741  LinkedStructureContainer m_linkedStructures;
1742 
1745  TerrainInstanceContainer m_terrains;
1746 
1747  bool m_disableGeometryAutoAdd;
1748  agxSDK::SimulationParameterRefVector m_simulationParameters;
1749 
1750 
1751  agx::RangeJobVector m_postSolveConstraintForceJobs;
1752  agx::ParallelTaskRef m_postSolveConstraintForceTask;
1753 
1754  agx::ref_ptr<agx::Referenced> m_energyManager;
1755  };
1756 
1757  /* Implementation */
1758  AGX_FORCE_INLINE agx::Real Simulation::getTimeStamp() const
1759  {
1760  return m_clock->getTime();
1761  }
1762 
1763  AGX_FORCE_INLINE agxCollide::Space* Simulation::getSpace()
1764  {
1765  return m_space.get();
1766  }
1767 
1768  AGX_FORCE_INLINE const agxCollide::Space* Simulation::getSpace() const
1769  {
1770  return m_space.get();
1771  }
1772 
1773  AGX_FORCE_INLINE const agx::DynamicsSystem* Simulation::getDynamicsSystem() const
1774  {
1775  return m_system.get();
1776  }
1777 
1778  AGX_FORCE_INLINE agx::DynamicsSystem* Simulation::getDynamicsSystem()
1779  {
1780  return m_system.get();
1781  }
1782 
1783  AGX_FORCE_INLINE agx::Real Simulation::getTimeStep() const
1784  {
1785  if (m_system) return m_system->getTimeGovernor()->getTimeStep();
1786  else return 0;
1787  }
1788 
1789  AGX_FORCE_INLINE agx::Clock* Simulation::getClock()
1790  {
1791  return m_clock;
1792  }
1793 
1794  AGX_FORCE_INLINE const agx::Clock* Simulation::getClock() const
1795  {
1796  return m_clock;
1797  }
1798 
1799  AGX_FORCE_INLINE bool Simulation::allowCreateParticles() const
1800  {
1801  return m_allowCreateParticles;
1802  }
1803 
1804  AGX_FORCE_INLINE const agx::SolveModelRefVector& Simulation::getSolveModels() const
1805  {
1806  return m_solveModels;
1807  }
1808 
1809  template< typename T >
1810  T* Simulation::getConstraint( const agx::Uuid& uuid )
1811  {
1812  return dynamic_cast< T* >( this->getConstraint( uuid ) );
1813  }
1814 
1815  template< typename T >
1816  const T* Simulation::getConstraint( const agx::Uuid& uuid ) const
1817  {
1818  return dynamic_cast< const T* >( this->getConstraint( uuid ) );
1819  }
1820 
1821  template< typename T >
1822  T* Simulation::getConstraint( const agx::Name& name )
1823  {
1824  return dynamic_cast< T* >( this->getConstraint( name ) );
1825  }
1826 
1827  template< typename T >
1828  const T* Simulation::getConstraint( const agx::Name& name ) const
1829  {
1830  return dynamic_cast< const T* >( this->getConstraint( name ) );
1831  }
1832 } // namespace agxSDK
1833 
1834 #ifdef _MSC_VER
1835 # pragma warning(pop) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow). Restored.
1836 #endif
agxTerrain::Terrain instance in a simulation, receiving step and contact callbacks in a controllable ...
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
This class is for detecting and handling particle collisions with geometries in the simulation...
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:515
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition: MacUtil.h:22
agx::Event2< Simulation *, agx::RigidBody * > RigidBodyEvent
Definition: Simulation.h:130
MaterialEvent removeMaterialEvent
Definition: Simulation.h:146
AGXTERRAIN_EXPORT void clear()
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
agx::Event2< Simulation *, agx::Constraint * > ConstraintEvent
Definition: Simulation.h:131
bool AGXPHYSICS_EXPORT read(const std::string &filename, agxStream::SerializablePtrVector &readObjects)
Open and read serializable objects from a file on disk with previously stored objects.
agx::Thread is a representation of an OS specific implementation of a computational thread...
Definition: Thread.h:198
agx::Constraint2DOF * getConstraint2DOF(const agx::Name &name)
Definition: Simulation.h:1513
RigidBodyEvent removeRigidBodyEvent
Definition: Simulation.h:140
agx::Event2< Simulation *, agxCollide::Geometry * > GeometryEvent
Definition: Simulation.h:129
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
Base class for a merge split algorithm handling a set of merged bodies.
Namespace contains functionality related to plotting.
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
This namespace consists of a set of classes for handling geometric intersection tests including boole...
This joint will preserve the initial distance between a body and a point in world coordinate or betwe...
Definition: DistanceJoint.h:27
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
MaterialEvent addMaterialEvent
Definition: Simulation.h:145
agx::Event2< Simulation *, agx::Material * > MaterialEvent
Definition: Simulation.h:132
Specialization for constraints that have two degree of freedom such as Cylindrical.
Definition: Constraint.h:761
uint8_t UInt8
Definition: Integer.h:38
Keeps track of the energy flow in the system.
#define AGXPHYSICS_EXPORT
agx::ref_ptr< Frame > FrameRef
Definition: Frame.h:52
The base class for a constraint.
Definition: Constraint.h:88
Class for receiving serialized agxSDK::Simulation:s from remote host.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:673
Namespace containing classes for handling debug rendering of collision geometries, constraints, contacts and rigid bodies.
Definition: Constraint.h:35
A representation of a generic task.
Definition: Task.h:57
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:59
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:74
agx::Real TimeStamp
Definition: TimeStamp.h:26
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc...
A Prismatic Universal Joint has two translational dof&#39;s constrained.
Spawns new bodys inside a given volume.
Definition: Emitter.h:44
This class will collect statistics and sizes of a simulation.
class for serializing a simulation into a series for files on disk <filename>_0001.agx etc.
RigidBodyEvent addRigidBodyEvent
Definition: Simulation.h:139
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:36
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
The base class for interactions.
Definition: Interaction.h:31
Structure holding several "normal" rigid bodies.
Definition: MergedBody.h:55
Templated vector class.
Definition: Vector.h:52
agx::HashVector< agxSDK::Assembly *, agxSDK::AssemblyRef > AssemblyHash
Definition: Simulation.h:117
Constraint that removes all 6 DOF between two bodies, or one body and the world.
Definition: LockJoint.h:28
A basic particle system that contains all the storages and buffers required for basic operation and a...
Class which will go through contacting/separating bodies and determine if the bodies can be merged (g...
Definition: MergeSplit.h:37
Interface and placeholder of controllers/helpers for wires.
Definition: Wire.h:61
uint32_t UInt
Definition: Integer.h:34
Constraint that removes the three translation DOF between two bodies (or one and the world)...
Definition: BallJoint.h:47
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:81
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
TaskGroup.
Definition: Task.h:585
A Universal Joint has one fixed relative point, the 3 translational dof&#39;s, and one constrained axis (...
GeometryEvent removeGeometryEvent
Definition: Simulation.h:137
bool AGXPHYSICS_EXPORT write(const std::string &filename, const agxStream::Serializable *data)
Write a Serializable object to a file.
JournalAttachEvent journalAttachedEvent
Definition: Simulation.h:151
ReadSelectionMask
Enum for specifying some additional, part of a simulation that can be restored from a serialization...
Definition: Simulation.h:1012
agx::Event2< Simulation *, agx::ContactMaterial * > ContactMaterialEvent
Definition: Simulation.h:133
CleanupSelectionMask
Specification of what should be cleaned up from a simulation during a call to the cleanup() method...
Definition: Simulation.h:992
ContactMaterialEvent removeContactMaterialEvent
Definition: Simulation.h:149
The hinge constraint between two rigid bodies or one rigid body and the world.
Definition: Hinge.h:103
Constraint that removes 3 DOF (rotational degrees of freedom) between two bodies, or one body and the...
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:54
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:375
ContactMaterialEvent addContactMaterialEvent
Definition: Simulation.h:148
A cylindrical joint is similar to a prismatic joint but with an extra degree of freedom free (rotatio...
#define CALLABLE
Definition: Object.h:73
agx::Constraint1DOF * getConstraint1DOF(const agx::Name &name)
Definition: Simulation.h:1512
The complete physical system with bodies, interactions, data layout, time stepper, and solver.
GeometryEvent addGeometryEvent
Definition: Simulation.h:136
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
agx::HashTable< agxCollide::Geometry *, agx::ref_ptr< Geometry > > GeometryTable
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:41
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...
Definition: Serializable.h:44
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
An EventListener can be associated to a Simulation and triggered upon various events.
Definition: EventListener.h:40
Simulation unique manager that handles logics around and parameters in contact materials given two ag...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
The class GravityField is responsible for calculating and applying a gravity force on a set of bodies...
Definition: GravityField.h:38
Clock class keeps representation of virtual/simulated time.
Definition: Clock.h:37
ConstraintEvent removeConstraintEvent
Definition: Simulation.h:143
int16_t Int16
Definition: Integer.h:44
ConstraintEvent addConstraintEvent
Definition: Simulation.h:142
Interface class used by internal objects running in parallel.
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
An agx::Device is an abstract representation of a device on which data can be stored and processed...
Definition: Device.h:57
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
#define GETCONSTRAINT_TYPE(CLASS_NAME, TYPENAME)
Definition: Simulation.h:679
uint32_t UInt32
Definition: Integer.h:40
agx::Event2< Simulation *, agx::Journal * > JournalAttachEvent
Definition: Simulation.h:134
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints, geometries.
Definition: Assembly.h:66
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:43