Beispiel #1
0
DTKAdapter::DTKAdapter(Teuchos::RCP<const Teuchos::Comm<int> > in_comm, EquationSystems & in_es):
    comm(in_comm),
    es(in_es),
    mesh(in_es.get_mesh()),
    dim(mesh.mesh_dimension())
{
  std::set<unsigned int> semi_local_nodes;
  get_semi_local_nodes(semi_local_nodes);

  num_local_nodes = semi_local_nodes.size();

  vertices.resize(num_local_nodes);
  Teuchos::ArrayRCP<double> coordinates(num_local_nodes * dim);

  // Fill in the vertices and coordinates
  {
    unsigned int i = 0;

    for(std::set<unsigned int>::iterator it = semi_local_nodes.begin();
        it != semi_local_nodes.end();
        ++it)
    {
      const Node & node = mesh.node(*it);

      vertices[i] = node.id();

      for(unsigned int j=0; j<dim; j++)
        coordinates[(j*num_local_nodes) + i] = node(j);

      i++;
    }
  }

  // Currently assuming all elements are the same!
  DataTransferKit::DTK_ElementTopology element_topology = get_element_topology(mesh.elem(0));
  unsigned int n_nodes_per_elem = mesh.elem(0)->n_nodes();

  unsigned int n_local_elem = mesh.n_local_elem();

  Teuchos::ArrayRCP<int> elements(n_local_elem);
  Teuchos::ArrayRCP<int> connectivity(n_nodes_per_elem*n_local_elem);

  // Fill in the elements and connectivity
  {
    unsigned int i = 0;

    MeshBase::const_element_iterator end = mesh.local_elements_end();
    for(MeshBase::const_element_iterator it = mesh.local_elements_begin();
        it != end;
        ++it)
    {
      const Elem & elem = *(*it);
      elements[i] = elem.id();

      for(unsigned int j=0; j<n_nodes_per_elem; j++)
        connectivity[(j*n_local_elem)+i] = elem.node(j);

      i++;
    }
  }

  Teuchos::ArrayRCP<int> permutation_list(n_nodes_per_elem);
  for (unsigned int i = 0; i < n_nodes_per_elem; ++i )
    permutation_list[i] = i;

  /*
  if(this->processor_id() == 1)
    sleep(1);

  libMesh::out<<"n_nodes_per_elem: "<<n_nodes_per_elem<<std::endl;

  libMesh::out<<"Dim: "<<dim<<std::endl;

  libMesh::err<<"Vertices size: "<<vertices.size()<<std::endl;
  {
    libMesh::err<<this->processor_id()<<" Vertices: ";

    for(unsigned int i=0; i<vertices.size(); i++)
      libMesh::err<<vertices[i]<<" ";

    libMesh::err<<std::endl;
  }

  libMesh::err<<"Coordinates size: "<<coordinates.size()<<std::endl;
  {
    libMesh::err<<this->processor_id()<<" Coordinates: ";

    for(unsigned int i=0; i<coordinates.size(); i++)
      libMesh::err<<coordinates[i]<<" ";

    libMesh::err<<std::endl;
  }

  libMesh::err<<"Connectivity size: "<<connectivity.size()<<std::endl;
  {
    libMesh::err<<this->processor_id()<<" Connectivity: ";

    for(unsigned int i=0; i<connectivity.size(); i++)
      libMesh::err<<connectivity[i]<<" ";

    libMesh::err<<std::endl;
  }

  libMesh::err<<"Permutation_List size: "<<permutation_list.size()<<std::endl;
  {
    libMesh::err<<this->processor_id()<<" Permutation_List: ";

    for(unsigned int i=0; i<permutation_list.size(); i++)
      libMesh::err<<permutation_list[i]<<" ";

    libMesh::err<<std::endl;
  }

  */
  Teuchos::RCP<MeshContainerType> mesh_container = Teuchos::rcp(
    new MeshContainerType(dim, vertices, coordinates,
                          element_topology, n_nodes_per_elem,
                          elements, connectivity, permutation_list) );

  // We only have 1 element topology in this grid so we make just one mesh block
  Teuchos::ArrayRCP<Teuchos::RCP<MeshContainerType> > mesh_blocks(1);
  mesh_blocks[0] = mesh_container;

  // Create the MeshManager
  mesh_manager = Teuchos::rcp(new DataTransferKit::MeshManager<MeshContainerType>(mesh_blocks, comm, dim) );

  // Pack the coordinates into a field, this will be the positions we'll ask for other systems fields at
  target_coords = Teuchos::rcp(new DataTransferKit::FieldManager<MeshContainerType>(mesh_container, comm));
}
DTKInterpolationAdapter::DTKInterpolationAdapter(Teuchos::RCP<const Teuchos::MpiComm<int> > in_comm, EquationSystems & in_es, const Point & offset, unsigned int from_dim):
    comm(in_comm),
    es(in_es),
    _offset(offset),
    mesh(in_es.get_mesh()),
    dim(mesh.mesh_dimension())
{
  MPI_Comm old_comm = Moose::swapLibMeshComm(*comm->getRawMpiComm());

  std::set<GlobalOrdinal> semi_local_nodes;
  get_semi_local_nodes(semi_local_nodes);

  num_local_nodes = semi_local_nodes.size();

  vertices.resize(num_local_nodes);
  Teuchos::ArrayRCP<double> coordinates(num_local_nodes * dim);

  Teuchos::ArrayRCP<double> target_coordinates(num_local_nodes * from_dim);

  // Fill in the vertices and coordinates
  {
    GlobalOrdinal i = 0;

    for (std::set<GlobalOrdinal>::iterator it = semi_local_nodes.begin();
        it != semi_local_nodes.end();
        ++it)
    {
      const Node & node = mesh.node(*it);

      vertices[i] = node.id();

      for (GlobalOrdinal j=0; j<dim; j++)
        coordinates[(j*num_local_nodes) + i] = node(j) + offset(j);

      for (GlobalOrdinal j=0; j<from_dim; j++)
        target_coordinates[(j*num_local_nodes) + i] = node(j) + offset(j);

      i++;
    }
  }

  // Currently assuming all elements are the same!
  DataTransferKit::DTK_ElementTopology element_topology = get_element_topology(mesh.elem(0));
  GlobalOrdinal n_nodes_per_elem = mesh.elem(0)->n_nodes();

  GlobalOrdinal n_local_elem = mesh.n_local_elem();

  elements.resize(n_local_elem);
  Teuchos::ArrayRCP<GlobalOrdinal> connectivity(n_nodes_per_elem*n_local_elem);

  Teuchos::ArrayRCP<double> elem_centroid_coordinates(n_local_elem*from_dim);

  // Fill in the elements and connectivity
  {
    GlobalOrdinal i = 0;

    MeshBase::const_element_iterator end = mesh.local_elements_end();
    for (MeshBase::const_element_iterator it = mesh.local_elements_begin();
        it != end;
        ++it)
    {
      const Elem & elem = *(*it);
      elements[i] = elem.id();

      for (GlobalOrdinal j=0; j<n_nodes_per_elem; j++)
        connectivity[(j*n_local_elem)+i] = elem.node(j);

      {
        Point centroid = elem.centroid();
        for (GlobalOrdinal j=0; j<from_dim; j++)
          elem_centroid_coordinates[(j*n_local_elem) + i] = centroid(j) + offset(j);
      }

      i++;
    }
  }

  Teuchos::ArrayRCP<int> permutation_list(n_nodes_per_elem);
  for (GlobalOrdinal i = 0; i < n_nodes_per_elem; ++i )
    permutation_list[i] = i;

  /*
  Moose::out<<"n_nodes_per_elem: "<<n_nodes_per_elem<<std::endl;

  Moose::out<<"Dim: "<<dim<<std::endl;

  Moose::err<<"Vertices size: "<<vertices.size()<<std::endl;
  {
    Moose::err<<libMesh::processor_id()<<" Vertices: ";

    for (unsigned int i=0; i<vertices.size(); i++)
      Moose::err<<vertices[i]<<" ";

    Moose::err<<std::endl;
  }

  Moose::err<<"Coordinates size: "<<coordinates.size()<<std::endl;
  {
    Moose::err<<libMesh::processor_id()<<" Coordinates: ";

    for (unsigned int i=0; i<coordinates.size(); i++)
      Moose::err<<coordinates[i]<<" ";

    Moose::err<<std::endl;
  }

  Moose::err<<"Connectivity size: "<<connectivity.size()<<std::endl;
  {
    Moose::err<<libMesh::processor_id()<<" Connectivity: ";

    for (unsigned int i=0; i<connectivity.size(); i++)
      Moose::err<<connectivity[i]<<" ";

    Moose::err<<std::endl;
  }

  Moose::err<<"Permutation_List size: "<<permutation_list.size()<<std::endl;
  {
    Moose::err<<libMesh::processor_id()<<" Permutation_List: ";

    for (unsigned int i=0; i<permutation_list.size(); i++)
      Moose::err<<permutation_list[i]<<" ";

    Moose::err<<std::endl;
  }

  */
  Teuchos::RCP<MeshContainerType> mesh_container = Teuchos::rcp(
    new MeshContainerType(dim, vertices, coordinates,
                          element_topology, n_nodes_per_elem,
                          elements, connectivity, permutation_list) );

  // We only have 1 element topology in this grid so we make just one mesh block
  Teuchos::ArrayRCP<Teuchos::RCP<MeshContainerType> > mesh_blocks(1);
  mesh_blocks[0] = mesh_container;

  // Create the MeshManager
  mesh_manager = Teuchos::rcp(new DataTransferKit::MeshManager<MeshContainerType>(mesh_blocks, comm, dim) );

  // Pack the coordinates into a field, this will be the positions we'll ask for other systems fields at
  if (from_dim == dim)
    target_coords = Teuchos::rcp(new DataTransferKit::FieldManager<MeshContainerType>(mesh_container, comm));
  else
  {
    Teuchos::ArrayRCP<GlobalOrdinal> empty_elements(0);
    Teuchos::ArrayRCP<GlobalOrdinal> empty_connectivity(0);

    Teuchos::RCP<MeshContainerType> coords_only_mesh_container = Teuchos::rcp(
      new MeshContainerType(from_dim, vertices, target_coordinates,
                            element_topology, n_nodes_per_elem,
                            empty_elements, empty_connectivity, permutation_list) );

    target_coords = Teuchos::rcp(new DataTransferKit::FieldManager<MeshContainerType>(coords_only_mesh_container, comm));
  }

  {
    Teuchos::ArrayRCP<GlobalOrdinal> empty_elements(0);
    Teuchos::ArrayRCP<GlobalOrdinal> empty_connectivity(0);

    Teuchos::RCP<MeshContainerType> centroid_coords_only_mesh_container = Teuchos::rcp(
      new MeshContainerType(from_dim, elements, elem_centroid_coordinates,
                            element_topology, n_nodes_per_elem,
                            empty_elements, empty_connectivity, permutation_list) );

    elem_centroid_coords = Teuchos::rcp(new DataTransferKit::FieldManager<MeshContainerType>(centroid_coords_only_mesh_container, comm));
  }

  // Swap back
  Moose::swapLibMeshComm(old_comm);
}
/*!
 * \brief Get the wave mesh.
 */
Teuchos::RCP<DataTransferKit::MeshManager<WaveAdapter::MeshType> >
WaveAdapter::getMesh( const RCP_Wave& wave )
{
    // Get the process rank.
    int my_rank = wave->get_comm()->getRank();

    // Set the vertex dimension - this is a 1D problem.
    int vertex_dimension = 1;

    // Compute globally unique vertex ids.
    Teuchos::RCP<std::vector<double> > grid = wave->get_grid();
    Teuchos::ArrayRCP<int> vertices( grid->size() );
    for ( int i = 0; i < (int) vertices.size(); ++i )
    {
	vertices[i] = i + my_rank*vertices.size();
    }

    // Get the grid vertex coordinates.
    Teuchos::ArrayRCP<double> coordinates( &(*grid)[0], 0, grid->size(), false );

    // Set the grid topology - this is 1D so we are using line segments.
    DataTransferKit::DTK_ElementTopology element_topology = 
	DataTransferKit::DTK_LINE_SEGMENT;

    // Each line segment will be constructed by 2 vertices.
    int vertices_per_element = 2;

    // Compute globally unique element ids.
    Teuchos::ArrayRCP<int> elements( grid->size() - 1 );
    for ( int i = 0; i < (int) elements.size(); ++i )
    {
	elements[i] = i + my_rank*elements.size();
    }

    // Generate element connectivity. The global vertex ids are used to
    // describe the construction of each line segment.
    Teuchos::ArrayRCP<int> connectivity( vertices_per_element*elements.size() );
    for ( int i = 0; i < (int) elements.size(); ++i )
    {
	connectivity[i] = vertices[i];
	connectivity[ elements.size() + i ] = vertices[i+1];
    }

    // Define the permutation list. Here our line segments are ordered the
    // same as DTK canonical ordering so the list is an monotonically
    // increasing set of integers.
    Teuchos::ArrayRCP<int> permutation_list( vertices_per_element );
    for ( int i = 0; i < vertices_per_element; ++i )
    {
	permutation_list[i] = i;
    }

    // Build a DTK Mesh container with the data. The MeshType typedef is set
    // in the header file.
    Teuchos::RCP<MeshType> mesh_container = Teuchos::rcp(
	new MeshType( vertex_dimension, vertices, coordinates, 
		      element_topology, vertices_per_element, 
		      elements, connectivity, permutation_list ) );

    // We only have 1 element topology in this grid so we make just one mesh
    // block. 
    Teuchos::ArrayRCP<Teuchos::RCP<MeshType> > mesh_blocks( 1 );
    mesh_blocks[0] = mesh_container;

    // Return a mesh manager.
    return Teuchos::rcp( new DataTransferKit::MeshManager<MeshType>( 
			     mesh_blocks, wave->get_comm(), 1 ) );
}