Exemplo n.º 1
0
bool walk( Actor& a, Vec dir )
{
    auto sgn = [](int x){return x>0? 1 : x<0? -1 : 0;};
    Vec newPos = a.pos + Vec( sgn, dir );

    ActorList::iterator actorHere = actor_at( newPos );

    if( actorHere != actors.end() )
    {
        std::string message( 1, a.image );

        bool killed = attack( a, *actorHere );
        log( "%c %s %c", a.image, killed? "killed":"hit", actorHere->image );
        if( killed )
            actors.erase( actorHere );
    }
    else if( map.get(newPos) != '#' )
    {
        a.pos = newPos;
    }
    else
    {
        return false;
    }

    a.cooldown += 25 / a.speed;

    return true;
}
Exemplo n.º 2
0
void Physics::newActors(ActorList const & newActors)
{
	for(ActorList::const_iterator itr = newActors.begin(); itr != newActors.end(); ++itr)
	{
		btVector3 vel = (*itr)->initialVel;
		Physics::MotionState * actorMotion = new Physics::MotionState( btTransform( btQuaternion(0,0,0,1), (*itr)->pos ), *itr);
		motionStates.push_back( actorMotion );
		
		PhysObject const & physObject = (*itr)->physObject;	//grabs physical info about the actor
		
		if(physObject.mass != 0)
			physObject.shape->calculateLocalInertia(physObject.mass, *(physObject.fallInertia) );	//dynamic object so calculate local inertia

		btRigidBody::btRigidBodyConstructionInfo bodyCI(physObject.mass, actorMotion, physObject.shape, *(physObject.fallInertia) );	//TODO this can be shared so stop recreating
		btRigidBody * body = new btRigidBody(bodyCI);
		dynamicsWorld.addRigidBody(body);
		
		body->setLinearVelocity(btVector3(vel.getX(),vel.getY(), vel.getZ()));
		rigidBodies.push_back(body);
		
	}
}
Exemplo n.º 3
0
void force_calc()
{
  // Communication step: distribute ghost positions
  cells_update_ghosts();

  // VIRTUAL_SITES pos (and vel for DPD) update for security reason !!!
#ifdef VIRTUAL_SITES
  update_mol_vel_pos();
  ghost_communicator(&cell_structure.update_ghost_pos_comm);
#endif

#if defined(VIRTUAL_SITES_RELATIVE) && defined(LB)
  // This is on a workaround stage:
  // When using virtual sites relative and LB at the same time, it is necessary
  // to reassemble the cell lists after all position updates, also of virtual
  // particles.
  if ((lattice_switch & LATTICE_LB) && cell_structure.type == CELL_STRUCTURE_DOMDEC && (!dd.use_vList) )
    cells_update_ghosts();
#endif

espressoSystemInterface.update();

#ifdef COLLISION_DETECTION
  prepare_collision_queue();
#endif

#ifdef LB_GPU
#ifdef SHANCHEN
  if (lattice_switch & LATTICE_LB_GPU && this_node == 0) lattice_boltzmann_calc_shanchen_gpu();
#endif // SHANCHEN

  // transfer_momentum_gpu check makes sure the LB fluid doesn't get updated on integrate 0
  // this_node==0 makes sure it is the master node where the gpu exists
  if (lattice_switch & LATTICE_LB_GPU && transfer_momentum_gpu && (this_node == 0) ) lb_calc_particle_lattice_ia_gpu();
#endif // LB_GPU

#ifdef ELECTROSTATICS
  if (iccp3m_initialized && iccp3m_cfg.set_flag)
    iccp3m_iteration();
#endif
  init_forces();

  for (ActorList::iterator actor = forceActors.begin();
          actor != forceActors.end(); ++actor)
  {
    (*actor)->computeForces(espressoSystemInterface);
#ifdef ROTATION
    (*actor)->computeTorques(espressoSystemInterface);
#endif
  }

  calc_long_range_forces();

  switch (cell_structure.type) {
  case CELL_STRUCTURE_LAYERED:
    layered_calculate_ia();
    break;
  case CELL_STRUCTURE_DOMDEC:
    if(dd.use_vList) {
      if (rebuild_verletlist)
        build_verlet_lists_and_calc_verlet_ia();
      else
    calculate_verlet_ia();
    }
    else
      calc_link_cell();
    break;
  case CELL_STRUCTURE_NSQUARE:
    nsq_calculate_ia();

  }

#ifdef OIF_GLOBAL_FORCES
    double area_volume[2]; //There are two global quantities that need to be evaluated: object's surface and object's volume. One can add another quantity.
	area_volume[0] = 0.0; 
	area_volume[1] = 0.0; 
    for (int i=0;i< MAX_OBJECTS_IN_FLUID;i++){
        calc_oif_global(area_volume,i);
        if (fabs(area_volume[0])<1e-100 && fabs(area_volume[1])<1e-100) break;
        add_oif_global_forces(area_volume,i);
    }
#endif
  
#ifdef IMMERSED_BOUNDARY
  // Must be done here. Forces need to be ghost-communicated
    IBM_VolumeConservation();
#endif

#ifdef LB
  if (lattice_switch & LATTICE_LB) calc_particle_lattice_ia() ;
#endif

#ifdef COMFORCE
  calc_comforce();
#endif

#ifdef METADYNAMICS
  /* Metadynamics main function */
  meta_perform();
#endif

#ifdef CUDA
  copy_forces_from_GPU();
#endif

  // VIRTUAL_SITES distribute forces
#ifdef VIRTUAL_SITES
  ghost_communicator(&cell_structure.collect_ghost_force_comm);
  init_forces_ghosts();
  distribute_mol_force();
#endif

  // Communication Step: ghost forces
  ghost_communicator(&cell_structure.collect_ghost_force_comm);

  // apply trap forces to trapped molecules
#ifdef MOLFORCES
  calc_and_apply_mol_constraints();
#endif

  // should be pretty late, since it needs to zero out the total force
#ifdef COMFIXED
  calc_comfixed();
#endif

  // mark that forces are now up-to-date
  recalc_forces = 0;

}
Exemplo n.º 4
0
void energy_calc(double *result)
{
  if (!interactions_sanity_checks())
    return;

  init_energies(&energy);

#ifdef CUDA
  clear_energy_on_GPU();
#endif

  espressoSystemInterface.update();

  // Compute the energies from the energyActors
  for (ActorList::iterator actor= energyActors.begin();
      actor != energyActors.end(); ++actor)
    (*actor)->computeEnergy(espressoSystemInterface);

  on_observable_calc();
  
  switch (cell_structure.type) {
  case CELL_STRUCTURE_LAYERED:
    layered_calculate_energies();
    break;
  case CELL_STRUCTURE_DOMDEC: 
    if(dd.use_vList) {
      if (rebuild_verletlist)  
	build_verlet_lists();
      calculate_verlet_energies();
    }
    else
      calculate_link_cell_energies();
    break;
  case CELL_STRUCTURE_NSQUARE:
    nsq_calculate_energies();
  }
  /* rescale kinetic energy */
  energy.data.e[0] /= (2.0*time_step*time_step);

  calc_long_range_energies();

#ifdef CUDA
  copy_energy_from_GPU();
#endif
  
  /* gather data */
  MPI_Reduce(energy.data.e, result, energy.data.n, MPI_DOUBLE, MPI_SUM, 0, comm_cart);

  if (n_external_potentials > 0) {
    double* energies = (double*) malloc(n_external_potentials*sizeof(double));
    for (int i=0; i<n_external_potentials; i++) {
      energies[i]=external_potentials[i].energy;
    }
    double* energies_sum =  (double*) malloc(n_external_potentials*sizeof(double)); 
    MPI_Reduce(energies, energies_sum, n_external_potentials, MPI_DOUBLE, MPI_SUM, 0, comm_cart); 
    for (int i=0; i<n_external_potentials; i++) {
      external_potentials[i].energy=energies_sum[i];
    }
    free(energies);
    free(energies_sum);
  }

}
Exemplo n.º 5
0
ActorList::iterator actor_at( Vec pos )
{
    return std::find_if ( 
        actors.begin(), actors.end(), [=](const Actor& n) { return n.pos == pos; }
    );
}