AGXDynamics  2.35.0.3
GranularDataExporter.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
18 #ifndef AGX_GRANULARDATAEXPORTER_H
19 #define AGX_GRANULARDATAEXPORTER_H
20 
21 #include <agx/agxPhysics_export.h>
24 #include <agxSDK/Simulation.h>
25 #include <agx/IndexSet.h>
26 #include <agx/AnalysisBox.h>
28 #include <iostream>
29 
30 namespace agx
31 {
53  {
54  public:
55  // Forward declarations
56  AGX_DECLARE_POINTER_TYPES(IDataFileWriter);
57  AGX_DECLARE_POINTER_TYPES(IDataExporter);
58  AGX_DECLARE_POINTER_TYPES(ContactDataExporter);
59  AGX_DECLARE_POINTER_TYPES(ParticleDataExporter);
60  AGX_DECLARE_POINTER_TYPES(ContactDataWriter);
61  AGX_DECLARE_POINTER_TYPES(ParticleDataWriter);
62 
63  public:
66  {
68  CONTACT_DATA
69  };
70 
72  static agx::String convertExportDataTypeToFilename(ExporterDataType exportDataType);
73 
74  public:
80 
84  void init();
85 
87  virtual void pre(const agx::TimeStamp& /*t*/) override;
88 
90  virtual void post(const agx::TimeStamp&) override;
91 
96  void writeToFile(const agx::String& file);
97 
103  void setAnalysisBox(agx::AnalysisBox* box);
104 
110  void setExporterType(ExporterDataType type);
111 
115  void finalizeAfterSimulation();
116 
117  protected:
118  virtual ~GranularDataExporter();
119 
120  virtual void onParticleCreated(agx::Index id) override;
121 
122  virtual void onParticleDestroyed(agx::Index id) override;
123 
124  void updateStartingContactIds();
125 
127  IndexHashSet getStartingParticleGeometryImpacts();
128 
130  IndexHashSet getStartingParticlePairImpacts();
131 
133  // Variables
135  protected:
140  };
141 
143  {
144  return m_startingParticleGeometryImpactContacts;
145  }
146 
148  {
149  return m_startingParticlePairImpactContacts;
150  }
151 
156  class AGXPHYSICS_EXPORT GranularDataExporter::IDataExporter : public agx::Referenced
157  {
158  public:
160  IDataExporter(agx::Physics::GranularBodySystem * system);
161 
167  void setAnalysisBox(agx::AnalysisBox* box);
168 
173  void exportPreStep(const IndexHashSet& destroyedParticles);
174 
179  void exportPostStep(const IndexHashSet& destroyedParticles);
180 
185  virtual void handleParticleDestroyed(agx::Index particleId);
186 
191  void finalizeExport(GranularDataExporter * exporter);
192 
197  virtual void createExportFile(const agx::String& filename) = 0;
198 
205 
206  protected:
207  virtual ~IDataExporter();
208 
209  virtual void _finalizeExport(GranularDataExporter * exporter) = 0;
210 
211  virtual void _exportPreStep(const IndexHashSet& destroyedParticles) = 0;
212 
213  virtual void _exportPostStep(const IndexHashSet& destroyedParticles) = 0;
214 
216  bool hasAnalysisBox() const;
217 
219  // Variables
221  protected:
226  };
227 
228 
230  AGX_FORCE_INLINE bool GranularDataExporter::IDataExporter::hasAnalysisBox() const { return m_analysisBox != nullptr; }
232 
233 
237  class AGXPHYSICS_EXPORT GranularDataExporter::ContactDataExporter : public GranularDataExporter::IDataExporter
238  {
239  public:
241  ContactDataExporter(agx::Physics::GranularBodySystem * system);
242 
244  virtual void handleParticleDestroyed(agx::Index particleId) override;
245 
250  virtual void createExportFile(const agx::String& filename) override;
251 
257  virtual GranularDataExporter::ExporterDataType getType() const override;
258 
259  protected:
260  void exportContactInformation(const detail::ParticlePairContactInformation& information);
261 
262  void exportContactInformation(const detail::ParticleGeometryContactInformation& information);
263 
264  protected:
265  virtual ~ContactDataExporter();
266 
267  virtual void _finalizeExport(GranularDataExporter * exporter) override;
268 
269  virtual void _exportPreStep(const IndexHashSet& destroyedParticles) override;
270 
271  virtual void _exportPostStep(const IndexHashSet& destroyedParticles) override;
272  };
273 
277  class AGXPHYSICS_EXPORT GranularDataExporter::ParticleDataExporter : public GranularDataExporter::IDataExporter
278  {
279  public:
281  ParticleDataExporter(agx::Physics::GranularBodySystem * system);
282 
287  virtual void handleParticleDestroyed(agx::Index particleId) override;
288 
293  virtual void createExportFile(const agx::String& filename) override;
294 
300  virtual GranularDataExporter::ExporterDataType getType() const override;
301 
302  protected:
303  virtual ~ParticleDataExporter();
304 
305  agx::Real getAccumulatedImpactEnergyFromParticle(agx::Index particleId);
306 
307  virtual void _finalizeExport(GranularDataExporter * exporter) override;
308 
309  virtual void _exportPreStep(const IndexHashSet& destroyedParticles) override;
310 
311  virtual void _exportPostStep(const IndexHashSet& destroyedParticles) override;
312 
313  void writeParticleInformation(const detail::ParticleInformation& information);
314 
315  void updateParticleEnergyTable();
316 
318  // Variables
320  private:
321  typedef agx::HashTable<agx::Index, detail::ParticleInformation> ParticleImpactDataTable;
322  protected:
324  };
325 
329  class AGXPHYSICS_EXPORT GranularDataExporter::IDataFileWriter : public agx::Referenced
330  {
331  public:
338  IDataFileWriter(const agx::String& filePrefix, const agx::String& postFix, const agx::String& separator);
339 
340  protected:
341  virtual ~IDataFileWriter();
342 
343  agx::String generateTimeStamp() const;
344 
345  void generateFileNames();
346 
347  void writeOutputString(const agx::String& output);
348 
349  protected:
351  virtual agx::String getHeader() = 0;
352 
354  // Variables
356  protected:
361  std::ofstream m_outStream;
362  };
363 
368  {
369  public:
376  ParticleDataWriter(const agx::String& filePrefix, const agx::String& postFix, const agx::String& separator);
377 
382  void writeParticleInformation(const detail::ParticleInformation& info);
383 
384  protected:
385  virtual ~ParticleDataWriter();
386 
387  protected:
389  virtual agx::String getHeader() override;
390  };
391 
395  class AGXPHYSICS_EXPORT GranularDataExporter::ContactDataWriter : public agx::GranularDataExporter::IDataFileWriter
396  {
397  public:
404  ContactDataWriter(const agx::String& filePrefix, const agx::String& postFix, const agx::String& separator);
405 
410  void writeContact(const detail::ParticleGeometryContactInformation& contact);
411 
416  void writeContact(const detail::ParticlePairContactInformation& contact);
417 
418  protected:
419  virtual ~ContactDataWriter();
420 
421  protected:
422  virtual agx::String getHeader() override;
423 
425  // Variables
427  protected:
428  };
429 
431 
432  AGXPHYSICS_EXPORT agx::Physics::ParticlePairContactData * getParticlePairImpacts(agx::Physics::GranularBodySystem * system);
433 
434  AGXPHYSICS_EXPORT agx::Physics::ParticleGeometryContactData * getParticleGeometryImpacts(agx::Physics::GranularBodySystem * system);
435 
437 
439 }
440 
441 #endif
agxPhysics_export.h
agx::GranularDataExporter::getStartingParticleGeometryImpacts
IndexHashSet getStartingParticleGeometryImpacts()
Returns the indices for the particle-geometry impact contacts currently stored in the storage.
Definition: GranularDataExporter.h:142
agx::GranularDataExporter::m_postFix
agx::String m_postFix
Definition: GranularDataExporter.h:358
agx::GranularDataExporter::IDataExporter
IDataExporter(agx::Physics::GranularBodySystem *system)
Constructor.
GranularImpactDataWriter.h
agx::GranularDataExporter::m_exportedParticles
IndexHashSet m_exportedParticles
Definition: GranularDataExporter.h:225
agx::Real
double Real
Definition: Real.h:42
agxSDK::StepEventListener
Derive from this class to implement a listener for simulation step events.
Definition: StepEventListener.h:37
Simulation.h
agxData::getType
AGXCORE_EXPORT Type * getType(const agx::String &name)
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agx::detail::ParticleEventListener
Particle EventListener that can be inherited and overridden in order to listen to particle events.
Definition: GranularImpactDataWriter.h:58
agx::AnalysisBox
Class that can be used to extract data from elements in a simulation within a specified bound.
Definition: AnalysisBox.h:31
agxData::EntityStorage
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
agx::GranularDataExporter::IDataFileWriter
IDataFileWriter(const agx::String &filePrefix, const agx::String &postFix, const agx::String &separator)
Constructor for creating the file writer.
StepEventListener.h
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::GranularDataExporter::ExporterDataType
ExporterDataType
Export Data Type.
Definition: GranularDataExporter.h:65
agx::getParticleGeometryImpacts
AGXPHYSICS_EXPORT agx::Physics::ParticleGeometryContactData * getParticleGeometryImpacts(agx::Physics::GranularBodySystem *system)
agx::getParticleGeometryImpactsStorage
AGXPHYSICS_EXPORT agxData::EntityStorage * getParticleGeometryImpactsStorage(agx::Physics::GranularBodySystem *system)
agx::GranularDataExporter::m_startingParticlePairImpactContacts
IndexHashSet m_startingParticlePairImpactContacts
Definition: GranularDataExporter.h:139
agx::GranularDataExporter::PARTICLE_DATA
@ PARTICLE_DATA
Definition: GranularDataExporter.h:67
agx::ParticleSystem
A basic particle system that contains all the storages and buffers required for basic operation and a...
Definition: ParticleSystem.h:67
agx::GranularDataExporter::m_startingParticleGeometryImpactContacts
IndexHashSet m_startingParticleGeometryImpactContacts
Definition: GranularDataExporter.h:138
agx::ref_ptr< IDataExporter >
IndexSet.h
agx::detail::ParticleInformation
Definition: GranularImpactDataWriter.h:47
agx::GranularDataExporter
Class used to extract data from a granular journal, in the form of writing contact and particle data ...
Definition: GranularDataExporter.h:52
agx::getParticlePairImpacts
AGXPHYSICS_EXPORT agx::Physics::ParticlePairContactData * getParticlePairImpacts(agx::Physics::GranularBodySystem *system)
agx::Index
UInt32 Index
Definition: Integer.h:52
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:871
agx::GranularDataExporter::getStartingParticlePairImpacts
IndexHashSet getStartingParticlePairImpacts()
Returns the indices for the particle-particle impact contacts currently stored in the storage.
Definition: GranularDataExporter.h:147
agx::GranularDataExporter::m_system
agx::Physics::GranularBodySystem * m_system
Definition: GranularDataExporter.h:136
agx::addGranularImpactCustomBuffers
AGXPHYSICS_EXPORT void addGranularImpactCustomBuffers(agx::ParticleSystem *system)
agx::Physics::GranularBodySystem
Definition: GranularBodySystem.h:32
agx::GranularDataExporter::m_fileprefix
agx::String m_fileprefix
Definition: GranularDataExporter.h:357
agx::HashSet< agx::Index >
agx::GranularDataExporter::m_particleImpactDataTable
ParticleImpactDataTable m_particleImpactDataTable
Definition: GranularDataExporter.h:323
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
agx::GranularDataExporter::m_fileWriter
IDataFileWriterRef m_fileWriter
Definition: GranularDataExporter.h:223
AnalysisBox.h
agx::AgXString< std::string >
agx::GranularDataExporter::m_outStream
std::ofstream m_outStream
Definition: GranularDataExporter.h:361
agx::init
void AGXPHYSICS_EXPORT init()
Initialize agx.
agx::GranularDataExporter::m_separator
agx::String m_separator
Definition: GranularDataExporter.h:359
agx::GranularDataExporter::m_analysisBox
agx::AnalysisBox * m_analysisBox
Definition: GranularDataExporter.h:224
agx::GranularDataExporter::m_dataExporter
IDataExporterRef m_dataExporter
Definition: GranularDataExporter.h:137
agx::getParticlePairImpactsStorage
AGXPHYSICS_EXPORT agxData::EntityStorage * getParticlePairImpactsStorage(agx::Physics::GranularBodySystem *system)
GranularBodySystem.h
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::IndexHashSet
agx::HashSet< agx::Index > IndexHashSet
Definition: agx_hash_types.h:59
agx::GranularDataExporter::m_completeName
agx::String m_completeName
Definition: GranularDataExporter.h:360