示例#1
0
// =============================================================================
void
VIO::EpetraMesh::Writer::
setValues( const Epetra_MultiVector          & x,
           const Teuchos::Array<std::string> & scalarsNames
         )
{
  unsigned int numVecs = x.NumVectors();
  unsigned int numVariables = x.GlobalLength();

  unsigned int numNodes = mesh_->getNodesMap()->NumGlobalElements();

  // make sure the sizes match the mesh
  if ( !mesh_.is_null() )
      TEUCHOS_ASSERT_EQUALITY( numVariables, 2*numNodes );

  // cast into a vtkUnstructuredGrid
  vtkSmartPointer<vtkUnstructuredGrid> vtkMesh =
      dynamic_cast<vtkUnstructuredGrid*> ( vtkDataSet_.GetPointer() );
  TEUCHOS_ASSERT_INEQUALITY( 0, !=, vtkMesh );

  // get scalarsNames, and insert default names if empty
  Teuchos::Array<std::string> scNames ( scalarsNames );
  if ( scNames.empty() )
  {
      scNames.resize ( numVecs );
      for ( int vec=0; vec<numVecs; vec++ )
          scNames[vec] = "x" + EpetraExt::toString ( vec );
  }

  // fill the scalar field
  vtkSmartPointer<vtkDoubleArray> scalars =
      vtkSmartPointer<vtkDoubleArray>::New();

  // real and imaginary part
  scalars->SetNumberOfComponents ( 2 );

  for ( int vec=0; vec<numVecs; vec++ )
  {
      scalars->SetName ( scNames[vec].c_str() );
      for ( int k=0; k<numNodes; k++ )
      {
//           const unsigned int dof_id = libmeshMesh_->node(k).dof_number(0,k,0);
          scalars->InsertNextValue ( x[vec][2*k] );
          scalars->InsertNextValue ( x[vec][2*k+1] );
      }
      vtkMesh->GetPointData()->AddArray ( scalars );
  }

  return;
}
BoundingBox GeometryManager<Geometry,GlobalOrdinal>::localBoundingBox() const
{
    double global_x_min = Teuchos::ScalarTraits<double>::rmax();
    double global_y_min = Teuchos::ScalarTraits<double>::rmax();
    double global_z_min = Teuchos::ScalarTraits<double>::rmax();
    double global_x_max = -Teuchos::ScalarTraits<double>::rmax();
    double global_y_max = -Teuchos::ScalarTraits<double>::rmax();
    double global_z_max = -Teuchos::ScalarTraits<double>::rmax();

    // Get the local bounding boxes compute the local bounding box.
    BoundingBox local_box;
    Teuchos::Tuple<double,6> box_bounds;
    Teuchos::Array<BoundingBox> boxes = boundingBoxes();
    Teuchos::Array<BoundingBox>::const_iterator box_iterator;
    DTK_CHECK( !boxes.empty() );
    for ( box_iterator = boxes.begin();
	  box_iterator != boxes.end();
	  ++box_iterator )
    {
	box_bounds = box_iterator->getBounds();

	if ( box_bounds[0] < global_x_min )
	{
	    global_x_min = box_bounds[0];
	}
	if ( box_bounds[1] < global_y_min )
	{
	    global_y_min = box_bounds[1];
	}
	if ( box_bounds[2] < global_z_min )
	{
	    global_z_min = box_bounds[2];
	}
	if ( box_bounds[3] > global_x_max )
	{
	    global_x_max = box_bounds[3];
	}
	if ( box_bounds[4] > global_y_max )
	{
	    global_y_max = box_bounds[4];
	}
	if ( box_bounds[5] > global_z_max )
	{
	    global_z_max = box_bounds[5];
	}
    }

    return BoundingBox( global_x_min, global_y_min, global_z_min,
			global_x_max, global_y_max, global_z_max );
}
// =============================================================================
void
VIO::Image::Writer::Abstract::
setImageData ( const Epetra_MultiVector              & x,
               const Teuchos::Tuple<unsigned int,2>  & Nx,
               const Point                           & h,
               const Teuchos::Array<int>             & p,
               const Teuchos::Array<std::string>     & scalarsNames
             )
{
    int numVecs   = x.NumVectors();
    int numPoints = ( Nx[0]+1 ) * ( Nx[1]+1 );

    // get scalarsNames, and insert default names if empty
    Teuchos::Array<std::string> scNames ( scalarsNames );
    if ( scNames.empty() )
    {
        scNames.resize ( numVecs );
        for ( int vec=0; vec<numVecs; vec++ )
            scNames[vec] = "x" + EpetraExt::toString ( vec );
    }

    // cast into vtkImageData
    vtkSmartPointer<vtkImageData> imageData =
        dynamic_cast<vtkImageData*> ( vtkDataSet_.GetPointer() );
    TEUCHOS_ASSERT_INEQUALITY( 0, !=, imageData );

    // set other image data
    imageData->SetDimensions ( Nx[0]+1, Nx[1]+1, 1 );
    imageData->SetOrigin ( 0.0, 0.0, 0.0 );
    imageData->SetSpacing ( h[0], h[1], 0.0 );

    // fill the scalar field
    vtkSmartPointer<vtkDoubleArray> scalars =
        vtkSmartPointer<vtkDoubleArray>::New();

    bool isScrambled = !p.empty();

    if ( isScrambled )
    {
        TEUCHOS_ASSERT_EQUALITY ( numPoints, p.length() );
        addFieldData ( p, "p" );
    }

    // fill the scalars vector and add it to imageData_
    if ( isScrambled )
    {
        double dummy = 0.0;
        for ( int vec=0; vec<numVecs; vec++ )
        {
            scalars->SetName ( scNames[vec].c_str() );
            for ( int k=0; k<numPoints; k++ )
                scalars->InsertNextValue ( p[k]>=0 ? x[vec][p[k]] : dummy );
            imageData->GetPointData()->AddArray ( scalars );
        }
    }
    else
        for ( int vec=0; vec<numVecs; vec++ )
        {
            scalars->SetName ( scNames[vec].c_str() );
            for ( int k=0; k<numPoints; k++ )
                scalars->InsertNextValue ( x[vec][k] );
            imageData->GetPointData()->AddArray ( scalars );
        }

    return;
}
// =============================================================================
void
VIO::Image::Writer::Abstract::
setImageData ( const ComplexMultiVector              & x,
               const Teuchos::Tuple<unsigned int,2>  & Nx,
               const Point                           & h,
               const Teuchos::Array<int>             & p,
               const Teuchos::Array<std::string>     & scalarsNames
             )
{
    int numVecs   = x.getNumVectors();
    int numPoints = ( Nx[0]+1 ) * ( Nx[1]+1 );

    // get scalarsNames, and insert default names if empty
    Teuchos::Array<std::string> scNames ( scalarsNames );
    if ( scNames.empty() )
    {
        scNames.resize ( numVecs );
        for ( int vec=0; vec<numVecs; vec++ )
            scNames[vec] = "z" + EpetraExt::toString ( vec );
    }
    
    // cast into vtkImageData
    vtkSmartPointer<vtkImageData> imageData =
        dynamic_cast<vtkImageData*> ( vtkDataSet_.GetPointer() );
    TEUCHOS_ASSERT_INEQUALITY( 0, !=, imageData );

    // set other image data
    imageData->SetDimensions ( Nx[0]+1, Nx[1]+1, 1 );
    imageData->SetOrigin ( 0.0, 0.0, 0.0 );
    imageData->SetSpacing ( h[0], h[1], 0.0 );

    // fill the scalar field
    vtkSmartPointer<vtkDoubleArray> scalars =
        vtkSmartPointer<vtkDoubleArray>::New();

    double dummy = 0.0;
    bool isScrambled = !p.empty();
    if ( isScrambled )
    {
        TEUCHOS_ASSERT_EQUALITY ( numPoints, p.length() );
        addFieldData ( p, "p" );
    }

    // real and imaginary part
    scalars->SetNumberOfComponents ( 2 );

    // fill the scalars vector and add it to imageData_
    Teuchos::ArrayRCP<const std::complex<double> > xView;
    for ( int vec=0; vec<numVecs; vec++ )
    {
        xView = x.getVector ( vec )->get1dView();
        scalars->SetName ( scNames[vec].c_str() );
        for ( int k=0; k<numPoints; k++ )
        {
            if ( isScrambled )
            {
                // TODO replace by InsertNextTuple
                scalars->InsertNextValue ( p[k]>=0 ? std::real ( xView[p[k]] ) : dummy );
                scalars->InsertNextValue ( p[k]>=0 ? std::imag ( xView[p[k]] ) : dummy );
            }
            else
            {
                scalars->InsertNextValue ( std::real ( xView[k] ) );
                scalars->InsertNextValue ( std::imag ( xView[k] ) );
            }
        }
        imageData->GetPointData()->AddArray ( scalars );
    }

    return;
}