Commit 7d29869c authored by George Zagaris's avatar George Zagaris
Browse files

ENH: Adding AMR dual-extraction example/utility

Adding AMRDualExtractor example to the repository --
A utility that demonstrates and tests the functionality
of the vtkAMRDualExtractor object. Further, common
functionality for AMR data that is employed in developing
AMR examples is now consolidated in AMRCommon so that this
functionality can be more readily reusable.
parent 3a785654
/*=========================================================================
Program: Visualization Toolkit
Module: AMRCommon.h
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.
=========================================================================*/
// .NAME AMRCommon.h -- Encapsulates common functionality for AMR data.
//
// .SECTION Description
// This header encapsulates some common functionality for AMR data to
// simplify and expedite the development of examples.
#ifndef AMRCOMMON_H_
#define AMRCOMMON_H_
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkXMLHierarchicalBoxDataWriter.h"
#include "vtkXMLHierarchicalBoxDataReader.h"
#include "vtkXMLMultiBlockDataWriter.h"
namespace AMRCommon {
// Description:
// Writes the given AMR dataset to a *.vth file with the given prefix.
void WriteAMRData( vtkHierarchicalBoxDataSet *amrData, std::string prefix )
{
// Sanity check
assert( "pre: AMR dataset is NULL!" && (amrData != NULL) );
vtkXMLHierarchicalBoxDataWriter *myAMRWriter=
vtkXMLHierarchicalBoxDataWriter::New();
assert( "pre: AMR Writer is NULL!" && (myAMRWriter != NULL) );
std::ostringstream oss;
oss << prefix << "." << myAMRWriter->GetDefaultFileExtension();
myAMRWriter->SetFileName( oss.str().c_str() );
myAMRWriter->SetInput( amrData );
myAMRWriter->Write();
myAMRWriter->Delete();
}
//------------------------------------------------------------------------------
// Description:
// Reads AMR data to the given data-structure from the prescribed file.
vtkHierarchicalBoxDataSet* ReadAMRData( std::string file )
{
// Sanity check
// assert( "pre: AMR dataset is NULL!" && (amrData != NULL) );
vtkXMLHierarchicalBoxDataReader *myAMRReader=
vtkXMLHierarchicalBoxDataReader::New();
assert( "pre: AMR Reader is NULL!" && (myAMRReader != NULL) );
std::ostringstream oss;
oss.str("");
oss.clear();
oss << file << ".vthb";
std::cout << "Reading AMR Data from: " << oss.str() << std::endl;
std::cout.flush();
myAMRReader->SetFileName( oss.str().c_str() );
myAMRReader->Update();
vtkHierarchicalBoxDataSet *amrData =
vtkHierarchicalBoxDataSet::SafeDownCast( myAMRReader->GetOutput() );
assert( "post: AMR data read is NULL!" && (amrData != NULL) );
return( amrData );
}
//------------------------------------------------------------------------------
// Description:
// Writes the given multi-block data to an XML file with the prescribed prefix
void WriteMultiBlockData( vtkMultiBlockDataSet *mbds, std::string prefix )
{
// Sanity check
assert( "pre: Multi-block dataset is NULL" && (mbds != NULL) );
vtkXMLMultiBlockDataWriter *writer = vtkXMLMultiBlockDataWriter::New();
std::ostringstream oss;
oss.str(""); oss.clear();
oss << prefix << "." << writer->GetDefaultFileExtension();
writer->SetFileName( oss.str( ).c_str( ) );
writer->SetInput( mbds );
writer->Write();
writer->Delete();
}
} // END namespace
#endif /* AMRCOMMON_H_ */
/*=========================================================================
Program: Visualization Toolkit
Module: AMRDualExtractor.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.
=========================================================================*/
// .NAME AMRDualExtractor.cxx -- Extracts the dual mesh from AMR data
//
// .SECTION Description
// This utility will read in AMR data, in *.vth native paraview format,
// and extract the corresponding mesh dual.
#include <cmath>
#include <sstream>
#include <cassert>
#include <mpi.h>
#include "vtkUniformGrid.h"
#include "vtkDataArray.h"
#include "vtkDoubleArray.h"
#include "vtkCell.h"
#include "vtkPoints.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkAMRBox.h"
#include "vtkAMRConnectivityFilter.h"
#include "vtkAMRDataTransferFilter.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkXMLHierarchicalBoxDataWriter.h"
#include "vtkMultiProcessController.h"
#include "vtkMPIController.h"
#include "vtkAMRUtilities.h"
#include "vtkAMRDualMeshExtractor.h"
#include "AMRCommon.h"
// Global Variables
vtkMultiProcessController *Controller;
int main( int argc, char **argv )
{
Controller = vtkMPIController::New();
Controller->Initialize( &argc, &argv );
assert("pre: Controller != NULL" && (Controller != NULL ) );
// STEP 0: Read in AMR dataset
vtkHierarchicalBoxDataSet *amrData=
AMRCommon::ReadAMRData( std::string(argv[1] ) );
AMRCommon::WriteAMRData( amrData, std::string("INPUTAMR") );
// STEP 1: Compute intergrid connectivity
std::cout << "Computing inter-block & inter-process connectivity!\n";
std::cout.flush( );
vtkAMRConnectivityFilter* connectivityFilter=vtkAMRConnectivityFilter::New( );
connectivityFilter->SetController( Controller );
connectivityFilter->SetAMRDataSet( amrData );
connectivityFilter->ComputeConnectivity();
std::cout << "Done computing connectivity!\n";
std::cout.flush( );
Controller->Barrier();
connectivityFilter->Print( std::cout );
Controller->Barrier();
// STEP 2: Data transfer
std::cout << " -- Transfering solution...\n";
std::cout.flush();
vtkAMRDataTransferFilter* transferFilter = vtkAMRDataTransferFilter::New();
transferFilter->SetController( Controller );
transferFilter->SetAMRDataSet( amrData );
transferFilter->SetNumberOfGhostLayers( 1 );
transferFilter->SetRemoteConnectivity(
connectivityFilter->GetRemoteConnectivity() );
transferFilter->SetLocalConnectivity(
connectivityFilter->GetLocalConnectivity() );
transferFilter->Transfer();
vtkHierarchicalBoxDataSet *newData = transferFilter->GetExtrudedData();
assert( "extruded data is NULL!" && (newData != NULL) );
AMRCommon::WriteAMRData( newData, "EXTRUDED" );
std::cout << " -- Generating dual mesh...";
std::cout.flush();
vtkAMRDualMeshExtractor *dme = vtkAMRDualMeshExtractor::New();
dme->SetInput( newData );
dme->Update();
std::cout << "[DONE]\n";
std::cout.flush();
std::cout << " -- Writing dual...";
std::cout.flush();
AMRCommon::WriteMultiBlockData( dme->GetOutput(), std::string("DUALMESH") );
std::cout << "[DONE]\n";
std::cout.flush();
// STEP 3: CleanUp
dme->Delete();
amrData->Delete();
connectivityFilter->Delete();
transferFilter->Delete();
Controller->Finalize();
Controller->Delete();
return 0;
}
......@@ -42,6 +42,18 @@ TARGET_LINK_LIBRARIES( AMRDataTransferPipeline
${MPI_LIBRARIES}
)
## Add AMRDualExtractor executable
ADD_EXECUTABLE( AMRDualExtractor AMRDualExtractor.cxx )
TARGET_LINK_LIBRARIES( AMRDualExtractor
vtkGraphics
vtkFiltering
vtkRendering
vtkIO
vtkAMR
vtkParallel
${MPI_LIBRARIES}
)
## Add Generate3DAMRDataSetWithPulse executable
ADD_EXECUTABLE( Generate3DAMRDataSetWithPulse Generate3DAMRDataSetWithPulse.cxx)
TARGET_LINK_LIBRARIES( Generate3DAMRDataSetWithPulse
......
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