示例#1
0
FCSResult fcs_mmm1d_tune(FCS handle, 
		       fcs_int local_particles, fcs_int local_max_particles, 
		       fcs_float *positions, fcs_float *charges)
{
  char* fnc_name = "fcs_mmm1d_tune";
  FCSResult result;
  
  result = fcs_mmm1d_check(handle, fnc_name);
  if (result != NULL) return result;
  
  /* Check box periodicity */
  fcs_int *periodicity = fcs_get_periodicity(handle);
  if (periodicity[0] != 0 ||
      periodicity[1] != 0 ||
      periodicity[2] != 1)
    return fcsResult_create(FCS_LOGICAL_ERROR, fnc_name, "mmm1d requires z-axis periodic boundary.");
  
  /* Check box shape */
  fcs_float *a = fcs_get_box_a(handle);
  fcs_float *b = fcs_get_box_b(handle);
  fcs_float *c = fcs_get_box_c(handle);
  if (!fcs_is_cubic(a, b, c))
    return fcsResult_create(FCS_LOGICAL_ERROR, fnc_name, "mmm1d requires a cubic box.");
  
  mmm1d_set_box_a(handle->method_context, a[0]);
  mmm1d_set_box_b(handle->method_context, b[1]);
  mmm1d_set_box_c(handle->method_context, c[2]);
  
  /* Effectively, tune initializes the algorithm */
  result = mmm1d_tune(handle->method_context, 
        local_particles,
        positions, charges);
  
  return result;
}
示例#2
0
int tclcommand_inter_coulomb_parse_mmm1d(Tcl_Interp *interp, int argc, char **argv)
{
  double switch_rad, maxPWerror;

  if (argc < 2) {
    Tcl_AppendResult(interp, "wrong # arguments: inter coulomb mmm1d <switch radius> "
		     "{<bessel cutoff>} <maximal error for near formula> | tune  <maximal pairwise error>", (char *) NULL);
    return TCL_ERROR;
  }

  if (ARG0_IS_S("tune")) {
    /* autodetermine bessel cutoff AND switching radius */
    if (! ARG_IS_D(1, maxPWerror))
      return TCL_ERROR;
    switch_rad = -1;
  }
  else {
    if (argc == 2) {
      /* autodetermine bessel cutoff */
      if ((! ARG_IS_D(0, switch_rad)) ||
	  (! ARG_IS_D(1, maxPWerror))) 
	return TCL_ERROR;
    }
    else {
      Tcl_AppendResult(interp, "wrong # arguments: inter coulomb mmm1d <switch radius> "
		       "<maximal error for near formula> | tune  <maximal pairwise error>", (char *) NULL);
      return TCL_ERROR;
    }
    
    if (switch_rad <= 0 || switch_rad > box_l[2]) {
      Tcl_AppendResult(interp, "switching radius is not between 0 and box_l[2]", (char *)NULL);
      return TCL_ERROR;
    }
  }

  MMM1D_set_params(switch_rad, maxPWerror);

  char *log = NULL;
  int result = mmm1d_tune(&log) == ES_OK ? TCL_OK : TCL_ERROR;

  Tcl_AppendResult(interp, log, NULL);
  if (log)
    free(log);

  return gather_runtime_errors(interp, result);
}