mdcore
0.1.5
|
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <float.h>
#include <string.h>
#include "errs.h"
#include "fptype.h"
#include "potential.h"
#include "potential_eval.h"
Defines | |
#define | vector(elcount, type) __attribute__((vector_size((elcount)*sizeof(type)))) type |
#define | error(id) ( potential_err = errs_register( id , potential_err_msg[-(id)] , __LINE__ , __FUNCTION__ , __FILE__ ) ) |
Functions | |
double | potential_LJ126 (double r, double A, double B) |
A basic 12-6 Lennard-Jones potential. | |
double | potential_LJ126_p (double r, double A, double B) |
A basic 12-6 Lennard-Jones potential (first derivative). | |
double | potential_LJ126_6p (double r, double A, double B) |
A basic 12-6 Lennard-Jones potential (sixth derivative). | |
double | potential_Coulomb (double r) |
The Coulomb potential. | |
double | potential_Coulomb_p (double r) |
The Coulomb potential (first derivative). | |
double | potential_Coulomb_6p (double r) |
TheCoulomb potential (sixth derivative). | |
double | potential_Ewald (double r, double kappa) |
The short-range part of an Ewald summation. | |
double | potential_Ewald_p (double r, double kappa) |
The short-range part of an Ewald summation (first derivative). | |
double | potential_Ewald_6p (double r, double kappa) |
The short-range part of an Ewald summation (sixth derivative). | |
double | potential_create_harmonic_f (double r) |
double | potential_create_harmonic_dfdr (double r) |
double | potential_create_harmonic_d6fdr6 (double r) |
struct potential * | potential_create_harmonic (double a, double b, double K, double r0, double tol) |
Creates a harmonic bond potential. | |
double | potential_create_harmonic_dihedral_f (double r) |
double | potential_create_harmonic_dihedral_dfdr (double r) |
double | potential_create_harmonic_dihedral_d6fdr6 (double r) |
struct potential * | potential_create_harmonic_dihedral (double K, int n, double delta, double tol) |
Creates a harmonic dihedral potential. | |
double | potential_create_harmonic_angle_f (double r) |
double | potential_create_harmonic_angle_dfdr (double r) |
double | potential_create_harmonic_angle_d6fdr6 (double r) |
struct potential * | potential_create_harmonic_angle (double a, double b, double K, double theta0, double tol) |
Creates a harmonic angle potential. | |
double | potential_create_Ewald_f (double r) |
double | potential_create_Ewald_dfdr (double r) |
double | potential_create_Ewald_d6fdr6 (double r) |
struct potential * | potential_create_Ewald (double a, double b, double q, double kappa, double tol) |
Creates a potential representing the real-space part of an Ewald potential. | |
double | potential_create_LJ126_Ewald_f (double r) |
double | potential_create_LJ126_Ewald_dfdr (double r) |
double | potential_create_LJ126_Ewald_d6fdr6 (double r) |
struct potential * | potential_create_LJ126_Ewald (double a, double b, double A, double B, double q, double kappa, double tol) |
Creates a potential representing the sum of a 12-6 Lennard-Jones potential and the real-space part of an Ewald potential. | |
double | potential_create_Coulomb_f (double r) |
double | potential_create_Coulomb_dfdr (double r) |
double | potential_create_Coulomb_d6fdr6 (double r) |
struct potential * | potential_create_Coulomb (double a, double b, double q, double tol) |
Creates a potential representing a shifted Coulomb potential. | |
double | potential_create_LJ126_Coulomb_f (double r) |
double | potential_create_LJ126_Coulomb_dfdr (double r) |
double | potential_create_LJ126_Coulomb_d6fdr6 (double r) |
struct potential * | potential_create_LJ126_Coulomb (double a, double b, double A, double B, double q, double tol) |
Creates a potential representing the sum of a 12-6 Lennard-Jones potential and a shifted Coulomb potential. | |
double | potential_create_LJ126_f (double r) |
double | potential_create_LJ126_dfdr (double r) |
double | potential_create_LJ126_d6fdr6 (double r) |
struct potential * | potential_create_LJ126 (double a, double b, double A, double B, double tol) |
Creates a potential representing a 12-6 Lennard-Jones potential. | |
void | potential_clear (struct potential *p) |
Free the memory associated with the given potential. | |
int | potential_init (struct potential *p, double(*f)(double), double(*fp)(double), double(*f6p)(double), FPTYPE a, FPTYPE b, FPTYPE tol) |
Construct a potential from the given function. | |
int | potential_init3 (struct potential *p, double(*f)(double), double(*fp)(double), double(*f6p)(double), FPTYPE a, FPTYPE b, FPTYPE tol) |
Construct a potential from the given function. | |
int | potential_getfp (double(*f)(double), int n, FPTYPE *x, double *fp) |
Compute the optimal first derivatives for the given set of nodes. | |
int | potential_getcoeffs (double(*f)(double), double(*fp)(double), FPTYPE *xi, int n, FPTYPE *c, FPTYPE *err) |
Compute the interpolation coefficients over a given set of nodes. | |
double | potential_getalpha (double(*f6p)(double), double a, double b) |
Compute the parameter for the optimal node distribution. | |
double | potential_getalpha3 (double(*f6p)(double), double a, double b) |
Compute the parameter for the optimal node distribution. | |
Variables | |
int | potential_err = potential_err_ok |
FPTYPE | c_null [] = { FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO } |
struct potential | potential_null = { { FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO } , c_null , 0.0 , DBL_MAX , potential_flag_none , 1 } |
char * | potential_err_msg [6] |
double | potential_create_harmonic_K |
double | potential_create_harmonic_r0 |
double | potential_create_harmonic_dihedral_K |
int | potential_create_harmonic_dihedral_n |
double | potential_create_harmonic_dihedral_delta |
double | potential_create_harmonic_angle_K |
double | potential_create_harmonic_angle_theta0 |
double | potential_create_Ewald_q |
double | potential_create_Ewald_kappa |
double | potential_create_LJ126_Ewald_A |
double | potential_create_LJ126_Ewald_B |
double | potential_create_LJ126_Ewald_kappa |
double | potential_create_LJ126_Ewald_q |
double | potential_create_Coulomb_q |
double | potential_create_Coulomb_b |
double | potential_create_LJ126_Coulomb_q |
double | potential_create_LJ126_Coulomb_b |
double | potential_create_LJ126_Coulomb_A |
double | potential_create_LJ126_Coulomb_B |
double | potential_create_LJ126_A |
double | potential_create_LJ126_B |
#define error | ( | id | ) | ( potential_err = errs_register( id , potential_err_msg[-(id)] , __LINE__ , __FUNCTION__ , __FILE__ ) ) |
#define vector | ( | elcount, | |
type | |||
) | __attribute__((vector_size((elcount)*sizeof(type)))) type |
Macro to easily define vector types.
void potential_clear | ( | struct potential * | p | ) |
Free the memory associated with the given potential.
p | Pointer to the potential to clear. |
double potential_Coulomb | ( | double | r | ) | [inline] |
The Coulomb potential.
r | The interaction radius. |
r
. double potential_Coulomb_6p | ( | double | r | ) | [inline] |
TheCoulomb potential (sixth derivative).
r | The interaction radius. |
r
. double potential_Coulomb_p | ( | double | r | ) | [inline] |
The Coulomb potential (first derivative).
r | The interaction radius. |
r
. struct potential* potential_create_Coulomb | ( | double | a, |
double | b, | ||
double | q, | ||
double | tol | ||
) | [read] |
Creates a potential representing a shifted Coulomb potential.
a | The smallest radius for which the potential will be constructed. |
b | The largest radius for which the potential will be constructed. |
q | The charge scaling of the potential. |
tol | The tolerance to which the interpolation should match the exact potential. |
NULL
on error (see potential_err). double potential_create_Coulomb_d6fdr6 | ( | double | r | ) |
double potential_create_Coulomb_dfdr | ( | double | r | ) |
double potential_create_Coulomb_f | ( | double | r | ) |
struct potential* potential_create_Ewald | ( | double | a, |
double | b, | ||
double | q, | ||
double | kappa, | ||
double | tol | ||
) | [read] |
Creates a potential representing the real-space part of an Ewald potential.
a | The smallest radius for which the potential will be constructed. |
b | The largest radius for which the potential will be constructed. |
q | The charge scaling of the potential. |
kappa | The screening distance of the Ewald potential. |
tol | The tolerance to which the interpolation should match the exact potential. |
NULL
on error (see potential_err). double potential_create_Ewald_d6fdr6 | ( | double | r | ) |
double potential_create_Ewald_dfdr | ( | double | r | ) |
double potential_create_Ewald_f | ( | double | r | ) |
struct potential* potential_create_harmonic | ( | double | a, |
double | b, | ||
double | K, | ||
double | r0, | ||
double | tol | ||
) | [read] |
Creates a harmonic bond potential.
a | The smallest radius for which the potential will be constructed. |
b | The largest radius for which the potential will be constructed. |
K | The energy of the bond. |
r0 | The minimum energy distance. |
tol | The tolerance to which the interpolation should match the exact potential. |
NULL
on error (see potential_err). struct potential* potential_create_harmonic_angle | ( | double | a, |
double | b, | ||
double | K, | ||
double | theta0, | ||
double | tol | ||
) | [read] |
Creates a harmonic angle potential.
a | The smallest angle for which the potential will be constructed. |
b | The largest angle for which the potential will be constructed. |
K | The energy of the angle. |
theta0 | The minimum energy angle. |
tol | The tolerance to which the interpolation should match the exact potential. |
NULL
on error (see potential_err). double potential_create_harmonic_angle_d6fdr6 | ( | double | r | ) |
double potential_create_harmonic_angle_dfdr | ( | double | r | ) |
double potential_create_harmonic_angle_f | ( | double | r | ) |
double potential_create_harmonic_d6fdr6 | ( | double | r | ) |
double potential_create_harmonic_dfdr | ( | double | r | ) |
struct potential* potential_create_harmonic_dihedral | ( | double | K, |
int | n, | ||
double | delta, | ||
double | tol | ||
) | [read] |
Creates a harmonic dihedral potential.
K | The energy of the dihedral. |
n | The multiplicity of the dihedral. |
delta | The minimum energy dihedral. |
tol | The tolerance to which the interpolation should match the exact potential. |
NULL
on error (see potential_err). double potential_create_harmonic_dihedral_d6fdr6 | ( | double | r | ) |
double potential_create_harmonic_dihedral_dfdr | ( | double | r | ) |
double potential_create_harmonic_dihedral_f | ( | double | r | ) |
double potential_create_harmonic_f | ( | double | r | ) |
struct potential* potential_create_LJ126 | ( | double | a, |
double | b, | ||
double | A, | ||
double | B, | ||
double | tol | ||
) | [read] |
Creates a potential representing a 12-6 Lennard-Jones potential.
a | The smallest radius for which the potential will be constructed. |
b | The largest radius for which the potential will be constructed. |
A | The first parameter of the Lennard-Jones potential. |
B | The second parameter of the Lennard-Jones potential. |
tol | The tolerance to which the interpolation should match the exact potential. |
NULL
on error (see potential_err). struct potential* potential_create_LJ126_Coulomb | ( | double | a, |
double | b, | ||
double | A, | ||
double | B, | ||
double | q, | ||
double | tol | ||
) | [read] |
Creates a potential representing the sum of a 12-6 Lennard-Jones potential and a shifted Coulomb potential.
a | The smallest radius for which the potential will be constructed. |
b | The largest radius for which the potential will be constructed. |
A | The first parameter of the Lennard-Jones potential. |
B | The second parameter of the Lennard-Jones potential. |
q | The charge scaling of the potential. |
tol | The tolerance to which the interpolation should match the exact potential. |
NULL
on error (see potential_err). double potential_create_LJ126_Coulomb_d6fdr6 | ( | double | r | ) |
double potential_create_LJ126_Coulomb_dfdr | ( | double | r | ) |
double potential_create_LJ126_Coulomb_f | ( | double | r | ) |
double potential_create_LJ126_d6fdr6 | ( | double | r | ) |
double potential_create_LJ126_dfdr | ( | double | r | ) |
struct potential* potential_create_LJ126_Ewald | ( | double | a, |
double | b, | ||
double | A, | ||
double | B, | ||
double | q, | ||
double | kappa, | ||
double | tol | ||
) | [read] |
Creates a potential representing the sum of a 12-6 Lennard-Jones potential and the real-space part of an Ewald potential.
a | The smallest radius for which the potential will be constructed. |
b | The largest radius for which the potential will be constructed. |
A | The first parameter of the Lennard-Jones potential. |
B | The second parameter of the Lennard-Jones potential. |
q | The charge scaling of the potential. |
kappa | The screening distance of the Ewald potential. |
tol | The tolerance to which the interpolation should match the exact potential. |
NULL
on error (see potential_err). double potential_create_LJ126_Ewald_d6fdr6 | ( | double | r | ) |
double potential_create_LJ126_Ewald_dfdr | ( | double | r | ) |
double potential_create_LJ126_Ewald_f | ( | double | r | ) |
double potential_create_LJ126_f | ( | double | r | ) |
double potential_Ewald | ( | double | r, |
double | kappa | ||
) | [inline] |
The short-range part of an Ewald summation.
r | The interaction radius. |
kappa | The screening length of the Ewald summation. |
r
. double potential_Ewald_6p | ( | double | r, |
double | kappa | ||
) | [inline] |
The short-range part of an Ewald summation (sixth derivative).
r | The interaction radius. |
kappa | The screening length of the Ewald summation. |
r
. double potential_Ewald_p | ( | double | r, |
double | kappa | ||
) | [inline] |
The short-range part of an Ewald summation (first derivative).
r | The interaction radius. |
kappa | The screening length of the Ewald summation. |
r
. double potential_getalpha | ( | double(*)(double) | f6p, |
double | a, | ||
double | b | ||
) |
Compute the parameter for the optimal node distribution.
f6p | Pointer to a function representing the 6th derivative of the interpoland. |
a | Left limit of the interpolation. |
b | Right limit of the interpolation. |
The value is computed using Brent's algortihm to 4 decimal digits.
double potential_getalpha3 | ( | double(*)(double) | f6p, |
double | a, | ||
double | b | ||
) |
Compute the parameter for the optimal node distribution.
f6p | Pointer to a function representing the 6th derivative of the interpoland. |
a | Left limit of the interpolation. |
b | Right limit of the interpolation. |
The value is computed using Brent's algortihm to 4 decimal digits.
int potential_getcoeffs | ( | double(*)(double) | f, |
double(*)(double) | fp, | ||
FPTYPE * | xi, | ||
int | n, | ||
FPTYPE * | c, | ||
FPTYPE * | err | ||
) |
Compute the interpolation coefficients over a given set of nodes.
f | Pointer to the function to be interpolated. |
fp | Pointer to the first derivative of f . |
xi | Pointer to an array of nodes between whicht the function f will be interpolated. |
n | Number of nodes in xi . |
c | Pointer to an array in which to store the interpolation coefficients. |
err | Pointer to a floating-point value in which an approximation of the interpolation error, relative to the maximum of f in each interval, is stored. |
Compute the coefficients of the function f
with derivative fp
over the n
intervals between the xi
and store an estimate of the maximum locally relative interpolation error in err
.
The array to which c
points must be large enough to hold at least potential_degree x n
values of type #FPTYPE.
int potential_getfp | ( | double(*)(double) | f, |
int | n, | ||
FPTYPE * | x, | ||
double * | fp | ||
) |
Compute the optimal first derivatives for the given set of nodes.
f | Pointer to the function to be interpolated. |
n | Number of intervals. |
xi | Pointer to an array of nodes between whicht the function f will be interpolated. |
fp | Pointer to an array in which to store the first derivatives of f . |
int potential_init | ( | struct potential * | p, |
double(*)(double) | f, | ||
double(*)(double) | fp, | ||
double(*)(double) | f6p, | ||
FPTYPE | a, | ||
FPTYPE | b, | ||
FPTYPE | tol | ||
) |
Construct a potential from the given function.
p | A pointer to an empty potential. |
f | A pointer to the potential function to be interpolated. |
fp | A pointer to the first derivative of f . |
f6p | A pointer to the sixth derivative of f . |
a | The smallest radius for which the potential will be constructed. |
b | The largest radius for which the potential will be constructed. |
tol | The absolute tolerance to which the interpolation should match the exact potential. |
Computes an interpolated potential function from f
in [a,b] to the locally relative tolerance
tol
.
The sixth derivative f6p
is used to compute the optimal node distribution. If f6p
is NULL
, the derivative is approximated numerically.
The zeroth interval contains a linear extension of f
for values < a.
int potential_init3 | ( | struct potential * | p, |
double(*)(double) | f, | ||
double(*)(double) | fp, | ||
double(*)(double) | f6p, | ||
FPTYPE | a, | ||
FPTYPE | b, | ||
FPTYPE | tol | ||
) |
Construct a potential from the given function.
p | A pointer to an empty potential. |
f | A pointer to the potential function to be interpolated. |
fp | A pointer to the first derivative of f . |
f6p | A pointer to the sixth derivative of f . |
a | The smallest radius for which the potential will be constructed. |
b | The largest radius for which the potential will be constructed. |
tol | The piecewise relative tolerance to which the interpolation should match the exact potential. |
Computes an interpolated potential function from f
in [a,b] to the locally relative tolerance
tol
.
The sixth derivative f6p
is used to compute the optimal node distribution. If f6p
is NULL
, the derivative is approximated numerically.
The zeroth interval contains a linear extension of f
for values < a.
double potential_LJ126 | ( | double | r, |
double | A, | ||
double | B | ||
) | [inline] |
A basic 12-6 Lennard-Jones potential.
r | The interaction radius. |
A | First parameter of the potential. |
B | Second parameter of the potential. |
r
. double potential_LJ126_6p | ( | double | r, |
double | A, | ||
double | B | ||
) | [inline] |
A basic 12-6 Lennard-Jones potential (sixth derivative).
r | The interaction radius. |
A | First parameter of the potential. |
B | Second parameter of the potential. |
r
. double potential_LJ126_p | ( | double | r, |
double | A, | ||
double | B | ||
) | [inline] |
A basic 12-6 Lennard-Jones potential (first derivative).
r | The interaction radius. |
A | First parameter of the potential. |
B | Second parameter of the potential. |
r
. FPTYPE c_null[] = { FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO } |
The null potential
double potential_create_Coulomb_b |
double potential_create_Coulomb_q |
double potential_create_Ewald_kappa |
double potential_create_Ewald_q |
double potential_create_harmonic_K |
double potential_create_harmonic_r0 |
double potential_create_LJ126_A |
double potential_create_LJ126_B |
The last error
char* potential_err_msg[6] |
{ "Nothing bad happened.", "An unexpected NULL pointer was encountered.", "A call to malloc failed, probably due to insufficient memory.", "The requested value was out of bounds.", "Not yet implemented.", "Maximum number of intervals reached before tolerance satisfied." }
struct potential potential_null = { { FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO , FPTYPE_ZERO } , c_null , 0.0 , DBL_MAX , potential_flag_none , 1 } |
Fictitious null potential.