IFEM  90A354
DataExporter.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
12 //==============================================================================
13 
14 #ifndef _DATA_EXPORTER_H
15 #define _DATA_EXPORTER_H
16 
17 #include "ControlFIFO.h"
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 class DataWriter;
23 class ProcessAdm;
24 class TimeStep;
25 namespace utl {
26 class LogStream;
27 }
28 
29 
38 {
39 public:
41  enum FieldType {
42  VECTOR,
43  INTVECTOR,
44  KNOTSPAN,
45  SIM,
46  NODALFORCES,
47  BASIS
48  };
49 
51  enum Results {
52  PRIMARY = 1,
54  SECONDARY = 4,
55  NORMS = 8,
56  EIGENMODES = 16,
57  ONCE = 32,
58  GRID = 128,
59  REDUNDANT = 256,
60  L2G_NODE = 512,
61  ELEMENT_MASK = 1024
62  };
63 
65  struct FileEntry {
66  std::string description;
68  int results;
72  const void* data;
73  std::vector<const void*> data2;
74  std::string prefix;
75  bool enabled;
76  int ncmps;
77  };
78 
83  DataExporter(bool dynWriters = false, int ndump = 1, int level0 = 0) :
84  m_delete(dynWriters), m_ndump(ndump), m_level(level0-1), m_last_step(-1) {}
85 
87  virtual ~DataExporter();
88 
90  void registerWriter(DataWriter* writer) { m_writers.push_back(writer); }
91 
99  bool registerField(const std::string& name,
100  const std::string& description,
101  FieldType field, int results = PRIMARY,
102  const std::string& prefix = "", int ncmps = 0);
103 
110  bool setFieldValue(const std::string& name,
111  const void* data,
112  const void* data2=nullptr,
113  const void* data3=nullptr,
114  const void* data4=nullptr);
115 
120  bool dumpTimeLevel(const TimeStep* tp = nullptr,
121  bool geoUpd = false, bool doLog = false);
122 
124  virtual void OnControl(const tinyxml2::XMLElement* context);
126  virtual std::string GetContext() const { return "datawriter"; }
127 
129  std::string getName() const;
130 
132  int getTimeLevel() const { return m_level; }
134  int getStride() const { return m_ndump; }
135 
136 protected:
138  std::map<std::string,FileEntry> m_entry;
140  std::vector<DataWriter*> m_writers;
141 
142  bool m_delete;
143  int m_ndump;
144  int m_level;
146 };
147 
149 using DataEntry = std::pair<std::string,DataExporter::FileEntry>;
150 
151 
160 {
161 protected:
163  DataWriter(const std::string& name, const ProcessAdm& adm,
164  const char* defaultExt = nullptr);
165 
166 public:
168  virtual ~DataWriter() {}
169 
171  virtual int getLastTimeLevel() = 0;
172 
175  virtual void openFile(int level) = 0;
176 
179  virtual void closeFile(int level) = 0;
180 
184  virtual void writeVector(int level, const DataEntry& entry) = 0;
185 
192  virtual void writeSIM(int level, double time, const DataEntry& entry,
193  bool geometryUpdated, const std::string& prefix) = 0;
194 
198  virtual void writeNodalForces(int level, const DataEntry& entry) = 0;
199 
204  virtual void writeKnotspan(int level, const DataEntry& entry,
205  const std::string& prefix) = 0;
206 
211  virtual void writeBasis(int level, const DataEntry& entry,
212  const std::string& prefix) = 0;
213 
217  virtual bool writeTimeInfo(int level, double time) = 0;
218 
222  virtual bool writeLog(const std::string& data, const std::string& name) = 0;
223 
225  const std::string& getName() const { return m_name; }
226 
227 protected:
228  std::string m_name;
229 
230  int m_size;
231  int m_rank;
232 };
233 
234 #endif
Application control over a FIFO.
std::pair< std::string, DataExporter::FileEntry > DataEntry
Convenience type alias.
Definition: DataExporter.h:149
Callback for FIFO option handling.
Definition: ControlFIFO.h:28
Administer and write data using DataWriters.
Definition: DataExporter.h:38
std::string getName() const
Returns name from (first) data writer.
Definition: DataExporter.C:189
int m_level
Current time level.
Definition: DataExporter.h:144
Results
An enum used to describe the results to write from a SIM.
Definition: DataExporter.h:51
@ REDUNDANT
Field is redundantly calculated on all processes.
Definition: DataExporter.h:59
@ NORMS
Storage of norms.
Definition: DataExporter.h:55
@ SECONDARY
Storage of secondary field.
Definition: DataExporter.h:54
@ EIGENMODES
Storage of eigenmodes.
Definition: DataExporter.h:56
@ PRIMARY
Storage of primary solutions.
Definition: DataExporter.h:52
@ ELEMENT_MASK
Storage of element activation flags.
Definition: DataExporter.h:61
@ ONCE
Only write field once.
Definition: DataExporter.h:57
@ GRID
Always store an updated grid.
Definition: DataExporter.h:58
@ DISPLACEMENT
Storage of vector fields as displacements.
Definition: DataExporter.h:53
@ L2G_NODE
Storage of local-to-global node mapping.
Definition: DataExporter.h:60
int getStride() const
Returns the data dump stride.
Definition: DataExporter.h:134
bool dumpTimeLevel(const TimeStep *tp=nullptr, bool geoUpd=false, bool doLog=false)
Dumps all registered fields using the registered writers.
Definition: DataExporter.C:95
std::map< std::string, FileEntry > m_entry
A map of field names -> field info structures.
Definition: DataExporter.h:138
virtual std::string GetContext() const
Returns context name for callback for external controller.
Definition: DataExporter.h:126
bool registerField(const std::string &name, const std::string &description, FieldType field, int results=PRIMARY, const std::string &prefix="", int ncmps=0)
Registers an entry for storage.
Definition: DataExporter.C:52
std::vector< DataWriter * > m_writers
A vector of registered data writers.
Definition: DataExporter.h:140
virtual ~DataExporter()
The destructor deletes the writers if dynWriters was true.
Definition: DataExporter.C:37
DataExporter(bool dynWriters=false, int ndump=1, int level0=0)
Default constructor.
Definition: DataExporter.h:83
virtual void OnControl(const tinyxml2::XMLElement *context)
Callback on receiving a XML control block from external controller.
Definition: DataExporter.C:167
FieldType
Supported field types.
Definition: DataExporter.h:41
void registerWriter(DataWriter *writer)
Adds the data writer to the list of registered writers.
Definition: DataExporter.h:90
int m_ndump
Time level stride for dumping.
Definition: DataExporter.h:143
bool m_delete
If true, we are in charge of freeing up datawriters.
Definition: DataExporter.h:142
bool setFieldValue(const std::string &name, const void *data, const void *data2=nullptr, const void *data3=nullptr, const void *data4=nullptr)
Sets the data values for a registered field.
Definition: DataExporter.C:76
int getTimeLevel() const
Returns current time level of the exporter.
Definition: DataExporter.h:132
int m_last_step
Last time step we dumped for.
Definition: DataExporter.h:145
Stores and reads data from a file.
Definition: DataExporter.h:160
virtual void closeFile(int level)=0
Closes the file.
int m_rank
MPI rank (processor ID)
Definition: DataExporter.h:231
virtual void writeVector(int level, const DataEntry &entry)=0
Writes a vector to file.
int m_size
Number of MPI nodes (processors)
Definition: DataExporter.h:230
virtual void writeSIM(int level, double time, const DataEntry &entry, bool geometryUpdated, const std::string &prefix)=0
Writes data from a SIM object to file.
virtual void openFile(int level)=0
Opens the file at a given time level.
virtual bool writeLog(const std::string &data, const std::string &name)=0
Write a log to output file.
virtual int getLastTimeLevel()=0
Returns the last time level stored in file.
virtual void writeBasis(int level, const DataEntry &entry, const std::string &prefix)=0
Write a basis to file.
virtual bool writeTimeInfo(int level, double time)=0
Writes time stepping info to file.
virtual void writeNodalForces(int level, const DataEntry &entry)=0
Writes nodal forces to file.
virtual ~DataWriter()
Empty destructor.
Definition: DataExporter.h:168
const std::string & getName() const
Returns the name of the file.
Definition: DataExporter.h:225
DataWriter(const std::string &name, const ProcessAdm &adm, const char *defaultExt=nullptr)
Protected constructor as this is a purely virtual class.
Definition: DataExporter.C:23
virtual void writeKnotspan(int level, const DataEntry &entry, const std::string &prefix)=0
Writes a knotspan field to file.
std::string m_name
File name.
Definition: DataExporter.h:228
Class for administration of MPI processes in IFEM library.
Definition: ProcessAdm.h:33
Class for encapsulation of general time stepping parameters.
Definition: TimeStep.h:31
Simulation scope.
Definition: ForceIntegrator.h:27
General utility classes and functions.
Definition: SIMoptions.h:22
A structure holding information about registered fields.
Definition: DataExporter.h:65
std::vector< const void * > data2
Pointers to the secondary data (e.g. a vector)
Definition: DataExporter.h:73
int ncmps
Number of components. Use to override SIM info.
Definition: DataExporter.h:76
bool enabled
Whether or not field is enabled.
Definition: DataExporter.h:75
std::string prefix
Field name prefix.
Definition: DataExporter.h:74
FieldType field
The type of the field.
Definition: DataExporter.h:67
std::string description
The description of the field.
Definition: DataExporter.h:66
const void * data
Pointer to the primary data (e.g. a SIM class)
Definition: DataExporter.h:72
int results
Which results to store.
Definition: DataExporter.h:68