AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Simulation.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 
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 
38 
39 #include <agxCollide/Space.h>
40 
41 #include <agxPlot/System.h>
42 
44 
45 #ifdef _MSC_VER
46 # pragma warning(push)
47 # pragma warning( disable : 4290 ) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
48 #endif
49 
50 namespace agx
51 {
52  class Interaction;
53  class ParticleSystem;
54  class RigidBody;
55  class MergeSplit;
56  class MergedBody;
57  class ParticleEmitter;
58  class RigidBodyEmitter;
59  class Journal;
60  class RemoteSolver;
61  class Solver;
62  class ObserverFrame;
63  class StabilityReport;
64 
65  class Hinge;
66  class Prismatic;
67  class DistanceJoint;
68  class LockJoint;
69  class BallJoint;
70  class PlaneJoint;
71  class AngularLockJoint;
72  class CylindricalJoint;
73  class UniversalJoint;
74  class PrismaticUniversalJoint;
75 }
76 
77 namespace agxCollide
78 {
79  class Geometry;
80 }
81 
82 namespace agxNet
83 {
84  class RemoteDebugClient;
85 }
86 
87 namespace agxRender
88 {
89  class RenderManager;
90 }
91 
92 namespace agxWire
93 {
94  class Wire;
95 }
96 
97 namespace agxModel
98 {
99  class SurfaceVelocityConveyorBelt;
100 }
101 
102 namespace agxSDK
103 {
104  class SimulationFrameReader;
105  class SimulationFrameWriter;
106  class EventListener;
107  class SimulationFrameWriter;
108  class GuiEventAdapterImplementation;
109  class PickHandler;
110  class MergeSplitHandler;
111  class TerrainInstance;
113 
115 
122  {
123  public:
130 
133 
136 
139 
142 
145 
147 
148  public:
153  static agxSDK::SimulationProxyRef createDefaultProxy( agxSDK::Simulation* simulation );
154 
155  public:
160  Simulation();
161 
167  bool add( agx::Material* material );
168 
173  bool add( agx::ContactMaterial* material );
174 
179  bool remove( agx::ContactMaterial* material );
180 
184  const agx::Material* getMaterial(const agx::Name& materialName) const;
185 
189  agx::Material* getMaterial(const agx::Name& materialName);
190 
194  agx::Material* getMaterial(const agx::Uuid& uuid);
195 
199  MaterialManager* getMaterialManager();
200 
204  const MaterialManager* getMaterialManager() const;
205 
210  bool remove( agx::Material* material );
211 
217  bool add( agxCollide::Geometry* geometry );
218 
228  bool remove( agxCollide::Geometry* geometry );
229 
237  bool add( agx::RigidBody* body, bool addGeometries = true );
238 
247  bool remove( agx::RigidBody* body, bool removeGeometries = true );
248 
254  bool add( agx::MergedBody* mergedBody );
255 
261  bool remove( agx::MergedBody* mergedBody );
262 
268  bool add( agx::Constraint* constraint );
269 
275  bool remove( agx::Constraint* constraint );
276 
282  bool add( agx::Interaction* interaction );
283 
289  bool remove( agx::Interaction* interaction );
290 
297  bool add( agxSDK::Assembly* assembly, bool addAllEntries = true );
298 
305  bool remove( agxSDK::Assembly* assembly, bool removeAllEntries = true );
306 
312  bool add( agx::Component* subComponent );
313 
319  bool remove( agx::Component* subComponent );
320 
326  bool add(agx::ObserverFrame* observerFrame);
327 
333  bool remove(agx::ObserverFrame* observerFrame);
334 
341  bool contains( const agx::Component* object ) const;
342 
348  bool add( agxControl::Action* action );
349 
355  bool remove( agxControl::Action* action );
356 
362  bool add( agxControl::Operation* operation );
363 
369  bool remove( agxControl::Operation* operation );
370 
376  bool add( agx::ParticleSystem* particleSystem );
377 
383  bool remove( agx::ParticleSystem* particleSystem);
384 
390  bool add( agx::Emitter* emitter );
391 
397  bool remove(agx::Emitter* emitter);
398 
404  bool add( agx::ParticleContactSensor* sensor );
405 
411  bool remove( agx::ParticleContactSensor* sensor );
412 
416  agx::ParticleEmitterRefVector getParticleEmitters();
417 
421  agx::EmitterRefVector getEmitters();
422 
426  agx::ParticleSystemRefVector& getParticleSystems();
427 
431  const agx::ParticleSystemRefVector& getParticleSystems() const;
432 
436  agx::ParticleSystem* getParticleSystem() const;
437 
443  bool add( agxSDK::TerrainInstance* terrain );
444 
450  bool remove( agxSDK::TerrainInstance* terrain );
451 
459  bool setUniformGravity( const agx::Vec3& g );
460 
465  agx::Vec3 getUniformGravity() const;
466 
471  void setGravityField( agx::GravityField* gravityField );
472 
474  agx::GravityField* getGravityField();
475 
477  const agx::GravityField* getGravityField() const;
478 
484  void setMainWorkThread(agx::Thread* thread);
485 
491  agx::RigidBody* getRigidBody( const agx::Name& name );
492 
498  const agx::RigidBody* getRigidBody( const agx::Name& name ) const;
499 
505  agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) ;
506 
512  const agx::RigidBody* getRigidBody( const agx::Uuid& uuid ) const;
513 
519  const agx::Constraint* getConstraint( const agx::Uuid& uuid ) const;
520 
526  agx::Constraint* getConstraint( const agx::Uuid& uuid );
527 
533  const agx::Constraint* getConstraint(const agx::Name& name) const;
534 
540  agx::Constraint* getConstraint(const agx::Name& name);
541 
547  const agxSDK::Assembly* getAssembly(const agx::Name& name) const;
548 
554  agxSDK::Assembly* getAssembly(const agx::Name& name);
555 
561  const agxSDK::Assembly* getAssembly(const agx::Uuid& uuid) const;
562 
568  agxSDK::Assembly* getAssembly(const agx::Uuid& uuid);
569 
575  const agx::Emitter* getEmitter(const agx::Uuid& uuid) const;
576 
582  agx::Emitter* getEmitter(const agx::Uuid& uuid);
583 
589  agx::Emitter* getEmitter(const agx::Name& name) const;
590 
596  agx::Emitter* getEmitter(const agx::Name& name);
597 
606  template < typename T >
607  T* getConstraint(const agx::Uuid& uuid);
608 
617  template < typename T >
618  const T* getConstraint(const agx::Uuid& uuid) const;
619 
628  template < typename T >
629  T* getConstraint( const agx::Name& name );
630 
639  template < typename T >
640  const T* getConstraint( const agx::Name& name ) const;
641 
642 #define GETCONSTRAINT_TYPE(CLASS_NAME, TYPENAME) \
643  CLASS_NAME *get ## TYPENAME(const agx::Name& name); \
644  CLASS_NAME *get ##TYPENAME(const agx::Uuid& uuid);
645 
646  GETCONSTRAINT_TYPE(agx::AngularLockJoint, AngularLockJoint)
647  GETCONSTRAINT_TYPE(agx::BallJoint, BallJoint)
648  GETCONSTRAINT_TYPE(agx::CylindricalJoint, CylindricalJoint)
649  GETCONSTRAINT_TYPE(agx::DistanceJoint, DistanceJoint)
650  GETCONSTRAINT_TYPE(agx::Hinge, Hinge)
651  GETCONSTRAINT_TYPE(agx::LockJoint, LockJoint)
652  GETCONSTRAINT_TYPE(agx::PlaneJoint, PlaneJoint)
653  GETCONSTRAINT_TYPE(agx::Prismatic, Prismatic)
654  GETCONSTRAINT_TYPE(agx::PrismaticUniversalJoint, PrismaticUniversalJoint)
655  GETCONSTRAINT_TYPE(agx::UniversalJoint, UniversalJoint)
656 #undef GETCONSTRAINT_TYPE
657 
663  const agxCollide::Geometry* getGeometry(const agx::Name& name ) const;
664 
670  agxCollide::Geometry* getGeometry(const agx::Name& name );
671 
677  const agxCollide::Geometry* getGeometry( const agx::Uuid& uuid ) const;
678 
684  agxCollide::Geometry* getGeometry( const agx::Uuid& uuid );
685 
691  const agxSDK::EventListener* getEventListener(const agx::Name& name ) const;
692 
698  agxSDK::EventListener* getEventListener(const agx::Name& name );
699 
705  const agxSDK::EventListener* getEventListener(const agx::Uuid& uuid) const;
706 
712  agxSDK::EventListener* getEventListener(const agx::Uuid& uuid);
713 
714 
720  const agxWire::Wire* getWire(const agx::Name& name) const;
721 
727  agxWire::Wire* getWire(const agx::Name& name);
728 
734  const agxWire::Wire* getWire(const agx::Uuid& uuid) const;
735 
741  agxWire::Wire* getWire(const agx::Uuid& uuid);
742 
748  agx::ObserverFrame* getObserver(const agx::Name& name);
749 
755  const agx::ObserverFrame* getObserver(const agx::Name& name) const;
756 
762  agx::ObserverFrame* getObserver(const agx::Uuid& uuid);
763 
769  const agx::ObserverFrame* getObserver(const agx::Uuid& uuid) const;
770 
777  agx::TimeStamp stepTo( agx::TimeStamp t );
778 
780  agx::Real getTimeStep() const;
781 
787  bool setTimeStep( agx::Real timeStep );
788 
792  agx::Clock* getClock();
793 
797  const agx::Clock* getClock() const;
798 
802  agx::Journal* getJournal();
803 
807  const agx::Journal* getJournal() const;
808 
809  #if AGX_USE_WEBSOCKETS()
810 
813  agx::RemoteSolver* getRemoteSolver();
814 
818  const agx::RemoteSolver* getRemoteSolver() const;
819  #endif
820 
827  bool breakStepTo();
828 
832  agx::Real getTimeStamp() const;
833 
838  void setTimeStamp( agx::TimeStamp t );
839 
844  void stepForward();
845 
849  agxCollide::Space* getSpace();
850 
854  const agxCollide::Space* getSpace() const;
855 
859  agx::DynamicsSystem* getDynamicsSystem();
860 
864  const agx::DynamicsSystem* getDynamicsSystem() const;
865 
869  agxPlot::System* getPlotSystem();
870 
874  const agxPlot::System* getPlotSystem() const;
875 
879  void setPlotSystem(agxPlot::System* plotSystem);
880 
884  void setSpace( agxCollide::Space* space );
885 
889  void setDynamicsSystem( agx::DynamicsSystem* system );
890 
891 
897  bool removeEventListener( agxSDK::EventListener* listener );
898 
909  bool addEventListener( agxSDK::EventListener* listener, int priority = EventManager::DEFAULT_PRIORITY );
910 
921  bool add( agxSDK::EventListener* listener, int priority = EventManager::DEFAULT_PRIORITY );
922 
928  bool remove( agxSDK::EventListener* listener );
929 
934  bool triggerEvent( const GuiEvent& e );
935 
939  const agxPlot::DataSeries* getTimeDataSeries() const;
940 
944  agxPlot::DataSeries* getTimeDataSeries();
945 
946 #ifdef SWIG
947  enum CleanupSelectionMask {
948  STEP_LISTENERS = 0x1,
949  CONTACT_LISTENERS = 0x2,
950  GUI_LISTENERS = 0x4,
951  LISTENERS = STEP_LISTENERS | CONTACT_LISTENERS | GUI_LISTENERS,
952  SYSTEM = 0x200,
953  SPACE = 0x400,
954  MATERIALS = 0x800,
955  ASSEMBLIES = 0x1000,
956  PARTICLE_SYSTEMS = 0x2000,
957  CONTACT_DATA = 0x4000,
958  CLEANUP_ALL = LISTENERS | SYSTEM | SPACE | MATERIALS | ASSEMBLIES | PARTICLE_SYSTEMS | CONTACT_DATA
959  };
960 #else
961 
966  STEP_LISTENERS = EventManager::STEP_LISTENERS,
967  CONTACT_LISTENERS = EventManager::CONTACT_LISTENERS,
968  GUI_LISTENERS = EventManager::GUI_LISTENERS,
969  LISTENERS = EventManager::LISTENERS,
970  SYSTEM = 0x200,
971  SPACE = 0x400,
972  MATERIALS = 0x800,
973  ASSEMBLIES = 0x1000,
974  PARTICLE_SYSTEMS = 0x2000,
975  CONTACT_DATA = 0x4000,
976  PLOTSYSTEM = 0x8000,
977  CLEANUP_ALL = LISTENERS | SYSTEM | SPACE | MATERIALS | ASSEMBLIES | PARTICLE_SYSTEMS | CONTACT_DATA | PLOTSYSTEM
978  };
979 #endif
980 
986  READ_NONE = 0x0,
987  READ_TIMESTEP = 0x1,
988  READ_TIMESTAMP = 0x2,
989  READ_GRAVITY = 0x4,
990  READ_SOLVER = 0x8,
991  READ_ALL = READ_TIMESTEP + READ_TIMESTAMP + READ_GRAVITY + READ_SOLVER,
992  READ_DEFAULT = READ_TIMESTEP /* + READ_TIMESTAMP */ + READ_GRAVITY + READ_SOLVER // Not using READ_TIMESTAMP
993  };
994 
1002  void cleanup( agx::UInt selection = CLEANUP_ALL, bool fast=false );
1003 
1009  void setActionManagerTimeStamp(const agx::TimeStamp& time);
1010 
1014  agxControl::ActionManager* getActionManager();
1015 
1019  void clearContactData();
1020 
1024  agx::Solver* getSolver();
1025 
1029  const agx::Solver* getSolver() const;
1030 
1034  void setPreIntegratePositions( bool flag );
1035 
1039  bool getPreIntegratePositions() const;
1040 
1046  bool add( agxStream::Serializable* object );
1047 
1053  bool remove( agxStream::Serializable* object );
1054 
1055 
1060  agxSDK::PickHandler* getPickHandler();
1061 
1066  const agxSDK::PickHandler* getPickHandler() const;
1067 
1072  void setPickHandler( agxSDK::PickHandler* pickHandler );
1073 
1078  void setStatisticsPath( const agx::String& path );
1079 
1083  void setStatisticsInterval( agx::Real interval );
1084 
1090  void setEnableStatistics( bool enable );
1091 
1093  bool getEnableStatistics() const;
1094 
1096  void setEnableStatisticsRendering( bool enable );
1097 
1099  bool getEnableStatisticsRendering() const;
1100 
1104  void setProfilingFrequency(agx::Real frequency);
1105 
1109  agx::Real getProfilingFrequency() const;
1110 
1114  const AssemblyHash& getAssemblies() const;
1115 
1116 
1120  void getEventListeners( EventListenerPtrVector& eventListeners ) const;
1121 
1125  const agxCollide::GeometryRefVector& getGeometries() const;
1126 
1130  const agx::RigidBodyRefVector& getRigidBodies() const;
1131 
1135  agx::RigidBodyRefVector& getRigidBodies();
1136 
1137 
1141  const agx::ConstraintRefSetVector& getConstraints() const;
1142 
1146  agx::ConstraintRefSetVector& getConstraints();
1147 
1151  const agx::ObserverFrameRefSetVector& getObserverFrames() const;
1152 
1156  agx::ObserverFrameRefSetVector& getObserverFrames();
1157 
1161  agx::RigidBodyPtrSetVector& getEnabledRigidBodies();
1162 
1166  const agx::RigidBodyPtrSetVector& getEnabledRigidBodies() const;
1167 
1173  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid) const;
1174 
1180  agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid);
1181 
1186  agx::ObserverFrame* getObserverFrame(const agx::Name& name);
1187 
1192  const agx::ObserverFrame* getObserverFrame(const agx::Name& name) const;
1193 
1194 
1200  size_t write( const agx::String& filename ) const;
1201 
1208  size_t write( std::ostream& stream, bool binary ) const;
1209 
1216  size_t read( const agx::String& filename, agxSDK::Assembly* parent = nullptr, agx::UInt selection = READ_DEFAULT);
1217 
1226  size_t read( std::istream& stream, bool isBinary, agxSDK::Assembly* parent = nullptr, agx::UInt selection = READ_DEFAULT);
1227 
1233  bool restore(const agx::String& filename, agx::UInt selection = READ_DEFAULT);
1234  bool restore(std::istream& stream, bool isBinary, agx::UInt selection = READ_DEFAULT);
1235 
1236 
1244  bool addRestoreListener( agxStream::RestoreListener *listener );
1245 
1251  bool removeRestoreListener( agxStream::RestoreListener *listener );
1252 
1257  void store( agxStream::OutputArchive& archive ) const;
1258 
1266  void restore( agxStream::InputArchive& in, agxSDK::Assembly* parent = nullptr, agx::UInt selection = READ_DEFAULT, bool replaceUsingCache = false );
1267 
1275  void setEnableRemoteDebugging( bool flag, agx::Int16 port = -1, bool useCompression = false, bool waitForSynchronization = true );
1276 
1280  bool getEnableRemoteDebugging() const;
1281 
1286  void setRemoteDebuggingTimeStep( agx::Real timeStep );
1287 
1291  agx::Real getRemoteDebuggingTimeStep() const;
1292 
1301  void setContactReductionBinResolution( agx::UInt8 binResolution );
1302 
1306  agx::UInt8 getContactReductionBinResolution() const;
1307 
1311  agx::MergeSplit* getMergeSplit();
1312 
1316  const agx::MergeSplit* getMergeSplit() const;
1317 
1323  agxSDK::MergeSplitHandler* getMergeSplitHandler() const;
1324 
1328  agxRender::RenderManager* getRenderManager();
1329 
1333  const agxRender::RenderManager* getRenderManager() const;
1334 
1338  void updateRenderManager();
1339 
1343  void updateStatisticsRenderData();
1344 
1354  void garbageCollect();
1355 
1361  void setContactReductionThreshold( agx::UInt threshold );
1362 
1366  agx::UInt getContactReductionThreshold() const;
1367 
1368 
1372  bool add(agxSDK::SimulationParameter *parameter);
1373 
1377  bool remove(agxSDK::SimulationParameter *parameter);
1378 
1382  const agxSDK::SimulationParameterRefVector& getParameters() const;
1383 
1387  agxSDK::SimulationParameter *getParameter(const agx::Name& name);
1388 
1392  agxSDK::EnergyManager* getEnergyManager() const;
1393 
1394  public:
1395  // Internal, but public methods
1396 
1398  void sendSimulation();
1399 
1404  SimulationSerializer* getSerializer();
1405 
1410  const SimulationSerializer* getSerializer() const;
1411 
1415  void setSerializer( SimulationSerializer* serializer);
1416 
1417 
1423  void updateActionManager();
1424 
1431  agxSDK::SimulationProxy* getSimulationProxy() const;
1432 
1439  void commit( agxSDK::SimulationProxy* simulationProxy );
1440 
1446  void handleStabiltyReport( const agx::StabilityReport* stabilityReport );
1447 
1448  agx::TaskGroup* getUpdateTask();
1449 
1450  void renderComponents();
1451  void createRenderTask();
1452  agx::SolveModel* getSolveModel(const agx::Name& name);
1453 
1454  const agx::SolveModelRefVector& getSolveModels() const;
1455 
1456  #if AGX_USE_WEBSOCKETS()
1457  void setRemoteSolver(agx::RemoteSolver* remoteSolver);
1458  #endif
1459 
1461  Simulation( agx::Device* device );
1462 
1463  static Simulation* load(agx::TiXmlElement* eSimulation, agx::Device* device);
1464 
1466  static agx::Model* ClassModel();
1467 
1473  void setEnableSimulationStatisticsListener( bool flag );
1474 
1475  SimulationStatisticsListener* getSimulationStatisticsListener();
1476  const SimulationStatisticsListener* getSimulationStatisticsListener() const;
1477 
1478  void addSolveModel(agx::SolveModel* model);
1479  void removeSolveModel(agx::SolveModel* model);
1480  void loadSolveModels(const agx::String& path, bool clear = false);
1481 
1482  bool getUseComplexImpactStage() const;
1483  void setUseComplexImpactStage(bool flag);
1484 
1485  // For LUA only
1486  agx::Constraint1DOF* getConstraint1DOF(const agx::Name& name) { return this->getConstraint<agx::Constraint1DOF>(name); }
1487  agx::Constraint2DOF* getConstraint2DOF(const agx::Name& name) { return this->getConstraint<agx::Constraint2DOF>(name); }
1488 
1492  agx::UInt getNumMergedBodies() const;
1493 
1498  agx::MergedBody* getMergedBody( agx::UInt i ) const;
1499 
1503  agx::UInt getNumTerrains() const;
1504 
1509  agxSDK::TerrainInstance* getTerrain( agx::UInt i ) const;
1510 
1512  void resetTaskTimers();
1513 
1517  void dumpTaskTimers(const agx::String& filePath = "BufferAllocations.xml");
1518 
1522  void dumpMemoryUsage(const agx::String& filePath = "TaskTimers.xml");
1523 
1524 
1526  bool allowCreateParticles() const;
1527 
1528  agx::Component *getHeader();
1529  void readStoragePermutations(agxStream::InputArchive& in, bool clearStorages = false);
1530  void writeStoragePermutations(agxStream::OutputArchive& archive) const;
1531 
1532  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);
1533 
1534  protected:
1536  friend class GuiEventAdapterImplementation;
1537  friend class agx::DynamicsSystem;
1540 
1542  virtual ~Simulation();
1543 
1544  private:
1545  void addListener(EventListener *listener);
1546  void removeListener(EventListener *listener);
1547  bool hasListener(EventListener *listener);
1548 
1549  private:
1551  void init();
1552 
1554  void initConfiguration();
1555 
1557  void updateStatisticsEnable();
1558 
1559  void setEnableComputeAllConstraintForces(bool flag);
1560  bool getEnableComputeAllConstraintForces() const;
1561 
1563  void resetGraphStatistics();
1564 
1566  agx::Vec4 getSubsystemColor(agx::RigidBody* body);
1567 
1569  void setupStatisticsLogging();
1570 
1571  void updateConstraintForceData();
1572 
1573  void createUpdateTask();
1574 
1575  void generateContactMaterials();
1576  void preCollide();
1577  void prepareContacts();
1578  void triggerParticleContactSensors();
1579  void triggerPreStepEvents();
1580  void triggerPostStepEvents();
1581  void triggerLastStepEvents();
1582  void terrainPostUpdate();
1583  void stepSystem();
1584  void resetDirtyMaterials();
1585  void updateRemoteDebugger();
1586  void recordStatistics();
1587  void recordPlaybackStatistics();
1588  void recordParticleCount();
1589  void recordWarmStartingData();
1590  void printStatistics();
1591  void updateClock();
1592 
1593 
1594  void pruneContacts();
1595  void contactPointReduction();
1596  void updateSleepState();
1597  void triggerPreCollideStepEvent();
1598  void triggerSeparationContactEventListeners();
1599  void triggerContactEventListeners();
1600  void assignContactMaterials();
1601  void dumpThreadLogs(agx::Task *);
1602 
1603  void applyPreIntegrationSettings();
1604 
1605  private:
1606  friend class agx::Solver;
1607  void registerParticleSystemPointers();
1608  void unregisterParticleSystemPointers();
1609  void removeParticleSolverObjects( agx::ParticleSystem* particleSystem );
1610 
1611  private:
1612 
1613  class StatisticsWriter;
1614 
1615  friend class agx::Journal;
1617  #if AGX_USE_WEBSOCKETS()
1618  friend class agx::RemoteSolver;
1619  #endif
1620 
1621  void setJournal(agx::Journal* journal);
1622  void setHasJournal(bool flag);
1623  void preStoreSynchronization();
1624 
1625  StatisticsEntries m_statisticsEntry;
1626  StatisticsWriter* m_statWriter;
1627 
1629 
1630  AssemblyHash m_assemblies;
1631 
1632  agxCollide::SpaceRef m_space;
1633  agx::DynamicsSystemRef m_system;
1634 
1635  agxPlot::SystemRef m_plotSystem;
1636  agxPlot::DataSeriesRef m_timeDataSeries;
1637 
1638  agx::ComponentRef m_header;
1639  bool m_stepToStarted;
1640 
1641  EventManagerRef m_eventManager;
1642  MaterialManagerRef m_materialManager;
1643 
1644  agxControl::ActionManagerRef m_actionManager;
1645  agx::TaskRef m_actionManagerTask;
1646 
1647  agx::observer_ptr< Referenced > m_pickHandler;
1648 
1649  SimulationSerializerRef m_serializationListener;
1650 
1651  agx::ParticleSystemRefVector m_particleSystems;
1652  agx::TaskGroupRef m_updateEmitters;
1653  agxData::EntityStorageRef m_emitterStorage;
1654 
1655  agx::ref_ptr<agx::Referenced> m_controlledServer;
1656  agx::ref_ptr<agx::Referenced> m_debugServer;
1657  agx::UInt8 m_contactReductionBinResolution;
1658  agx::UInt m_contactReductionThreshold;
1659  agx::ComponentRefVector m_subComponents;
1660  agx::Real m_remoteDebuggerTimeStep;
1661  agx::TimeStamp m_remoteDebuggerTimeStamp;
1662  agx::TaskGroupRef m_updateTask;
1663  agx::TaskRefVector m_preIntegrateTasks;
1664  bool m_preIntegrate;
1665  bool m_fastCleanup;
1666  bool m_allowCreateParticles;
1667 
1668  agx::Timer m_stepTimer;
1669  agx::Timer m_updateRenderManagerTimer;
1670  agx::ClockRef m_clock;
1671  agx::TaskRef m_renderTask;
1672  agx::GravityFieldRef m_gravityField;
1673 
1674  agx::SolveModelTable m_solveModelTable;
1675  agx::SolveModelRefVector m_solveModels;
1676 
1677  agx::ref_ptr<agx::Referenced> m_renderManager;
1678  agx::Thread* m_mainWorkThread;
1679 
1680  void* m_journal;
1681  bool m_hasJournal;
1682  void* m_remoteSolver;
1683 
1684  agxData::EntityStorageRef m_constraintForcesStorage;
1685  bool m_enableComputeAllConstraintForces;
1686  bool m_inDestructor;
1687  SimulationProxyRef m_simulationProxy;
1688  agx::ParticleContactSensorRefVector m_particleContactSensors;
1689 
1691  ParticleContactSensorTable m_particleContactSensorTable;
1692 
1694  RestoreListenerHash m_restoreListeners;
1695  agxSDK::SimulationStatisticsListenerRef m_simulationStatisticsListener;
1696  agx::Real m_profilingFrequency;
1697  agxData::ValueRefT<bool> m_useComplexImpactStage;
1698 
1700  StabilityReportContainer m_stabilityReports;
1701 
1704  MergedBodiesContainer m_mergedBodies;
1705 
1707  MergeSplitHandlerPointer m_mergeSplitHandler;
1708 
1711  LinkedStructureContainer m_linkedStructures;
1712 
1715  TerrainInstanceContainer m_terrains;
1716 
1717  bool m_disableGeometryAutoAdd;
1718  agxSDK::SimulationParameterRefVector m_simulationParameters;
1719 
1720 
1721  agx::RangeJobVector m_postSolveConstraintForceJobs;
1722  agx::ParallelTaskRef m_postSolveConstraintForceTask;
1723 
1724  agx::ref_ptr<agx::Referenced> m_energyManager;
1725  };
1726 
1727  /* Implementation */
1729  {
1730  return m_clock->getTime();
1731  }
1732 
1734  {
1735  return m_space.get();
1736  }
1737 
1739  {
1740  return m_space.get();
1741  }
1742 
1744  {
1745  return m_system.get();
1746  }
1747 
1749  {
1750  return m_system.get();
1751  }
1752 
1753 
1754 
1756  {
1757  return m_plotSystem.get();
1758  }
1759 
1761  {
1762  return m_plotSystem.get();
1763  }
1764 
1766  {
1767  return m_timeDataSeries.get();
1768  }
1769 
1771  {
1772  return m_timeDataSeries.get();
1773  }
1774 
1775 
1776 
1777 
1779  {
1780  if (m_system) return m_system->getTimeGovernor()->getTimeStep();
1781  else return 0;
1782  }
1783 
1785  {
1786  return m_clock;
1787  }
1788 
1790  {
1791  return m_clock;
1792  }
1793 
1795  {
1796  return m_allowCreateParticles;
1797  }
1798 
1799  AGX_FORCE_INLINE const agx::SolveModelRefVector& Simulation::getSolveModels() const
1800  {
1801  return m_solveModels;
1802  }
1803 
1804  template< typename T >
1806  {
1807  return dynamic_cast< T* >( this->getConstraint( uuid ) );
1808  }
1809 
1810  template< typename T >
1811  const T* Simulation::getConstraint( const agx::Uuid& uuid ) const
1812  {
1813  return dynamic_cast< const T* >( this->getConstraint( uuid ) );
1814  }
1815 
1816  template< typename T >
1818  {
1819  return dynamic_cast< T* >( this->getConstraint( name ) );
1820  }
1821 
1822  template< typename T >
1823  const T* Simulation::getConstraint( const agx::Name& name ) const
1824  {
1825  return dynamic_cast< const T* >( this->getConstraint( name ) );
1826  }
1827 } // namespace agxSDK
1828 
1829 #ifdef _MSC_VER
1830 # pragma warning(pop) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow). Restored.
1831 #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:503
agx::Event2< Simulation *, agx::RigidBody * > RigidBodyEvent
Definition: Simulation.h:125
MaterialEvent removeMaterialEvent
Definition: Simulation.h:141
AGXTERRAIN_EXPORT void clear()
void AGXPHYSICS_EXPORT init()
Initialize agx.
const agx::SolveModelRefVector & getSolveModels() const
Definition: Simulation.h:1799
agx::Event2< Simulation *, agx::Constraint * > ConstraintEvent
Definition: Simulation.h:126
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:197
agx::Constraint2DOF * getConstraint2DOF(const agx::Name &name)
Definition: Simulation.h:1487
RigidBodyEvent removeRigidBodyEvent
Definition: Simulation.h:135
agx::Clock * getClock()
Definition: Simulation.h:1784
agx::Event2< Simulation *, agxCollide::Geometry * > GeometryEvent
Definition: Simulation.h:124
Base class for a merge split algorithm handling a set of merged bodies.
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
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
MaterialEvent addMaterialEvent
Definition: Simulation.h:140
agx::Event2< Simulation *, agx::Material * > MaterialEvent
Definition: Simulation.h:127
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:759
uint8_t UInt8
Definition: Integer.h:38
Keeps track of the energy flow in the system.
#define AGXPHYSICS_EXPORT
The base class for a constraint.
Definition: Constraint.h:86
Class for receiving serialized agxSDK::Simulation:s from remote host.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:674
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:62
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:73
agx::Real TimeStamp
Definition: TimeStamp.h:26
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc...
agxPlot::System * getPlotSystem()
Definition: Simulation.h:1760
Spawns new bodys inside a given volume.
Definition: Emitter.h:37
This class will collect statistics and sizes of a simulation.
class for serializing a simulation into a series for files on disk &lt;filename&gt;_0001.agx etc.
RigidBodyEvent addRigidBodyEvent
Definition: Simulation.h:134
const agx::Constraint * getConstraint(const agx::Uuid &uuid) const
Find (linear search) and return a pointer to a Constraint with the given uuid.
Definition: Simulation.h:1811
The geometry representation used by the collision detection engine.
Definition: Geometry.h:88
agxCollide::Space * getSpace()
Definition: Simulation.h:1733
The base class for interactions.
Definition: Interaction.h:30
Structure holding several &quot;normal&quot; rigid bodies.
Definition: MergedBody.h:54
Templated vector class.
Definition: Vector.h:52
agx::HashVector< agxSDK::Assembly *, agxSDK::AssemblyRef > AssemblyHash
Definition: Simulation.h:112
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
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:81
TaskGroup.
Definition: Task.h:585
GeometryEvent removeGeometryEvent
Definition: Simulation.h:132
bool AGXPHYSICS_EXPORT write(const std::string &filename, const agxStream::Serializable *data)
Write a Serializable object to a file.
JournalAttachEvent journalAttachedEvent
Definition: Simulation.h:146
ReadSelectionMask
Enum for specifying some additional, part of a simulation that can be restored from a serialization...
Definition: Simulation.h:985
agx::Event2< Simulation *, agx::ContactMaterial * > ContactMaterialEvent
Definition: Simulation.h:128
CleanupSelectionMask
Specification of what should be cleaned up from a simulation during a call to the cleanup() method...
Definition: Simulation.h:965
ContactMaterialEvent removeContactMaterialEvent
Definition: Simulation.h:144
Constraint that removes 3 DOF (rotational degrees of freedom) between two bodies, or one body and the...
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:384
ContactMaterialEvent addContactMaterialEvent
Definition: Simulation.h:143
#define CALLABLE
Definition: Object.h:76
agx::Constraint1DOF * getConstraint1DOF(const agx::Name &name)
Definition: Simulation.h:1486
The complete physical system with bodies, interactions, data layout, time stepper, and solver.
GeometryEvent addGeometryEvent
Definition: Simulation.h:131
T * get() const
Definition: ref_ptr.h:256
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:37
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:121
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:138
int16_t Int16
Definition: Integer.h:44
ConstraintEvent addConstraintEvent
Definition: Simulation.h:137
bool allowCreateParticles() const
Definition: Simulation.h:1794
agx::Real getTimeStep() const
Definition: Simulation.h:1778
Interface class used by internal objects running in parallel.
const agxPlot::DataSeries * getTimeDataSeries() const
A data series that contains all time stamps of the simulation.
Definition: Simulation.h:1765
double Real
Definition: Real.h:42
agx::Real getTimeStamp() const
Definition: Simulation.h:1728
agx::Real getTime() const
agx::DynamicsSystem * getDynamicsSystem()
Definition: Simulation.h:1748
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
#define GETCONSTRAINT_TYPE(CLASS_NAME, TYPENAME)
Definition: Simulation.h:642
agx::Event2< Simulation *, agx::Journal * > JournalAttachEvent
Definition: Simulation.h:129
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints, geometries.
Definition: Assembly.h:73
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:42