1 #include "VPICDataSet.h"
2 
3 //////////////////////////////////////////////////////////////////////////////
4 //
5 // Top level structure for VPIC data file components
6 //
7 //////////////////////////////////////////////////////////////////////////////
8 
VPICDataSet()9 VPICDataSet::VPICDataSet()
10 {
11    this->rank = 0;
12    this->totalRank = 1;
13    this->currentTimeStep = 0;
14    this->view = 0;
15 }
16 
17 //////////////////////////////////////////////////////////////////////////////
18 //
19 // Destructor
20 //
21 //////////////////////////////////////////////////////////////////////////////
22 
~VPICDataSet()23 VPICDataSet::~VPICDataSet()
24 {
25    if (this->view)
26       delete this->view;
27 }
28 
29 //////////////////////////////////////////////////////////////////////////////
30 //
31 // Initialize an empty VPICDataSet by setting variable names and
32 // checking for block or point structured data
33 //
34 //////////////////////////////////////////////////////////////////////////////
35 
initialize(const string & inFile)36 void VPICDataSet::initialize(const string& inFile)
37 {
38    // Read the information about variables in the run from the .vpc file
39    this->global.readGlobal(inFile);
40 
41    // Build all name information for file access
42    this->global.buildFileNames();
43 
44    // Build the table which shows distribution of files over problem space
45    this->global.buildFileLayoutTable();
46 
47    // Initialize the variable structures
48    this->global.initializeVariables();
49 
50    // Create the initial view which is the entire problem
51    this->view = new VPICView(this->rank, this->totalRank, this->global);
52    this->view->initialize(
53                 this->currentTimeStep,
54                 this->global.getLayoutSize(),
55                 this->global.getLayoutID(),
56                 this->global.getPartSize(),
57                 this->global.getPhysicalOrigin(),
58                 this->global.getPhysicalStep());
59 
60    // Save the initial view extents which are the entire problem
61    int* layoutSize = this->global.getLayoutSize();
62    this->curXExtent[0] = 0;     this->curXExtent[1] = layoutSize[0] - 1;
63    this->curYExtent[0] = 0;     this->curYExtent[1] = layoutSize[1] - 1;
64    this->curZExtent[0] = 0;     this->curZExtent[1] = layoutSize[2] - 1;
65 }
66 
67 //////////////////////////////////////////////////////////////////////////////
68 //
69 // If the extents of decomposition are different from those of the total
70 // problem, add a view and set current view to point at it
71 // extent[DIMENSION][low|high]
72 //
73 //////////////////////////////////////////////////////////////////////////////
74 
setView(int * xExtent,int * yExtent,int * zExtent)75 void VPICDataSet::setView(int* xExtent, int* yExtent, int* zExtent)
76 {
77    // If extents haven't been set yet return
78    if (xExtent[0] == -1)
79       return;
80 
81    // If the view extents have not been changed return
82    if (xExtent[0] == curXExtent[0] && xExtent[1] == curXExtent[1] &&
83        yExtent[0] == curYExtent[0] && yExtent[1] == curYExtent[1] &&
84        zExtent[0] == curZExtent[0] && zExtent[1] == curZExtent[1])
85             return;
86 
87    // Fetch the global information about the problem size and decomposition
88    int*** layoutID = this->global.getLayoutID();
89    int* partSize = this->global.getPartSize();
90    float* origin = this->global.getPhysicalOrigin();
91    float* step = this->global.getPhysicalStep();
92 
93    // Verify that the view extents requested match the extents available
94    if (xExtent[1] < xExtent[0]) xExtent[1] = xExtent[0];
95    if (yExtent[1] < yExtent[0]) yExtent[1] = yExtent[0];
96    if (zExtent[1] < zExtent[0]) zExtent[1] = zExtent[0];
97 
98    // Save the new current extents
99    this->curXExtent[0] = xExtent[0];    this->curXExtent[1] = xExtent[1];
100    this->curYExtent[0] = yExtent[0];    this->curYExtent[1] = yExtent[1];
101    this->curZExtent[0] = zExtent[0];    this->curZExtent[1] = zExtent[1];
102 
103    // Set the layout size for the new view
104    int subLayoutSize[DIMENSION];
105    subLayoutSize[0] = xExtent[1] - xExtent[0] + 1;
106    subLayoutSize[1] = yExtent[1] - yExtent[0] + 1;
107    subLayoutSize[2] = zExtent[1] - zExtent[0] + 1;
108 
109    // Create the matching file ID structure to match the extents in the new view
110    int*** subLayoutID = new int**[subLayoutSize[0]];
111    for (int i = 0; i < subLayoutSize[0]; i++) {
112       subLayoutID[i] = new int*[subLayoutSize[1]];
113       for (int j = 0; j < subLayoutSize[1]; j++)
114          subLayoutID[i][j] = new int[subLayoutSize[2]];
115    }
116 
117    // Assign the file IDs controlled by this view
118    int kindx = 0;
119    for (int k = zExtent[0]; k <= zExtent[1]; k++) {
120       int jindx = 0;
121       for (int j = yExtent[0]; j <= yExtent[1]; j++) {
122          int iindx = 0;
123          for (int i = xExtent[0]; i <= xExtent[1]; i++) {
124             subLayoutID[iindx][jindx][kindx] = layoutID[i][j][k];
125             iindx++;
126          }
127          jindx++;
128       }
129       kindx++;
130    }
131 
132    float subOrigin[DIMENSION];
133    subOrigin[0] = origin[0] + (xExtent[0] * partSize[0] * step[0]);
134    subOrigin[1] = origin[1] + (yExtent[0] * partSize[1] * step[1]);
135    subOrigin[2] = origin[2] + (zExtent[0] * partSize[2] * step[2]);
136 
137    // Create a new view with new size and file IDs
138    delete this->view;
139    this->view = new VPICView(this->rank, this->totalRank, this->global);
140    this->view->initialize(
141                 this->currentTimeStep,
142                 subLayoutSize,
143                 subLayoutID,
144                 this->global.getPartSize(),
145                 subOrigin,
146                 this->global.getPhysicalStep());
147 
148    for (int i = 0; i < subLayoutSize[0]; i++) {
149       for (int j = 0; j < subLayoutSize[1]; j++)
150          delete [] subLayoutID[i][j];
151       delete [] subLayoutID[i];
152    }
153    delete [] subLayoutID;
154 
155 }
156 
157 //////////////////////////////////////////////////////////////////////////////
158 //
159 // Load the variable data for the given time step for this processor
160 // Each processor has many file parts which supply pieces of data
161 // Have each file part load into the overall data block by using its
162 // offset into that data block.  Each data part has a set format but
163 // in order to do different time steps, change the name of the file
164 // which is to be accessed
165 //
166 //////////////////////////////////////////////////////////////////////////////
167 
loadVariableData(float * varData,int varOffset,int * localDim,int timeStep,int variable,int component)168 void VPICDataSet::loadVariableData(
169         float* varData,
170         int varOffset,
171         int* localDim,
172         int timeStep,
173         int variable,
174         int component)
175 {
176    this->currentTimeStep = timeStep;
177    this->view->loadVariableData(varData, varOffset,
178                                 localDim, timeStep, variable, component);
179 }
180 
181 //////////////////////////////////////////////////////////////////////////////
182 //
183 // Access methods
184 //
185 //////////////////////////////////////////////////////////////////////////////
186 
getLayoutSize(int size[])187 void VPICDataSet::getLayoutSize(int size[])
188 {
189   int* layoutSize = this->global.getLayoutSize();
190   for (int dim = 0; dim < DIMENSION; dim++)
191     size[dim] = layoutSize[dim];
192 }
193 
194 //////////////////////////////////////////////////////////////////////////////
195 //
196 // Is this processor used to render the current view
197 //
198 //////////////////////////////////////////////////////////////////////////////
199 
getProcessorUsed()200 int VPICDataSet::getProcessorUsed()
201 {
202    if (this->view->getNumberOfParts() == 0)
203       return 0;
204    else
205       return 1;
206 }
207 
208 //////////////////////////////////////////////////////////////////////////////
209 //
210 // Print information about the data set
211 //
212 //////////////////////////////////////////////////////////////////////////////
213 
PrintSelf(ostream & os,int indent)214 void VPICDataSet::PrintSelf(ostream& os, int indent)
215 {
216    if (this->rank == 0) {
217       os << endl;
218       this->global.PrintSelf(os, indent);
219    }
220 }
221