示例#1
0
/**
 * set all obligatory parameters for an FCS solver
 */
FCSResult fcs_set_common(FCS handle, fcs_int near_field_flag, const fcs_float *box_a, const fcs_float *box_b, const fcs_float *box_c, const fcs_float *box_origin, const fcs_int *periodicity, fcs_int total_particles)
{
  const char *fnc_name = "fcs_set_common";
  FCSResult result;

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  result = fcs_set_near_field_flag(handle, near_field_flag);
  if (result != FCS_RESULT_SUCCESS) return result;

  result = fcs_set_box_a(handle, box_a);
  if (result != FCS_RESULT_SUCCESS) return result;

  result = fcs_set_box_b(handle, box_b);
  if (result != FCS_RESULT_SUCCESS) return result;

  result = fcs_set_box_c(handle, box_c);
  if (result != FCS_RESULT_SUCCESS) return result;

  result = fcs_set_box_origin(handle, box_origin);
  if (result != FCS_RESULT_SUCCESS) return result;

  result = fcs_set_periodicity(handle, periodicity);
  if (result != FCS_RESULT_SUCCESS) return result;

  result = fcs_set_total_particles(handle, total_particles);
  if (result != FCS_RESULT_SUCCESS) return result;

  return FCS_RESULT_SUCCESS;
}
示例#2
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;
}
示例#3
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);
}
示例#4
0
/**
 * compute the correction to the field and total energy 
 */
FCSResult fcs_compute_dipole_correction(FCS handle, fcs_int local_particles,
  fcs_float* positions, fcs_float *charges, fcs_float epsilon,
  fcs_float *field_correction, fcs_float *energy_correction)
{
  const char *fnc_name = "fcs_compute_dipole_correction";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  /* Local dipole moment */
  fcs_float local_dipole_moment[3] = {0.0, 0.0, 0.0};
  /* Global dipole moment */
  fcs_float dipole_moment[3];

  fcs_int pid;
  fcs_int dim;

  if (fcs_float_is_zero(epsilon) || epsilon > 0.0) {
    /* Compute the global dipole moment */
    for (pid = 0; pid < local_particles; pid++)
      for (dim = 0; dim < 3; dim++)
        local_dipole_moment[dim] += charges[pid]*positions[pid*3+dim];
    MPI_Allreduce(local_dipole_moment, dipole_moment, 3, FCS_MPI_FLOAT,
      MPI_SUM, handle->communicator);

    const fcs_float *a = fcs_get_box_a(handle);
    const fcs_float *b = fcs_get_box_b(handle);
    const fcs_float *c = fcs_get_box_c(handle);
    
    /* Volume of the parallelepiped */
    fcs_float volume = 
        a[0] * (b[1]*c[2] - b[2]*c[1]) 
      + a[1] * (b[2]*c[0] - b[0]*c[2])
      + a[2] * (b[0]*c[1] - b[1]*c[0]);

    fcs_float pref = 4.0*3.14159265358979323846264338328 
      / (3.0*volume*(epsilon + 1.0));

    if (energy_correction)
      *energy_correction = 0.5*pref*(dipole_moment[0]*dipole_moment[0]
        + dipole_moment[1]*dipole_moment[1]
        + dipole_moment[2]*dipole_moment[2]);
    
    if (field_correction) {
      field_correction[0] = -pref*dipole_moment[0];
      field_correction[1] = -pref*dipole_moment[1];
      field_correction[2] = -pref*dipole_moment[2];
    }
  } else {
    /* metallic BC (epsilon=+infty) */
    if (energy_correction)
      *energy_correction = 0.0;
    if (field_correction) {
      field_correction[0] = 0.0;
      field_correction[1] = 0.0;
      field_correction[2] = 0.0;
    }
  }

  return FCS_RESULT_SUCCESS;
}
示例#5
0
/**
 * set whether parameter values of the FCS solver have changed
 */
FCSResult fcs_set_values_changed(FCS handle, fcs_int values_changed)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  handle->values_changed = values_changed;

  return FCS_RESULT_SUCCESS;
}
示例#6
0
/**
 * set the method context information
 */
FCSResult fcs_set_method_context(FCS handle, void *method_context)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  handle->method_context = method_context;

  return FCS_RESULT_SUCCESS;
}
示例#7
0
/**
 * sort additional byte particle data
 */
FCSResult fcs_resort_bytes(FCS handle, void *src, void *dst, fcs_int n)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  if (handle->resort_bytes == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, __func__, "resorting not supported");

  return handle->resort_bytes(handle, src, dst, n, fcs_get_communicator(handle));
}
示例#8
0
/**
 * return the new local number of particles
 */
FCSResult fcs_get_resort_particles(FCS handle, fcs_int *resort_particles)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  if (handle->get_resort_particles == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, __func__, "resorting not supported");

  return handle->get_resort_particles(handle, resort_particles);
}
示例#9
0
/**
 * set whether resort support is requested
 */
FCSResult fcs_set_resort(FCS handle, fcs_int resort)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  if (handle->set_resort == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, __func__, "resorting not supported");

  return handle->set_resort(handle, resort);
}
示例#10
0
/**
 * return the user-defined cutoff radius for the near-field
 */
FCSResult fcs_get_r_cut(FCS handle, fcs_float *r_cut)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  if (handle->get_r_cut == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, __func__, "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);
}
示例#11
0
/**
 * set the error tolerance of the FCS solver
 */
FCSResult fcs_set_tolerance(FCS handle, fcs_int tolerance_type, fcs_float tolerance)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

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

  return handle->set_tolerance(handle, tolerance_type, tolerance);
}
示例#12
0
/**
 * set whether parameter values of the FCS solver have changed
 */
FCSResult fcs_set_values_changed(FCS handle, fcs_int values_changed)
{
  const char *fnc_name = "fcs_set_values_changed";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  handle->values_changed = values_changed;

  return FCS_RESULT_SUCCESS;
}
示例#13
0
/**
 * set the method context information
 */
FCSResult fcs_set_method_context(FCS handle, void *method_context)
{
  const char *fnc_name = "fcs_set_method_context";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  handle->method_context = method_context;

  return FCS_RESULT_SUCCESS;
}
示例#14
0
/**
 * set the near-field flag
 */
FCSResult fcs_set_near_field_flag(FCS handle, fcs_int near_field_flag)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  handle->near_field_flag = near_field_flag;

  fcs_set_values_changed(handle,1);

  return FCS_RESULT_SUCCESS;
}
示例#15
0
/**
 * function to set the maximum number of particles that can be stored in the specified local particle data arrays
 */
FCSResult fcs_set_max_local_particles(FCS handle, fcs_int max_local_particles)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  handle->max_local_particles = max_local_particles;

  fcs_set_values_changed(handle, 1);

  return FCS_RESULT_SUCCESS;
}
示例#16
0
/**
 * sort additional float particle data
 */
FCSResult fcs_resort_floats(FCS handle, fcs_float *src, fcs_float *dst, fcs_int n)
{
  const char* fnc_name = "fcs_resort_floats";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (handle->resort_floats == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, fnc_name, "resorting not supported");

  return handle->resort_floats(handle, src, dst, n, fcs_get_communicator(handle));
}
示例#17
0
/**
 * return whether resort support is available
 */
FCSResult fcs_get_resort_availability(FCS handle, fcs_int *availability)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  *availability = 0;

  if (handle->get_resort_availability == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, __func__, "resorting not supported");

  return handle->get_resort_availability(handle, availability);
}
示例#18
0
/**
 * set the maximum distance the particles have moved since the call of ::fcs_run
 */
FCSResult fcs_set_max_particle_move(FCS handle, fcs_float max_particle_move)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

/*  if (handle->set_max_particle_move == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, __func__, "max. particle move not supported");*/

  if (handle->set_max_particle_move == NULL) return FCS_RESULT_SUCCESS;

  return handle->set_max_particle_move(handle, max_particle_move);
}
示例#19
0
/**
 * return the new local number of particles
 */
FCSResult fcs_get_resort_particles(FCS handle, fcs_int *resort_particles)
{
  const char *fnc_name = "fcs_get_resort_particles";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (handle->get_resort_particles == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, fnc_name, "resorting not supported");

  return handle->get_resort_particles(handle, resort_particles);
}
示例#20
0
/**
 * disable a user-defined cutoff radius for the near-field
 */
FCSResult fcs_unset_r_cut(FCS handle)
{
  const char *fnc_name = "fcs_unset_r_cut";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (handle->unset_r_cut == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, fnc_name, "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);
}
示例#21
0
/**
 * set whether resort support is requested
 */
FCSResult fcs_set_resort(FCS handle, fcs_int resort)
{
  const char *fnc_name = "fcs_set_resort";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  if (handle->set_resort == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, fnc_name, "resorting not supported");

  return handle->set_resort(handle, resort);
}
示例#22
0
/**
 * set whether the virial should be computed
 */
FCSResult fcs_set_compute_virial(FCS handle, fcs_int compute_virial)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

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

  if (handle->set_compute_virial == NULL)
    return fcs_result_create(FCS_ERROR_NOT_IMPLEMENTED, __func__, "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);
}
示例#23
0
/**
 * return the error tolerance of the FCS solver
 */
FCSResult fcs_get_tolerance(FCS handle, fcs_int *tolerance_type, fcs_float *tolerance)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  *tolerance_type = FCS_TOLERANCE_TYPE_UNDEFINED;
  *tolerance = -1.0; 

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

  return handle->get_tolerance(handle, tolerance_type, tolerance);
}
示例#24
0
/**
 * return the comuputed virial
 */
FCSResult fcs_get_virial(FCS handle, fcs_float *virial)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

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

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

  return handle->get_virial(handle, virial);
}
示例#25
0
/**
 * function to set the maximum number of particles that can be stored in the specified local particle data arrays
 */
FCSResult fcs_set_max_local_particles(FCS handle, fcs_int max_local_particles)
{
  const char *fnc_name = "fcs_set_max_local_particles";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  handle->max_local_particles = max_local_particles;

  fcs_set_values_changed(handle, 1);

  return FCS_RESULT_SUCCESS;
}
示例#26
0
/**
 * set the near-field flag
 */
FCSResult fcs_set_near_field_flag(FCS handle, fcs_int near_field_flag)
{
  const char *fnc_name = "fcs_set_near_field_flag";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  handle->near_field_flag = near_field_flag;

  fcs_set_values_changed(handle,1);

  return FCS_RESULT_SUCCESS;
}
示例#27
0
/**
 * set the dimensions of the system
 */
FCSResult fcs_set_dimensions(FCS handle, fcs_int dim)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  if (dim > 3 || dim < 1)
    return fcs_result_create(FCS_ERROR_WRONG_ARGUMENT, __func__, "dimensions must be between 1 and 3");

  handle->dimensions = dim;

  fcs_set_values_changed(handle, 1);

  return FCS_RESULT_SUCCESS;
}
示例#28
0
/**
 * set the total number of particles in the system
 */
FCSResult fcs_set_total_particles(FCS handle, fcs_int total_particles)
{
  CHECK_HANDLE_RETURN_RESULT(handle, __func__);

  if (total_particles < 1)
    return fcs_result_create(FCS_ERROR_WRONG_ARGUMENT, __func__, "total number of particles must be at least 1");
  
  handle->total_particles = total_particles;

  fcs_set_values_changed(handle, 1);

  return FCS_RESULT_SUCCESS;
}
示例#29
0
/**
 * return whether resort support is available
 */
FCSResult fcs_get_resort_availability(FCS handle, fcs_int *availability)
{
  const char *fnc_name = "fcs_get_resort_availability";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

  *availability = 0;

  if (handle->get_resort_availability == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, fnc_name, "resorting not supported");

  return handle->get_resort_availability(handle, availability);
}
示例#30
0
/**
 * set the maximum distance the particles have moved since the call of ::fcs_run
 */
FCSResult fcs_set_max_particle_move(FCS handle, fcs_float max_particle_move)
{
  const char *fnc_name = "fcs_set_max_particle_move";

  CHECK_HANDLE_RETURN_RESULT(handle, fnc_name);

/*  if (handle->set_max_particle_move == NULL)
    return fcs_result_create(FCS_ERROR_INCOMPATIBLE_METHOD, fnc_name, "max. particle move not supported");*/

  if (handle->set_max_particle_move == NULL) return FCS_SUCCESS;

  return handle->set_max_particle_move(handle, max_particle_move);
}