Ejemplo n.º 1
0
/* A list of trapped molecules present on this node is created (local_trapped_mols)*/
void get_local_trapped_mols (IntList *local_trapped_mols)
{
  int c, i, mol, j, fixed;

  for (c = 0; c < local_cells.n; c++) {
    for(i = 0; i < local_cells.cell[c]->n; i++) {
      mol = local_cells.cell[c]->part[i].p.mol_id;
      if ( mol >= n_molecules ) {
	char *errtxt = runtime_error(128 + 3*ES_INTEGER_SPACE);
	ERROR_SPRINTF(errtxt, "{ 094 can't calculate molforces no such molecule as %d }",mol);
	return;
      }

      /* Check to see if this molecule is fixed */
      fixed =0;
      for(j = 0; j < 3; j++) {
#ifdef EXTERNAL_FORCES
	if (topology[mol].trap_flag & COORD_FIXED(j)) fixed = 1;
	if (topology[mol].noforce_flag & COORD_FIXED(j)) fixed = 1;
#endif
      }  
      if (fixed) {
	/* if this molecule isn't already in local_trapped_mols then add it in */
	if (!intlist_contains(local_trapped_mols,mol)) {
	  realloc_intlist(local_trapped_mols, local_trapped_mols->max + 1);
	  local_trapped_mols->e[local_trapped_mols->max-1] = mol;
	  local_trapped_mols->n = local_trapped_mols->max;
	}
      }
    }
  }
}
Ejemplo n.º 2
0
void mpi_comm_mol_info(IntList *local_trapped_mols) {
  int i, j, k, mol, count;
  double com[3] = {0,0,0};
  double v[3] = {0,0,0};
  double f[3] = {0,0,0};
  double mass = 0;
  /* number of trapped molecules on each node */
  int *n_local_mols;
  /* sum of all elements of n_local_mols */
  int sum_n_local_mols;
  /* lists of which molecules are on each node in order of ascending node number */
  int *local_mols;
  MPI_Status status;

  n_local_mols = malloc(n_nodes*sizeof(int));
  sum_n_local_mols = 0;

  /* Everyone tells me how many trapped molecules are on their node */
  for (i=1; i <n_nodes; i++) {
    MPI_Recv(&(n_local_mols[i]),1,MPI_INT,i,99,MPI_COMM_WORLD,&status);
  }

  for (i=1; i <n_nodes; i++) {
    sum_n_local_mols += n_local_mols[i];
  }
  local_mols = malloc(sum_n_local_mols*sizeof(int));

  /* Everyone tells me which trapped molecules are on their node */
  count = 0;
  for (i=1; i <n_nodes; i++) {
    MPI_Recv(&(local_mols[count]),n_local_mols[i],MPI_INT,i,99,MPI_COMM_WORLD,&status);
    count += n_local_mols[i];
  }

  /* Initialise the centre of masses, velocities and forces to 0
     except for molecules present on master node which are initialized to the local values on the master node
     The centre of masses and velocities are weighted by the total mass on the master node */
  for (i = 0; i < n_molecules; i++) {
    mol =i;
    if (intlist_contains(local_trapped_mols,i)) {
      for (j = 0; j < 3; j++) {
	topology[mol].com[j] = topology[mol].com[j] * topology[mol].mass;
	topology[mol].v[j] = topology[mol].v[j] * topology[mol].mass;
	topology[mol].f[j] = topology[mol].f[j];
      }
    } else {
      topology[mol].mass = 0;
      for (j = 0; j < 3; j++) {
	topology[mol].com[j] = 0;
	topology[mol].v[j] = 0;
	topology[mol].f[j] = 0;
      }
    }
  }
  
  /* The masses, coms, velocities and forces for trapped molecules are received from the slave nodes.
     They are added into the running sums in topology[mol] */
  count = 0;
  for (i = 1; i < n_nodes; i++) {
    for (j = 0; j < n_local_mols[i]; j++) {
      mol = local_mols[count];
      count += 1;
      MPI_Recv(&mass,1,MPI_DOUBLE,i,99,MPI_COMM_WORLD,&status);
      MPI_Recv(com,3,MPI_DOUBLE,i,99,MPI_COMM_WORLD,&status);
      MPI_Recv(v,3,MPI_DOUBLE,i,99,MPI_COMM_WORLD,&status);
      MPI_Recv(f,3,MPI_DOUBLE,i,99,MPI_COMM_WORLD,&status);
      topology[mol].mass = topology[mol].mass + mass;
      for (k = 0; k< 3; k++) {
	topology[mol].com[k] += com[k]*mass;
	topology[mol].v[k] += v[k]*mass;
	topology[mol].f[k] += f[k];
      }
    }    
  }

  /* The centre of masses and velocities are renormalized by the total molecular weights */
  for (mol = 0; mol < n_molecules; mol++) {
    for (k=0;k <3; k ++) {
      topology[mol].com[k] = topology[mol].com[k]/topology[mol].mass;
      topology[mol].v[k] = topology[mol].v[k]/topology[mol].mass;
    }
  }

  /* The force exerted by the traps on the molecules are calculated */
  calc_trap_force();

  /* The molecule information and trap forces are sent back to the slave nodes. */
  count = 0;
  for (i = 1; i < n_nodes ; i++) {
    for (j = 0; j < n_local_mols[i]; j++) {
      mol = local_mols[count];
      count += 1;
      MPI_Send(&(topology[mol].mass),1,MPI_DOUBLE,i,99,MPI_COMM_WORLD);
      MPI_Send(topology[mol].com,3,MPI_DOUBLE,i,99,MPI_COMM_WORLD);
      MPI_Send(topology[mol].v,3,MPI_DOUBLE,i,99,MPI_COMM_WORLD);
      MPI_Send(topology[mol].f,3,MPI_DOUBLE,i,99,MPI_COMM_WORLD);
      MPI_Send(topology[mol].trap_force,3,MPI_DOUBLE,i,99,MPI_COMM_WORLD);
    }
  }

  free(local_mols);
  free(n_local_mols);

}