1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // VPICPart class contains data for a time step on one processor
4 //
5 //////////////////////////////////////////////////////////////////////////////
6
7 #ifndef VPICPart_h
8 #define VPICPart_h
9
10 #include "VPICDefinition.h"
11 #include "VPICHeader.h"
12 #include <fstream>
13
14 using namespace std;
15
16 class VPIC_EXPORT VPICPart {
17 public:
18 VPICPart(int id);
19 ~VPICPart();
20
21 // Initialize for a partition
22 void setFiles(string* names, int count);
23 void initialize();
24
25 // Calculate the location of this part in the subgrid for a processor
26 void calculatePartLocation(int* stride);
27
28 // Load variable data from file part into array
29 void loadVariableData(
30 float* varData, // Pre allocated array to fill
31 int varOffset, // Offset into varData
32 int* subdimension, // Dimension on this processor
33 int fileKind, // Field or species
34 int basicType, // FLOAT or INTEGER
35 int byteCount, // Size of basic type
36 long int offset, // Offset to variable to load
37 int stride[]); // Stride over the data
38
39 // Relative offset of this part within this processor
setPartOffset(int x,int y,int z)40 void setPartOffset(int x, int y, int z)
41 {
42 this->partOffset[0] = x;
43 this->partOffset[1] = y;
44 this->partOffset[2] = z;
45 }
46
setSimID(int id)47 void setSimID(int id) { this->simID = id; }
setVizID(int id)48 void setVizID(int id) { this->vizID = id; }
getSimID()49 int getSimID() { return this->simID; }
getVizID()50 int getVizID() { return this->vizID; }
51
getDumpTime()52 int getDumpTime() { return this->header.getDumpTime(); }
getNumberOfDimensions()53 int getNumberOfDimensions() { return this->header.getNumberOfDimensions(); }
getNumberOfGhostGrids()54 int getNumberOfGhostGrids() { return this->numberOfGhostGrids; }
55
getGridSize(int gridsize[])56 void getGridSize(int gridsize[]) { this->header.getGridSize(gridsize); }
getGhostSize(int ghostsize[])57 void getGhostSize(int ghostsize[]) { this->header.getGhostSize(ghostsize); }
getOrigin(float origin[])58 void getOrigin(float origin[]) { this->header.getOrigin(origin); }
getStep(float step[])59 void getStep(float step[]) { this->header.getStep(step); }
60
61 void PrintSelf(ostream& os, int indent);
62
63 private:
64 string* fileName; // field, ehydro, hhydro data files
65 int simID; // Simulation processor that wrote file
66 int vizID; // Visualization processor that draws part
67
68 VPICHeader header; // Header information for part
69
70 int gridSize[DIMENSION]; // Grid size for this part
71 int ghostSize[DIMENSION]; // Grid size for this part with ghost border
72 int numberOfGrids; // Size of this part of grid
73 int numberOfGhostGrids; // Size of this part of grid with ghost cells
74
75 int partOffset[DIMENSION]; // Where this part fits in the processor
76 int gridOffset[DIMENSION]; // Where this part fits in the grid
77 };
78
79 /////////////////////////////////////////////////////////////////////////////
80 //
81 // Templated read of a basic data type from a file, to be stored in a
82 // block of float supplied by the visualizer
83 //
84 /////////////////////////////////////////////////////////////////////////////
85
86 template< class basicType >
LoadData(int,int,float * varData,int varOffset,basicType * block,int * subdimension,int * blockDim,int blockSize,int * gridOffset,string fileName,long int offset,int stride[])87 void LoadData(
88 int , //vizID,
89 int , //simID,
90 float* varData, // Grid over all parts to be filled
91 int varOffset, // Offset into the cached paraView block
92 // Allows for ghost cells
93 basicType* block, // Type of data to read from file
94 int* subdimension, // Subdimension for processor owning this part
95 int* blockDim, // Dimension of data in the file
96 int blockSize, // Amount of data for variable in file
97 int* gridOffset, // Offset with total data on proc for this part
98 string fileName, // Field or species data file
99 long int offset, // Load data from this offset
100 int stride[]) // Stride over data requested
101 {
102 // Get the file pointer to the offset for this variable and component
103 // Read the contiguous variable data from the file
104 FILE* filePtr = fopen(fileName.c_str(), "r");
105 if (filePtr == 0) {
106 cerr << "Failed to open file " << fileName << endl;
107 return;
108 }
109 fseek(filePtr, offset, SEEK_SET);
110
111 // Data read in includes ghost cells
112 block = new basicType[blockSize];
113 fread(block, sizeof(basicType), blockSize, filePtr);
114 fclose(filePtr);
115
116 // Iterate over all data which includes ghost cells
117 // Transfer the non-ghost data to the correct offset within varData
118 int varIndex; // Index into returned visualizer block
119 int blockIndex; // Index into file part data block
120
121 int bx, by, bz; // Block data index from VPIC file with strides
122 int vx, vy, vz; // Visualizer data index with no strides
123
124 // Always skip the first ghost position because value is 0
125 for (bz = 1, vz = varOffset;
126 bz < (blockDim[2] - 1);
127 bz += stride[2], vz++) {
128
129 // Offset into entire viz data block for this file's part of data
130 int offsetz = gridOffset[2] + vz;
131
132 for (by = 1, vy = varOffset;
133 by < (blockDim[1] - 1);
134 by += stride[1], vy++) {
135
136 // Offset into entire viz data block for this file's part of data
137 int offsety = gridOffset[1] + vy;
138
139 for (bx = 1, vx = varOffset;
140 bx < (blockDim[0] - 1);
141 bx += stride[0], vx++) {
142
143 // Offset into entire viz data block for this file's part of data
144 int offsetx = gridOffset[0] + vx;
145
146 blockIndex = (bz * blockDim[0] * blockDim[1]) +
147 (by * blockDim[0]) + bx;
148
149
150 // Calculate the index into the sub grid for this processor
151 // Store the final ghost cell unless it is beyond the subextent
152 if (offsetx != subdimension[0] &&
153 offsety != subdimension[1] &&
154 offsetz != subdimension[2]) {
155
156 varIndex = (offsetz * subdimension[0] * subdimension[1]) +
157 (offsety * subdimension[0]) + offsetx;
158
159 varData[varIndex] = (float) block[blockIndex];
160 // varData[varIndex] = (float) simID;
161 }
162 }
163 }
164 }
165 delete [] block;
166 }
167
168 #endif
169