AGX Dynamics  2.38.0.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:
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
agxPhysics_export.h
agx::GranularImpactDataWriter::IMPACT_BUFFER
static const char *const IMPACT_BUFFER
Definition: GranularImpactDataWriter.h:133
agx::GranularImpactDataWriter::m_journalAttachedCallback
agxSDK::Simulation::JournalAttachEvent::CallbackType m_journalAttachedCallback
Definition: GranularImpactDataWriter.h:249
agx::detail::ParticleEventListener::getDestroyedParticles
IndexHashSet getDestroyedParticles() const
Returns the currently destroyed particles registered from the coupled GranularBodySystem.
Definition: GranularImpactDataWriter.h:119
agx::SymmetricPair
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:31
agx::GranularImpactDataWriter::ACCUMULATED_IMPACT_BUFFER
static const char *const ACCUMULATED_IMPACT_BUFFER
Definition: GranularImpactDataWriter.h:134
agx::Journal
Definition: Journal.h:46
agx::GranularImpactDataWriter::PARTICLEGEOMETRYCONTACT_BUFFER
static const char *const PARTICLEGEOMETRYCONTACT_BUFFER
Definition: GranularImpactDataWriter.h:136
agx::Real
double Real
Definition: Real.h:42
agx::GranularImpactDataWriter::m_activeParticleGeometryPairs
ParticleGeometryTimeTable m_activeParticleGeometryPairs
Definition: GranularImpactDataWriter.h:194
agxSDK::StepEventListener
Derive from this class to implement a listener for simulation step events.
Definition: StepEventListener.h:37
BitState.h
agx::GranularImpactDataWriter::m_impactDataSimulationWriter
ImpactDataSimulationWriterRef m_impactDataSimulationWriter
Definition: GranularImpactDataWriter.h:192
Simulation.h
agx::GranularImpactDataWriter::CONTACTENERGY_BUFFER
static const char *const CONTACTENERGY_BUFFER
Definition: GranularImpactDataWriter.h:137
agx::GranularImpactDataWriter::RealContainer
agx::RealVector RealContainer
Definition: GranularImpactDataWriter.h:145
agx::Physics::ParticlePairContactPtr
Pointer to a entity instance of type Physics.ParticlePairContact.
Definition: ParticlePairContactEntity.h:240
agx::detail::ParticleEventListener
Particle EventListener that can be inherited and overridden in order to listen to particle events.
Definition: GranularImpactDataWriter.h:58
agx::GranularImpactDataWriter::m_activeParticlePairs
ParticlePairTimeTable m_activeParticlePairs
Definition: GranularImpactDataWriter.h:195
agxData::EntityStorage
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
StepEventListener.h
agx::EventT< Callback2< Simulation *, agx::Journal * > >::CallbackType
Callback2< Simulation *, agx::Journal * > CallbackType
Definition: Event.h:37
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agx::detail::ParticleInformation::radius
agx::Real radius
Definition: GranularImpactDataWriter.h:50
agx::VectorPOD< Real >
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agx::detail::ParticleGeometryContactInformation
Definition: GranularImpactDataWriter.h:41
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::GranularImpactDataWriter::ParticleGeometryTimeTable
agx::HashTable< agx::Physics::GranularBody::GranularGeometryPair, agx::TimeStamp > ParticleGeometryTimeTable
Definition: GranularImpactDataWriter.h:143
agxData::Array
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
agx::GranularImpactDataWriter::m_particlePairStorage
agxData::EntityStorageRef m_particlePairStorage
Definition: GranularImpactDataWriter.h:247
agx::ref_ptr< ParticleStorageListener >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agx::detail::ParticleGeometryContactInformation::contactPtr
agx::Physics::ParticleGeometryContactPtr contactPtr
Definition: GranularImpactDataWriter.h:43
agx::GranularImpactDataWriter::m_simulation
agxSDK::Simulation * m_simulation
Definition: GranularImpactDataWriter.h:189
agx::detail::ParticleInformation
Definition: GranularImpactDataWriter.h:47
agx::Physics::ParticleGeometryContactPtr
Pointer to a entity instance of type Physics.ParticleGeometryContact.
Definition: ParticleGeometryContactEntity.h:267
agx::GranularImpactDataWriter::ParticlePairTimeTable
agx::HashTable< agx::Physics::GranularBody::GranularGranularPair, agx::TimeStamp > ParticlePairTimeTable
Definition: GranularImpactDataWriter.h:144
Journal.h
agx::Index
UInt32 Index
Definition: Integer.h:44
agx::detail::ParticleInformation::position
agx::Vec3 position
Definition: GranularImpactDataWriter.h:52
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:926
agx::Physics::GranularBodySystem
Definition: GranularBodySystem.h:32
agx::GranularImpactDataWriter::m_particleGeometryStorage
agxData::EntityStorageRef m_particleGeometryStorage
Definition: GranularImpactDataWriter.h:248
agx::GranularImpactDataWriter
Definition: GranularImpactDataWriter.h:128
agx::HashSet< agx::Index >
agx::detail::ParticleInformation::particleId
agx::Index particleId
Definition: GranularImpactDataWriter.h:49
agx::GranularImpactDataWriter::PARTICLEPAIRCONTACT_BUFFER
static const char *const PARTICLEPAIRCONTACT_BUFFER
Definition: GranularImpactDataWriter.h:135
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agx::detail::ParticlePairContactInformation
Definition: GranularImpactDataWriter.h:35
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
agx::detail::ParticleInformation::accumulatedEnergy
agx::Real accumulatedEnergy
Definition: GranularImpactDataWriter.h:51
AnalysisBox.h
agx::GranularImpactDataWriter::m_system
agx::Physics::GranularBodySystem * m_system
Definition: GranularImpactDataWriter.h:190
agx::Vec3T< Real >
agx::Physics::GranularBody::GranularGeometryPair
std::pair< GranularBodyPtr, GeometryPtr > GranularGeometryPair
Definition: CachedContact.h:46
agx::GranularImpactDataWriter::m_destroyedId
IndexHashSet m_destroyedId
Definition: GranularImpactDataWriter.h:193
agxData::EntityPtr
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:51
agx::GranularImpactDataWriter::m_impactThreshold
Real m_impactThreshold
Definition: GranularImpactDataWriter.h:191
GranularBodySystem.h
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::GranularImpactDataWriter::ParticlePairKey
agx::Physics::GranularBody::GranularGranularPair ParticlePairKey
Definition: GranularImpactDataWriter.h:142
agxData::EntityRange
Definition: EntityPtr.h:247
agx::GranularImpactDataWriter::ParticleGeometryKey
agx::Physics::GranularBody::GranularGeometryPair ParticleGeometryKey
Definition: GranularImpactDataWriter.h:141
agx::detail::ParticlePairContactInformation::contactPtr
agx::Physics::ParticlePairContactPtr contactPtr
Definition: GranularImpactDataWriter.h:37