forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkPLSDynaReader.cxx
257 lines (213 loc) · 7.55 KB
/
vtkPLSDynaReader.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPLSDynaReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*----------------------------------------------------------------------------
Copyright (c) Sandia Corporation
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/
// NOTE TO DEVELOPERS: ========================================================
//
// This is a parallel version of the LSDynaReader.
// Its primary tasks are to determine which parts should be read on each process
// and to send the relevant information from the master node to all slave nodes
#include "vtkPLSDynaReader.h"
#include "LSDynaMetaData.h"
#include "LSDynaFamily.h"
#include "vtkLSDynaPartCollection.h"
#include "vtkIntArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkMultiProcessController.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkUnstructuredGrid.h"
vtkStandardNewMacro(vtkPLSDynaReader);
struct vtkPLSDynaReader::vtkPLSDynaReaderInternal
{
unsigned int MinDataset;
unsigned int MaxDataset;
unsigned int UpdatePiece;
unsigned int UpdateNumPieces;
vtkIdType NumProcesses;
vtkIdType ProcessRank;
vtkPLSDynaReaderInternal():
MinDataset(0),
MaxDataset(0),
UpdatePiece(0),
UpdateNumPieces(0)
{}
};
//-----------------------------------------------------------------------------
vtkPLSDynaReader::vtkPLSDynaReader()
{
this->Controller = NULL;
//need to construct the internal datastructure before call SetController
this->Internal = new vtkPLSDynaReader::vtkPLSDynaReaderInternal();
this->SetController(vtkMultiProcessController::GetGlobalController());
}
//-----------------------------------------------------------------------------
vtkPLSDynaReader::~vtkPLSDynaReader()
{
this->SetController(NULL);
delete this->Internal;
}
void vtkPLSDynaReader::PrintSelf( ostream &os, vtkIndent indent )
{
os << indent << "Controller: " << this->Controller << endl;
this->Superclass::PrintSelf( os, indent );
}
//----------------------------------------------------------------------------
void vtkPLSDynaReader::SetController(vtkMultiProcessController *c)
{
if ((c == NULL) || (c->GetNumberOfProcesses() == 0))
{
this->Internal->NumProcesses = 1;
this->Internal->ProcessRank = 0;
}
if (this->Controller == c)
{
return;
}
this->Modified();
if (this->Controller)
{
this->Controller->UnRegister(this);
this->Controller = NULL;
}
if (c == NULL)
{
return;
}
this->Controller = c;
c->Register(this);
this->Internal->NumProcesses = c->GetNumberOfProcesses();
this->Internal->ProcessRank = c->GetLocalProcessId();
}
//-----------------------------------------------------------------------------
int vtkPLSDynaReader::CanReadFile( const char* fname )
{
return this->Superclass::CanReadFile(fname);
}
//-----------------------------------------------------------------------------
int vtkPLSDynaReader::RequestInformation( vtkInformation* request,
vtkInformationVector** iinfo,
vtkInformationVector* outputVector )
{
vtkInformation* outInfo = outputVector->GetInformationObject(0);
//call the parents request information on all the nodes.
//This is not optimal, but sooo much information is stored in the
//metadata that is read during request information that sending it over the wire
//might not be faster than each node contending for the info. Plus it would
//be a massive chunk of code
this->Superclass::RequestInformation(request,iinfo,outputVector);
//force an override of the serial reader setting the number of pieces to 1
outInfo->Set(vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(),
-1);
return 1;
}
//-----------------------------------------------------------------------------
int vtkPLSDynaReader::RequestData(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector )
{
//get the information needed to determine which subsection of the full
//data set we need to load
vtkInformation* outInfo = outputVector->GetInformationObject(0);
this->Internal->UpdatePiece =
outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
this->Internal->UpdateNumPieces =
outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
return this->Superclass::RequestData(request,inputVector,outputVector);
}
//----------------------------------------------------------------------------
int vtkPLSDynaReader::ReadTopology()
{
bool readTopology=false;
if(!this->Parts)
{
readTopology=true;
this->Parts = vtkLSDynaPartCollection::New();
vtkIdType* minCellIds = new vtkIdType[LSDynaMetaData::NUM_CELL_TYPES];
vtkIdType* maxCellIds = new vtkIdType[LSDynaMetaData::NUM_CELL_TYPES];
this->GetPartRanges(minCellIds,maxCellIds);
this->Parts->InitCollection(this->P,minCellIds,maxCellIds);
delete[] minCellIds;
delete[] maxCellIds;
}
if(!readTopology)
{
return 0;
}
if( this->ReadPartSizes())
{
vtkErrorMacro( "Could not read cell sizes." );
return 1;
}
if ( this->ReadConnectivityAndMaterial() )
{
vtkErrorMacro( "Could not read connectivity." );
return 1;
}
//finalize the topology on each process, each process will remove
//any part that it doesn't have a cell for.
this->Parts->FinalizeTopology();
if(this->ReadNodes())
{
vtkErrorMacro("Could not read static node values.");
return 1;
}
// we need to read the user ids after we have read the topology
// so we know how many cells are in each part
if ( this->ReadUserIds() )
{
vtkErrorMacro( "Could not read user node/element IDs." );
return 1;
}
return 0;
}
//----------------------------------------------------------------------------
//determine which parts will be read by this processor
void vtkPLSDynaReader::GetPartRanges(vtkIdType* mins, vtkIdType* maxs)
{
//1 == load the whole data
//determine which domains in this mesh this processor is responsible for
if ( this->Internal->UpdateNumPieces > 1 )
{
double numCells;
for(int i=0; i < LSDynaMetaData::NUM_CELL_TYPES;++i)
{
numCells = static_cast<double>(this->P->NumberOfCells[i]);
if(numCells > 1000)
{
double percent = (1.0 / this->Internal->UpdateNumPieces) * numCells;
mins[i] = static_cast<vtkIdType>(
percent * this->Internal->UpdatePiece);
maxs[i] = static_cast<vtkIdType>(
percent * (this->Internal->UpdatePiece+1));
}
else
{
//else not enough cells to worth dividing the reading
mins[i]=0;
maxs[i]=static_cast<vtkIdType>(
(this->Internal->ProcessRank==0)?numCells:0);
}
}
}
else
{
for(int i=0; i < LSDynaMetaData::NUM_CELL_TYPES;++i)
{
mins[i] = 0;
maxs[i] = this->P->NumberOfCells[i];
}
}
}