VTK
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#include "LSDynaExport.h"
33
34#include <string.h>
35#include <stdio.h>
36#include <iostream>
37#include <string>
38#include <vector>
39#include <sys/types.h>
40#include <sys/stat.h>
41#include <fcntl.h>
42
43//this is needs to be moved over to fseekpos and ftellpos
44//in the future
45#ifndef _WIN32
46# include <unistd.h>
47typedef off_t vtkLSDynaOff_t; // sanity
48typedef int vtkLSDynaFile_t;
49# define VTK_LSDYNA_BADFILE -1
50# define VTK_LSDYNA_TELL(fid) lseek( fid, 0, SEEK_CUR )
51# define VTK_LSDYNA_SEEK(fid,off,whence) lseek( fid, off, whence )
52# define VTK_LSDYNA_SEEKTELL(fid,off,whence) lseek( fid, off, whence )
53# define VTK_LSDYNA_READ(fid,ptr,cnt) read(fid,ptr,cnt)
54# define VTK_LSDYNA_ISBADFILE(fid) (fid < 0)
55# define VTK_LSDYNA_CLOSEFILE(fid) close(fid)
56#else // _WIN32
57typedef long vtkLSDynaOff_t; // insanity
58typedef FILE* vtkLSDynaFile_t;
59# define VTK_LSDYNA_BADFILE 0
60# define VTK_LSDYNA_TELL(fid) ftell( fid )
61# define VTK_LSDYNA_SEEK(fid,off,whence) fseek( fid, off, whence )
62# define VTK_LSDYNA_SEEKTELL(fid,off,whence) fseek( fid, off, whence ), ftell( fid )
63# define VTK_LSDYNA_READ(fid,ptr,cnt) fread(ptr,1,cnt,fid)
64# define VTK_LSDYNA_ISBADFILE(fid) (fid == 0)
65# define VTK_LSDYNA_CLOSEFILE(fid) fclose(fid)
66#endif
67#ifdef VTKSNL_HAVE_ERRNO_H
68# include <errno.h>
69#endif
70
72{
73public:
76
78 {
81 };
82
85
88
90
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
138 enum WordType {
141 Int
142 };
143
144 static const float EOFMarker;
145 static const char* SectionTypeToString( SectionType s );
146
147 int SkipToWord( SectionType sType, vtkIdType sId, vtkIdType wordNumber );
149 int SkipWords( vtkIdType numWords );
150 int BufferChunk( WordType wType, vtkIdType chunkSizeInWords );
152
153 //Description:
154 //Setup reading of a number of words to be split across multiple
155 //bufferChunk. This is used to read really large buffer sections
156 //in more reasonable sizes. The paramters are used to specify the total buffer
157 //size. The buffer size will always be evenly divisable by numComps and total
158 //word size of all buffers will be numTuples*numComps
159 vtkIdType InitPartialChunkBuffering(const vtkIdType& numTuples, const vtkIdType& numComps );
161
162 inline char* GetNextWordAsChars();
163 inline double GetNextWordAsFloat();
165
166 //Get the raw chunk buffer as a buffer of type T
167 template<typename T>
168 T* GetBufferAs();
169
170 // Not needed (yet):
171 // void GetCurrentWord( SectionType& stype, vtkIdType& sId, vtkIdType& wN );
173 void MarkSectionStart( int adapteLevel, SectionType m );
174
177
180
184
185 int GetCurrentAdaptLevel() const { return this->FAdapt; }
186 int TimeAdaptLevel( int i ) const { return this->TimeAdaptLevels[i]; }
187
188 vtkIdType GetCurrentFWord() const { return this->FWord; }
189
190 int GetWordSize() const;
191 // Reset erases all information about the current database.
192 // It does not free memory allocated for the current chunk.
193 void Reset();
194
196 void DumpMarks( std::ostream& os );
197
198 //Closes the current file descripter. This is called after
199 //we are done reading in request data
201
203
204protected:
211 std::vector<std::string> Files;
214 std::vector<vtkIdType> FileSizes;
216 std::vector<int> FileAdaptLevels;
219 std::vector<int> Adaptations;
231 //std::vector<double> TimeValues;
242 std::vector<LSDynaFamilyAdaptLevel> AdaptationsMarkers;
245 std::vector<LSDynaFamilySectionMark> TimeStepMarks;
247 std::vector<int> TimeAdaptLevels;
249 unsigned char* Chunk;
253 // How much of the the allocated space is filled with valid data (assert
254 // ChunkValid <= ChunkAlloc).
258
260 struct BufferingInfo;
261 BufferingInfo* BufferInfo;
262};
263
264//-----------------------------------------------------------------------------
266{
267 if ( this->ChunkWord >= this->ChunkValid ) fprintf( stderr, "Read char past end of buffer\n" );
268 return (char*) (&this->Chunk[ (this->ChunkWord++)*this->WordSize ]);
269}
270
271//-----------------------------------------------------------------------------
273{
274 if ( this->ChunkWord >= this->ChunkValid ) fprintf( stderr, "Read float past end of buffer\n" );
275 switch (this->WordSize)
276 {
277 case 4:
278 {
279 vtkTypeFloat32 value;
280 memcpy(&value, &this->Chunk[ this->ChunkWord++ << 2 ], sizeof(value));
281 return value;
282 }
283 case 8:
284 default:
285 {
286 vtkTypeFloat64 value;
287 memcpy(&value, &this->Chunk[ this->ChunkWord++ << 3 ], sizeof(value));
288 return value;
289 }
290 }
291}
292
293//-----------------------------------------------------------------------------
295{
296 if ( this->ChunkWord >= this->ChunkValid )
297 {
298 fprintf( stderr, "Read int past end of buffer\n" );
299 }
300 switch (this->WordSize)
301 {
302 case 4:
303 {
304 vtkTypeInt32 value;
305 memcpy(&value, &this->Chunk[ this->ChunkWord++ << 2 ], sizeof(value));
306 return value;
307 }
308 case 8:
309 default:
310 {
312 memcpy(&value, &this->Chunk[ this->ChunkWord++ << 3 ], sizeof(value));
313 return value;
314 }
315 }
316}
317
318//-----------------------------------------------------------------------------
319template<typename T>
321{
322 return reinterpret_cast<T*>(this->Chunk);
323}
324
325
326#endif // __LSDynaFamily_h
int vtkLSDynaFile_t
Definition: LSDynaFamily.h:48
off_t vtkLSDynaOff_t
Definition: LSDynaFamily.h:47
LSDynaFamilySectionMark Marks[NumberOfSectionTypes]
Definition: LSDynaFamily.h:122
vtkIdType GetCurrentFWord() const
Definition: LSDynaFamily.h:188
int BufferChunk(WordType wType, vtkIdType chunkSizeInWords)
int ScanDatabaseDirectory()
vtkIdType GetNextWordAsInt()
Definition: LSDynaFamily.h:294
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:249
bool FileHandlesClosed
Definition: LSDynaFamily.h:259
BufferingInfo * BufferInfo
Definition: LSDynaFamily.h:261
vtkIdType StateSize
How many words is a timestep on disk?
Definition: LSDynaFamily.h:239
int WordSize
Whether words are 4 or 8 bytes.
Definition: LSDynaFamily.h:237
std::vector< int > Adaptations
Which files mark the start of a new mesh adaptation.
Definition: LSDynaFamily.h:219
std::vector< int > TimeAdaptLevels
The adaptation level associated with each time step.
Definition: LSDynaFamily.h:247
void OpenFileHandles()
int GetCurrentAdaptLevel() const
Definition: LSDynaFamily.h:185
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:242
static const float EOFMarker
Definition: LSDynaFamily.h:144
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:233
int AdvanceFile()
double GetNextWordAsFloat()
Definition: LSDynaFamily.h:272
void MarkSectionStart(int adapteLevel, SectionType m)
vtkIdType GetNumberOfFiles()
int FAdapt
The current adaptation level.
Definition: LSDynaFamily.h:226
int SkipWords(vtkIdType numWords)
int SwapEndian
Whether files are reverse endian-ness of architecture.
Definition: LSDynaFamily.h:235
void SetDatabaseDirectory(std::string dd)
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:223
std::vector< vtkIdType > FileSizes
The size of each file in the database.
Definition: LSDynaFamily.h:214
int GetWordSize() const
std::string DatabaseDirectory
The directory containing d3plot files.
Definition: LSDynaFamily.h:206
vtkLSDynaFile_t FD
The currently open file descriptor.
Definition: LSDynaFamily.h:221
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:252
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:216
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:257
std::string DatabaseBaseName
The name (title string) of the database.
Definition: LSDynaFamily.h:209
int ClearBuffer()
int TimeAdaptLevel(int i) const
Definition: LSDynaFamily.h:186
void SetDatabaseBaseName(std::string bn)
T * GetBufferAs()
Definition: LSDynaFamily.h:320
vtkIdType ChunkValid
Definition: LSDynaFamily.h:255
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:245
int JumpToMark(SectionType m)
char * GetNextWordAsChars()
Definition: LSDynaFamily.h:265
std::vector< std::string > Files
The list of files that make up the database.
Definition: LSDynaFamily.h:211
vtkIdType FWord
The offset of Chunk in currently open file.
Definition: LSDynaFamily.h:228
@ value
Definition: vtkX3D.h:220
@ string
Definition: vtkX3D.h:490
int vtkIdType
Definition: vtkType.h:287