Beispiel #1
0
std::vector< mesh::Entity > GeomDecomp::entity_coordinates(stk::mesh::BulkData& bulk_data, const mesh::Entity                 & entity,
                                                                  const VectorField            & nodal_coor,
                                                                  std::vector<std::vector<double> >  & coordinates)
{
  coordinates.clear();
  std::vector< mesh::Entity > mesh_nodes;

  const mesh::EntityRank enttype   = bulk_data.entity_rank(entity);
  if ( enttype == NODE_RANK )
  {
    throw std::runtime_error("GeomDecomp::entity_coordinates Error: Can not be called for nodal entities.");
  } else {

    // Loop over node relations in mesh entities
    const percept::MyPairIterRelation nr   (bulk_data, entity , NODE_RANK);

    for (unsigned inr=0; inr < nr.size(); ++inr)
    {
      const percept::MyPairIterRelation::MyRelation  &rel = nr[inr];
      //if (rel.entity_rank() ==  NODE_RANK) { // %fixme: need to check for USES relation
      if (bulk_data.entity_rank(rel.entity()) ==  NODE_RANK) { // %fixme: need to check for USES relation
        const mesh::Entity nent = rel.entity();
        //const unsigned ndim(nodal_coor.max_size(NODE_RANK)/sizeof(double)); // TODO - is there a better way to get this info?
        const unsigned ndim(nodal_coor.max_size(NODE_RANK)); // TODO - is there a better way to get this info?
        double * coor = mesh::field_data(nodal_coor, nent);
        if (!coor) {
          throw std::runtime_error("GeomDecomp::entity_coordinates Error: The coordinate field does not exist.");
        }
        std::vector<double> temp(ndim);
        for ( unsigned i = 0; i < ndim; ++i ) { temp[i] = coor[i]; }
        coordinates.push_back(temp);
        mesh_nodes.push_back(nent);
      }
    }
  }
  return mesh_nodes;
}
Beispiel #2
0
std::vector<std::vector<double> > GeomDecomp::compute_entity_centroid(stk::mesh::BulkData& bulk_data, const mesh::Entity & entity,
                                                                   const VectorField & nodal_coor_ref,
                                                                   std::vector<double>   & centroid)
{
  std::vector<std::vector<double> > coordinates;
  stk::mesh::EntityRank entity_rank = bulk_data.entity_rank(entity);
  if (entity_rank == stk::topology::ELEMENT_RANK + 1)
    {
      for (stk::mesh::EntityRank irank=stk::topology::NODE_RANK; irank <= stk::topology::ELEMENT_RANK; ++irank)
        {
          const percept::MyPairIterRelation nr(bulk_data, entity , irank);
          for (unsigned ii=0; ii < nr.size(); ++ii)
            {
              stk::mesh::Entity elem = nr[ii].entity();
              std::vector<std::vector<double> > coordinates_1;
              entity_coordinates(bulk_data, elem, nodal_coor_ref, coordinates_1);
              coordinates.insert(coordinates.end(), coordinates_1.begin(), coordinates_1.end());
            }
        }
    }
  else
    {
      entity_coordinates(bulk_data, entity, nodal_coor_ref, coordinates);
    }

  const int num_nodes = coordinates.size();
  const int ndim      = coordinates.front().size();

  centroid.resize(ndim);
  for (int i=0; i<ndim; ++i) { centroid[i] = 0; }
  for ( int j = 0; j < num_nodes; ++j ) {
    for ( int i = 0; i < ndim; ++i ) { centroid[i] += coordinates[j][i]; }
  }
  if (1 != num_nodes) {
    for (int i=0; i<ndim; ++i) { centroid[i] /= num_nodes; }
  }
  return coordinates;
}
Intrepid::FieldContainer<double> STKMeshHelpers::extractEntityNodeCoordinates( 
    const Teuchos::Array<stk::mesh::Entity>& stk_entities, 
    const stk::mesh::BulkData& bulk_data,
    const int space_dim )
{
    // Cast the field.
    const stk::mesh::FieldBase* coord_field_base= 
	bulk_data.mesh_meta_data().coordinate_field();
    const stk::mesh::Field<double,FieldType>* coord_field =
	dynamic_cast<const stk::mesh::Field<double,FieldType>* >(
	    coord_field_base);

    // Allocate the coordinate array.
    int num_cells = stk_entities.size();
    int num_nodes = 0;
    stk::mesh::EntityRank stk_rank = stk::topology::INVALID_RANK;
    if ( num_cells > 0 )
    {
	stk_rank = bulk_data.entity_rank(stk_entities[0]);
	if ( stk::topology::NODE_RANK == stk_rank )
	{
	    num_nodes = 1;
	}
	else
	{
	    const stk::mesh::Entity* begin = 
		bulk_data.begin_nodes( stk_entities[0] );
	    const stk::mesh::Entity* end = 
		bulk_data.end_nodes( stk_entities[0] );
	    num_nodes = std::distance( begin, end );
	}
    }
    Intrepid::FieldContainer<double> coords( num_cells, num_nodes, space_dim );

    // Extract the coordinates.
    double* node_coords = 0;
    for ( int c = 0; c < num_cells; ++c )
    {
	if ( stk::topology::NODE_RANK == stk_rank )
	{
	    node_coords = stk::mesh::field_data( *coord_field, stk_entities[c] );
	    for ( int d = 0; d < space_dim; ++d )
	    {
		coords(c,0,d) = node_coords[d];
	    }
	}
	else
	{
	    const stk::mesh::Entity* begin = bulk_data.begin_nodes( stk_entities[c] );
	    DTK_REMEMBER(
		const stk::mesh::Entity* end = bulk_data.end_nodes( stk_entities[c] ) 
		);
	    DTK_CHECK( std::distance(begin,end) == num_nodes );
	    for ( int n = 0; n < num_nodes; ++n )
	    {
		node_coords = stk::mesh::field_data( *coord_field, begin[n] );
		for ( int d = 0; d < space_dim; ++d )
		{
		    coords(c,n,d) = node_coords[d];
		}
	    }
	}
    }

    return coords;
}