ESPResSo 3.2.0-11-g9950804-git
Extensible Simulation Package for Soft Matter Research
Defines | Functions | Variables
p3m-dipolar.c File Reference

P3M algorithm for long range magnetic dipole-dipole interaction. More...

#include "p3m-dipolar.h"
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
#include "integrate.h"
#include "global.h"
#include "grid.h"
#include "domain_decomposition.h"
#include "particle_data.h"
#include "communication.h"
#include "fft-dipolar.h"
#include "thermostat.h"
#include "cells.h"
#include "tuning.h"
Include dependency graph for p3m-dipolar.c:

Go to the source code of this file.

Defines

#define REQ_P3M_INIT_D   2001
 Tag for communication in P3M_init() -> send_calc_mesh().
#define REQ_P3M_GATHER_D   2011
 Tag for communication in p3m_gather_fft_grid().
#define REQ_P3M_SPREAD_D   2021
 Tag for communication in p3m_spread_force_grid().
#define P3M_TUNE_MAX_CUTS   50

Functions

static double calc_surface_term (int force_flag, int energy_flag)
static double dp3m_average_dipolar_self_energy (double box_l, int mesh)
static double dp3m_perform_aliasing_sums_dipolar_self_energy (int n[3])
void dp3m_pre_init (void)
void dp3m_init ()
 Initialize all structures, parameters and arrays needed for the P3M algorithm for dipole-dipole interactions.
void dp3m_free_dipoles ()
void dp3m_set_tune_params (double r_cut, int mesh, int cao, double alpha, double accuracy, int n_interpol)
int dp3m_set_params (double r_cut, int mesh, int cao, double alpha, double accuracy)
int dp3m_set_mesh_offset (double x, double y, double z)
int dp3m_set_eps (double eps)
int dp3m_set_ninterpol (int n)
void dp3m_dipole_assign (void)
 assign the physical dipoles using the tabulated assignment function.
void dp3m_assign_dipole (double real_pos[3], double mu, double dip[3], int cp_cnt)
 assign a single dipole into the current charge grid.
void dp3m_shrink_wrap_dipole_grid (int n_dipoles)
 shrink wrap the dipoles grid
static void P3M_assign_torques (double prefac, int d_rs)
static void dp3m_assign_forces_dip (double prefac, int d_rs)
double dp3m_calc_kspace_forces (int force_flag, int energy_flag)
 compute the k-space part of forces and energies for the magnetic dipole-dipole interaction
double dp3m_get_accuracy (int mesh, int cao, double r_cut_iL, double *_alpha_L, double *_rs_err, double *_ks_err)
 Tune dipolar P3M parameters to desired accuracy.
static double dp3m_mcr_time (int mesh, int cao, double r_cut_iL, double alpha_L)
 get the optimal alpha and the corresponding computation time for fixed mesh, cao, r_cut and alpha
static double dp3m_mc_time (char **log, int mesh, int cao, double r_cut_iL_min, double r_cut_iL_max, double *_r_cut_iL, double *_alpha_L, double *_accuracy)
 get the optimal alpha and the corresponding computation time for fixed mesh, cao.
static double dp3m_m_time (char **log, int mesh, int cao_min, int cao_max, int *_cao, double r_cut_iL_min, double r_cut_iL_max, double *_r_cut_iL, double *_alpha_L, double *_accuracy)
 get the optimal alpha and the corresponding computation time for fixed mesh.
int dp3m_adaptive_tune (char **logger)
 Tuning of dipolar P3M.
void p3m_print_dp3m_struct (p3m_parameter_struct ps)
void dp3m_count_magnetic_particles ()
 Calculate number of magnetic particles, the sum of the squared charges and the squared sum of the charges.
int dp3m_sanity_checks ()
 sanity checks
void dp3m_scaleby_box_l ()
 Updates p3m_parameter_struct::alpha and p3m_parameter_struct::r_cut if box_l changed.
Private Functions
static void dp3m_calc_send_mesh ()
 Calculates for magnetic dipoles the properties of the send/recv sub-meshes of the local FFT mesh.
static void dp3m_init_a_ai_cao_cut ()
 Initializes for magnetic dipoles the (inverse) mesh constant p3m_parameter_struct::a (p3m_parameter_struct::ai) and the cutoff for charge assignment p3m_parameter_struct::cao_cut, which has to be done by dp3m_init once and by dp3m_scaleby_box_l whenever the box_l changed.
static void dp3m_calc_lm_ld_pos ()
 Calculate for magnetic dipoles the spacial position of the left down mesh point of the local mesh, to be stored in p3m_local_mesh::ld_pos; function called by dp3m_calc_local_ca_mesh once and by dp3m_scaleby_box_l whenever the box_l changed.
static void dp3m_gather_fft_grid (double *mesh)
 Gather FFT grid.
static void dp3m_spread_force_grid (double *mesh)
 Spread force grid.
static void dp3m_realloc_ca_fields (int newsize)
 realloc charge assignment fields.
static int dp3m_sanity_checks_boxl (void)
 checks for correctness for magnetic dipoles in P3M of the cao_cut, necessary when the box length changes
static void dp3m_calc_local_ca_mesh ()
 Calculates properties of the local FFT mesh for the charge assignment process.
static void dp3m_interpolate_dipole_assignment_function ()
 Interpolates the P-th order charge assignment function from Hockney/Eastwood 5-189 (or 8-61).
static void dp3m_calc_meshift ()
 shifts the mesh points by mesh/2
static void dp3m_calc_differential_operator ()
 Calculates the Fourier transformed differential operator.
static void dp3m_calc_influence_function_force ()
 Calculates the influence function optimized for the dipolar forces.
static void dp3m_calc_influence_function_energy ()
 Calculates the influence function optimized for the dipolar energy and torques.
static void dp3m_compute_constants_energy_dipolar ()
 Calculates the constants necessary to correct the dipolar energy to minimize the error.
static double dp3m_perform_aliasing_sums_force (int n[3], double nominator[1])
 Calculates the aliasing sums for the optimal influence function.
static double dp3m_perform_aliasing_sums_energy (int n[3], double nominator[1])
static double dp3m_k_space_error (double box_size, double prefac, int mesh, int cao, int n_c_part, double sum_q2, double alpha_L)
P3M Tuning Functions (private)
double P3M_DIPOLAR_real_space_error (double box_size, double prefac, double r_cut_iL, int n_c_part, double sum_q2, double alpha_L)
static void dp3m_tune_aliasing_sums (int nx, int ny, int nz, int mesh, double mesh_i, int cao, double alpha_L_i, double *alias1, double *alias2)
double dp3m_rtbisection (double box_size, double prefac, double r_cut_iL, int n_c_part, double sum_q2, double x1, double x2, double xacc, double tuned_accuracy)
Exported Functions
void dp3m_set_bjerrum ()
 set bjerrum length for dipolar p3m

Variables

dp3m_data_struct dp3m
 dipolar P3M parameters.

Detailed Description

P3M algorithm for long range magnetic dipole-dipole interaction.

NB: In general the magnetic dipole-dipole functions bear the same name than the charge-charge but, adding in front of the name a D and replacing where "charge" appears by "dipole". In this way one can recognize the similarity of the functions but avoiding nasty confusions in their use.

PS: By default the magnetic epsilon is metallic = 0.

Definition in file p3m-dipolar.c.


Define Documentation

#define P3M_TUNE_MAX_CUTS   50

Definition at line 1531 of file p3m-dipolar.c.

#define REQ_P3M_GATHER_D   2011

Tag for communication in p3m_gather_fft_grid().

Definition at line 61 of file p3m-dipolar.c.

Referenced by dp3m_gather_fft_grid().

#define REQ_P3M_INIT_D   2001

Tag for communication in P3M_init() -> send_calc_mesh().

Definition at line 59 of file p3m-dipolar.c.

Referenced by dp3m_calc_send_mesh().

#define REQ_P3M_SPREAD_D   2021

Tag for communication in p3m_spread_force_grid().

Definition at line 63 of file p3m-dipolar.c.

Referenced by dp3m_spread_force_grid().


Function Documentation

double calc_surface_term ( int  force_flag,
int  energy_flag 
) [static]
int dp3m_adaptive_tune ( char **  logger)

Tuning of dipolar P3M.

The algorithm basically determines the mesh, cao and then the real space cutoff, in this nested order.

For each mesh, the cao optimal for the mesh tested previously is used as an initial guess, and the algorithm tries whether increasing or decreasing it leads to a better solution. This is efficient, since the optimal cao only changes little with the meshes in general.

The real space cutoff for a given mesh and cao is determined via a bisection on the error estimate, which determines where the error estimate equals the required accuracy. Therefore the smallest possible, i.e. fastest real space cutoff is determined.

Both the search over mesh and cao stop to search in a specific direction once the computation time is significantly higher than the currently known optimum.

Definition at line 1865 of file p3m-dipolar.c.

References p3m_parameter_struct::accuracy, p3m_parameter_struct::alpha_L, box_l, box_l_i, p3m_parameter_struct::cao, dmin(), dp3m_m_time(), dp3m_scaleby_box_l(), ES_DOUBLE_SPACE, ES_ERROR, ES_INTEGER_SPACE, ES_OK, p3m_parameter_struct::mesh, min_box_l, min_local_box_l, mpi_bcast_coulomb_params(), mpi_bcast_event(), P3M_COUNT_DIPOLES, P3M_MAX_MESH, P3M_TIME_GRAN, P3M_TRACE, dp3m_data_struct::params, p3m_parameter_struct::r_cut_iL, skin, strcat_alloc(), dp3m_data_struct::sum_dip_part, dp3m_data_struct::sum_mu2, and this_node.

Referenced by tclcommand_inter_magnetic_parse_dp3m_tune_params().

void dp3m_assign_dipole ( double  real_pos[3],
double  mu,
double  dip[3],
int  cp_cnt 
)
static void dp3m_assign_forces_dip ( double  prefac,
int  d_rs 
) [static]
double dp3m_average_dipolar_self_energy ( double  box_l,
int  mesh 
) [static]
void dp3m_calc_differential_operator ( ) [static]

Calculates the Fourier transformed differential operator.

Remark: This is done on the level of n-vectors and not k-vectors, i.e. the prefactor i*2*PI/L is missing!

Definition at line 1345 of file p3m-dipolar.c.

References dp3m_data_struct::d_op, dround(), i, p3m_parameter_struct::mesh, dp3m_data_struct::params, and realloc.

Referenced by dp3m_init().

void dp3m_calc_influence_function_energy ( ) [static]
void dp3m_calc_influence_function_force ( ) [static]
double dp3m_calc_kspace_forces ( int  force_flag,
int  energy_flag 
)
void dp3m_calc_lm_ld_pos ( ) [static]

Calculate for magnetic dipoles the spacial position of the left down mesh point of the local mesh, to be stored in p3m_local_mesh::ld_pos; function called by dp3m_calc_local_ca_mesh once and by dp3m_scaleby_box_l whenever the box_l changed.

Calculate the spacial position of the left down mesh point of the local mesh, to be stored in p3m_local_mesh::ld_pos; function called by dp3m_calc_local_ca_mesh once and by dp3m_scaleby_box_l whenever the box_l changed.

Definition at line 2205 of file p3m-dipolar.c.

References p3m_parameter_struct::a, i, p3m_local_mesh::ld_ind, p3m_local_mesh::ld_pos, dp3m_data_struct::local_mesh, p3m_parameter_struct::mesh_off, and dp3m_data_struct::params.

Referenced by dp3m_calc_local_ca_mesh(), and dp3m_scaleby_box_l().

void dp3m_calc_local_ca_mesh ( ) [static]
void dp3m_calc_meshift ( void  ) [static]
void dp3m_calc_send_mesh ( ) [static]

Calculates for magnetic dipoles the properties of the send/recv sub-meshes of the local FFT mesh.

In order to calculate the recv sub-meshes there is a communication of the margins between neighbouring nodes.

Definition at line 2368 of file p3m-dipolar.c.

References comm_cart, p3m_local_mesh::dim, i, p3m_local_mesh::in_ur, dp3m_data_struct::local_mesh, p3m_local_mesh::margin, p3m_send_mesh::max, MPI_INT, MPI_Recv(), MPI_Send(), node_neighbors, node_pos, p3m_send_mesh::r_dim, p3m_send_mesh::r_ld, p3m_local_mesh::r_margin, p3m_send_mesh::r_size, p3m_send_mesh::r_ur, REQ_P3M_INIT_D, p3m_send_mesh::s_dim, p3m_send_mesh::s_ld, p3m_send_mesh::s_size, p3m_send_mesh::s_ur, dp3m_data_struct::sm, and this_node.

Referenced by dp3m_init().

void dp3m_compute_constants_energy_dipolar ( ) [static]

Calculates the constants necessary to correct the dipolar energy to minimize the error.

Definition at line 2466 of file p3m-dipolar.c.

References p3m_parameter_struct::alpha_L, box_l, dp3m_average_dipolar_self_energy(), dp3m_data_struct::energy_correction, p3m_parameter_struct::mesh, P3M_TRACE, dp3m_data_struct::params, PI, dp3m_data_struct::sum_mu2, this_node, and wupii.

Referenced by dp3m_calc_kspace_forces().

void dp3m_count_magnetic_particles ( )

Calculate number of magnetic particles, the sum of the squared charges and the squared sum of the charges.

Definition at line 2017 of file p3m-dipolar.c.

References CellPList::cell, comm_cart, i, local_cells, MPI_Allreduce(), MPI_DOUBLE, MPI_SUM, CellPList::n, ParticleList::n, part, ParticleList::part, SQR(), dp3m_data_struct::sum_dip_part, and dp3m_data_struct::sum_mu2.

Referenced by dp3m_init(), mpi_bcast_event_slave(), and on_observable_calc().

void dp3m_dipole_assign ( void  )

assign the physical dipoles using the tabulated assignment function.

If Dstore_ca_frac is true, then the charge fractions are buffered in Dcur_ca_fmp and Dcur_ca_frac.

Definition at line 628 of file p3m-dipolar.c.

References CellPList::cell, ParticlePosition::dip, ParticleProperties::dipm, dp3m_assign_dipole(), dp3m_shrink_wrap_dipole_grid(), i, local_cells, dp3m_data_struct::local_mesh, CellPList::n, ParticleList::n, Particle::p, ParticleList::part, Particle::r, dp3m_data_struct::rs_mesh_dip, and p3m_local_mesh::size.

Referenced by calc_long_range_energies(), calc_long_range_forces(), and calc_long_range_virials().

void dp3m_free_dipoles ( )
void dp3m_gather_fft_grid ( double *  mesh) [static]
double dp3m_get_accuracy ( int  mesh,
int  cao,
double  r_cut_iL,
double *  _alpha_L,
double *  _rs_err,
double *  _ks_err 
)

Tune dipolar P3M parameters to desired accuracy.

Usage:

inter dipolar <bjerrum> p3m tune accuracy <value> [r_cut <value> mesh <value> cao <value>] 

The parameters are tuned to obtain the desired accuracy in best time, by running mpi_integrate(0) for several parameter sets.

The function utilizes the analytic expression of the error estimate for the dipolar P3M method see JCP,2008 paper by J.J.Cerda et al in order to obtain the rms error in the force for a system of N randomly distributed particles in a cubic box. For the real space error the estimate of Kolafa/Perram is used.

Parameter range if not given explicit values: For p3m_parameter_struct::r_cut_iL the function uses the values (min_local_box_l -skin) / (n * box_l), n being an integer (this implies the assumption that p3m_parameter_struct::r_cut_iL is the largest cutoff in the system!). For p3m_parameter_struct::mesh the function uses the two values which matches best the equation: number of mesh point = number of magnetic dipolar particles. For p3m_parameter_struct::cao the function considers all possible values.

For each setting p3m_parameter_struct::alpha_L is calculated assuming that the error contributions of real and reciprocal space should be equal.

After checking if the total error fulfils the accuracy goal the time needed for one force calculation (including verlet list update) is measured via mpi_integrate (0).

The function returns a log of the performed tuning.

The function is based on routines for charges. get the minimal error for this combination of parameters. In fact, the real space error is tuned such that it contributes half of the total error, and then the Fourier space error is calculated. Returns the error and the optimal alpha, or 0 if this combination does not work at all

Definition at line 1573 of file p3m-dipolar.c.

References p3m_parameter_struct::accuracy, box_l, coulomb, dp3m_k_space_error(), dp3m_rtbisection(), Coulomb_parameters::Dprefactor, M_SQRT2, P3M_DIPOLAR_real_space_error(), P3M_TRACE, dp3m_data_struct::params, SQR(), dp3m_data_struct::sum_dip_part, and dp3m_data_struct::sum_mu2.

Referenced by dp3m_mc_time().

void dp3m_init ( void  )
void dp3m_init_a_ai_cao_cut ( ) [static]

Initializes for magnetic dipoles the (inverse) mesh constant p3m_parameter_struct::a (p3m_parameter_struct::ai) and the cutoff for charge assignment p3m_parameter_struct::cao_cut, which has to be done by dp3m_init once and by dp3m_scaleby_box_l whenever the box_l changed.

Initializes the (inverse) mesh constant p3m_parameter_struct::a (p3m_parameter_struct::ai) and the cutoff for charge assignment p3m_parameter_struct::cao_cut, which has to be done by dp3m_init once and by dp3m_scaleby_box_l whenever the box_l changed.

Definition at line 2217 of file p3m-dipolar.c.

References p3m_parameter_struct::a, p3m_parameter_struct::ai, box_l, p3m_parameter_struct::cao, p3m_parameter_struct::cao_cut, i, p3m_parameter_struct::mesh, and dp3m_data_struct::params.

Referenced by dp3m_init(), and dp3m_scaleby_box_l().

void dp3m_interpolate_dipole_assignment_function ( ) [static]

Interpolates the P-th order charge assignment function from Hockney/Eastwood 5-189 (or 8-61).

The following charge fractions are also tabulated in Deserno/Holm.

Definition at line 603 of file p3m-dipolar.c.

References p3m_parameter_struct::cao, i, dp3m_data_struct::int_caf, p3m_parameter_struct::inter, p3m_parameter_struct::inter2, p3m_caf(), P3M_TRACE, dp3m_data_struct::params, realloc, and this_node.

Referenced by dp3m_init().

static double dp3m_k_space_error ( double  box_size,
double  prefac,
int  mesh,
int  cao,
int  n_c_part,
double  sum_q2,
double  alpha_L 
) [static]
static double dp3m_m_time ( char **  log,
int  mesh,
int  cao_min,
int  cao_max,
int *  _cao,
double  r_cut_iL_min,
double  r_cut_iL_max,
double *  _r_cut_iL,
double *  _alpha_L,
double *  _accuracy 
) [static]

get the optimal alpha and the corresponding computation time for fixed mesh.

*cao should contain an initial guess, which is then adapted by stepping up and down. Returns the time upon completion, -1 if the force evaluation does not work, and -2 if the accuracy cannot be met

Definition at line 1729 of file p3m-dipolar.c.

References dp3m_mc_time(), P3M_TIME_GRAN, and P3M_TRACE.

Referenced by dp3m_adaptive_tune().

static double dp3m_mc_time ( char **  log,
int  mesh,
int  cao,
double  r_cut_iL_min,
double  r_cut_iL_max,
double *  _r_cut_iL,
double *  _alpha_L,
double *  _accuracy 
) [static]

get the optimal alpha and the corresponding computation time for fixed mesh, cao.

The r_cut is determined via a simple bisection. Returns -1 if the force evaluation does not work, -2 if there is no valid r_cut, and -3 if the charge assigment order is to large for this grid

Definition at line 1639 of file p3m-dipolar.c.

References p3m_parameter_struct::accuracy, box_l, coulomb, DIPOLAR_MDLC_P3M, Coulomb_parameters::Dmethod, dmin(), dp3m_get_accuracy(), dp3m_mcr_time(), ERROR_SPRINTF, ES_DOUBLE_SPACE, ES_INTEGER_SPACE, i, local_box_l, min_box_l, min_local_box_l, min_num_cells, n_cells, P3M_RCUT_PREC, P3M_TRACE, dp3m_data_struct::params, runtime_error(), skin, and strcat_alloc().

Referenced by dp3m_m_time().

static double dp3m_mcr_time ( int  mesh,
int  cao,
double  r_cut_iL,
double  alpha_L 
) [static]
double dp3m_perform_aliasing_sums_dipolar_self_energy ( int  n[3]) [static]
double dp3m_perform_aliasing_sums_energy ( int  n[3],
double  nominator[1] 
) [static]
double dp3m_perform_aliasing_sums_force ( int  n[3],
double  nominator[1] 
) [static]

Calculates the aliasing sums for the optimal influence function.

Calculates the aliasing sums in the nominator and denominator of the expression for the optimal influence function (see Hockney/Eastwood: 8-22, p. 275).

Parameters:
nn-vector for which the aliasing sum is to be performed.
nominatoraliasing sums in the nominator.
Returns:
denominator aliasing sum in the denominator

Definition at line 1402 of file p3m-dipolar.c.

References p3m_parameter_struct::alpha_L, p3m_parameter_struct::cao, dp3m_data_struct::d_op, p3m_parameter_struct::mesh, dp3m_data_struct::meshift, P3M_BRILLOUIN, dp3m_data_struct::params, PI, sinc(), and SQR().

Referenced by dp3m_calc_influence_function_force().

void dp3m_pre_init ( void  )
void dp3m_realloc_ca_fields ( int  newsize) [static]
double dp3m_rtbisection ( double  box_size,
double  prefac,
double  r_cut_iL,
int  n_c_part,
double  sum_q2,
double  x1,
double  x2,
double  xacc,
double  tuned_accuracy 
)

Definition at line 2178 of file p3m-dipolar.c.

References P3M_DIPOLAR_real_space_error().

Referenced by dp3m_get_accuracy().

int dp3m_sanity_checks ( )
int dp3m_sanity_checks_boxl ( void  ) [static]

checks for correctness for magnetic dipoles in P3M of the cao_cut, necessary when the box length changes

Definition at line 2281 of file p3m-dipolar.c.

References box_l, p3m_parameter_struct::cao_cut, ERROR_SPRINTF, ES_DOUBLE_SPACE, i, local_box_l, dp3m_data_struct::params, and runtime_error().

Referenced by dp3m_sanity_checks(), and dp3m_scaleby_box_l().

void dp3m_scaleby_box_l ( )
void dp3m_set_bjerrum ( )
int dp3m_set_eps ( double  eps)
int dp3m_set_mesh_offset ( double  x,
double  y,
double  z 
)
int dp3m_set_ninterpol ( int  n)
int dp3m_set_params ( double  r_cut,
int  mesh,
int  cao,
double  alpha,
double  accuracy 
)
void dp3m_set_tune_params ( double  r_cut,
int  mesh,
int  cao,
double  alpha,
double  accuracy,
int  n_interpol 
)
void dp3m_shrink_wrap_dipole_grid ( int  n_dipoles)

shrink wrap the dipoles grid

Definition at line 774 of file p3m-dipolar.c.

References dp3m_data_struct::ca_num, and dp3m_realloc_ca_fields().

Referenced by dp3m_dipole_assign().

void dp3m_spread_force_grid ( double *  mesh) [static]
void dp3m_tune_aliasing_sums ( int  nx,
int  ny,
int  nz,
int  mesh,
double  mesh_i,
int  cao,
double  alpha_L_i,
double *  alias1,
double *  alias2 
) [static]

Definition at line 2091 of file p3m-dipolar.c.

References P3M_BRILLOUIN, PI, sinc(), and SQR().

Referenced by dp3m_k_space_error().

static void P3M_assign_torques ( double  prefac,
int  d_rs 
) [static]
double P3M_DIPOLAR_real_space_error ( double  box_size,
double  prefac,
double  r_cut_iL,
int  n_c_part,
double  sum_q2,
double  alpha_L 
)

Definition at line 2138 of file p3m-dipolar.c.

Referenced by dp3m_get_accuracy(), and dp3m_rtbisection().

void p3m_print_dp3m_struct ( p3m_parameter_struct  ps)

Variable Documentation