VTK  9.1.0
LSDynaFamily.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: LSDynaFamily.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
15/*----------------------------------------------------------------------------
16 Copyright (c) Sandia Corporation
17 See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
18----------------------------------------------------------------------------*/
19
20// .NAME LSDynaFamily
21// .SECTION Description
22// A class to abstract away I/O from families of output files.
23// This performs the actual reads and writes plus any required byte swapping.
24// Also contains a subclass, LSDynaFamilyAdaptLevel, used to store
25// file+offset
26// information for each mesh adaptation's state info.
27
28#ifndef __LSDynaFamily_h
29#define __LSDynaFamily_h
30
31#include "vtkType.h"
32
33#include <fcntl.h>
34#include <iostream>
35#include <stdio.h>
36#include <string.h>
37#include <string>
38#include <sys/stat.h>
39#include <sys/types.h>
40#include <vector>
41
42// this is needs to be moved over to fseekpos and ftellpos
43// in the future
44#ifndef _WIN32
45#include <unistd.h>
46typedef off_t vtkLSDynaOff_t; // sanity
47typedef int vtkLSDynaFile_t;
48#define VTK_LSDYNA_BADFILE -1
49#define VTK_LSDYNA_TELL(fid) lseek(fid, 0, SEEK_CUR)
50#define VTK_LSDYNA_SEEK(fid, off, whence) lseek(fid, off, whence)
51#define VTK_LSDYNA_SEEKTELL(fid, off, whence) lseek(fid, off, whence)
52#define VTK_LSDYNA_READ(fid, ptr, cnt) read(fid, ptr, cnt)
53#define VTK_LSDYNA_ISBADFILE(fid) (fid < 0)
54#define VTK_LSDYNA_CLOSEFILE(fid) close(fid)
55#else // _WIN32
56typedef long vtkLSDynaOff_t; // insanity
57typedef FILE* vtkLSDynaFile_t;
58#define VTK_LSDYNA_BADFILE 0
59#define VTK_LSDYNA_TELL(fid) ftell(fid)
60#define VTK_LSDYNA_SEEK(fid, off, whence) fseek(fid, off, whence)
61#define VTK_LSDYNA_SEEKTELL(fid, off, whence) fseek(fid, off, whence), ftell(fid)
62#define VTK_LSDYNA_READ(fid, ptr, cnt) fread(ptr, 1, cnt, fid)
63#define VTK_LSDYNA_ISBADFILE(fid) (fid == 0)
64#define VTK_LSDYNA_CLOSEFILE(fid) fclose(fid)
65#endif
66#ifdef VTKSNL_HAVE_ERRNO_H
67#include <errno.h>
68#endif
69
71{
72public:
75
77 {
80 };
81
84
87
89
91 {
92 // These are the "section" marks:
93 // They are absolute (independent of current timestep).
97 // These are the "subsection" marks:
98 // == ControlSection has no subsections
99 // == StaticSection has these "absolute" marks:
109 // == TimeStepSection has these marks, relative to timestep 0 (so they are
110 // not valid for an arbitrary timestep, but may easily be used to compute
111 // an offset for any time step by adding a multiple of the state size):
115 // THIS MUST BE LAST
117 };
118
120 {
121 public:
123
125 {
127 mark.FileNumber = 0;
128 mark.Offset = 0;
129 for (int i = 0; i < LSDynaFamily::NumberOfSectionTypes; ++i)
130 {
131 this->Marks[i] = mark;
132 }
133 }
134 };
135
136 static const char* SectionTypeNames[];
137
139 {
142 Int
143 };
144
145 static const float EOFMarker;
146 static const char* SectionTypeToString(SectionType s);
147
148 int SkipToWord(SectionType sType, vtkIdType sId, vtkIdType wordNumber);
150 int SkipWords(vtkIdType numWords);
151 int BufferChunk(WordType wType, vtkIdType chunkSizeInWords);
153
154 // Description:
155 // Setup reading of a number of words to be split across multiple
156 // bufferChunk. This is used to read really large buffer sections
157 // in more reasonable sizes. The parameters are used to specify the total buffer
158 // size. The buffer size will always be evenly divisable by numComps and total
159 // word size of all buffers will be numTuples*numComps
160 vtkIdType InitPartialChunkBuffering(const vtkIdType& numTuples, const vtkIdType& numComps);
162
163 inline char* GetNextWordAsChars();
164 inline double GetNextWordAsFloat();
166
167 // Get the raw chunk buffer as a buffer of type T
168 template <typename T>
169 T* GetBufferAs();
170
171 // Not needed (yet):
172 // void GetCurrentWord( SectionType& stype, vtkIdType& sId, vtkIdType& wN );
174 void MarkSectionStart(int adaptLevel, SectionType m);
175
178
181
185
186 int GetCurrentAdaptLevel() const { return this->FAdapt; }
187 int TimeAdaptLevel(int i) const { return this->TimeAdaptLevels[i]; }
188
189 vtkIdType GetCurrentFWord() const { return this->FWord; }
190
191 int GetWordSize() const;
192 // Reset erases all information about the current database.
193 // It does not free memory allocated for the current chunk.
194 void Reset();
195
197 void DumpMarks(std::ostream& os);
198
199 // Closes the current file descripter. This is called after
200 // we are done reading in request data
202
204
205protected:
212 std::vector<std::string> Files;
215 std::vector<vtkIdType> FileSizes;
217 std::vector<int> FileAdaptLevels;
220 std::vector<int> Adaptations;
232 // std::vector<double> TimeValues;
243 std::vector<LSDynaFamilyAdaptLevel> AdaptationsMarkers;
246 std::vector<LSDynaFamilySectionMark> TimeStepMarks;
248 std::vector<int> TimeAdaptLevels;
250 unsigned char* Chunk;
254 // How much of the allocated space is filled with valid data (assert
255 // ChunkValid <= ChunkAlloc).
259
261 struct BufferingInfo;
262 BufferingInfo* BufferInfo;
263};
264
265//-----------------------------------------------------------------------------
267{
268 if (this->ChunkWord >= this->ChunkValid)
269 fprintf(stderr, "Read char past end of buffer\n");
270 return (char*)(&this->Chunk[(this->ChunkWord++) * this->WordSize]);
271}
272
273//-----------------------------------------------------------------------------
275{
276 if (this->ChunkWord >= this->ChunkValid)
277 fprintf(stderr, "Read float past end of buffer\n");
278 switch (this->WordSize)
279 {
280 case 4:
281 {
282 vtkTypeFloat32 value;
283 memcpy(&value, &this->Chunk[this->ChunkWord++ << 2], sizeof(value));
284 return value;
285 }
286 case 8:
287 default:
288 {
289 vtkTypeFloat64 value;
290 memcpy(&value, &this->Chunk[this->ChunkWord++ << 3], sizeof(value));
291 return value;
292 }
293 }
294}
295
296//-----------------------------------------------------------------------------
298{
299 if (this->ChunkWord >= this->ChunkValid)
300 {
301 fprintf(stderr, "Read int past end of buffer\n");
302 }
303 switch (this->WordSize)
304 {
305 case 4:
306 {
307 vtkTypeInt32 value;
308 memcpy(&value, &this->Chunk[this->ChunkWord++ << 2], sizeof(value));
309 return value;
310 }
311 case 8:
312 default:
313 {
315 memcpy(&value, &this->Chunk[this->ChunkWord++ << 3], sizeof(value));
316 return value;
317 }
318 }
319}
320
321//-----------------------------------------------------------------------------
322template <typename T>
324{
325 return reinterpret_cast<T*>(this->Chunk);
326}
327
328#endif // __LSDynaFamily_h
int vtkLSDynaFile_t
Definition: LSDynaFamily.h:47
off_t vtkLSDynaOff_t
Definition: LSDynaFamily.h:46
LSDynaFamilySectionMark Marks[NumberOfSectionTypes]
Definition: LSDynaFamily.h:122
vtkIdType GetCurrentFWord() const
Definition: LSDynaFamily.h:189
int BufferChunk(WordType wType, vtkIdType chunkSizeInWords)
int ScanDatabaseDirectory()
vtkIdType GetNextWordAsInt()
Definition: LSDynaFamily.h:297
static const char * SectionTypeNames[]
Definition: LSDynaFamily.h:136
unsigned char * Chunk
A buffer containing file contents of file FNum starting with word FWord.
Definition: LSDynaFamily.h:250
bool FileHandlesClosed
Definition: LSDynaFamily.h:260
BufferingInfo * BufferInfo
Definition: LSDynaFamily.h:262
vtkIdType StateSize
How many words is a timestep on disk?
Definition: LSDynaFamily.h:240
void SetDatabaseBaseName(const std::string &bn)
int WordSize
Whether words are 4 or 8 bytes.
Definition: LSDynaFamily.h:238
std::vector< int > Adaptations
Which files mark the start of a new mesh adaptation.
Definition: LSDynaFamily.h:220
std::vector< int > TimeAdaptLevels
The adaptation level associated with each time step.
Definition: LSDynaFamily.h:248
void OpenFileHandles()
int GetCurrentAdaptLevel() const
Definition: LSDynaFamily.h:186
void CloseFileHandles()
std::vector< LSDynaFamilyAdaptLevel > AdaptationsMarkers
A vector of arrays of offsets to various header information sections (that do not vary with timestep)...
Definition: LSDynaFamily.h:243
static const float EOFMarker
Definition: LSDynaFamily.h:145
int DetermineStorageModel()
int SkipToWord(SectionType sType, vtkIdType sId, vtkIdType wordNumber)
vtkIdType TimeStep
A comprehensive list of all time values across all files (and mesh adaptations)
Definition: LSDynaFamily.h:234
int AdvanceFile()
double GetNextWordAsFloat()
Definition: LSDynaFamily.h:274
vtkIdType GetNumberOfFiles()
int FAdapt
The current adaptation level.
Definition: LSDynaFamily.h:227
int SkipWords(vtkIdType numWords)
int SwapEndian
Whether files are reverse endian-ness of architecture.
Definition: LSDynaFamily.h:236
vtkIdType GetNextChunk(const WordType &wType)
std::string GetDatabaseBaseName()
int MarkTimeStep()
std::string GetDatabaseDirectory()
vtkIdType FNum
The index of currently open file descriptor into list of files.
Definition: LSDynaFamily.h:224
std::vector< vtkIdType > FileSizes
The size of each file in the database.
Definition: LSDynaFamily.h:215
int GetWordSize() const
void SetDatabaseDirectory(const std::string &dd)
std::string DatabaseDirectory
The directory containing d3plot files.
Definition: LSDynaFamily.h:207
vtkLSDynaFile_t FD
The currently open file descriptor.
Definition: LSDynaFamily.h:222
vtkIdType GetStateSize() const
vtkIdType ChunkWord
A pointer to the next word in Chunk that will be returned when the reader requests a word.
Definition: LSDynaFamily.h:253
vtkIdType GetFileSize(int i)
vtkIdType InitPartialChunkBuffering(const vtkIdType &numTuples, const vtkIdType &numComps)
std::vector< int > FileAdaptLevels
The adaptation level associated with each file.
Definition: LSDynaFamily.h:217
void DumpMarks(std::ostream &os)
Print all adaptation and time step marker information.
vtkIdType ChunkAlloc
The allocated size (in words) of Chunk.
Definition: LSDynaFamily.h:258
std::string DatabaseBaseName
The name (title string) of the database.
Definition: LSDynaFamily.h:210
int ClearBuffer()
int TimeAdaptLevel(int i) const
Definition: LSDynaFamily.h:187
T * GetBufferAs()
Definition: LSDynaFamily.h:323
void MarkSectionStart(int adaptLevel, SectionType m)
vtkIdType ChunkValid
Definition: LSDynaFamily.h:256
std::string GetFileName(int i)
void SetStateSize(vtkIdType sz)
static const char * SectionTypeToString(SectionType s)
std::vector< LSDynaFamilySectionMark > TimeStepMarks
An array of bookmarks pointing to the start of state information for each timestep.
Definition: LSDynaFamily.h:246
int JumpToMark(SectionType m)
char * GetNextWordAsChars()
Definition: LSDynaFamily.h:266
std::vector< std::string > Files
The list of files that make up the database.
Definition: LSDynaFamily.h:212
vtkIdType FWord
The offset of Chunk in currently open file.
Definition: LSDynaFamily.h:229
@ value
Definition: vtkX3D.h:226
@ string
Definition: vtkX3D.h:496
int vtkIdType
Definition: vtkType.h:332