AGX Dynamics  2.35.0.1
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 
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 
104 
111 
116 
117  protected:
119 
120  virtual void onParticleCreated(agx::Index id) override;
121 
122  virtual void onParticleDestroyed(agx::Index id) override;
123 
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:
161 
168 
173  void exportPreStep(const IndexHashSet& destroyedParticles);
174 
179  void exportPostStep(const IndexHashSet& destroyedParticles);
180 
185  virtual void handleParticleDestroyed(agx::Index particleId);
186 
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:
242 
244  virtual void handleParticleDestroyed(agx::Index particleId) override;
245 
250  virtual void createExportFile(const agx::String& filename) override;
251 
258 
259  protected:
261 
263 
264  protected:
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 
278  {
279  public:
282 
287  virtual void handleParticleDestroyed(agx::Index particleId) override;
288 
293  virtual void createExportFile(const agx::String& filename) override;
294 
301 
302  protected:
304 
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 
314 
316 
318  // Variables
320  private:
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 
344 
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 
383 
384  protected:
386 
387  protected:
389  virtual agx::String getHeader() override;
390  };
391 
396  {
397  public:
404  ContactDataWriter(const agx::String& filePrefix, const agx::String& postFix, const agx::String& separator);
405 
411 
417 
418  protected:
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
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXPHYSICS_EXPORT
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
Derive from this class to implement a listener for simulation step events.
Class that can be used to extract data from elements in a simulation within a specified bound.
Definition: AnalysisBox.h:32
Class used to extract data from a granular journal, in the form of writing contact and particle data ...
virtual void onParticleDestroyed(agx::Index id) override
virtual agx::String getHeader() override
Each FileWriter implementation implements a different header, since different data is exported.
IndexHashSet m_startingParticleGeometryImpactContacts
virtual void _exportPostStep(const IndexHashSet &destroyedParticles)=0
void finalizeExport(GranularDataExporter *exporter)
Called during the last steps of the export.
void writeOutputString(const agx::String &output)
IDataExporter(agx::Physics::GranularBodySystem *system)
Constructor.
IndexHashSet getStartingParticleGeometryImpacts()
Returns the indices for the particle-geometry impact contacts currently stored in the storage.
void setAnalysisBox(agx::AnalysisBox *box)
Sets the AnalysisBox that should be used by the exporter.
void writeContact(const detail::ParticleGeometryContactInformation &contact)
Writes particle information to file.
virtual void _finalizeExport(GranularDataExporter *exporter) override
virtual GranularDataExporter::ExporterDataType getType() const override
Returns the type of the exporter, which is overridden by child classes.
void writeParticleInformation(const detail::ParticleInformation &info)
Writes particle information to file.
void exportPostStep(const IndexHashSet &destroyedParticles)
Manually called by the exporter parent when performing pre export step.
virtual void handleParticleDestroyed(agx::Index particleId) override
Is called when a particle is destroyed in the simulation.
IDataFileWriter(const agx::String &filePrefix, const agx::String &postFix, const agx::String &separator)
Constructor for creating the file writer.
static agx::String convertExportDataTypeToFilename(ExporterDataType exportDataType)
Convert export data type to filename.
void exportPreStep(const IndexHashSet &destroyedParticles)
Manually called by the exporter parent when performing pre export step.
IndexHashSet m_startingParticlePairImpactContacts
virtual void handleParticleDestroyed(agx::Index particleId)
Callback that is called when a particle is destroyed.
void exportContactInformation(const detail::ParticlePairContactInformation &information)
virtual void onParticleCreated(agx::Index id) override
agx::Physics::GranularBodySystem * m_system
virtual void _finalizeExport(GranularDataExporter *exporter)=0
ParticleDataExporter(agx::Physics::GranularBodySystem *system)
Constructor.
virtual void _exportPreStep(const IndexHashSet &destroyedParticles)=0
ContactDataExporter(agx::Physics::GranularBodySystem *system)
Default constructor.
virtual agx::String getHeader()=0
Each FileWriter implementation implements a different header, since different data is exported.
ParticleImpactDataTable m_particleImpactDataTable
ContactDataWriter(const agx::String &filePrefix, const agx::String &postFix, const agx::String &separator)
Constructor for creating the file writer.
virtual void pre(const agx::TimeStamp &) override
Pre step function.
IndexHashSet getStartingParticlePairImpacts()
Returns the indices for the particle-particle impact contacts currently stored in the storage.
agx::String generateTimeStamp() const
void setExporterType(ExporterDataType type)
Sets the exporter type, i.e which type of data that should be exported.
virtual void _exportPreStep(const IndexHashSet &destroyedParticles) override
virtual GranularDataExporter::ExporterDataType getType() const =0
Returns the type of the exporter, which is overridden by child classes.
virtual void createExportFile(const agx::String &filename)=0
Sets and creates a file with the given path where the exporter writes information.
agx::Real getAccumulatedImpactEnergyFromParticle(agx::Index particleId)
void init()
Initializes the exporter.
void exportContactInformation(const detail::ParticleGeometryContactInformation &information)
virtual void _exportPostStep(const IndexHashSet &destroyedParticles) override
virtual void post(const agx::TimeStamp &) override
Post step function.
agx::AnalysisBox * m_analysisBox
void finalizeAfterSimulation()
Function that is called manually after the simulation is done.
void writeParticleInformation(const detail::ParticleInformation &information)
void writeContact(const detail::ParticlePairContactInformation &contact)
Writes particle information to file.
ParticleDataWriter(const agx::String &filePrefix, const agx::String &postFix, const agx::String &separator)
Constructor for creating the file writer.
virtual void createExportFile(const agx::String &filename) override
Creates the file which the contact data should be written to.
void writeToFile(const agx::String &file)
Sets and creates a file with the given path where the exporter writes information.
GranularDataExporter(agx::Physics::GranularBodySystem *system)
Constructor of GranularDataExporter.
Inheritance with partial specialization due to bug with ref_ptr containers.
A basic particle system that contains all the storages and buffers required for basic operation and a...
Base class providing referencing counted objects.
Definition: Referenced.h:114
Particle EventListener that can be inherited and overridden in order to listen to particle events.
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
AGXPHYSICS_EXPORT agx::Physics::ParticlePairContactData * getParticlePairImpacts(agx::Physics::GranularBodySystem *system)
AGXPHYSICS_EXPORT agxData::EntityStorage * getParticlePairImpactsStorage(agx::Physics::GranularBodySystem *system)
AGXPHYSICS_EXPORT void addGranularImpactCustomBuffers(agx::ParticleSystem *system)
AGXPHYSICS_EXPORT agx::Physics::ParticleGeometryContactData * getParticleGeometryImpacts(agx::Physics::GranularBodySystem *system)
double Real
Definition: Real.h:42
agx::Real TimeStamp
Definition: TimeStamp.h:26
AGXPHYSICS_EXPORT agxData::EntityStorage * getParticleGeometryImpactsStorage(agx::Physics::GranularBodySystem *system)
UInt32 Index
Definition: Integer.h:52