mirror of https://github.com/phonopy/phonopy.git
Minor refactoring for born and dielectric in C
This commit is contained in:
parent
0028e15007
commit
236ba5a882
47
c/_phonopy.c
47
c/_phonopy.c
|
@ -587,7 +587,7 @@ static PyObject * py_get_nac_dynamical_matrix(PyObject *self, PyObject *args)
|
|||
PyArrayObject* mass;
|
||||
PyArrayObject* super2prim_map;
|
||||
PyArrayObject* prim2super_map;
|
||||
PyArrayObject* born;
|
||||
PyArrayObject* py_born;
|
||||
double factor;
|
||||
|
||||
double* dm;
|
||||
|
@ -596,7 +596,7 @@ static PyObject * py_get_nac_dynamical_matrix(PyObject *self, PyObject *args)
|
|||
double* q;
|
||||
double (*svecs)[27][3];
|
||||
double* m;
|
||||
double* z;
|
||||
double (*born)[3][3];
|
||||
int* multi;
|
||||
int* s2p_map;
|
||||
int* p2s_map;
|
||||
|
@ -604,7 +604,7 @@ static PyObject * py_get_nac_dynamical_matrix(PyObject *self, PyObject *args)
|
|||
int num_satom;
|
||||
|
||||
int n;
|
||||
double *charge_sum;
|
||||
double (*charge_sum)[3][3];
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOOOOOOOOOd",
|
||||
&dynamical_matrix,
|
||||
|
@ -616,7 +616,7 @@ static PyObject * py_get_nac_dynamical_matrix(PyObject *self, PyObject *args)
|
|||
&super2prim_map,
|
||||
&prim2super_map,
|
||||
&py_q_cart,
|
||||
&born,
|
||||
&py_born,
|
||||
&factor))
|
||||
return NULL;
|
||||
|
||||
|
@ -626,17 +626,18 @@ static PyObject * py_get_nac_dynamical_matrix(PyObject *self, PyObject *args)
|
|||
q = (double*)PyArray_DATA(py_q);
|
||||
svecs = (double(*)[27][3])PyArray_DATA(py_shortest_vectors);
|
||||
m = (double*)PyArray_DATA(mass);
|
||||
z = (double*)PyArray_DATA(born);
|
||||
born = (double(*)[3][3])PyArray_DATA(py_born);
|
||||
multi = (int*)PyArray_DATA(multiplicity);
|
||||
s2p_map = (int*)PyArray_DATA(super2prim_map);
|
||||
p2s_map = (int*)PyArray_DATA(prim2super_map);
|
||||
num_patom = PyArray_DIMS(prim2super_map)[0];
|
||||
num_satom = PyArray_DIMS(super2prim_map)[0];
|
||||
|
||||
charge_sum = (double*) malloc(sizeof(double) * num_patom * num_patom * 9);
|
||||
charge_sum = (double(*)[3][3])
|
||||
malloc(sizeof(double[3][3]) * num_patom * num_patom);
|
||||
n = num_satom / num_patom;
|
||||
|
||||
dym_get_charge_sum(charge_sum, num_patom, factor / n, q_cart, z);
|
||||
dym_get_charge_sum(charge_sum, num_patom, factor / n, q_cart, born);
|
||||
dym_get_dynamical_matrix_at_q(dm,
|
||||
num_patom,
|
||||
num_satom,
|
||||
|
@ -662,8 +663,8 @@ static PyObject * py_get_dipole_dipole(PyObject *self, PyObject *args)
|
|||
PyArrayObject* G_list_py;
|
||||
PyArrayObject* q_vector_py;
|
||||
PyArrayObject* q_direction_py;
|
||||
PyArrayObject* born_py;
|
||||
PyArrayObject* dielectric_py;
|
||||
PyArrayObject* py_born;
|
||||
PyArrayObject* py_dielectric;
|
||||
PyArrayObject* pos_py;
|
||||
double factor;
|
||||
double lambda;
|
||||
|
@ -674,8 +675,8 @@ static PyObject * py_get_dipole_dipole(PyObject *self, PyObject *args)
|
|||
double* G_list;
|
||||
double* q_vector;
|
||||
double* q_direction;
|
||||
double* born;
|
||||
double* dielectric;
|
||||
double (*born)[3][3];
|
||||
double (*dielectric)[3];
|
||||
double *pos;
|
||||
int num_patom, num_G;
|
||||
|
||||
|
@ -685,8 +686,8 @@ static PyObject * py_get_dipole_dipole(PyObject *self, PyObject *args)
|
|||
&G_list_py,
|
||||
&q_vector_py,
|
||||
&q_direction_py,
|
||||
&born_py,
|
||||
&dielectric_py,
|
||||
&py_born,
|
||||
&py_dielectric,
|
||||
&pos_py,
|
||||
&factor,
|
||||
&lambda,
|
||||
|
@ -703,8 +704,8 @@ static PyObject * py_get_dipole_dipole(PyObject *self, PyObject *args)
|
|||
q_direction = (double*)PyArray_DATA(q_direction_py);
|
||||
}
|
||||
q_vector = (double*)PyArray_DATA(q_vector_py);
|
||||
born = (double*)PyArray_DATA(born_py);
|
||||
dielectric = (double*)PyArray_DATA(dielectric_py);
|
||||
born = (double*)PyArray_DATA(py_born);
|
||||
dielectric = (double(*)[3])PyArray_DATA(py_dielectric);
|
||||
pos = (double*)PyArray_DATA(pos_py);
|
||||
num_G = PyArray_DIMS(G_list_py)[0];
|
||||
num_patom = PyArray_DIMS(pos_py)[0];
|
||||
|
@ -730,21 +731,21 @@ static PyObject * py_get_dipole_dipole_q0(PyObject *self, PyObject *args)
|
|||
{
|
||||
PyArrayObject* dd_q0_py;
|
||||
PyArrayObject* G_list_py;
|
||||
PyArrayObject* dielectric_py;
|
||||
PyArrayObject* py_dielectric;
|
||||
PyArrayObject* pos_py;
|
||||
double lambda;
|
||||
double tolerance;
|
||||
|
||||
double* dd_q0;
|
||||
double* G_list;
|
||||
double* dielectric;
|
||||
double (*dielectric)[3];
|
||||
double *pos;
|
||||
int num_patom, num_G;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOOOdd",
|
||||
&dd_q0_py,
|
||||
&G_list_py,
|
||||
&dielectric_py,
|
||||
&py_dielectric,
|
||||
&pos_py,
|
||||
&lambda,
|
||||
&tolerance))
|
||||
|
@ -753,7 +754,7 @@ static PyObject * py_get_dipole_dipole_q0(PyObject *self, PyObject *args)
|
|||
|
||||
dd_q0 = (double*)PyArray_DATA(dd_q0_py);
|
||||
G_list = (double*)PyArray_DATA(G_list_py);
|
||||
dielectric = (double*)PyArray_DATA(dielectric_py);
|
||||
dielectric = (double(*)[3])PyArray_DATA(py_dielectric);
|
||||
pos = (double*)PyArray_DATA(pos_py);
|
||||
num_G = PyArray_DIMS(G_list_py)[0];
|
||||
num_patom = PyArray_DIMS(pos_py)[0];
|
||||
|
@ -781,7 +782,7 @@ static PyObject * py_get_derivative_dynmat(PyObject *self, PyObject *args)
|
|||
PyArrayObject* mass;
|
||||
PyArrayObject* super2prim_map;
|
||||
PyArrayObject* prim2super_map;
|
||||
PyArrayObject* born;
|
||||
PyArrayObject* py_born;
|
||||
PyArrayObject* dielectric;
|
||||
PyArrayObject* q_direction;
|
||||
double nac_factor;
|
||||
|
@ -813,7 +814,7 @@ static PyObject * py_get_derivative_dynmat(PyObject *self, PyObject *args)
|
|||
&super2prim_map,
|
||||
&prim2super_map,
|
||||
&nac_factor,
|
||||
&born,
|
||||
&py_born,
|
||||
&dielectric,
|
||||
&q_direction)) {
|
||||
return NULL;
|
||||
|
@ -831,10 +832,10 @@ static PyObject * py_get_derivative_dynmat(PyObject *self, PyObject *args)
|
|||
num_patom = PyArray_DIMS(prim2super_map)[0];
|
||||
num_satom = PyArray_DIMS(super2prim_map)[0];
|
||||
|
||||
if ((PyObject*)born == Py_None) {
|
||||
if ((PyObject*)py_born == Py_None) {
|
||||
z = NULL;
|
||||
} else {
|
||||
z = (double*)PyArray_DATA(born);
|
||||
z = (double*)PyArray_DATA(py_born);
|
||||
}
|
||||
if ((PyObject*)dielectric == Py_None) {
|
||||
epsilon = NULL;
|
||||
|
|
|
@ -42,12 +42,12 @@ static void get_dynmat_ij(double *dynamical_matrix,
|
|||
const int num_satom,
|
||||
const double *fc,
|
||||
const double q[3],
|
||||
const double (*svecs)[27][3],
|
||||
PHPYCONST double (*svecs)[27][3],
|
||||
const int *multi,
|
||||
const double *mass,
|
||||
const int *s2p_map,
|
||||
const int *p2s_map,
|
||||
const double *charge_sum,
|
||||
PHPYCONST double (*charge_sum)[3][3],
|
||||
const int i,
|
||||
const int j);
|
||||
static void get_dm(double dm_real[3][3],
|
||||
|
@ -60,19 +60,19 @@ static void get_dm(double dm_real[3][3],
|
|||
const int *multi,
|
||||
const double mass_sqrt,
|
||||
const int *p2s_map,
|
||||
const double *charge_sum,
|
||||
PHPYCONST double (*charge_sum)[3][3],
|
||||
const int i,
|
||||
const int j,
|
||||
const int k);
|
||||
static double get_dielectric_part(const double q_cart[3],
|
||||
const double *dielectric);
|
||||
PHPYCONST double dielectric[3][3]);
|
||||
static void get_KK(double *dd_part, /* [natom, 3, natom, 3, (real, imag)] */
|
||||
const double *G_list, /* [num_G, 3] */
|
||||
const int num_G,
|
||||
const int num_patom,
|
||||
const double q_cart[3],
|
||||
const double q_direction[3],
|
||||
const double *dielectric,
|
||||
PHPYCONST double dielectric[3][3],
|
||||
const double *pos, /* [natom, 3] */
|
||||
const double lambda,
|
||||
const double tolerance);
|
||||
|
@ -87,7 +87,7 @@ int dym_get_dynamical_matrix_at_q(double *dynamical_matrix,
|
|||
const double *mass,
|
||||
const int *s2p_map,
|
||||
const int *p2s_map,
|
||||
const double *charge_sum,
|
||||
PHPYCONST double (*charge_sum)[3][3],
|
||||
const int with_openmp)
|
||||
{
|
||||
int i, j, ij, adrs, adrsT;
|
||||
|
@ -151,10 +151,10 @@ void dym_get_dipole_dipole(double *dd, /* [natom, 3, natom, 3, (real, imag)] */
|
|||
const double *G_list, /* [num_G, 3] */
|
||||
const int num_G,
|
||||
const int num_patom,
|
||||
const double *q_cart,
|
||||
const double *q_direction,
|
||||
const double *born,
|
||||
const double *dielectric,
|
||||
const double q_cart[3],
|
||||
const double q_direction[3],
|
||||
PHPYCONST double (*born)[3][3],
|
||||
PHPYCONST double dielectric[3][3],
|
||||
const double *pos, /* [natom, 3] */
|
||||
const double factor, /* 4pi/V*unit-conv */
|
||||
const double lambda,
|
||||
|
@ -206,7 +206,7 @@ void dym_get_dipole_dipole(double *dd, /* [natom, 3, natom, 3, (real, imag)] */
|
|||
for (m = 0; m < 3; m++) { /* alpha' */
|
||||
for (n = 0; n < 3; n++) { /* beta' */
|
||||
adrs_tmp = i * num_patom * 18 + m * num_patom * 6 + j * 6 + n * 2;
|
||||
zz = born[i * 9 + k * 3 + m] * born[j * 9 + l * 3 + n];
|
||||
zz = born[i][k][m] * born[j][l][n];
|
||||
dd[adrs] += dd_tmp[adrs_tmp] * zz;
|
||||
dd[adrs + 1] += dd_tmp[adrs_tmp + 1] * zz;
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ void dym_get_dipole_dipole_q0(double *dd_q0, /* [natom, 3, 3, (real, imag)] */
|
|||
const double *G_list, /* [num_G, 3] */
|
||||
const int num_G,
|
||||
const int num_patom,
|
||||
const double *dielectric,
|
||||
PHPYCONST double dielectric[3][3],
|
||||
const double *pos, /* [natom, 3] */
|
||||
const double lambda,
|
||||
const double tolerance)
|
||||
|
@ -278,11 +278,11 @@ void dym_get_dipole_dipole_q0(double *dd_q0, /* [natom, 3, 3, (real, imag)] */
|
|||
}
|
||||
|
||||
|
||||
void dym_get_charge_sum(double *charge_sum,
|
||||
void dym_get_charge_sum(double (*charge_sum)[3][3],
|
||||
const int num_patom,
|
||||
const double factor, /* 4pi/V*unit-conv and denominator */
|
||||
const double q_cart[3],
|
||||
const double *born)
|
||||
PHPYCONST double (*born)[3][3])
|
||||
{
|
||||
int i, j, k, a, b;
|
||||
double (*q_born)[3];
|
||||
|
@ -297,7 +297,7 @@ void dym_get_charge_sum(double *charge_sum,
|
|||
for (i = 0; i < num_patom; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
for (k = 0; k < 3; k++) {
|
||||
q_born[i][j] += q_cart[k] * born[i * 9 + k * 3 + j];
|
||||
q_born[i][j] += q_cart[k] * born[i][k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ void dym_get_charge_sum(double *charge_sum,
|
|||
for (j = 0; j < num_patom; j++) {
|
||||
for (a = 0; a < 3; a++) {
|
||||
for (b = 0; b < 3; b++) {
|
||||
charge_sum[i * 9 * num_patom + j * 9 + a * 3 + b] =
|
||||
charge_sum[i * num_patom + j][a][b] =
|
||||
q_born[i][a] * q_born[j][b] * factor;
|
||||
}
|
||||
}
|
||||
|
@ -377,12 +377,12 @@ static void get_dynmat_ij(double *dynamical_matrix,
|
|||
const int num_satom,
|
||||
const double *fc,
|
||||
const double q[3],
|
||||
const double (*svecs)[27][3],
|
||||
PHPYCONST double (*svecs)[27][3],
|
||||
const int *multi,
|
||||
const double *mass,
|
||||
const int *s2p_map,
|
||||
const int *p2s_map,
|
||||
const double *charge_sum,
|
||||
PHPYCONST double (*charge_sum)[3][3],
|
||||
const int i,
|
||||
const int j)
|
||||
{
|
||||
|
@ -438,7 +438,7 @@ static void get_dm(double dm_real[3][3],
|
|||
const int *multi,
|
||||
const double mass_sqrt,
|
||||
const int *p2s_map,
|
||||
const double *charge_sum,
|
||||
PHPYCONST double (*charge_sum)[3][3],
|
||||
const int i,
|
||||
const int j,
|
||||
const int k)
|
||||
|
@ -462,8 +462,7 @@ static void get_dm(double dm_real[3][3],
|
|||
for (m = 0; m < 3; m++) {
|
||||
if (charge_sum) {
|
||||
fc_elem = (fc[p2s_map[i] * num_satom * 9 + k * 9 + l * 3 + m] +
|
||||
charge_sum[i * num_patom * 9 +
|
||||
j * 9 + l * 3 + m]) / mass_sqrt;
|
||||
charge_sum[i * num_patom + j][l][m]) / mass_sqrt;
|
||||
} else {
|
||||
fc_elem = fc[p2s_map[i] * num_satom * 9 +
|
||||
k * 9 + l * 3 + m] / mass_sqrt;
|
||||
|
@ -475,7 +474,7 @@ static void get_dm(double dm_real[3][3],
|
|||
}
|
||||
|
||||
static double get_dielectric_part(const double q_cart[3],
|
||||
const double *dielectric)
|
||||
PHPYCONST double dielectric[3][3])
|
||||
{
|
||||
int i, j;
|
||||
double x[3];
|
||||
|
@ -484,7 +483,7 @@ static double get_dielectric_part(const double q_cart[3],
|
|||
for (i = 0; i < 3; i++) {
|
||||
x[i] = 0;
|
||||
for (j = 0; j < 3; j++) {
|
||||
x[i] += dielectric[i * 3 + j] * q_cart[j];
|
||||
x[i] += dielectric[i][j] * q_cart[j];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -502,7 +501,7 @@ static void get_KK(double *dd_part, /* [natom, 3, natom, 3, (real, imag)] */
|
|||
const int num_patom,
|
||||
const double q_cart[3],
|
||||
const double q_direction[3],
|
||||
const double *dielectric,
|
||||
PHPYCONST double dielectric[3][3],
|
||||
const double *pos, /* [natom, 3] */
|
||||
const double lambda,
|
||||
const double tolerance)
|
||||
|
|
|
@ -47,17 +47,17 @@ int dym_get_dynamical_matrix_at_q(double *dynamical_matrix,
|
|||
const double *mass,
|
||||
const int *s2p_map,
|
||||
const int *p2s_map,
|
||||
const double *charge_sum,
|
||||
PHPYCONST double (*charge_sum)[3][3],
|
||||
const int with_openmp);
|
||||
void dym_get_dipole_dipole(double *dd, /* [natom, 3, natom, 3, (real, imag)] */
|
||||
const double *dd_q0, /* [natom, 3, 3, (real, imag)] */
|
||||
const double *G_list, /* [num_G, 3] */
|
||||
const int num_G,
|
||||
const int num_patom,
|
||||
const double *q_cart,
|
||||
const double *q_direction,
|
||||
const double *born,
|
||||
const double *dielectric,
|
||||
const double q_cart[3],
|
||||
const double q_direction[3],
|
||||
PHPYCONST double (*born)[3][3],
|
||||
PHPYCONST double dielectric[3][3],
|
||||
const double *pos, /* [natom, 3] */
|
||||
const double factor, /* 4pi/V*unit-conv */
|
||||
const double lambda,
|
||||
|
@ -66,15 +66,15 @@ void dym_get_dipole_dipole_q0(double *dd_q0, /* [natom, 3, 3, (real, imag)] */
|
|||
const double *G_list, /* [num_G, 3] */
|
||||
const int num_G,
|
||||
const int num_patom,
|
||||
const double *dielectric,
|
||||
PHPYCONST double dielectric[3][3],
|
||||
const double *pos, /* [natom, 3] */
|
||||
const double lambda,
|
||||
const double tolerance);
|
||||
void dym_get_charge_sum(double *charge_sum,
|
||||
void dym_get_charge_sum(double (*charge_sum)[3][3],
|
||||
const int num_patom,
|
||||
const double factor,
|
||||
const double q_cart[3],
|
||||
const double *born);
|
||||
PHPYCONST double (*born)[3][3]);
|
||||
/* fc[num_patom, num_satom, 3, 3] */
|
||||
/* dm[num_comm_points, num_patom * 3, num_patom *3] */
|
||||
/* comm_points[num_satom, num_patom, 27, 3] */
|
||||
|
|
Loading…
Reference in New Issue