#include "vtkCPVTKPipeline.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vtkStandardNewMacro(vtkCPVTKPipeline); //---------------------------------------------------------------------------- vtkCPVTKPipeline::vtkCPVTKPipeline() { this->OutputFrequency = 0; } //---------------------------------------------------------------------------- vtkCPVTKPipeline::~vtkCPVTKPipeline() { } //---------------------------------------------------------------------------- void vtkCPVTKPipeline::Initialize(int outputFrequency, std::string& fileName) { this->OutputFrequency = outputFrequency; this->FileName = fileName; } //---------------------------------------------------------------------------- int vtkCPVTKPipeline::RequestDataDescription( vtkCPDataDescription* dataDescription) { if(!dataDescription) { vtkWarningMacro("dataDescription is NULL."); return 0; } if(this->FileName.empty()) { vtkWarningMacro("No output file name given to output results to."); return 0; } if(dataDescription->GetForceOutput() == true || (this->OutputFrequency != 0 && dataDescription->GetTimeStep() % this->OutputFrequency == 0) ) { dataDescription->GetInputDescriptionByName("input")->AllFieldsOn(); dataDescription->GetInputDescriptionByName("input")->GenerateMeshOn(); return 1; } return 0; } //---------------------------------------------------------------------------- int vtkCPVTKPipeline::CoProcess( vtkCPDataDescription* dataDescription) { if(!dataDescription) { vtkWarningMacro("DataDescription is NULL"); return 0; } vtkUnstructuredGrid* grid = vtkUnstructuredGrid::SafeDownCast( dataDescription->GetInputDescriptionByName("input")->GetGrid()); if(grid == NULL) { vtkWarningMacro("DataDescription is missing input unstructured grid."); return 0; } if(this->RequestDataDescription(dataDescription) == 0) { return 1; } vtkNew producer; producer->SetOutput(grid); vtkNew calculator; calculator->SetInputConnection(producer->GetOutputPort()); calculator->SetAttributeMode(1); calculator->SetResultArrayName("velocity magnitude"); calculator->SetFunction("mag(velocity)"); // update now so that we can get the global data bounds of // the velocity magnitude for thresholding calculator->Update(); double range[2]; vtkUnstructuredGrid::SafeDownCast(calculator->GetOutput())->GetPointData() ->GetArray("velocity magnitude")->GetRange(range, 0); double globalRange[2]; vtkMultiProcessController::GetGlobalController()->AllReduce( range+1, globalRange+1, 1, vtkCommunicator::MAX_OP); vtkNew threshold; threshold->SetInputConnection(calculator->GetOutputPort()); threshold->SetInputArrayToProcess( 0, 0, 0, "vtkDataObject::FIELD_ASSOCIATION_POINTS", "velocity magnitude"); threshold->ThresholdBetween(0.9*globalRange[1], globalRange[1]); // If process 0 doesn't have any points or cells, the writer may // have problems in parallel so we use completeArrays to fill in // the missing information. vtkNew completeArrays; completeArrays->SetInputConnection(threshold->GetOutputPort()); vtkNew writer; writer->SetInputConnection(completeArrays->GetOutputPort()); std::ostringstream o; o << dataDescription->GetTimeStep(); std::string name = this->FileName + o.str() + ".pvtu"; writer->SetFileName(name.c_str()); writer->Update(); return 1; } //---------------------------------------------------------------------------- void vtkCPVTKPipeline::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); os << indent << "OutputFrequency: " << this->OutputFrequency << "\n"; os << indent << "FileName: " << this->FileName << "\n"; }