int tclcommand_inter_parse_scafacos(Tcl_Interp *interp, int argc, char ** argv) {
  if(argc < 1)
    return TCL_ERROR;

  // Scafacos can be used either for charges or for dipoles, not for both.
  if (dipolar) {
    if (coulomb.method==COULOMB_SCAFACOS) {
      runtimeErrorMsg() << "Scafacos already in use for charges.";
      return TCL_ERROR;
    }
  }
  else 
  {
    #ifdef SCAFACOS_DIPOLES
    if (coulomb.Dmethod==DIPOLAR_SCAFACOS) {
      runtimeErrorMsg() << "Scafacos already in use for dipoles.";
      return TCL_ERROR;
    }
    #endif
  }





  
  const std::string method(argv[0]);
  
  std::stringstream params;

  if(argc > 1) {
    for(int i = 1; i < argc; i++) {
      params << std::string(argv[i]);
      if(i != (argc-1))
        params << ",";
    }
  }

  // Coulomb ia
  if (! dipolar)
  {
    coulomb.method  = COULOMB_SCAFACOS;
  }
  else
  // Dipolar interaction
  {
    #ifdef SCAFACOS_DIPOLES
      coulomb.Dmethod  = DIPOLAR_SCAFACOS;
    #else
      runtimeErrorMsg() << "Dipolar support for SCAFACOS not compiled in. Activate via SCAFACOS_DIPOLES in myconfig.hpp.";
    #endif
  }

  mpi_bcast_coulomb_params();
  Scafacos::set_parameters(method, params.str(),dipolar);


  
  return TCL_OK;
}
Example #2
0
int getintersection(double pos1[3], double pos2[3],int given, int get, double value, double *answer, double box_size[3])
{
  /*pos1 and pos2 are two particle positions.                                                  */
  /*given and get are integers from 0 to 2. 0 = x direction. 1 = y direction. 2 = z direction  */
  /*there is a point on the line between the two particles p1 and p2 such that r[given]=value  */
  /*this procedure returns the value of r[get] at that point                                   */

  double p2r[3];
  int i;

  for (i=0;i<3;i++) {
    p2r[i] = drem_down((pos2[i]-pos1[i])+box_size[i]/2.0,box_size[i])-box_size[i]/2.0;
  }
  value = drem_down((value-pos1[given])+box_size[given]/2.0,box_size[given])-box_size[given]/2.0;
  //PTENSOR_TRACE(fprintf(stderr,"%d: getintersection: p1 is %f %f %f p2 is %f %f %f p2r is %f %f %f newvalue is %f\n",this_node,pos1[0],pos1[1],pos1[2],pos2[0],pos2[1],pos2[2],p2r[0],p2r[1],p2r[2],value););
  
  if ((value)*(p2r[given]) < -0.0001) {
      runtimeErrorMsg() <<"analyze stress_profile: getintersection: intersection is not between the two given particles - " << value << " is not between " << 0.0 << " and " << p2r[given] << " and box size is " << box_size[given] << ", given is " << given << "\n";
    return 0; 
  } else if (given == get) {
    *answer =  drem_down(value + pos1[given],box_size[given]);;
  } else if (0==p2r[given]) {
      runtimeErrorMsg() <<"analyze stress_profile: getintersection: intersection is a line, not a point - value is " << value << " same as " << 0.0 << " and " << p2r[given] << "\n";
    return 0;   
  } else {
    *answer =  drem_down(pos1[get]+p2r[get]/p2r[given]*value,box_size[get]);
  }
  return 1;
}
Example #3
0
inline void check_particle_force(Particle *part) {
  for (int i=0; i< 3; i++) {
    if (isnan(part->f.f[i])) {
      runtimeErrorMsg() << "force on particle "<< part->p.identity << " was NAN.";
    }
  }

#ifdef ROTATION
  for (int i=0; i< 3; i++) {
    if (isnan(part->f.torque[i])) {
      runtimeErrorMsg() << "torque on particle "<< part->p.identity << " was NAN.";
    }
  }
#endif
}
Example #4
0
void Lattice::interpolate(double* pos, double* value) {
    if (this->interpolation_type == INTERPOLATION_LINEAR) {
        interpolate_linear(pos, value);
    } else {
        runtimeErrorMsg() <<"Unknown interpolation type";
    }
}
Example #5
0
void set_dipolar(bool d) {
  if (scafacos){ 
    scafacos->set_dipolar(d);
  }
  else
    runtimeErrorMsg() << "Scafacos not initialized.";
}
Example #6
0
/** Initialize all data structures for nemd. */
void nemd_init(int n_slabs, int n_exchange, double shear_rate) 
{
  int i;
  
  INTEG_TRACE(fprintf(stderr,"%d: nemd_init: n_slabs=%d n_exchange=%d\n",this_node, n_slabs, n_exchange));

  /* check node grid */
  if( n_nodes > 1 ) {
      runtimeErrorMsg() <<"NEMD is a single node feature";
    return;
  }

  /* first free old structures befor initializing new ones */
  if(nemddata.n_slabs > -1) nemd_free();
  /* exit nemd integration */
  if(n_slabs == 0) return;

  /* fill nemd structure */
  nemddata.n_slabs          = n_slabs;
  nemddata.top_slab         = 0;
  nemddata.mid_slab         = n_slabs/2;

  nemddata.thickness        = box_l[2]/(double)nemddata.n_slabs;
  nemddata.invthickness     = 1.0 / nemddata.thickness;

  nemddata.shear_rate       = shear_rate;
  nemddata.slab_vel         = time_step*shear_rate*box_l[2]/4.0;

  nemddata.n_exchange       = n_exchange;
 
  nemddata.slab             = (Slab *)Utils::malloc(nemddata.n_slabs*sizeof(Slab));
  nemddata.velocity_profile = (double *)Utils::malloc(nemddata.n_slabs*sizeof(double));

  nemddata.momentum = 0.0;
  nemddata.momentum_norm = 0;

  /* initialize slabs and velocity profile */
  for(i=0;i<nemddata.n_slabs;i++) {
    nemddata.velocity_profile[i]     = 0.0;

    nemddata.slab[i].v_mean          = 0.0;
    nemddata.slab[i].n_parts_in_slab = 0;
    nemddata.slab[i].v_min           = 0.0;
    nemddata.slab[i].ind_min         = 0;
    nemddata.slab[i].fastest         = NULL;
    nemddata.slab[i].n_fastest       = 0;
    nemddata.slab[i].vel_diff        = 0.0;
  }
  /* allocate arrays for indices of fastest particles in slab */
  if(nemddata.n_exchange > 0) {
    nemddata.slab[nemddata.top_slab].fastest = (int *)Utils::malloc(nemddata.n_exchange*sizeof(int));
    nemddata.slab[nemddata.mid_slab].fastest = (int *)Utils::malloc(nemddata.n_exchange*sizeof(int));
  }
  for(i=0;i<nemddata.n_exchange;i++) {
    nemddata.slab[nemddata.top_slab].fastest[i] = -1;
    nemddata.slab[nemddata.mid_slab].fastest[i] = -1;
  }
  nemddata.slab[nemddata.top_slab].v_min   = -1e10;
  nemddata.slab[nemddata.mid_slab].v_min   = +1e10;
}
Example #7
0
/** Calculate the local fluid momentum.
 * The calculation is implemented explicitly for the special case of D3Q19.
 * @param index The local lattice site (Input).
 * @param j local fluid speed
 */
inline void lb_calc_local_j(index_t index, double *j) {

#ifndef D3Q19
#error Only D3Q19 is implemened!
#endif
  if (!(lattice_switch & LATTICE_LB)) {
    runtimeErrorMsg() <<"Error in lb_calc_local_j in " << __FILE__ << __LINE__ << ": CPU LB not switched on.";
    j[0]=j[1]=j[2]=0;
    return;
  }

  j[0] =   lbfluid[0][1][index]  - lbfluid[0][2][index]
         + lbfluid[0][7][index]  - lbfluid[0][8][index]  
         + lbfluid[0][9][index]  - lbfluid[0][10][index] 
         + lbfluid[0][11][index] - lbfluid[0][12][index] 
         + lbfluid[0][13][index] - lbfluid[0][14][index];
  j[1] =   lbfluid[0][3][index]  - lbfluid[0][4][index]
         + lbfluid[0][7][index]  - lbfluid[0][8][index]  
         - lbfluid[0][9][index]  + lbfluid[0][10][index]
         + lbfluid[0][15][index] - lbfluid[0][16][index] 
         + lbfluid[0][17][index] - lbfluid[0][18][index]; 
  j[2] =   lbfluid[0][5][index]  - lbfluid[0][6][index]  
         + lbfluid[0][11][index] - lbfluid[0][12][index] 
         - lbfluid[0][13][index] + lbfluid[0][14][index]
         + lbfluid[0][15][index] - lbfluid[0][16][index] 
         - lbfluid[0][17][index] + lbfluid[0][18][index];

}
Example #8
0
void print_bond_len()
{
  int i, k, c, np;
  Cell *cell;
  Particle *p;
  Bonded_ia_parameters *b_ia;
  double r_ij[3];
  printf("%d: ", this_node);
  for (c = 0; c < local_cells.n; c++) {
    cell = local_cells.cell[c];
    p  = cell->part;
    np = cell->n;
    for(i = 0; i < np; i++) {
       k=0;
       while(k<p[i].bl.n)
       {
             b_ia = &bonded_ia_params[p[i].bl.e[k]];
	     if(b_ia->type == BONDED_IA_RIGID_BOND)
             {
	       Particle *p2 = local_particles[p[i].bl.e[k++]];
           if (!p2) {
           runtimeErrorMsg() <<"rigid bond broken between particles " << p[i].p.identity << " and " << p[i].bl.e[k-1] << " (particles not stored on the same node)";
		 return;
	       }

	       get_mi_vector(r_ij, p[i].r.p , p2->r.p);
	       printf(" bl (%d %d): %f\t", p[i].p.identity, p2->p.identity,sqrlen(r_ij));
             }
	     else
	       k += b_ia->num;
       } //while k loop
    } //for i loop
  }// for c loop
  printf("\n");
}
Example #9
0
void correct_pos_shake()
{
   int    repeat_,  cnt=0;
   int repeat=1;

   while (repeat!=0 && cnt<SHAKE_MAX_ITERATIONS)
   {
     init_correction_vector();
     repeat_ = 0;
     compute_pos_corr_vec(&repeat_);
     ghost_communicator(&cell_structure.collect_ghost_force_comm);
     app_pos_correction();
     /**Ghost Positions Update*/
     ghost_communicator(&cell_structure.update_ghost_pos_comm);
     if(this_node==0)
         MPI_Reduce(&repeat_, &repeat, 1, MPI_INT, MPI_SUM, 0, comm_cart);
     else
         MPI_Reduce(&repeat_, NULL, 1, MPI_INT, MPI_SUM, 0, comm_cart);
     MPI_Bcast(&repeat, 1, MPI_INT, 0, comm_cart);

       cnt++;
   }// while(repeat) loop
   if (cnt >= SHAKE_MAX_ITERATIONS) {
       runtimeErrorMsg() <<"RATTLE failed to converge after " << cnt << " iterations";
   }

   check_resort_particles();
}
Example #10
0
/** Calculate the local fluid density.
 * The calculation is implemented explicitly for the special case of D3Q19.
 * @param index the local lattice site (Input).
 * @param rho   local fluid density
 */
inline void lb_calc_local_rho(index_t index, double *rho) {

#ifndef D3Q19
#error Only D3Q19 is implemened!
#endif

  // unit conversion: mass density
  if (!(lattice_switch & LATTICE_LB)) {
    runtimeErrorMsg() << "Error in lb_calc_local_rho in " << __FILE__ << __LINE__ << ": CPU LB not switched on.";
    *rho =0;
    return;
  }

  double avg_rho = lbpar.rho[0]*lbpar.agrid*lbpar.agrid*lbpar.agrid;

  *rho =   avg_rho
         + lbfluid[0][0][index]
         + lbfluid[0][1][index]  + lbfluid[0][2][index]
         + lbfluid[0][3][index]  + lbfluid[0][4][index]
         + lbfluid[0][5][index]  + lbfluid[0][6][index] 
         + lbfluid[0][7][index]  + lbfluid[0][8][index]  
	       + lbfluid[0][9][index]  + lbfluid[0][10][index]
         + lbfluid[0][11][index] + lbfluid[0][12][index] 
	       + lbfluid[0][13][index] + lbfluid[0][14][index] 
         + lbfluid[0][15][index] + lbfluid[0][16][index] 
	       + lbfluid[0][17][index] + lbfluid[0][18][index];

}
Example #11
0
void Lattice::interpolate_linear(double* pos, double* value) {
    int left_halo_index[3];
    double d[3];
    if (this->halo_size <= 0) {
        runtimeErrorMsg() <<"Error in interpolate_linear: halo size is 0";
        return;
    }
    for (int dim = 0; dim<3; dim++) {
        left_halo_index[dim]=(int) floor((pos[dim]-this->local_offset[dim])/this->agrid[dim]) + this->halo_size;
        d[dim]=((pos[dim]-this->local_offset[dim])/this->agrid[dim] - floor((pos[dim]-this->local_offset[dim])/this->agrid[dim]));
        if (left_halo_index[dim] < 0 || left_halo_index[dim] >= this->halo_grid[dim]) {
            runtimeErrorMsg() <<"Error in interpolate_linear: Particle out of range";
            return;
        }
    }
    double w[8];
    index_t index[8];
    w[0] = (1-d[0])*(1-d[1])*(1-d[2]);
    index[0]=get_linear_index(   left_halo_index[0], left_halo_index[1], left_halo_index[2], this->halo_grid);
    w[1] = ( +d[0])*(1-d[1])*(1-d[2]);
    index[1]=get_linear_index(   left_halo_index[0]+1, left_halo_index[1], left_halo_index[2], this->halo_grid);
    w[2] = (1-d[0])*( +d[1])*(1-d[2]);
    index[2]=get_linear_index(   left_halo_index[0], left_halo_index[1]+1, left_halo_index[2], this->halo_grid);
    w[3] = ( +d[0])*( +d[1])*(1-d[2]);
    index[3]=get_linear_index(   left_halo_index[0]+1, left_halo_index[1]+1, left_halo_index[2], this->halo_grid);

    w[4] = (1-d[0])*(1-d[1])*( +d[2]);
    index[4]=get_linear_index(   left_halo_index[0], left_halo_index[1], left_halo_index[2]+1, this->halo_grid);
    w[5] = ( +d[0])*(1-d[1])*( +d[2]);
    index[5]=get_linear_index(   left_halo_index[0]+1, left_halo_index[1], left_halo_index[2]+1, this->halo_grid);
    w[6] = (1-d[0])*( +d[1])*( +d[2]);
    index[6]=get_linear_index(   left_halo_index[0], left_halo_index[1]+1, left_halo_index[2]+1, this->halo_grid);
    w[7] = ( +d[0])*( +d[1])*( +d[2]);
    index[7]=get_linear_index(   left_halo_index[0]+1, left_halo_index[1]+1, left_halo_index[2]+1, this->halo_grid);

    for (unsigned int i = 0; i<this->dim; i++) {
        value[i] = 0;
    }

    double* local_value;
    for (unsigned int i=0; i<8; i++) {
        get_data_for_linear_index(index[i], (void**) &local_value);
        for (unsigned int j = 0; j<this->dim; j++) {
            value[j]+=w[i]*local_value[j];
        }
    }
}
Example #12
0
/** Rotate all particle coordinates around an axis given by phi,theta through the center of mass by an angle alpha */
void rotate_system(double phi, double theta, double alpha)
{
  if (n_nodes!=1) {
      runtimeErrorMsg() <<"Rotate_system only works on a single cpu core";
  }

  local_rotate_system(phi, theta, alpha);
}
void add_external_potential_energy(Particle* p) {
  for (int i=0; i<n_external_potentials; i++) {
    if (external_potentials[i].type==EXTERNAL_POTENTIAL_TYPE_TABULATED) {
      add_external_potential_tabulated_energy(&external_potentials[i], p);
    } else {
      runtimeErrorMsg() <<"unknown external potential type";
      return;
    }
  }
}
Example #14
0
inline void lb_local_fields_get_boundary_flag(index_t index, int *boundary) {
  
  if (!(lattice_switch & LATTICE_LB)) {
    runtimeErrorMsg() <<"Error in lb_local_fields_get_boundary_flag in " << __FILE__ << __LINE__ << ": CPU LB not switched on.";
    *boundary = 0;
    return;
  }

  *boundary = lbfields[index].boundary;
}
Example #15
0
/** Velocity correction vectors are computed*/
void compute_vel_corr_vec(int *repeat_)
{
  Bonded_ia_parameters *ia_params;
  int i, j, k, c, np;
  Cell *cell;
  Particle *p, *p1, *p2;
  double v_ij[3], r_ij[3], K, vel_corr;

  for (c = 0; c < local_cells.n; c++)
    {
      cell = local_cells.cell[c];
      p  = cell->part;
      np = cell->n;
      for(i = 0; i < np; i++) {
        p1 = &p[i];
        k=0;
	while(k<p1->bl.n)
	  {
	    ia_params = &bonded_ia_params[p1->bl.e[k++]];
	    if( ia_params->type == BONDED_IA_RIGID_BOND )
	      {
		p2 = local_particles[p1->bl.e[k++]];
        if (!p2) {
            runtimeErrorMsg() <<"rigid bond broken between particles " << p1->p.identity << " and " << p1->bl.e[k-1] << " (particles not stored on the same node)";
		  return;
		}

		vecsub(p1->m.v, p2->m.v, v_ij);
                get_mi_vector(r_ij, p1->r.p, p2->r.p);
		if(fabs(scalar(v_ij, r_ij)) > ia_params->p.rigid_bond.v_tol)
	        {
		  K = scalar(v_ij, r_ij)/ia_params->p.rigid_bond.d2;
#ifdef MASS
		  K /= ((*p1).p.mass + (*p2).p.mass);
#else
		  K /= 2.0;
#endif
		for (j=0;j<3;j++)
		  {
		    vel_corr = K*r_ij[j];
		    p1->f.f[j] -= vel_corr*(*p2).p.mass;
		    p2->f.f[j] += vel_corr*(*p1).p.mass;
		  }
		  *repeat_ = *repeat_ + 1 ;
		}
	      }
	    else
	      k += ia_params->num;
	  } //while loop
      } //for i loop
    } //for c loop
}
Example #16
0
/**Compute positional corrections*/
void compute_pos_corr_vec(int *repeat_)
{
  Bonded_ia_parameters *ia_params;
  int i, j, k, c, np, cnt=-1;
  Cell *cell;
  Particle *p, *p1, *p2;
  double r_ij_t[3], r_ij[3], r_ij_dot, G, pos_corr, r_ij2;

  for (c = 0; c < local_cells.n; c++) {
    cell = local_cells.cell[c];
    p  = cell->part;
    np = cell->n;
    for(i = 0; i < np; i++) {
      p1 = &p[i];
      k=0;
      while(k<p1->bl.n) {
	ia_params = &bonded_ia_params[p1->bl.e[k++]];
	if( ia_params->type == BONDED_IA_RIGID_BOND ) {
	  cnt++;
	  p2 = local_particles[p1->bl.e[k++]];
      if (!p2) {
          runtimeErrorMsg() <<"rigid bond broken between particles " << p1->p.identity << " and " << p1->bl.e[k-1] << " (particles not stored on the same node)";
	    return;
	  }

	  get_mi_vector(r_ij  , p1->r.p    , p2->r.p    );
	  r_ij2 = sqrlen(r_ij);
	  if(fabs(1.0 - r_ij2/ia_params->p.rigid_bond.d2) > ia_params->p.rigid_bond.p_tol) {
            get_mi_vector(r_ij_t, p1->r.p_old, p2->r.p_old);
	    r_ij_dot = scalar(r_ij_t, r_ij);
	    G = 0.50*(ia_params->p.rigid_bond.d2 - r_ij2 )/r_ij_dot;
#ifdef MASS
	    G /= ((*p1).p.mass+(*p2).p.mass);
#else
	    G /= 2;
#endif
	    for (j=0;j<3;j++) {
	      pos_corr = G*r_ij_t[j];
	      p1->f.f[j] += pos_corr*(*p2).p.mass;
	      p2->f.f[j] -= pos_corr*(*p1).p.mass;
	    }
	    /*Increase the 'repeat' flag by one */
	      *repeat_ = *repeat_ + 1;
	  }
	}
	else
	  /* skip bond partners of nonrigid bond */
          k+=ia_params->num;
      } //while loop
    } //for i loop
  } //for c loop
}
Example #17
0
void nemd_change_momentum() 
{
  int i;
  double tmp_v0;
  Slab *mid_slab, *top_slab;

  if(nemd_method == NEMD_METHOD_OFF) return;

  INTEG_TRACE(fprintf(stderr,"%d: nemd_change_momentum: Method %d\n",this_node,nemd_method));

  mid_slab = &nemddata.slab[nemddata.mid_slab];
  top_slab = &nemddata.slab[nemddata.top_slab];

  if(nemd_method == NEMD_METHOD_EXCHANGE ) {
    /* exit if there are not enough particles */
    INTEG_TRACE(fprintf(stderr,"%d: parts_in_slabs: top %d mid %d\n",this_node,top_slab->n_parts_in_slab,mid_slab->n_parts_in_slab));
    if(mid_slab->n_fastest != nemddata.n_exchange || 
       top_slab->n_fastest != nemddata.n_exchange) {
        runtimeErrorMsg() <<"nemd_exchange_momentum: Not enough particles in slab!";
      /* cannot continue */
      return;
    }

    /* perform momentum exchange */
    for(i=0;i<nemddata.n_exchange;i++) {
      /* store momentum change */
      nemddata.momentum += local_particles[top_slab->fastest[i]]->m.v[0]; 
      nemddata.momentum -= local_particles[mid_slab->fastest[i]]->m.v[0]; 
      tmp_v0 = local_particles[mid_slab->fastest[i]]->m.v[0];
      local_particles[mid_slab->fastest[i]]->m.v[0] = local_particles[top_slab->fastest[i]]->m.v[0];
      local_particles[top_slab->fastest[i]]->m.v[0] = tmp_v0;
    }

    /* prepare next round */
    top_slab->n_fastest = 0;
    top_slab->v_min     = -1e10;
    mid_slab->n_fastest = 0;
    mid_slab->v_min     = 1e10;
  }
  else if (nemd_method ==  NEMD_METHOD_SHEARRATE) {
    double vel_mean; 
    /* calculate velocity difference vel_diff = vel_required - vel_actual */
    vel_mean = top_slab->v_mean/(double)top_slab->n_parts_in_slab;
    top_slab->vel_diff = nemddata.slab_vel - vel_mean;
    vel_mean = mid_slab->v_mean/(double)mid_slab->n_parts_in_slab;
    mid_slab->vel_diff = - (nemddata.slab_vel + vel_mean);
    /* store momentum change */
    nemddata.momentum += top_slab->n_parts_in_slab*top_slab->vel_diff;
    nemddata.momentum -= mid_slab->n_parts_in_slab*mid_slab->vel_diff;
  }
  nemddata.momentum_norm ++;
}
Example #18
0
/** Calculate the local fluid stress.
 * The calculation is implemented explicitly for the special case of D3Q19.
 * @param index The local lattice site (Input).
 * @param pi local fluid pressure
 */
inline void lb_calc_local_pi(index_t index, double *pi) {

  double rho;
  double j[3];
  
  if (!(lattice_switch & LATTICE_LB)) {
      runtimeErrorMsg() <<"Error in lb_calc_local_pi in " << __FILE__ << __LINE__ << ": CPU LB not switched on.";
    j[0] = j[1] = j[2] = 0;
    return;
  }
  
  lb_calc_local_fields(index, &rho, j, pi);
}
Example #19
0
void analyze_activate(int ind) {
  int i;
  double pos[3];
  n_part_conf = n_part;

  for(i=0; i<n_part_conf; i++) {
    pos[0] = configs[ind][3*i];
    pos[1] = configs[ind][3*i+1];
    pos[2] = configs[ind][3*i+2];
    if (place_particle(i, pos)==ES_ERROR) {
        runtimeErrorMsg() <<"failed upon replacing particle " << i << "  in Espresso";
    }
  }
}
int tclcommand_analyze_parse_and_print_pressure_mol(Tcl_Interp *interp,int argc, char **argv)
{
   char buffer[TCL_DOUBLE_SPACE];
   int type1, type2;
   double psum;
   #ifdef ELECTROSTATICS
   #ifndef INTER_RF
   Tcl_ResetResult(interp);
   Tcl_AppendResult(interp, "parse_and_print_pressure_mol is only possible with INTER_RF ", (char *)NULL);
   return (TCL_ERROR);
   #endif
   #endif
   updatePartCfg(WITHOUT_BONDS);
   if (!sortPartCfg()) {
       runtimeErrorMsg() <<"parse_and_print_pressure_mol: could not sort particle config, particle ids not consecutive?";
      return TCL_ERROR;
   }
   if (argc < 2) {
      Tcl_ResetResult(interp);
      Tcl_AppendResult(interp, "usage: analyze pressure_mol <type1> <type2>", (char *)NULL);
      return (TCL_ERROR);
   }

   if (!ARG0_IS_I(type1)) {
      Tcl_ResetResult(interp);
      Tcl_AppendResult(interp, "usage: analyze pressure_mol <type1> <type2>", (char *)NULL);
      return (TCL_ERROR);
   }
   if (!ARG1_IS_I(type2)) {
      Tcl_ResetResult(interp);
      Tcl_AppendResult(interp, "usage: analyze pressure_mol <type1> <type2>", (char *)NULL);
      return (TCL_ERROR);
   }
   argc-=2; argv+=2;

   if (n_molecules==0) {
      Tcl_ResetResult(interp);
      Tcl_AppendResult(interp, "No molecules defined !", (char *)NULL);
      return (TCL_ERROR);
   }
   psum=calc_pressure_mol(type1,type2);
   //sprintf(buffer,"%i",type1);
   //Tcl_AppendResult(interp,"{ analyze pressure_mol ",buffer," ",(char *)NULL);   
   //sprintf(buffer,"%i",type2);
   //Tcl_AppendResult(interp,buffer," ",(char *)NULL);   
   sprintf(buffer,"%e",psum);
   Tcl_AppendResult(interp, buffer,(char *)NULL);
   return TCL_OK;
}
Example #21
0
/* calc_three_body_bonded_forces is called by add_three_body_bonded_stress. This
   routine is only entered for angular potentials. */
inline void calc_three_body_bonded_forces(Particle *p1, Particle *p2, Particle *p3,
        Bonded_ia_parameters *iaparams, double force1[3], double force2[3], double force3[3]) {

#ifdef TABULATED
    //char* errtxt;
#endif

    switch(iaparams->type) {
#ifdef BOND_ANGLE_OLD
    case BONDED_IA_ANGLE_OLD:
        // p1 is *p_mid, p2 is *p_left, p3 is *p_right
        calc_angle_3body_forces(p1, p2, p3, iaparams, force1, force2, force3);
        break;
#endif
#ifdef BOND_ANGLE
    case BONDED_IA_ANGLE_HARMONIC:
        // p1 is *p_mid, p2 is *p_left, p3 is *p_right
        calc_angle_harmonic_3body_forces(p1, p2, p3, iaparams, force1, force2, force3);
        break;
    case BONDED_IA_ANGLE_COSINE:
        // p1 is *p_mid, p2 is *p_left, p3 is *p_right
        calc_angle_cosine_3body_forces(p1, p2, p3, iaparams, force1, force2, force3);
        break;
    case BONDED_IA_ANGLE_COSSQUARE:
        // p1 is *p_mid, p2 is *p_left, p3 is *p_right
        calc_angle_cossquare_3body_forces(p1, p2, p3, iaparams, force1, force2, force3);
        break;
#endif
#ifdef TABULATED
    case BONDED_IA_TABULATED:
        switch(iaparams->p.tab.type) {
        case TAB_BOND_ANGLE:
            // p1 is *p_mid, p2 is *p_left, p3 is *p_right
            calc_angle_3body_tabulated_forces(p1, p2, p3, iaparams, force1, force2, force3);
            break;
        default:
            runtimeErrorMsg() <<"calc_bonded_force: tabulated bond type of atom " << p1->p.identity << " unknown\n";
            return;
        }
        break;
#endif
    default :
        fprintf(stderr,"calc_three_body_bonded_forces: \
            WARNING: Bond type %d , atom %d unhandled, Atom 2: %d\n", \
                iaparams->type, p1->p.identity, p2->p.identity);
        break;
    }
}
Example #22
0
//int Lattice::init(double *agrid, double* offset, int halo_size, size_t dim) {
int Lattice::init(double *agrid, double* offset, int halo_size, size_t dim) {
    this->dim=dim;

    /* determine the number of local lattice nodes */
    for (int d=0; d<3; d++) {
        this->agrid[d] = agrid[d];
        this->global_grid[d] = (int)dround(box_l[d]/agrid[d]);
        this->offset[d]=offset[d];
        this->local_index_offset[d]=(int) ceil((my_left[d]-this->offset[d])/this->agrid[d]);
        this->local_offset[d] = this->offset[d] +
            this->local_index_offset[d]*this->agrid[d];
        this->grid[d] = (int) ceil ( ( my_right[d] - this->local_offset[d]-ROUND_ERROR_PREC )
                                     / this->agrid[d]);
    }

    // sanity checks
    for (int dir=0;dir<3;dir++) {
      // check if local_box_l is compatible with lattice spacing
      if (fabs(local_box_l[dir]-this->grid[dir]*agrid[dir]) > ROUND_ERROR_PREC*box_l[dir]) {
          runtimeErrorMsg() << "Lattice spacing agrid["<< dir << "]=" << agrid[dir] \
              << " is incompatible with local_box_l["<< dir << "]=" << local_box_l[dir]\
              << " ( box_l["<< dir << "]=" << box_l[dir] \
              << " node_grid["<< dir << "]=" << node_grid[dir] <<" )";
      }
    }

    this->element_size = this->dim*sizeof(double);

    LATTICE_TRACE(fprintf(stderr,"%d: box_l (%.3f,%.3f,%.3f) grid (%d,%d,%d) node_neighbors (%d,%d,%d,%d,%d,%d)\n",this_node,local_box_l[0],local_box_l[1],local_box_l[2],this->grid[0],this->grid[1],this->grid[2],node_neighbors[0],node_neighbors[1],node_neighbors[2],node_neighbors[3],node_neighbors[4],node_neighbors[5]));

    this->halo_size = halo_size;
    /* determine the number of total nodes including halo */
    this->halo_grid[0] = this->grid[0] + 2*halo_size ;
    this->halo_grid[1] = this->grid[1] + 2*halo_size ;
    this->halo_grid[2] = this->grid[2] + 2*halo_size ;

    this->grid_volume = this->grid[0]*this->grid[1]*this->grid[2] ;
    this->halo_grid_volume = this->halo_grid[0]*this->halo_grid[1]*this->halo_grid[2] ;
    this->halo_grid_surface = this->halo_grid_volume - this->grid_volume ;
    this->halo_offset = get_linear_index(halo_size,halo_size,halo_size,this->halo_grid) ;

    this->interpolation_type = INTERPOLATION_LINEAR;

    allocate_memory();
    return ES_OK;

}
int tclcommand_analyze_parse_and_print_energy_kinetic_mol(Tcl_Interp *interp,int argc, char **argv)
{
   char buffer[TCL_DOUBLE_SPACE];
   int type;
   double Ekin;
   updatePartCfg(WITHOUT_BONDS);
   if (!sortPartCfg()) {
       runtimeErrorMsg() <<"parse_and_print_energy_kinetic_mol: could not sort particle config, particle ids not consecutive?";
      return TCL_ERROR;
   }
   if (argc < 1) {
      Tcl_ResetResult(interp);
      Tcl_AppendResult(interp, "usage: analyze energy_kinetic <type>", (char *)NULL);
      return (TCL_ERROR);
   }

   if (!ARG0_IS_I(type)) {
      Tcl_ResetResult(interp);
      Tcl_AppendResult(interp, "usage: analyze energy_kinetic <type>", (char *)NULL);
      return (TCL_ERROR);
   }
   argc-=1; argv+=1;

   if (n_molecules==0) {
      Tcl_ResetResult(interp);
      Tcl_AppendResult(interp, "No molecules defined !", (char *)NULL);
      return (TCL_ERROR);
   }
   Ekin=calc_energy_kinetic_mol(type);
   if (Ekin < 0.0) {
     Tcl_ResetResult(interp);
      sprintf(buffer,"%i",-(int)Ekin);
      Tcl_AppendResult(interp,"Could not fetch com in calc_energy_kinetic_mol! From mol_id",buffer, (char *)NULL);
      return (TCL_ERROR);
   }
   //sprintf(buffer,"%i",type);
   //Tcl_AppendResult(interp,"{ analyze pressure_mol ",buffer," ",(char *)NULL);   
   sprintf(buffer,"%e",Ekin);
   Tcl_AppendResult(interp, buffer,(char *)NULL);
   return TCL_OK;
}
Example #24
0
/** Calculate bonded virials for one particle.
    For performance reasons the force routines add their values directly to the particles.
    So here we do some tricks to get the value out without changing the forces.
    @param p1 particle for which to calculate virials
*/
inline void add_bonded_virials(Particle *p1)
{
    double dx[3], force[3] = {0,0,0};
    //char *errtxt;
    Particle *p2;
    Bonded_ia_parameters *iaparams;

    int i, k, l;
    int type_num;

    i = 0;
    while(i<p1->bl.n) {
        type_num = p1->bl.e[i++];
        iaparams = &bonded_ia_params[type_num];

        /* fetch particle 2 */
        p2 = local_particles[p1->bl.e[i++]];
        if ( ! p2 ) {
            // for harmonic spring:
            // if cutoff was defined and p2 is not there it is anyway outside the cutoff, see calc_maximal_cutoff()
            if ((type_num==BONDED_IA_HARMONIC)&&(iaparams->p.harmonic.r_cut>0)) return;
            runtimeErrorMsg() <<"bond broken between particles " << p1->p.identity << " and " << p1->bl.e[i-1] << " (particles not stored on the same node)";
            return;
        }

        get_mi_vector(dx, p1->r.p, p2->r.p);
        calc_bonded_force(p1,p2,iaparams,&i,dx,force);
        *obsstat_bonded(&virials, type_num) += dx[0]*force[0] + dx[1]*force[1] + dx[2]*force[2];

        /* stress tensor part */
        for(k=0; k<3; k++)
            for(l=0; l<3; l++)
                obsstat_bonded(&p_tensor, type_num)[k*3 + l] += force[k]*dx[l];

    }
}
Example #25
0
/** Calculate the contribution to the stress tensor from angular potentials.
    The central particle of the three-particle interaction is responsible
    for the contribution of the entire interaction - this is the coding
    not the physics.
*/
inline void add_three_body_bonded_stress(Particle *p1) {
    double dx12[3]; // espresso notation
    double dx21[3];
    double dx31[3];
    double force1[3];
    double force2[3];
    double force3[3];

    //char *errtxt;
    Particle *p2;
    Particle *p3;
    Bonded_ia_parameters *iaparams;

    int i, k, j, l;
    int type_num;
    BondedInteraction type;

    i = 0;
    while(i < p1->bl.n) {
        /* scan bond list for angular interactions */
        type_num = p1->bl.e[i];
        iaparams = &bonded_ia_params[type_num];
        type = iaparams->type;

        if(type == BONDED_IA_ANGLE_HARMONIC || type == BONDED_IA_ANGLE_COSINE || type == BONDED_IA_ANGLE_COSSQUARE) {
            p2 = local_particles[p1->bl.e[++i]];
            p3 = local_particles[p1->bl.e[++i]];

            get_mi_vector(dx12, p1->r.p, p2->r.p);
            for(j = 0; j < 3; j++)
                dx21[j] = -dx12[j];

            get_mi_vector(dx31, p3->r.p, p1->r.p);

            for(j = 0; j < 3; j++) {
                force1[j] = 0.0;
                force2[j] = 0.0;
                force3[j] = 0.0;
            }

            calc_three_body_bonded_forces(p1, p2, p3, iaparams, force1, force2, force3);

            /* uncomment the next line to see that the virial is indeed zero */
            //printf("W = %g\n", scalar(force2, dx21) + scalar(force3, dx31));

            /* three-body bonded interactions contribute to the stress but not the scalar pressure */
            for(k = 0; k < 3; k++) {
                for(l = 0; l < 3; l++) {
                    obsstat_bonded(&p_tensor, type_num)[3 * k + l] += force2[k] * dx21[l] + force3[k] * dx31[l];
                }
            }
            i = i + 1;
        }
        // skip over non-angular interactions
        else if(type == BONDED_IA_FENE) {
            i = i + 2;
        }
        else if(type == BONDED_IA_OIF_GLOBAL_FORCES) {
            i = i + 3;
        }
        else if(type == BONDED_IA_OIF_LOCAL_FORCES) {
            i = i + 4;
        }
        else if(type == BONDED_IA_OIF_OUT_DIRECTION) {
            i = i + 3;
        }
        else if(type == BONDED_IA_HARMONIC) {
            i = i + 2;
        }
#ifdef LENNARD_JONES
        else if(type == BONDED_IA_SUBT_LJ) {
            i = i + 2;
        }
#endif
        else if(type == BONDED_IA_ANGLEDIST) {
            i = i + 3;
        }
        else if(type == BONDED_IA_DIHEDRAL) {
            i = i + 4;
        }
#ifdef TABULATED
        else if(type == BONDED_IA_TABULATED) {
            if(iaparams->p.tab.type == TAB_BOND_LENGTH) {
                i = i + 2;
            }
            else if(iaparams->p.tab.type == TAB_BOND_ANGLE) {
                p2 = local_particles[p1->bl.e[++i]];
                p3 = local_particles[p1->bl.e[++i]];

                get_mi_vector(dx12, p1->r.p, p2->r.p);
                for(j = 0; j < 3; j++)
                    dx21[j] = -dx12[j];

                get_mi_vector(dx31, p3->r.p, p1->r.p);

                for(j = 0; j < 3; j++) {
                    force1[j] = 0.0;
                    force2[j] = 0.0;
                    force3[j] = 0.0;
                }

                calc_three_body_bonded_forces(p1, p2, p3, iaparams, force1, force2, force3);

                /* uncomment the next line to see that the virial is indeed zero */
                //printf("W = %g\n", scalar(force2, dx21) + scalar(force3, dx31));

                /* three-body bonded interactions contribute to the stress but not the scalar pressure */
                for(k = 0; k < 3; k++) {
                    for(l = 0; l < 3; l++) {
                        obsstat_bonded(&p_tensor, type_num)[3 * k + l] += force2[k] * dx21[l] + force3[k] * dx31[l];
                    }
                }
                i = i + 1;
            }
            else if (iaparams->p.tab.type == TAB_BOND_DIHEDRAL) {
                i = i + 4;
            }
            else {
                runtimeErrorMsg() <<"add_three_body_bonded_stress: match not found for particle " << p1->p.identity << ".\n";
            }
        }
#endif
#ifdef BOND_CONSTRAINT
        else if(type == BONDED_IA_RIGID_BOND) {
            i = i + 2;
        }
#endif
#ifdef BOND_VIRTUAL
        else if(type == BONDED_IA_VIRTUAL_BOND) {
            i = i + 2;
        }
#endif
        else {
            runtimeErrorMsg() <<"add_three_body_bonded_stress: match not found for particle " << p1->p.identity << ".\n";
        }
    }
}
Example #26
0
inline void calc_bonded_force(Particle *p1, Particle *p2, Bonded_ia_parameters *iaparams, int *i, double dx[3], double force[3]) {
#ifdef TABULATED
    //char* errtxt;
#endif

    /* Calculates the bonded force between two particles */
    switch(iaparams->type) {
    case BONDED_IA_FENE:
        calc_fene_pair_force(p1,p2,iaparams,dx,force);
        break;
#ifdef ROTATION
    case BONDED_IA_HARMONIC_DUMBBELL:
        calc_harmonic_dumbbell_pair_force(p1,p2,iaparams,dx,force);
        break;
#endif
    case BONDED_IA_HARMONIC:
        calc_harmonic_pair_force(p1,p2,iaparams,dx,force);
        break;
#ifdef LENNARD_JONES
    case BONDED_IA_SUBT_LJ:
        calc_subt_lj_pair_force(p1,p2,iaparams,dx,force);
        break;
#endif
    /* since it is not clear at the moment how to handle a many body interaction here, I skip it */
    case BONDED_IA_ANGLE_HARMONIC:
        (*i)++;
        force[0] = force[1] = force[2] = 0;
        break;
    case BONDED_IA_ANGLE_COSINE:
        (*i)++;
        force[0] = force[1] = force[2] = 0;
        break;
    case BONDED_IA_ANGLE_COSSQUARE:
        (*i)++;
        force[0] = force[1] = force[2] = 0;
        break;
    case BONDED_IA_ANGLEDIST:
        (*i)++;
        force[0] = force[1] = force[2] = 0;
        break;
    case BONDED_IA_DIHEDRAL:
        (*i)+=2;
        force[0] = force[1] = force[2] = 0;
        break;

#ifdef TABULATED
    case BONDED_IA_TABULATED:
        // printf("BONDED TAB, Particle: %d, P2: %d TYPE_TAB: %d\n",p1->p.identity,p2->p.identity,iparams->p.tab.type);
        switch(iaparams->p.tab.type) {
        case TAB_BOND_LENGTH:
            calc_tab_bond_force(p1, p2, iaparams, dx, force);
            break;
        case TAB_BOND_ANGLE:
            (*i)++;
            force[0] = force[1] = force[2] = 0;
            break;
        case TAB_BOND_DIHEDRAL:
            (*i)+=2;
            force[0] = force[1] = force[2] = 0;
            break;
        default:
            runtimeErrorMsg() <<"calc_bonded_force: tabulated bond type of atom " << p1->p.identity << " unknown\n";
            return;
        }
        break;
#endif
#ifdef OVERLAPPED
    case BONDED_IA_OVERLAPPED:
        // printf("BONDED OVERLAP, Particle: %d, P2: %d TYPE_OVERLAP: %d\n",p1->p.identity,p2->p.identity,iparams->p.tab.type);
        //char *errtxt;
        switch(iaparams->p.overlap.type) {
        case OVERLAP_BOND_LENGTH:
            calc_overlap_bond_force(p1, p2, iaparams, dx, force);
            break;
        case OVERLAP_BOND_ANGLE:
            (*i)++;
            force[0] = force[1] = force[2] = 0;
            break;
        case OVERLAP_BOND_DIHEDRAL:
            (*i)+=2;
            force[0] = force[1] = force[2] = 0;
            break;
        default:
            runtimeErrorMsg() <<"calc_bonded_force: overlapped bond type of atom " << p1->p.identity << " unknown\n";
            return;
        }
        break;
#endif
#ifdef BOND_CONSTRAINT
    case BONDED_IA_RIGID_BOND:
        force[0] = force[1] = force[2] = 0;
        break;
#endif
#ifdef BOND_VIRTUAL
    case BONDED_IA_VIRTUAL_BOND:
        force[0] = force[1] = force[2] = 0;
        break;
#endif
    default :
        //      fprintf(stderr,"add_bonded_virials: WARNING: Bond type %d of atom %d unhandled\n",bonded_ia_params[type_num].type,p1->p.identity);
        fprintf(stderr,"add_bonded_virials: WARNING: Bond type %d , atom %d unhandled, Atom 2: %d\n",iaparams->type,p1->p.identity,p2->p.identity);
        force[0] = force[1] = force[2] = 0;
        break;
    }
}
Example #27
0
/** Initialize boundary conditions for all constraints in the system. */
void lb_init_boundaries() {

  int n, x, y, z;
  //char *errtxt;
  double pos[3], dist, dist_tmp=0.0, dist_vec[3];
  
  if (lattice_switch & LATTICE_LB_GPU) {
#if defined (LB_GPU) && defined (LB_BOUNDARIES_GPU)
    int number_of_boundnodes = 0;
    int *host_boundary_node_list= (int*)Utils::malloc(sizeof(int));
    int *host_boundary_index_list= (int*)Utils::malloc(sizeof(int));
    size_t size_of_index;
    int boundary_number = -1; // the number the boundary will actually belong to.
  
#ifdef EK_BOUNDARIES
    ekfloat *host_wallcharge_species_density = NULL;
    float node_wallcharge = 0.0f;
    int wallcharge_species = -1, charged_boundaries = 0;
    int node_charged = 0;

    for(n = 0; n < int(n_lb_boundaries); n++)
      lb_boundaries[n].net_charge = 0.0;

    if (ek_initialized)
    {
      host_wallcharge_species_density = (ekfloat*) Utils::malloc(ek_parameters.number_of_nodes * sizeof(ekfloat));
      for(n = 0; n < int(n_lb_boundaries); n++) {
        if(lb_boundaries[n].charge_density != 0.0) {
          charged_boundaries = 1;
          break;
        }
      }
      if (pdb_charge_lattice) {
        charged_boundaries = 1;
      }
        
      for(n = 0; n < int(ek_parameters.number_of_species); n++)
        if(ek_parameters.valency[n] != 0.0) {
          wallcharge_species = n;
          break;
        }
      
      if(wallcharge_species == -1 && charged_boundaries) {
          runtimeErrorMsg() <<"no charged species available to create wall charge\n";
      }
    }
#endif

    for(z=0; z<int(lbpar_gpu.dim_z); z++) {
      for(y=0; y<int(lbpar_gpu.dim_y); y++) {
        for (x=0; x<int(lbpar_gpu.dim_x); x++) {
          pos[0] = (x+0.5)*lbpar_gpu.agrid;
          pos[1] = (y+0.5)*lbpar_gpu.agrid;
          pos[2] = (z+0.5)*lbpar_gpu.agrid;
        
          dist = 1e99;
        
#ifdef EK_BOUNDARIES
          if (ek_initialized)
          {
            host_wallcharge_species_density[ek_parameters.dim_y*ek_parameters.dim_x*z + ek_parameters.dim_x*y + x] = 0.0f;
            node_charged = 0;
            node_wallcharge = 0.0f;
          }
#endif

          for (n=0; n < n_lb_boundaries; n++) {
            switch (lb_boundaries[n].type) {
              case LB_BOUNDARY_WAL:
                calculate_wall_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.wal, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_SPH:
                calculate_sphere_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.sph, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_CYL:
                calculate_cylinder_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.cyl, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_RHOMBOID:
                calculate_rhomboid_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.rhomboid, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_POR:
                calculate_pore_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.pore, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_STOMATOCYTE:
                calculate_stomatocyte_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.stomatocyte, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_HOLLOW_CONE:
                calculate_hollow_cone_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.hollow_cone, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_SPHEROCYLINDER:
                calculate_spherocylinder_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.spherocyl, &dist_tmp, dist_vec);
                break;

			  case LB_BOUNDARY_VOXEL:	// voxel data do not need dist
				//calculate_voxel_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.voxel, &dist_tmp, dist_vec);
				dist_tmp=1e99;
				break;

              default:
                runtimeErrorMsg() <<"lbboundary type "<< lb_boundaries[n].type << " not implemented in lb_init_boundaries()\n";
            }
            
            if (dist > dist_tmp || n == 0) {
              dist = dist_tmp;
              boundary_number = n;
            }
#ifdef EK_BOUNDARIES
            if (ek_initialized)
            {
              if(dist_tmp <= 0 && lb_boundaries[n].charge_density != 0.0f) {
                node_charged = 1;
                node_wallcharge += lb_boundaries[n].charge_density * ek_parameters.agrid*ek_parameters.agrid*ek_parameters.agrid;
                lb_boundaries[n].net_charge += lb_boundaries[n].charge_density * ek_parameters.agrid*ek_parameters.agrid*ek_parameters.agrid;
              }
            }
#endif
          }

#ifdef EK_BOUNDARIES 
          if(pdb_boundary_lattice && 
             pdb_boundary_lattice[ek_parameters.dim_y*ek_parameters.dim_x*z + ek_parameters.dim_x*y + x]) {
            dist = -1;
            boundary_number = n_lb_boundaries; // Makes sure that boundary_number is not used by a constraint
          }
#endif
          if (dist <= 0 && boundary_number >= 0 && (n_lb_boundaries > 0 || pdb_boundary_lattice)) {
            size_of_index = (number_of_boundnodes+1)*sizeof(int);
            host_boundary_node_list = (int *) Utils::realloc(host_boundary_node_list, size_of_index);
            host_boundary_index_list = (int *) Utils::realloc(host_boundary_index_list, size_of_index);
            host_boundary_node_list[number_of_boundnodes] = x + lbpar_gpu.dim_x*y + lbpar_gpu.dim_x*lbpar_gpu.dim_y*z;
            host_boundary_index_list[number_of_boundnodes] = boundary_number + 1; 
            number_of_boundnodes++;  
            //printf("boundindex %i: \n", number_of_boundnodes);  
          }
        
#ifdef EK_BOUNDARIES
          if (ek_initialized)
          {
            ek_parameters.number_of_boundary_nodes = number_of_boundnodes;

            if(wallcharge_species != -1) {
              if(pdb_charge_lattice &&
                 pdb_charge_lattice[ek_parameters.dim_y*ek_parameters.dim_x*z + ek_parameters.dim_x*y + x] != 0.0f) {
                node_charged = 1;
                node_wallcharge += pdb_charge_lattice[ek_parameters.dim_y*ek_parameters.dim_x*z + ek_parameters.dim_x*y + x];
              }
              if(node_charged)
                host_wallcharge_species_density[ek_parameters.dim_y*ek_parameters.dim_x*z + ek_parameters.dim_x*y + x] = node_wallcharge / ek_parameters.valency[wallcharge_species];
              else if(dist <= 0)
                host_wallcharge_species_density[ek_parameters.dim_y*ek_parameters.dim_x*z + ek_parameters.dim_x*y + x] = 0.0f;
              else
                host_wallcharge_species_density[ek_parameters.dim_y*ek_parameters.dim_x*z + ek_parameters.dim_x*y + x] = ek_parameters.density[wallcharge_species] * ek_parameters.agrid*ek_parameters.agrid*ek_parameters.agrid;
            }
          }
#endif
        }
      }
    }

    /**call of cuda fkt*/
    float* boundary_velocity = (float *) Utils::malloc(3*(n_lb_boundaries+1)*sizeof(float));

    for (n=0; n<n_lb_boundaries; n++) {
      boundary_velocity[3*n+0]=lb_boundaries[n].velocity[0];
      boundary_velocity[3*n+1]=lb_boundaries[n].velocity[1];
      boundary_velocity[3*n+2]=lb_boundaries[n].velocity[2];
    }

    boundary_velocity[3*n_lb_boundaries+0] = 0.0f;
    boundary_velocity[3*n_lb_boundaries+1] = 0.0f;
    boundary_velocity[3*n_lb_boundaries+2] = 0.0f;

    if (n_lb_boundaries || pdb_boundary_lattice)
      lb_init_boundaries_GPU(n_lb_boundaries, number_of_boundnodes, host_boundary_node_list, host_boundary_index_list, boundary_velocity);

    free(boundary_velocity);
    free(host_boundary_node_list);
    free(host_boundary_index_list);
    
#ifdef EK_BOUNDARIES
    if (ek_initialized)
    {
      ek_init_species_density_wallcharge(host_wallcharge_species_density, wallcharge_species);
      free(host_wallcharge_species_density);
    }
#endif

#endif /* defined (LB_GPU) && defined (LB_BOUNDARIES_GPU) */
  }
  else {
#if defined (LB) && defined (LB_BOUNDARIES)   
    int node_domain_position[3], offset[3];
    int the_boundary=-1;
    map_node_array(this_node, node_domain_position);

    offset[0] = node_domain_position[0]*lblattice.grid[0];
    offset[1] = node_domain_position[1]*lblattice.grid[1];
    offset[2] = node_domain_position[2]*lblattice.grid[2];
    
    for (n=0;n<lblattice.halo_grid_volume;n++) {
      lbfields[n].boundary = 0;
    }
    
    if (lblattice.halo_grid_volume==0)
      return;
    
    for (z=0; z<lblattice.grid[2]+2; z++) {
      for (y=0; y<lblattice.grid[1]+2; y++) {
        for (x=0; x<lblattice.grid[0]+2; x++) {	    
          pos[0] = (offset[0]+(x-0.5))*lblattice.agrid[0];
          pos[1] = (offset[1]+(y-0.5))*lblattice.agrid[1];
          pos[2] = (offset[2]+(z-0.5))*lblattice.agrid[2];
          
          dist = 1e99;

          for (n=0;n<n_lb_boundaries;n++) {
            switch (lb_boundaries[n].type) {
              case LB_BOUNDARY_WAL:
                calculate_wall_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.wal, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_SPH:
                calculate_sphere_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.sph, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_CYL:
                calculate_cylinder_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.cyl, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_RHOMBOID:
                calculate_rhomboid_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.rhomboid, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_POR:
                calculate_pore_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.pore, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_STOMATOCYTE:
                calculate_stomatocyte_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.stomatocyte, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_HOLLOW_CONE:
                calculate_hollow_cone_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.hollow_cone, &dist_tmp, dist_vec);
                break;
                
              case LB_BOUNDARY_VOXEL:	// voxel data do not need dist
                dist_tmp=1e99;
                //calculate_voxel_dist((Particle*) NULL, pos, (Particle*) NULL, &lb_boundaries[n].c.voxel, &dist_tmp, dist_vec);
				break;
                
              default:
                runtimeErrorMsg() <<"lbboundary type " << lb_boundaries[n].type << " not implemented in lb_init_boundaries()\n";
            }
            
            if (dist_tmp<dist || n == 0) {
              dist = dist_tmp;
              the_boundary = n;
            }
          }       
          
    	  if (dist <= 0 && the_boundary >= 0 && n_lb_boundaries > 0) {
     	      lbfields[get_linear_index(x,y,z,lblattice.halo_grid)].boundary = the_boundary+1;
     	      //printf("boundindex %i: \n", get_linear_index(x,y,z,lblattice.halo_grid));   
          }
          else {
            lbfields[get_linear_index(x,y,z,lblattice.halo_grid)].boundary = 0;
          }
        }
      }
    } 
    //printf("init voxels\n\n");
    // SET VOXEL BOUNDARIES DIRECTLY 
    int xxx,yyy,zzz=0;
    char line[80];
	for (n=0;n<n_lb_boundaries;n++) {
		switch (lb_boundaries[n].type) {                
			case LB_BOUNDARY_VOXEL:
				//lbfields[get_linear_index(lb_boundaries[n].c.voxel.pos[0],lb_boundaries[n].c.voxel.pos[1],lb_boundaries[n].c.voxel.pos[2],lblattice.halo_grid)].boundary = n+1;
				FILE *fp;
				//fp=fopen("/home/mgusenbauer/Daten/Copy/DUK/GentlePump/Optimierer/NSvsLBM/geometry_files/bottleneck_fine_voxel_data_d20_converted_noMirror.csv", "r");
				//fp=fopen("/home/mgusenbauer/Daten/Copy/DUK/GentlePump/Optimierer/NSvsLBM/geometry_files/bottleneck_fine_voxel_data_d80_converted_noMirror.csv", "r");
				//fp=fopen("/home/mgusenbauer/Daten/Copy/DUK/GentlePump/Optimierer/NSvsLBM/geometry_files/bottleneck_fine_voxel_data_d80_converted.csv", "r");
				fp=fopen(lb_boundaries[n].c.voxel.filename, "r");

				while(fgets(line, 80, fp) != NULL)
			   {
				 /* get a line, up to 80 chars from fp,  done if NULL */
				 sscanf (line, "%d %d %d", &xxx,&yyy,&zzz);
				 //printf("%d %d %d\n", xxx,yyy,zzz);
				 //lbfields[get_linear_index(xxx,yyy+30,zzz,lblattice.halo_grid)].boundary = n+1;
				 lbfields[get_linear_index(xxx,yyy,zzz,lblattice.halo_grid)].boundary = n+1;
			   }
			   fclose(fp); 
				
				

				break;

			default:
				break;
		}
	}
	
	// CHECK FOR BOUNDARY NEIGHBOURS AND SET FLUID NORMAL VECTOR 
	//int neighbours = {0,0,0,0,0,0};
	//int x=0,y=0,z=0;
	//double nn[]={0.0,0.0,0.0,0.0,0.0,0.0};
	//for (n=0;n<n_lb_boundaries;n++) {
		//switch (lb_boundaries[n].type) {                
			//case LB_BOUNDARY_VOXEL:
				//x=lb_boundaries[n].c.voxel.pos[0];
				//y=lb_boundaries[n].c.voxel.pos[1];
				//z=lb_boundaries[n].c.voxel.pos[2];
				//if(((x-1) >= 0) && (lbfields[get_linear_index(x-1,y,z,lblattice.halo_grid)].boundary == 0)) nn[0] = -1.0;//neighbours[0] = -1;
				//if(((x+1) <= lblattice.grid[0]) && (lbfields[get_linear_index(x+1,y,z,lblattice.halo_grid)].boundary == 0)) nn[1] = 1.0;//neighbours[1] = 1;
				////printf("%.0lf %.0lf ",nn[0],nn[1]);
				//lb_boundaries[n].c.voxel.n[0] = nn[0]+nn[1];
				////nn=0.0;
				
				//if(((y-1) >= 0) && (lbfields[get_linear_index(x,y-1,z,lblattice.halo_grid)].boundary == 0)) nn[2] = -1.0;//neighbours[2] = -1;
				//if(((y+1) <= lblattice.grid[1]) && (lbfields[get_linear_index(x,y+1,z,lblattice.halo_grid)].boundary == 0)) nn[3] = 1.0;//neighbours[3] = 1;
				////printf("%.0lf %.0lf ",nn[2],nn[3]);
				//lb_boundaries[n].c.voxel.n[1] = nn[2]+nn[3];
				////nn=0.0;
				
				//if(((z-1) >= 0) && (lbfields[get_linear_index(x,y,z-1,lblattice.halo_grid)].boundary == 0)) nn[4] = -1.0;//neighbours[4] = -1;
				//if(((z+1) <= lblattice.grid[2]) && (lbfields[get_linear_index(x,y,z+1,lblattice.halo_grid)].boundary == 0)) nn[5] = 1.0;//neighbours[5]= 1;
				////printf("%.0lf %.0lf ",nn[4],nn[5]);
				//lb_boundaries[n].c.voxel.n[2] = nn[4]+nn[5];
				//nn[0]=0.0,nn[1]=0.0,nn[2]=0.0,nn[3]=0.0,nn[4]=0.0,nn[5]=0.0;
				
				////printf("t %d pos: %.0lf %.0lf %.0lf, fluid normal %.0lf %.0lf %.0lf\n",n, x,y,z,lb_boundaries[n].c.voxel.normal[0],lb_boundaries[n].c.voxel.normal[1],lb_boundaries[n].c.voxel.normal[2]);
				////printf("boundaries: %d %d %d %d %d %d\n",lbfields[get_linear_index(x-1,y,z,lblattice.halo_grid)].boundary,lbfields[get_linear_index(x+1,y,z,lblattice.halo_grid)].boundary,lbfields[get_linear_index(x,y-1,z,lblattice.halo_grid)].boundary,lbfields[get_linear_index(x,y+1,z,lblattice.halo_grid)].boundary,lbfields[get_linear_index(x,y,z-1,lblattice.halo_grid)].boundary,lbfields[get_linear_index(x,y,z+1,lblattice.halo_grid)].boundary);
				//break;

			//default:
				//break;
		//}
	//}
	
	//// DO THE SAME FOR THE CONSTRAINTS: CONSTRAINTS MUST BE SET AND THE SAME AS LB_BOUNDARY !!!
	//for(n=0;n<n_constraints;n++) {
		//switch(constraints[n].type) {
			//case CONSTRAINT_VOXEL: 
				//x=constraints[n].c.voxel.pos[0];
				//y=constraints[n].c.voxel.pos[1];
				//z=constraints[n].c.voxel.pos[2];
				//if(((x-1) >= 0) && (lbfields[get_linear_index(x-1,y,z,lblattice.halo_grid)].boundary == 0)) nn[0] = -1.0;//neighbours[0] = -1;
				//if(((x+1) <= lblattice.grid[0]) && (lbfields[get_linear_index(x+1,y,z,lblattice.halo_grid)].boundary == 0)) nn[1] = 1.0;//neighbours[1] = 1;
				////printf("%.0lf %.0lf ",nn[0],nn[1]);
				//constraints[n].c.voxel.n[0] = nn[0]+nn[1];
				////nn=0.0;
				
				//if(((y-1) >= 0) && (lbfields[get_linear_index(x,y-1,z,lblattice.halo_grid)].boundary == 0)) nn[2] = -1.0;//neighbours[2] = -1;
				//if(((y+1) <= lblattice.grid[1]) && (lbfields[get_linear_index(x,y+1,z,lblattice.halo_grid)].boundary == 0)) nn[3] = 1.0;//neighbours[3] = 1;
				////printf("%.0lf %.0lf ",nn[2],nn[3]);
				//constraints[n].c.voxel.n[1] = nn[2]+nn[3];
				////nn=0.0;
				
				//if(((z-1) >= 0) && (lbfields[get_linear_index(x,y,z-1,lblattice.halo_grid)].boundary == 0)) nn[4] = -1.0;//neighbours[4] = -1;
				//if(((z+1) <= lblattice.grid[2]) && (lbfields[get_linear_index(x,y,z+1,lblattice.halo_grid)].boundary == 0)) nn[5] = 1.0;//neighbours[5]= 1;
				////printf("%.0lf %.0lf ",nn[4],nn[5]);
				//constraints[n].c.voxel.n[2] = nn[4]+nn[5];
				//nn[0]=0.0,nn[1]=0.0,nn[2]=0.0,nn[3]=0.0,nn[4]=0.0,nn[5]=0.0;
	
				//break;
			//default:
				//break;		
		//}	
	//}

    
    //#ifdef VOXEL_BOUNDARIES
    /*
	for (z=0; z<lblattice.grid[2]+2; z++) {
      for (y=0; y<lblattice.grid[1]+2; y++) {
        for (x=0; x<lblattice.grid[0]+2; x++) {
			lbfields[get_linear_index(x,y,z,lblattice.halo_grid)].boundary = 1;
		}
	  }
	}
	static const char filename[] = "/home/mgusenbauer/Daten/Copy/DUK/GentlePump/Optimierer/voxels/stl/data_final.csv";
	FILE *file = fopen ( filename, "r" );
	int coords[3];
	printf("start new\n");
	if ( file != NULL ){
		char line [ 128 ]; // or other suitable maximum line size 
		while ( fgets ( line, sizeof line, file ) != NULL ) {// read a line
			//fputs ( line, stdout ); // write the line 
			//coords = line.Split(' ').Select(n => Convert.ToInt32(n)).ToArray();
			//printf("readline: %s\n",line);
			int i;
			sscanf(line, "%d %d %d", &coords[0],&coords[1],&coords[2]);
			//printf("%d %d %d\n", coords[0],coords[1],coords[2]);
			lbfields[get_linear_index(coords[0]+5,coords[1]+5,coords[2]+5,lblattice.halo_grid)].boundary = 0;
		}
		fclose ( file );
	}
	printf("end new\n");
	*/
#endif
  }
}
int lattice_read_file(Lattice* lattice, char* filename) {
 // ExternalPotentialTabulated *e = &(external_potentials[number].e.tabulated);
  FILE* infile = fopen(filename, "r");
  
  if (!infile)  {
    runtimeErrorMsg() <<"Could not open file "<< filename << "\n";
    return ES_ERROR;
  }
  char first_line[100];
  char* token;
  double res[3];
  double size[3];
  double offset[3]={0,0,0};
  int dim=0;
  if (fgets(first_line, 100, infile) == NULL) {
      fprintf(stderr, "Nothing read from file\n");
      return ES_ERROR;
  }

  token = strtok(first_line, " \t");
  if (!token) { fprintf(stderr, "Error reading dimensionality\n"); return ES_ERROR; }
  dim = atoi(token);
  if (dim<=0)  { fprintf(stderr, "Error reading dimensionality\n"); return ES_ERROR; }
  
  token = strtok(NULL, " \t");
  if (!token) { fprintf(stderr, "Could not read box_l[0]\n"); return ES_ERROR; }
  size[0] = atof(token);

  token = strtok(NULL, " \t");
  if (!token) { fprintf(stderr, "Could not read box_l[1]\n"); return ES_ERROR; }
  size[1] = atof(token);
  
  token = strtok(NULL, " \t");
  if (!token) { fprintf(stderr, "Could not read box_l[2]\n"); return ES_ERROR;}
  size[2] = atof(token);

  token = strtok(NULL, " \t");
  if (!token) { fprintf(stderr, "Could not read res[0]\n"); return ES_ERROR;}
  res[0] = atof(token);
  
  token = strtok(NULL, " \t");
  if (!token) { fprintf(stderr, "Could not read res[1]\n"); return ES_ERROR;}
  res[1] = atof(token);
  
  token = strtok(NULL, " \t");
  if (!token) { fprintf(stderr, "Could not read res[2]\n"); return ES_ERROR;}
  res[2] = atof(token);

  token = strtok(NULL, " \t");
  if (token) {
    offset[0]=atof(token);
    token = strtok(NULL, " \t");
    if (!token) { fprintf(stderr, "Could not read offset[1]\n"); return ES_ERROR;}
    offset[1] = atof(token);
    token = strtok(NULL, " \t");
    if (!token) { fprintf(stderr, "Could not read offset[2]\n"); return ES_ERROR;}
    offset[2] = atof(token);
  }
  lattice->offset[0]=offset[0];
  lattice->offset[1]=offset[1];
  lattice->offset[2]=offset[2];

  int halosize=1;

  if (size[0] > 0 && fabs(size[0] - box_l[0]) > ROUND_ERROR_PREC) {
    runtimeErrorMsg() <<"Box size in x is wrong "<< size[0] << " vs " << box_l[0] <<"\n";
    return ES_ERROR;
  }
  if (size[1] > 0 && fabs(size[1] - box_l[1]) > ROUND_ERROR_PREC) {
    runtimeErrorMsg() <<"Box size in y is wrong "<< size[1] << " vs " << box_l[1] <<"\n";
    return ES_ERROR;
  }
  if (size[2] > 0 && fabs(size[2] - box_l[2]) > ROUND_ERROR_PREC) {
    runtimeErrorMsg() <<"Box size in z is wrong "<< size[2] << " vs " << box_l[2] <<"\n";
    return ES_ERROR;
  }


  if (res[0] > 0)
    if (skin/res[0]>halosize) halosize = (int)ceil(skin/res[0]);
  if (res[1] > 0)
    if (skin/res[1]>halosize) halosize = (int)ceil(skin/res[1]);
  if (res[2] > 0)
    if (skin/res[2]>halosize) halosize = (int)ceil(skin/res[2]);

  // Now we count how many entries we have:

  lattice->init(res, offset, halosize, dim);
  lattice->interpolation_type = INTERPOLATION_LINEAR;

  char* line = (char*) Utils::malloc((3+dim)*ES_DOUBLE_SPACE);
  double pos[3];
  double f[3];
  int i;
  
  while (fgets(line, 200, infile)) {
    if (strlen(line)<2)
      continue;
    token = strtok(line, " \t");
    if (!token) { fprintf(stderr, "Could not read pos[0]\n"); return ES_ERROR; }
    pos[0] = atof(token);

    token = strtok(NULL, " \t");
    if (!token) { fprintf(stderr, "Could not read pos[1] in line:\n%s\n", line); return ES_ERROR; }
    pos[1] = atof(token);
    
    token = strtok(NULL, " \t");
    if (!token) { fprintf(stderr, "Could not read pos[1]\n"); return ES_ERROR; }
    pos[2] = atof(token);
    for (i=0; i<dim;i++) {
      token = strtok(NULL, " \t");
      if (!token) { fprintf(stderr, "Could not read f[%d]\n", i); return ES_ERROR; }
      f[i] = atof(token);
    }
    lattice->set_data_for_global_position_with_periodic_image(pos, f);
  }
  free(line);

  write_local_lattice_to_file("lattice", lattice);
  
  if (check_runtime_errors()!=0)
    return ES_ERROR;
  return ES_OK;
}
Example #29
0
void calc_long_range_forces()
{
#ifdef ELECTROSTATICS  
	/* calculate k-space part of electrostatic interaction. */
  switch (coulomb.method) {
#ifdef P3M
  case COULOMB_ELC_P3M:
    if (elc_params.dielectric_contrast_on) {
      ELC_P3M_modify_p3m_sums_both();
      ELC_p3m_charge_assign_both();
      ELC_P3M_self_forces();
    }
    else
      p3m_charge_assign();
    
    p3m_calc_kspace_forces(1,0);
    
    if (elc_params.dielectric_contrast_on)
      ELC_P3M_restore_p3m_sums();
    
    ELC_add_force();
    
    break;
#endif
#ifdef CUDA
  case COULOMB_P3M_GPU:
    if (this_node == 0) {
      FORCE_TRACE(printf("Computing GPU P3M forces.\n"));
      p3m_gpu_add_farfield_force();
    }
    /* there is no NPT handling here as long as we cannot compute energies.
       This is checked in integrator_npt_sanity_checks() when integration starts. */
    break;
#endif
#ifdef P3M
  case COULOMB_P3M:
    FORCE_TRACE(printf("%d: Computing P3M forces.\n", this_node));
    p3m_charge_assign();
#ifdef NPT
    if (integ_switch == INTEG_METHOD_NPT_ISO)
      nptiso.p_vir[0] += p3m_calc_kspace_forces(1,1);
    else
#endif
      p3m_calc_kspace_forces(1, 0);
    break;
#endif
  case COULOMB_MAGGS:
    maggs_calc_forces();
    break;
  case COULOMB_MMM2D:
    MMM2D_add_far_force();
    MMM2D_dielectric_layers_force_contribution();
    break;
#ifdef SCAFACOS
  case COULOMB_SCAFACOS:
    Electrostatics::Scafacos::add_long_range_force();
    break;
#endif
  default:
    break;
  }

/* If enabled, calculate electrostatics contribution from electrokinetics species. */ 
#ifdef EK_ELECTROSTATIC_COUPLING
  ek_calculate_electrostatic_coupling();
#endif

#endif  /*ifdef ELECTROSTATICS */
 
#ifdef DIPOLES  
  /* calculate k-space part of the magnetostatic interaction. */
  switch (coulomb.Dmethod) {
#ifdef DP3M
  case DIPOLAR_MDLC_P3M:
    add_mdlc_force_corrections();
    //fall through 
  case DIPOLAR_P3M:
    dp3m_dipole_assign();
#ifdef NPT
    if(integ_switch == INTEG_METHOD_NPT_ISO) {
      nptiso.p_vir[0] += dp3m_calc_kspace_forces(1,1);
      fprintf(stderr,"dipolar_P3M at this moment is added to p_vir[0]\n");    
    } else
#endif
      dp3m_calc_kspace_forces(1,0);
    
    break;
#endif
  case DIPOLAR_ALL_WITH_ALL_AND_NO_REPLICA: 
    dawaanr_calculations(1,0);
    break;
  case DIPOLAR_MDLC_DS:
    add_mdlc_force_corrections();
    //fall through 
  case DIPOLAR_DS: 
    magnetic_dipolar_direct_sum_calculations(1,0);
    break;
  case DIPOLAR_DS_GPU: 
    // Do nothing. It's an actor
    break;
  case DIPOLAR_NONE:
      break;
  default:
      runtimeErrorMsg() <<"unknown dipolar method";
      break;
  }
#endif  /*ifdef DIPOLES */
}
Example #30
0
bool dipolar() {
  if (scafacos) return scafacos->dipolar();
  runtimeErrorMsg() << "Scafacos not initialized";
}