AGX Dynamics  2.37.3.2
GranularImpactDataWriter.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 #ifndef AGX_GRANULARIMPACTANALYSIS_H
18  #define AGX_GRANULARIMPACTANALYSIS_H
19 
20 #include <agx/agxPhysics_export.h>
22 #include <agx/Journal.h>
24 #include <agxSDK/Simulation.h>
25 #include <agx/AnalysisBox.h>
26 #include <agx/BitState.h>
27 #include <iostream>
28 
29 namespace agx
30 {
31  // Detail namespace
32  namespace detail
33  {
34  // Container for contact information
36  {
38  };
39 
40  // Container for contact information
42  {
44  };
45 
46  // Container for information about the accumulated impacts experienced by a pellet.
48  {
53  };
54 
59  {
60  public:
61  // Constructor
63 
65  IndexHashSet getDestroyedParticles() const;
66 
67  protected:
68  virtual void onParticleDestroyed(agx::Index id) = 0;
69 
70  virtual void onParticleCreated(agx::Index id) = 0;
71 
72  bool particleIsDestroyed(agx::Index id);
73 
74  void clearDestroyedParticles();
75 
76  private:
77  void triggerParticleDestroyed(agx::Index id);
78 
79  void triggerParticleCreated(agx::Index id);
80 
82  // Internal classes
84  AGX_DECLARE_POINTER_TYPES(ParticleStorageListener);
85  class ParticleStorageListener : public agxData::EntityStorage::EventListener, public agx::Referenced
86  {
87  public:
88  ParticleStorageListener(ParticleEventListener* listener);
89 
90  virtual void destroyCallback(agxData::EntityStorage* storage) override;
91  virtual void createInstanceCallback(agxData::EntityStorage* storage, agxData::EntityPtr instance) override;
92  virtual void createInstancesCallback(agxData::EntityStorage* storage, agxData::EntityRange range) override;
93  virtual void destroyInstanceCallback(agxData::EntityStorage* storage, agxData::EntityPtr instance) override;
94  virtual void destroyInstancesCallback(agxData::EntityStorage* storage, agxData::Array<agxData::EntityPtr> instances) override;
95  virtual void createInstancesCallback(agxData::EntityStorage* storage, agxData::Array<agxData::EntityPtr> instances) override;
96  virtual void destroyInstancesCallback(agxData::EntityStorage* storage, agxData::EntityRange instances) override;
97 
98  protected:
99  virtual ~ParticleStorageListener();
100 
102  // Variables
104  protected:
105  ParticleEventListener * m_listener;
106  };
107 
108  protected:
109  virtual ~ParticleEventListener();
111  // Variables
113  private:
115  ParticleStorageListenerRef m_particleStorageListener;
116  IndexHashSet m_destroyedIds;
117  };
118 
120  }
121 
129  {
130  public:
131 #ifndef SWIG
132  // Simulation buffer names for the data that the ImpactDataWriter records into the simulation
133  static const char* const IMPACT_BUFFER;
134  static const char* const ACCUMULATED_IMPACT_BUFFER;
135  static const char* const PARTICLEPAIRCONTACT_BUFFER;
136  static const char* const PARTICLEGEOMETRYCONTACT_BUFFER;
137  static const char* const CONTACTENERGY_BUFFER;
138 #endif
139 
140  public:
146 
147  AGX_DECLARE_POINTER_TYPES(ImpactDataSimulationWriter);
148  public:
155  GranularImpactDataWriter(agx::Physics::GranularBodySystem * system, agx::Real recordThreshold = 1E-3);
156 
158  virtual void pre(const agx::TimeStamp& /*t*/) override;
159 
161  virtual void post(const agx::TimeStamp&) override;
162 
167  virtual void addNotification() override;
168 
172  virtual void removeNotification() override;
173 
175 
176  protected:
177  virtual ~GranularImpactDataWriter();
178 
179  protected:
180 
181 
182  private:
184 
186  // Variables
188  protected:
194  ParticleGeometryTimeTable m_activeParticleGeometryPairs;
195  ParticlePairTimeTable m_activeParticlePairs;
196  };
197 
198  /*
199  Internal class that writes the contact and particle data to simulation under the specified GranularBodySystem.
200  */
201  class AGXPHYSICS_EXPORT GranularImpactDataWriter::ImpactDataSimulationWriter : public agx::Referenced
202  {
203  public:
209  ImpactDataSimulationWriter(agx::Physics::GranularBodySystem * system);
210 
212  void addNotification(agxSDK::Simulation * simulation);
213 
215  void removeNotification(agxSDK::Simulation * simulation);
216 
218  void writeContactInformation(const detail::ParticlePairContactInformation& contact);
219 
221  void writeContactInformation(const detail::ParticleGeometryContactInformation& contact);
222 
224  size_t getNumParticlePairImpacts() const;
225 
227  size_t getNumParticleGeometryImpacts() const;
228 
229  ImpactDataSimulationWriter& operator=(const ImpactDataSimulationWriter&) = delete;
230  protected:
231  virtual ~ImpactDataSimulationWriter();
232 
233  void initParticleBuffers();
234 
235  void journalAttachedCallback(agxSDK::Simulation * simulation, agx::Journal *journal);
236 
238  void createJournalBindings(agx::Journal * journal);
239 
240  void writeParticleContactInfo(agx::Index id, agx::Real contactEnergy);
241 
243  // Variables
245  protected:
250  };
251 }
252 
253 #endif
Pointer to a entity instance of type Physics.ParticleGeometryContact.
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a) ...
Definition: SymmetricPair.h:31
agx::Physics::GranularBody::GranularGranularPair ParticlePairKey
Derive from this class to implement a listener for simulation step events.
agx::Physics::ParticleGeometryContactPtr contactPtr
Pointer to a entity instance of type Physics.ParticlePairContact.
agxSDK::Simulation::JournalAttachEvent::CallbackType m_journalAttachedCallback
static const char *const IMPACT_BUFFER
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
static const char *const ACCUMULATED_IMPACT_BUFFER
#define AGXPHYSICS_EXPORT
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:51
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
IndexHashSet getDestroyedParticles() const
Returns the currently destroyed particles registered from the coupled GranularBodySystem.
#define AGX_FORCE_INLINE
Definition: Object.h:59
agx::Real TimeStamp
Definition: TimeStamp.h:26
std::pair< GranularBodyPtr, GeometryPtr > GranularGeometryPair
Definition: CachedContact.h:46
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
static const char *const PARTICLEGEOMETRYCONTACT_BUFFER
ParticleGeometryTimeTable m_activeParticleGeometryPairs
Base class providing referencing counted objects.
Definition: Referenced.h:119
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::Physics::GranularBodySystem * m_system
static const char *const PARTICLEPAIRCONTACT_BUFFER
UInt32 Index
Definition: Integer.h:52
agx::Physics::ParticlePairContactPtr contactPtr
Particle EventListener that can be inherited and overridden in order to listen to particle events...
ImpactDataSimulationWriterRef m_impactDataSimulationWriter
agxData::EntityStorageRef m_particleGeometryStorage
Templated callback with two arguments.
Definition: Callback.h:139
agxData::EntityStorageRef m_particlePairStorage
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
ParticlePairTimeTable m_activeParticlePairs
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
double Real
Definition: Real.h:42
agx::HashTable< agx::Physics::GranularBody::GranularGeometryPair, agx::TimeStamp > ParticleGeometryTimeTable
Inheritance with partial specialization due to bug with ref_ptr containers.
static const char *const CONTACTENERGY_BUFFER
agx::Physics::GranularBody::GranularGeometryPair ParticleGeometryKey
agx::HashTable< agx::Physics::GranularBody::GranularGranularPair, agx::TimeStamp > ParticlePairTimeTable