Commit cb542863 authored by David Partyka's avatar David Partyka

BUG: Fix bugs with ghost cells and properly data files.

Pat Fasel add fixes to properly load in blade data and topography data.
parent 78114364
......@@ -63,14 +63,13 @@ vtkWindBladeReader::vtkWindBladeReader()
// Set up two output ports, one for fields, one for blades
this->SetNumberOfOutputPorts(2);
/*vtkUnstructuredGrid* blade = vtkUnstructuredGrid::New();
blade->ReleaseData();
this->GetExecutive()->SetOutputData(1, blade);
blade->Delete();*/
// Irregularly spaced grid description for entire problem
this->Points = vtkPoints::New();
this->SetSpacing = 1;
this->xSpacing = vtkFloatArray::New();
this->ySpacing = vtkFloatArray::New();
this->zSpacing = vtkFloatArray::New();
this->zTopographicValues = 0;
// Blade geometry
this->BPoints = vtkPoints::New();
......@@ -142,6 +141,12 @@ vtkWindBladeReader::~vtkWindBladeReader()
this->YPosition->Delete();
this->HubHeight->Delete();
this->BladeCount->Delete();
this->xSpacing->Delete();
this->ySpacing->Delete();
this->zSpacing->Delete();
if (this->zTopographicValues != 0)
delete [] zTopographicValues;
this->Points->Delete();
this->BPoints->Delete();
......@@ -193,6 +198,7 @@ int vtkWindBladeReader::RequestInformation(
vtkInformation* fieldInfo = outputVector->GetInformationObject(0);
vtkStructuredGrid *field = vtkStructuredGrid::SafeDownCast(
fieldInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkUnstructuredGrid* blade = GetBladeOutput();
// Read global size and variable information from input file one time
if (this->NumberOfVariables == 0) {
......@@ -219,8 +225,13 @@ int vtkWindBladeReader::RequestInformation(
this->WholeExtent[5] = this->Dimension[2] - 1;
field->SetWholeExtent(this->WholeExtent);
field->SetDimensions(this->Dimension);
fieldInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
this->WholeExtent, 6);
blade->SetWholeExtent(this->WholeExtent);
// Create the rectilinear coordinate spacing for entire problem
CreateCoordinates();
// Collect temporal information
this->TimeSteps = NULL;
......@@ -262,35 +273,6 @@ int vtkWindBladeReader::RequestUpdateExtent(
{
// If Modified is not set, blades do not turn
this->Modified();
vtkInformation* fieldInfo = outputVector->GetInformationObject(0);
vtkStructuredGrid *field = GetFieldOutput();
field->SetDimensions(this->Dimension);
field->SetWholeExtent(this->WholeExtent);
// not used? vtkInformation* bladeInfo = outputVector->GetInformationObject(1);
vtkUnstructuredGrid* blade = GetBladeOutput();
blade->SetWholeExtent(this->WholeExtent);
// Fetch the extents on this processor from stream and set in output object
fieldInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(),
this->SubExtent);
// Set the subextent dimension size
this->SubDimension[0] = this->SubExtent[1] - this->SubExtent[0] + 1;
this->SubDimension[1] = this->SubExtent[3] - this->SubExtent[2] + 1;
this->SubDimension[2] = this->SubExtent[5] - this->SubExtent[4] + 1;
// Total size of the subextent
this->NumberOfTuples = 1;
for (int dim = 0; dim < DIMENSION; dim++)
this->NumberOfTuples *= this->SubDimension[dim];
// Set the variable spacing for this subextent one time only
if (this->SetSpacing == 1) {
CreateCoordinates();
this->SetSpacing = 0;
}
return 1;
}
......@@ -312,12 +294,24 @@ int vtkWindBladeReader::RequestData(
vtkInformation* fieldInfo = outVector->GetInformationObject(0);
vtkStructuredGrid *field = GetFieldOutput();
// Set the info for this processor every time
field->SetDimensions(this->Dimension);
field->SetWholeExtent(this->WholeExtent);
// Set the extent info for this processor
fieldInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(),
this->SubExtent);
field->SetExtent(this->SubExtent);
// Set the rectilinear coordinates matching the requested subextents
// Extents may include ghost cells for filters that require them
FillCoordinates();
field->SetPoints(this->Points);
this->SubDimension[0] = this->SubExtent[1] - this->SubExtent[0] + 1;
this->SubDimension[1] = this->SubExtent[3] - this->SubExtent[2] + 1;
this->SubDimension[2] = this->SubExtent[5] - this->SubExtent[4] + 1;
this->NumberOfTuples = 1;
for (int dim = 0; dim < DIMENSION; dim++)
this->NumberOfTuples *= this->SubDimension[dim];
// Collect the time step requested
double* requestedTimeSteps = NULL;
int numRequestedTimeSteps = 0;
......@@ -548,7 +542,6 @@ void vtkWindBladeReader::CalculateVorticity(int vort, int uvw, int density)
for (int k = this->SubExtent[4]; k <= this->SubExtent[5]; k++) {
for (int j = this->SubExtent[2]; j <= this->SubExtent[3]; j++) {
for (int i = this->SubExtent[0]; i <= this->SubExtent[1]; i++) {
// not used? int index = (k * planeSize) + (j * rowSize) + i;
// Edges are initialized to 0
if (j == this->SubExtent[2] || j == this->SubExtent[3] ||
......@@ -810,8 +803,6 @@ void vtkWindBladeReader::FindVariableOffsets()
{
// Open the first data file
ostringstream fileName;
cout << "DataDirectory: " << this->DataDirectory << endl;
cout << "DataBaseName: " << this->DataBaseName << endl;
fileName << this->RootDirectory << Slash
<< this->DataDirectory << Slash
<< this->DataBaseName << this->TimeStepFirst;
......@@ -842,48 +833,75 @@ void vtkWindBladeReader::FindVariableOffsets()
fclose(this->FilePtr);
}
//----------------------------------------------------------------------------
// Fill in the rectilinear points for the requested subextents
//----------------------------------------------------------------------------
void vtkWindBladeReader::FillCoordinates()
{
this->Points->Delete();
this->Points = vtkPoints::New();
// If dataset is flat, x and y are constant spacing, z is stretched
if (this->UseTopographyFile == 0) {
// Save vtkPoints instead of spacing coordinates because topography file
// requires this to be vtkStructuredGrid and not vtkRectilinearGrid
for (int k = this->SubExtent[4]; k <= this->SubExtent[5]; k++) {
float z = this->zSpacing->GetValue(k);
for (int j = this->SubExtent[2]; j <= this->SubExtent[3]; j++) {
float y = this->ySpacing->GetValue(j);
for (int i = this->SubExtent[0]; i <= this->SubExtent[1]; i++) {
float x = this->xSpacing->GetValue(i);
this->Points->InsertNextPoint(x, y, z);
}
}
}
}
// If dataset is topographic, x and y are constant spacing center on (0,0)
// Z data is calculated from an x by y topographic data file
else {
int planeSize = this->Dimension[0] * this->Dimension[1];
int rowSize = this->Dimension[0];
for (int k = this->SubExtent[4]; k <= this->SubExtent[5]; k++) {
for (int j = this->SubExtent[2]; j <= this->SubExtent[3]; j++) {
float y = this->ySpacing->GetValue(j);
for (int i = this->SubExtent[0]; i <= this->SubExtent[1]; i++) {
float x = this->xSpacing->GetValue(i);
int index = (k * planeSize) + (j * rowSize) + i;
this->Points->InsertNextPoint(x, y, this->zTopographicValues[index]);
}
}
}
}
}
//----------------------------------------------------------------------------
// Calculate the Points for flat Rectilinear type grid or topographic
// generalized StructuredGrid which is what is being created here
//----------------------------------------------------------------------------
void vtkWindBladeReader::CreateCoordinates()
{
vtkFloatArray* xSpacing = vtkFloatArray::New();
vtkFloatArray* ySpacing = vtkFloatArray::New();
vtkFloatArray* zSpacing = vtkFloatArray::New();
// If dataset is flat, x and y are constant spacing, z is stretched
if (this->UseTopographyFile == 0) {
float value = 0.0;
for (int i = 0; i < this->Dimension[0]; i++) {
xSpacing->InsertNextValue(value);
this->xSpacing->InsertNextValue(value);
value += this->Step[0];
}
value = 0.0;
for (int j = 0; j < this->Dimension[1]; j++) {
ySpacing->InsertNextValue(value);
this->ySpacing->InsertNextValue(value);
value += this->Step[1];
}
double maxZ = this->Step[2] * this->Dimension[2];
for (int k = 0; k < this->Dimension[2]; k++) {
double zcoord = (k * this->Step[2]) + (0.5 * this->Step[2]);
double zcartesian = GDeform(zcoord, maxZ, 0);
zSpacing->InsertNextValue(zcartesian);
}
// Save vtkPoints instead of spacing coordinates because topography file
// requires this to be vtkStructuredGrid and not vtkRectilinearGrid
for (int k = this->SubExtent[4]; k <= this->SubExtent[5]; k++) {
float z = zSpacing->GetValue(k);
for (int j = this->SubExtent[2]; j <= this->SubExtent[3]; j++) {
float y = ySpacing->GetValue(j);
for (int i = this->SubExtent[0]; i <= this->SubExtent[1]; i++) {
float x = xSpacing->GetValue(i);
this->Points->InsertNextPoint(x, y, z);
}
}
this->zSpacing->InsertNextValue(zcartesian);
}
}
......@@ -892,33 +910,15 @@ void vtkWindBladeReader::CreateCoordinates()
else {
float xHalf = (((this->Dimension[0] + 1.0) / 2.0) - 1.0) * this->Step[0];
for (int i = 0; i < this->Dimension[0]; i++)
xSpacing->InsertNextValue((i * this->Step[0]) - xHalf);
this->xSpacing->InsertNextValue((i * this->Step[0]) - xHalf);
float yHalf = (((this->Dimension[1] + 1.0) / 2.0) - 1.0) * this->Step[1];
for (int j = 0; j < this->Dimension[1]; j++)
ySpacing->InsertNextValue((j * this->Step[1]) - yHalf);
float* zValues = new float[this->BlockSize];
CreateZTopography(zValues);
int planeSize = this->Dimension[0] * this->Dimension[1];
int rowSize = this->Dimension[0];
this->ySpacing->InsertNextValue((j * this->Step[1]) - yHalf);
for (int k = this->SubExtent[4]; k <= this->SubExtent[5]; k++) {
for (int j = this->SubExtent[2]; j <= this->SubExtent[3]; j++) {
float y = ySpacing->GetValue(j);
for (int i = this->SubExtent[0]; i <= this->SubExtent[1]; i++) {
float x = xSpacing->GetValue(i);
int index = (k * planeSize) + (j * rowSize) + i;
this->Points->InsertNextPoint(x, y, zValues[index]);
}
}
}
delete [] zValues;
this->zTopographicValues = new float[this->BlockSize];
CreateZTopography(this->zTopographicValues);
}
xSpacing->Delete();
ySpacing->Delete();
zSpacing->Delete();
}
//----------------------------------------------------------------------------
......@@ -927,7 +927,10 @@ void vtkWindBladeReader::CreateCoordinates()
void vtkWindBladeReader::CreateZTopography(float* zValues)
{
// Read the x,y topography data file
FILE* filePtr = fopen(this->TopographyFile.c_str(), "r");
ostringstream fileName;
fileName << this->RootDirectory << Slash
<< this->TopographyFile;
FILE* filePtr = fopen(fileName.str().c_str(), "r");
int blockSize = this->Dimension[0] * this->Dimension[1];
float* topoData = new float[blockSize];
......@@ -1141,8 +1144,6 @@ void vtkWindBladeReader::SetupBladeData()
{
// Load the tower information
ostringstream fileName;
cout << "TurbineDirectory: " << this->TurbineDirectory << endl;
cout << "TurbineTowerName: " << this->TurbineTowerName << endl;
fileName << this->RootDirectory << Slash
<< this->TurbineDirectory << Slash
<< this->TurbineTowerName;
......@@ -1174,8 +1175,6 @@ void vtkWindBladeReader::SetupBladeData()
// Calculate the number of cells in unstructured turbine blades
ostringstream fileName2;
cout << "TurbineDirectory: " << this->TurbineDirectory << endl;
cout << "TurbineBladeName: " << this->TurbineBladeName << endl;
fileName2 << this->RootDirectory << Slash
<< this->TurbineDirectory << Slash
<< this->TurbineBladeName << this->TimeStepFirst;
......@@ -1201,7 +1200,9 @@ void vtkWindBladeReader::LoadBladeData(int timeStep)
{
// Open the file for this time step
ostringstream fileName;
fileName << this->TurbineDirectory << Slash << this->TurbineBladeName
fileName << this->RootDirectory << Slash
<< this->TurbineDirectory << Slash
<< this->TurbineBladeName
<< this->TimeSteps[timeStep];
ifstream inStr(fileName.str().c_str());
char inBuf[LINE_SIZE];
......
......@@ -111,10 +111,15 @@ protected:
vtkStdString TopographyFile; // Name of topography data file
vtkPoints* Points; // Structured grid geometry
vtkPoints* BPoints; // Unstructured grid geometry
int SetSpacing; // Set spacing once
float Compression; // Stretching at Z surface [0,1]
float Fit; // Cubic or quadratic [0,1]
// Rectilinear coordinate spacing
vtkFloatArray* xSpacing;
vtkFloatArray* ySpacing;
vtkFloatArray* zSpacing;
float* zTopographicValues;
// Variable information
int NumberOfFileVariables; // Number of variables in data file
int NumberOfDerivedVariables; // Number of variables derived from file
......@@ -177,6 +182,7 @@ protected:
void LoadBladeData(int timeStep);
// Calculate the coordinates
void FillCoordinates();
void CreateCoordinates();
void CreateZTopography(float* zdata);
float GDeform(float sigma, float sigmaMax, int flag);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment