Example #1
0
void System::detach()
{
    typedef std::vector< Entity* > EntityVector;
    EntityVector entitiesToDetach;

    for ( SystemMap::iterator i( theSystemMap.begin() ),
                              e( theSystemMap.end() );
          i != e; ++i )
    {
        entitiesToDetach.push_back( ( *i ).second );
    }

    for ( ProcessMap::iterator i( theProcessMap.begin() ),
                               e( theProcessMap.end() );
          i != e; ++i )
    {
        entitiesToDetach.push_back( ( *i ).second );
    }

    for ( VariableMap::iterator i( theVariableMap.begin() ),
                                e( theVariableMap.end() );
          i != e; ++i )
    {
        entitiesToDetach.push_back( ( *i ).second );
    }

    for ( EntityVector::iterator i( entitiesToDetach.begin() ),
                                 e( entitiesToDetach.end() );
          i != e; ++i )
    {
        ( *i )->detach();
    }

    if ( theStepper )
    {
        try { theStepper->unregisterSystem( this ); } catch ( NotFound const& ) {}
        theStepper = 0;
    }

    theSizeVariable = 0;

    Entity::detach();
}
Example #2
0
EntityVector Serializer::deserialize()
{
	EntityVector entities;
	QDomNodeList nodes = mDomElement.elementsByTagName(nodeKey);
	for (unsigned i = 0; i < nodes.length(); i++)
	{
		QDomNode node = nodes.at(i);
		QDomElement element = node.toElement();
		Entity entity = parseNode(element);
		entities.push_back(entity);
	}
	return entities;
}
Example #3
0
void Game::killDeadEntities(){
	EntityVector entities;
	for (EntityVector::iterator i = mEntities.begin(); i != mEntities.end(); i++)
	{
		Entity *entity = *i;
		if (entity->isAlive()) {
			entities.push_back(entity);
		}
		else{
			delete entity;
		}
	}
	mEntities = entities;
}
Example #4
0
stk::topology get_subcell_nodes(const BulkData& mesh, const Entity entity,
        EntityRank subcell_rank,
        unsigned subcell_identifier,
        EntityVector & subcell_nodes)
{
    ThrowAssert(subcell_rank <= stk::topology::ELEMENT_RANK);

    subcell_nodes.clear();

    // get cell topology
    stk::topology celltopology = mesh.bucket(entity).topology();

    //error checking
    {
//no celltopology defined
        if(celltopology == stk::topology::INVALID_TOPOLOGY)
        {
            return celltopology;
        }

// valid ranks fall within the dimension of the cell topology
        const bool bad_rank = subcell_rank >= celltopology.dimension();
        ThrowInvalidArgMsgIf( bad_rank, "subcell_rank is >= celltopology dimension\n");

// subcell_identifier must be less than the subcell count
        const bool bad_id = subcell_identifier >= celltopology.num_sub_topology(subcell_rank);
        ThrowInvalidArgMsgIf( bad_id, "subcell_id is >= subcell_count\n");
    }

    // Get the cell topology of the subcell
    stk::topology subcell_topology =
            celltopology.sub_topology(subcell_rank, subcell_identifier);

    const int num_nodes_in_subcell = subcell_topology.num_nodes();

    // For the subcell, get it's local nodes ids
    std::vector<unsigned> subcell_node_local_ids(num_nodes_in_subcell);
    celltopology.sub_topology_node_ordinals(subcell_rank, subcell_identifier, subcell_node_local_ids.begin());

    Entity const *node_relations = mesh.begin_nodes(entity);
    subcell_nodes.reserve(num_nodes_in_subcell);

    for(int i = 0; i < num_nodes_in_subcell; ++i)
    {
        subcell_nodes.push_back(node_relations[subcell_node_local_ids[i]]);
    }

    return subcell_topology;
}
Example #5
0
void Game::removeDeadEntities()
{
	//Remove each entity that returns isAlive() = false
	EntityVector entities;
	for (EntityVector::iterator i = mEntities.begin(); i != mEntities.end(); i++)
	{
		Entity *entity = *i;
		if (entity->isAlive())
		{
			entities.push_back(entity);
		}
		else
		{
			if (entity != ship)
			{
				delete entity;
			}
		}
	}
	mEntities = entities;
}
Example #6
0
TEST(UnitTestingOfBulkData, test_other_ghosting_2)
{
  //
  // testing if modification flags propagate properly for ghosted entities
  //
  // To test this, we focus on a single node shared on 2 procs, ghosted on others
  //

  /**
   * 1D Mesh (node,owner)--[elem,owner]---(...)
   *
   * <---(70,0)--[500,0]--(41,1)--[301,1]---(42,2)---[402,2]---(70,0)--->
   *
   * <---(50,0)--[100,0]--(21,1)--[201,1]---(32,2)---[302,2]---(50,0)--->
   *
   */

  // elem, node0, node1, owner
  EntityId elems_0[][4] = { {100, 21, 50, 0}, {201, 21, 32, 1}, {302, 32, 50, 2},
                            {500, 41, 70, 0}, {301, 41, 42, 1}, {402, 42, 70, 2}  };
  // node, owner
  EntityId nodes_0[][2] = { {21,1}, {50,0}, {32, 2}, {41, 1}, {42, 1}, {70, 0} };

  unsigned nelems = sizeof(elems_0)/4/sizeof(EntityId);
  unsigned nnodes = sizeof(nodes_0)/2/sizeof(EntityId);

  stk::ParallelMachine pm = MPI_COMM_WORLD;

  // Set up meta and bulk data
  const unsigned spatial_dim = 2;

  std::vector<std::string> entity_rank_names = stk::mesh::entity_rank_names();
  entity_rank_names.push_back("FAMILY_TREE");

  MetaData meta_data(spatial_dim, entity_rank_names);
  //Part & part_tmp = meta_data.declare_part( "temp");

  meta_data.commit();
  BulkData mesh(meta_data, pm);
  //BulkData mesh(MetaData::get_meta_data(meta_data), pm);
  int p_rank = mesh.parallel_rank();
  int p_size = mesh.parallel_size();

  if (p_size != 3) return;

  //
  // Begin modification cycle so we can create the entities and relations
  //

  // We're just going to add everything to the universal part
  stk::mesh::PartVector empty_parts;

  // Create elements
  const EntityRank elem_rank = stk::topology::ELEMENT_RANK;
  Entity elem = Entity();

  mesh.modification_begin();

  for (unsigned ielem=0; ielem < nelems; ielem++)
    {
      if (static_cast<int>(elems_0[ielem][3]) == p_rank)
        {
          elem = mesh.declare_entity(elem_rank, elems_0[ielem][0], empty_parts);

          EntityVector nodes;
          // Create node on all procs
          nodes.push_back( mesh.declare_entity(NODE_RANK, elems_0[ielem][2], empty_parts) );
          nodes.push_back( mesh.declare_entity(NODE_RANK, elems_0[ielem][1], empty_parts) );

          // Add relations to nodes
          mesh.declare_relation( elem, nodes[0], 0 );
          mesh.declare_relation( elem, nodes[1], 1 );

        }
    }

  mesh.modification_end();

  Entity node1 = Entity();

  // change node owners
  mesh.modification_begin();

  std::vector<EntityProc> change;

  for (unsigned inode=0; inode < nnodes; inode++)
    {
      node1 = mesh.get_entity(stk::topology::NODE_RANK, nodes_0[inode][0]);
      if (mesh.is_valid(node1) && mesh.parallel_owner_rank(node1) == p_rank)
        {
          int dest = nodes_0[inode][1];
          EntityProc eproc(node1, dest);
          change.push_back(eproc);
        }
    }

  mesh.change_entity_owner( change );

  mesh.modification_end();

  checkBuckets(mesh);

  MPI_Barrier(MPI_COMM_WORLD);


  // attempt to delete a node and its elems but on a ghosted proc
  mesh.modification_begin();

  if (p_rank == 2)
    {
      node1 = mesh.get_entity(stk::topology::NODE_RANK, 21);
      Entity elem1 = mesh.get_entity(stk::topology::ELEMENT_RANK, 201);
      Entity elem2 = mesh.get_entity(stk::topology::ELEMENT_RANK, 100);

      bool did_it_elem = mesh.destroy_entity(elem1);
      did_it_elem = did_it_elem & mesh.destroy_entity(elem2);
      ASSERT_TRUE(did_it_elem);
      bool did_it = mesh.destroy_entity(node1);
      ASSERT_TRUE(did_it);
    }

  mesh.modification_end();

  checkBuckets(mesh);

  // this node should no longer exist anywhere
  node1 = mesh.get_entity(stk::topology::NODE_RANK, 21);

  // uncomment to force failure of test
  // ASSERT_TRUE(node1 == 0);

}
Example #7
0
TEST ( UnitTestBulkData_new , testGhostHandleRemainsValidAfterRefresh )
{
  //
  // Testing if a handle to a ghosted entity remains valid before and after a
  // modification cycle in which the ghost is refreshed.
  //
  // To test this, we focus on a single node shared on 2 procs, ghosted on others
  //
  //
  // 1D Mesh (node,owner)--[elem,owner]---(...)
  //
  // <---(50,0)--[100,0]--(21,1)--[201,1]---(32,2)---[302,2]---(50,0)--->
  //

  // elem, node0, node1, owner
  EntityId elems_0[][4] = { {100, 21, 50, 0}, {201, 21, 32, 1}, {302, 32, 50, 2} };
  // node, owner
  EntityId nodes_0[][2] = { {21,1}, {50,0}, {32, 2} };

  const unsigned nelems = sizeof(elems_0)/4/sizeof(EntityId);
  const unsigned nnodes = sizeof(nodes_0)/2/sizeof(EntityId);

  stk::ParallelMachine pm = MPI_COMM_WORLD;

  // Set up meta and bulk data
  const unsigned spatial_dim = 2;

  std::vector<std::string> entity_rank_names = stk::mesh::entity_rank_names();
  entity_rank_names.push_back("FAMILY_TREE");

  MetaData meta_data(spatial_dim, entity_rank_names);
  //Part & part_tmp = meta_data.declare_part( "temp");

  meta_data.commit();
  unsigned max_bucket_size = 1;
  BulkData mesh(meta_data, pm, max_bucket_size);
  //BulkData mesh(MetaData::get_meta_data(meta_data), pm);
  int p_rank = mesh.parallel_rank();
  int p_size = mesh.parallel_size();

  if (p_size != 3) return;

  //
  // Begin modification cycle so we can create the entities and relations
  //
  {
    // We're just going to add everything to the universal part
    PartVector empty_parts;

    // Create elements
    const EntityRank elem_rank = stk::topology::ELEMENT_RANK;
    Entity elem = Entity();

    mesh.modification_begin();

    for (unsigned ielem=0; ielem < nelems; ielem++) {
      if (static_cast<int>(elems_0[ielem][3]) == p_rank) {
        elem = mesh.declare_entity(elem_rank, elems_0[ielem][0], empty_parts);

        EntityVector nodes;
        // Create node on all procs
        nodes.push_back( mesh.declare_entity(stk::topology::NODE_RANK, elems_0[ielem][2], empty_parts) );
        nodes.push_back( mesh.declare_entity(stk::topology::NODE_RANK, elems_0[ielem][1], empty_parts) );

        // Add relations to nodes
        mesh.declare_relation( elem, nodes[0], 0 );
        mesh.declare_relation( elem, nodes[1], 1 );
      }
    }

    mesh.modification_end();
  }

  // change node owners
  {
    mesh.modification_begin();

    std::vector<EntityProc> change;

    for (unsigned inode=0; inode < nnodes; inode++) {
      Entity node = mesh.get_entity(stk::topology::NODE_RANK, nodes_0[inode][0]);
      if (mesh.is_valid(node) && mesh.parallel_owner_rank(node) == p_rank) {
        int dest = nodes_0[inode][1];
        EntityProc eproc(node, dest);
        change.push_back(eproc);
      }
    }

    mesh.change_entity_owner( change );

    mesh.modification_end();
  }

  // The real test is here
  {
    Entity node_21_handle_before_elem_deletion = mesh.get_entity(stk::topology::NODE_RANK, 21);
    if (p_rank == 2) {
      ASSERT_TRUE(mesh.in_receive_ghost(mesh.entity_key(node_21_handle_before_elem_deletion)));
    }

    // attempt to delete a node and its elems but on a ghosted proc
    mesh.modification_begin();

    Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 100);
    if (mesh.is_valid(elem)) mesh.destroy_entity(elem);

    mesh.modification_end();

    // Key check is here
    if (p_rank == 2) {
      ASSERT_TRUE(mesh.is_valid(node_21_handle_before_elem_deletion));
    }
  }
}