AGX Dynamics  2.37.2.0
GranularDataExporter.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 
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:
322  protected:
323  ParticleImpactDataTable m_particleImpactDataTable;
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 
367  class AGXPHYSICS_EXPORT GranularDataExporter::ParticleDataWriter : public agx::GranularDataExporter::IDataFileWriter
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
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
AGXCORE_EXPORT Type * getType(const agx::String &name)
agx::AnalysisBox * m_analysisBox
Derive from this class to implement a listener for simulation step events.
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
AGXPHYSICS_EXPORT void addGranularImpactCustomBuffers(agx::ParticleSystem *system)
agx::Physics::GranularBodySystem * m_system
IndexHashSet getStartingParticleGeometryImpacts()
Returns the indices for the particle-geometry impact contacts currently stored in the storage...
#define AGXPHYSICS_EXPORT
IDataExporter(agx::Physics::GranularBodySystem *system)
Constructor.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
agx::Real TimeStamp
Definition: TimeStamp.h:26
Class used to extract data from a granular journal, in the form of writing contact and particle data ...
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGXPHYSICS_EXPORT agxData::EntityStorage * getParticleGeometryImpactsStorage(agx::Physics::GranularBodySystem *system)
IndexHashSet getStartingParticlePairImpacts()
Returns the indices for the particle-particle impact contacts currently stored in the storage...
A basic particle system that contains all the storages and buffers required for basic operation and a...
AGXPHYSICS_EXPORT agxData::EntityStorage * getParticlePairImpactsStorage(agx::Physics::GranularBodySystem *system)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
IDataFileWriter(const agx::String &filePrefix, const agx::String &postFix, const agx::String &separator)
Constructor for creating the file writer.
ExporterDataType
Export Data Type.
UInt32 Index
Definition: Integer.h:52
AGXPHYSICS_EXPORT agx::Physics::ParticleGeometryContactData * getParticleGeometryImpacts(agx::Physics::GranularBodySystem *system)
Particle EventListener that can be inherited and overridden in order to listen to particle events...
ParticleImpactDataTable m_particleImpactDataTable
Class that can be used to extract data from elements in a simulation within a specified bound...
Definition: AnalysisBox.h:31
IndexHashSet m_startingParticlePairImpactContacts
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
AGXPHYSICS_EXPORT agx::Physics::ParticlePairContactData * getParticlePairImpacts(agx::Physics::GranularBodySystem *system)
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
IndexHashSet m_startingParticleGeometryImpactContacts