Example #1
0
/**
 * print the parameters of an FCS solver to stdout
 */
FCSResult fcs_print_parameters(FCS handle)
{
  const char *fnc_name = "fcs_print_parameters";
  FCSResult result;

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  printf("chosen method: %s\n", fcs_get_method_name(handle));

  printf("near field computations done by solver: %c\n", (fcs_get_near_field_flag(handle)?'T':'F'));
  printf("box vectors: [%10.4" FCS_LMOD_FLOAT "f %10.4" FCS_LMOD_FLOAT "f %10.4" FCS_LMOD_FLOAT "f], [%10.4" FCS_LMOD_FLOAT "f %10.4" FCS_LMOD_FLOAT "f %10.4" FCS_LMOD_FLOAT "f], [%10.4" FCS_LMOD_FLOAT "f %10.4" FCS_LMOD_FLOAT "f %10.4" FCS_LMOD_FLOAT "f]\n",
    fcs_get_box_a(handle)[0], fcs_get_box_a(handle)[1], fcs_get_box_a(handle)[2],
    fcs_get_box_b(handle)[0], fcs_get_box_b(handle)[1], fcs_get_box_b(handle)[2],
    fcs_get_box_c(handle)[0], fcs_get_box_c(handle)[1], fcs_get_box_c(handle)[2]);
  printf("box origin: [%10.4" FCS_LMOD_FLOAT "f %10.4" FCS_LMOD_FLOAT "f %10.4" FCS_LMOD_FLOAT "f]\n",
    fcs_get_box_origin(handle)[0], fcs_get_box_origin(handle)[1], fcs_get_box_origin(handle)[2]);
  printf("periodicity: %c %c %c\n", ((fcs_get_periodicity(handle)[0] == 1)?'T':'F'), ((fcs_get_periodicity(handle)[1] == 1)?'T':'F'),((fcs_get_periodicity(handle)[2] == 1)?'T':'F'));
  printf("total particles: %" FCS_LMOD_INT "d\n", fcs_get_total_particles(handle));
  printf("solver specific data:\n");

  if (handle->print_parameters)
  {
    result = handle->print_parameters(handle);
    if (result != FCS_RESULT_SUCCESS) fcs_result_print_result(result);
  }

  result = fcs_common_print_parameters(handle);
  if (result != FCS_RESULT_SUCCESS) fcs_result_print_result(result);

  return FCS_RESULT_SUCCESS;
}
Example #2
0
/**
 * run the solver method
 */
FCSResult fcs_run(FCS handle, fcs_int local_particles,
  fcs_float *positions, fcs_float *charges, fcs_float *field, fcs_float *potentials)
{
  const char *fnc_name = "fcs_run";
  FCSResult result;

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (local_particles < 0)
    return fcs_result_create(FCS_ERROR_WRONG_ARGUMENT, fnc_name, "number of local particles must be non negative");

  if (fcs_get_values_changed(handle))
  {
    result = fcs_tune(handle, local_particles, positions, charges);
    if (result != FCS_RESULT_SUCCESS) return result;
  }

  if (!fcs_init_check(handle) || !fcs_run_check(handle))
    return fcs_result_create(FCS_ERROR_MISSING_ELEMENT, fnc_name, "not all needed data has been inserted into the given handle");

  if (handle->run == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, fnc_name, "Running solver method '%s' not implemented", fcs_get_method_name(handle));

  return handle->run(handle, local_particles, positions, charges, field, potentials);
}
Example #3
0
/**
 * tune method specific parameters depending on the particles
 */
FCSResult fcs_tune(FCS handle, fcs_int local_particles,
  fcs_float *positions, fcs_float *charges)
{
  const char *fnc_name = "fcs_tune";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (local_particles < 0)
    return fcs_result_create(FCS_ERROR_WRONG_ARGUMENT, fnc_name, 
                             "number of local particles must be non negative");

  if (!fcs_init_check(handle) || !fcs_tune_check(handle))
    return fcs_result_create(FCS_ERROR_MISSING_ELEMENT, fnc_name, 
                             "not all needed data has been inserted into the given handle");

  fcs_set_values_changed(handle, 0);

  if (handle->tune == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, fnc_name, "Tuning solver method '%s' not implemented", fcs_get_method_name(handle));

  return handle->tune(handle, local_particles, positions, charges);
}
Example #4
0
/**
 * return the user-defined cutoff radius for the near-field
 */
FCSResult fcs_get_r_cut(FCS handle, fcs_float *r_cut)
{
  const char *fnc_name = "fcs_get_r_cut";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (handle->get_r_cut == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, fnc_name, "Returning a user-defined cutoff radius for the near-field not implemented for solver method '%s'", fcs_get_method_name(handle));

  return handle->get_r_cut(handle, r_cut);
}
Example #5
0
/**
 * set the error tolerance of the FCS solver
 */
FCSResult fcs_set_tolerance(FCS handle, fcs_int tolerance_type, fcs_float tolerance)
{
  const char *fnc_name = "fcs_set_tolerance";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (handle->set_tolerance == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, fnc_name, "Setting tolerance not implemented for solver method '%s'", fcs_get_method_name(handle));

  return handle->set_tolerance(handle, tolerance_type, tolerance);
}
Example #6
0
/**
 * return the error tolerance of the FCS solver
 */
FCSResult fcs_get_tolerance(FCS handle, fcs_int *tolerance_type, fcs_float *tolerance)
{
  const char *fnc_name = "fcs_get_tolerance";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  *tolerance_type = FCS_TOLERANCE_TYPE_UNDEFINED;
  *tolerance = -1.0; 

  if (handle->get_tolerance == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, fnc_name, "Return tolerance not implemented for solver method '%s'", fcs_get_method_name(handle));

  return handle->get_tolerance(handle, tolerance_type, tolerance);
}
Example #7
0
/**
 * set whether the virial should be computed
 */
FCSResult fcs_set_compute_virial(FCS handle, fcs_int compute_virial)
{
  const char *fnc_name = "fcs_require_virial";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (compute_virial != 0 && compute_virial != 1)
    return fcs_result_create(FCS_ERROR_WRONG_ARGUMENT, fnc_name, "parameter compute_virial must be 0 or 1");

  if (handle->set_compute_virial == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, fnc_name, "Setting whether the virial should be computed not implemented for solver method '%s'", fcs_get_method_name(handle));

  return handle->set_compute_virial(handle, compute_virial);
}
Example #8
0
/**
 * return the comuputed virial
 */
FCSResult fcs_get_virial(FCS handle, fcs_float *virial)
{
  const char *fnc_name = "fcs_get_virial";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (virial == NULL)
    return fcs_result_create(FCS_ERROR_NULL_ARGUMENT, fnc_name, "null pointer supplied as argument");

  if (handle->get_virial == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, fnc_name, "Returning the computed virial not implemented for solver method '%s'", fcs_get_method_name(handle));

  return handle->get_virial(handle, virial);
}
Example #9
0
/**
 * compute the near-field component of the field
 */
FCSResult fcs_compute_near_field(FCS handle, fcs_float dist, fcs_float *field)
{
  const char *fnc_name = "fcs_compute_near_field";

  switch (fcs_get_method(handle))
  {
#ifdef FCS_ENABLE_P2NFFT
    case FCS_METHOD_P2NFFT:
      *field = fcs_p2nfft_compute_near_field(handle, dist);
      return FCS_RESULT_SUCCESS;
#endif
#ifdef FCS_ENABLE_P3M
    case FCS_METHOD_P3M:
      {
        fcs_p3m_near_parameters_t params;
        fcs_p3m_get_near_parameters(handle, &params);
        *field = fcs_p3m_compute_near_field(params, dist);
      }
      return FCS_RESULT_SUCCESS;
#endif
  }

  return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, fnc_name, "Computing the near-field component of the field not implemented for solver method '%s'", fcs_get_method_name(handle));
}
Example #10
0
/**
 * run the solver method
 */
FCSResult fcs_run(FCS handle, fcs_int local_particles,
  fcs_float *positions, fcs_float *charges, fcs_float *field, fcs_float *potentials)
{
  FCSResult result;

  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  if (local_particles < 0)
    return fcs_result_create(FCS_ERROR_WRONG_ARGUMENT, __func__, "number of local particles must be non negative");

  if (fcs_get_values_changed(handle))
  {
    result = fcs_tune(handle, local_particles, positions, charges);
    if (result != FCS_RESULT_SUCCESS) return result;
  }

  if (!fcs_init_check(handle) || !fcs_run_check(handle))
    return fcs_result_create(FCS_ERROR_MISSING_ELEMENT, __func__, "not all needed data has been inserted into the given handle");

  if (handle->run == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, __func__, "Running solver method '%s' not implemented", fcs_get_method_name(handle));

  fcs_float original_box_origin[3] = { handle->box_origin[0], handle->box_origin[1], handle->box_origin[2] };

  if (handle->shift_positions)
  {
    fcs_shift_positions(local_particles, positions, original_box_origin);
    handle->box_origin[0] = handle->box_origin[1] = handle->box_origin[2] = 0;
  }

  result = handle->run(handle, local_particles, positions, charges, field, potentials);

  if (handle->shift_positions)
  {
    fcs_unshift_positions(local_particles, positions, original_box_origin);
    handle->box_origin[0] = original_box_origin[0];
    handle->box_origin[1] = original_box_origin[1];
    handle->box_origin[2] = original_box_origin[2];
  }

  return result;
}
Example #11
0
/**
 * disable a user-defined cutoff radius for the near-field
 */
FCSResult fcs_unset_r_cut(FCS handle)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  if (handle->unset_r_cut == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, __func__, "Disabling a user-defined cutoff radius for the near-field not implemented for solver method '%s'", fcs_get_method_name(handle));

  return handle->unset_r_cut(handle);
}
Example #12
0
/**
 * return whether the virial should be computed
 */
FCSResult fcs_get_compute_virial(FCS handle, fcs_int *compute_virial)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  if (compute_virial == NULL)
    return fcs_result_create(FCS_ERROR_NULL_ARGUMENT, __func__, "null pointer supplied as argument");

  if (handle->get_compute_virial == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, __func__, "Returning whether the virial should be computed not implemented for solver method '%s'", fcs_get_method_name(handle));

  return handle->get_compute_virial(handle, compute_virial);
}
Example #13
0
/**
 * compute the near-field component of the potential
 */
FCSResult fcs_compute_near_potential(FCS handle, fcs_float dist, fcs_float *potential)
{
  switch (fcs_get_method(handle))
  {
#ifdef FCS_ENABLE_P2NFFT
    case FCS_METHOD_P2NFFT:
      *potential = fcs_p2nfft_compute_near_potential(handle, dist);
      return FCS_RESULT_SUCCESS;
#endif
#ifdef FCS_ENABLE_P3M
    case FCS_METHOD_P3M:
      {
        fcs_p3m_near_parameters_t params;
        fcs_p3m_get_near_parameters(handle, &params);
        *potential = fcs_p3m_compute_near_potential(params, dist);
      }
      return FCS_RESULT_SUCCESS;
#endif
  }

  return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, __func__, "Computing the near-field component of the potential not implemented for solver method '%s'", fcs_get_method_name(handle));
}