Skip to content

Commit

Permalink
Set fc3-r0-average default
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Dec 25, 2023
1 parent 7f55f9b commit 1529da2
Show file tree
Hide file tree
Showing 10 changed files with 735 additions and 769 deletions.
7 changes: 0 additions & 7 deletions c/interaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ static void real_to_normal(double *fc3_normal_squared, const long (*g_pos)[4],
}
r2r_real_to_reciprocal(fc3_reciprocal, q_vecs, fc3, is_compact_fc3,
atom_triplets, openmp_at_bands);
if (atom_triplets->make_r0_average) {
for (i = 0; i < num_band * num_band * num_band; i++) {
fc3_reciprocal[i] = lapack_make_complex_double(
lapack_complex_double_real(fc3_reciprocal[i]) / 3,
lapack_complex_double_imag(fc3_reciprocal[i]) / 3);
}
}

#ifdef MEASURE_R2N
if (openmp_at_bands && num_triplets > 0) {
Expand Down
161 changes: 109 additions & 52 deletions c/real_to_reciprocal.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@
#include "phonoc_array.h"
#include "phonoc_const.h"

static void real_to_reciprocal(lapack_complex_double *fc3_reciprocal,
const double q_vecs[3][3], const double *fc3,
const long is_compact_fc3,
const AtomTriplets *atom_triplets,
const long openmp_at_bands);
static void real_to_reciprocal_legacy(lapack_complex_double *fc3_reciprocal,
const double q_vecs[3][3],
const double *fc3,
const long is_compact_fc3,
const AtomTriplets *atom_triplets,
const long openmp_at_bands);
static void real_to_reciprocal_r0_average(lapack_complex_double *fc3_reciprocal,
const double q_vecs[3][3],
const double *fc3,
const long is_compact_fc3,
const AtomTriplets *atom_triplets,
const long openmp_at_bands);
static void real_to_reciprocal_elements(lapack_complex_double *fc3_rec_elem,
const double q1[3], const double q2[3],
const double *fc3,
Expand All @@ -70,8 +77,65 @@ void r2r_real_to_reciprocal(lapack_complex_double *fc3_reciprocal,
const long is_compact_fc3,
const AtomTriplets *atom_triplets,
const long openmp_at_bands) {
real_to_reciprocal(fc3_reciprocal, q_vecs, fc3, is_compact_fc3,
atom_triplets, openmp_at_bands);
long i, num_band;

if (atom_triplets->make_r0_average) {
real_to_reciprocal_r0_average(fc3_reciprocal, q_vecs, fc3,
is_compact_fc3, atom_triplets,
openmp_at_bands);
num_band = atom_triplets->multi_dims[1] * 3;
for (i = 0; i < num_band * num_band * num_band; i++) {
fc3_reciprocal[i] = lapack_make_complex_double(
lapack_complex_double_real(fc3_reciprocal[i]) / 3,
lapack_complex_double_imag(fc3_reciprocal[i]) / 3);
}
} else {
real_to_reciprocal_legacy(fc3_reciprocal, q_vecs, fc3, is_compact_fc3,
atom_triplets, openmp_at_bands);
}
}

static void real_to_reciprocal_legacy(lapack_complex_double *fc3_reciprocal,
const double q_vecs[3][3],
const double *fc3,
const long is_compact_fc3,
const AtomTriplets *atom_triplets,
const long openmp_at_bands) {
long i, j, k, l, m, n, ijk;
long num_patom, num_band;
lapack_complex_double pre_phase_factor, fc3_rec_elem[27], fc3_rec;

num_patom = atom_triplets->multi_dims[1];
num_band = num_patom * 3;

#ifdef _OPENMP
#pragma omp parallel for private(i, j, k, l, m, n, fc3_rec_elem, fc3_rec, \
pre_phase_factor) if (openmp_at_bands)
#endif
for (ijk = 0; ijk < num_patom * num_patom * num_patom; ijk++) {
i = ijk / (num_patom * num_patom);
j = (ijk - (i * num_patom * num_patom)) / num_patom;
k = ijk % num_patom;

pre_phase_factor = get_pre_phase_factor(i, q_vecs, atom_triplets);

real_to_reciprocal_elements(fc3_rec_elem, q_vecs[1], q_vecs[2], fc3,
is_compact_fc3, atom_triplets, i, j, k, 0);
for (l = 0; l < 3; l++) {
for (m = 0; m < 3; m++) {
for (n = 0; n < 3; n++) {
fc3_rec = phonoc_complex_prod(
fc3_rec_elem[l * 9 + m * 3 + n], pre_phase_factor);
fc3_reciprocal[(i * 3 + l) * num_band * num_band +
(j * 3 + m) * num_band + k * 3 + n] =
sum_lapack_complex_double(
fc3_reciprocal[(i * 3 + l) * num_band * num_band +
(j * 3 + m) * num_band + k * 3 + n],
fc3_rec);
}
}
}
}
}

// Summations are performed with respect to three different lattice reference
Expand All @@ -80,11 +144,12 @@ void r2r_real_to_reciprocal(lapack_complex_double *fc3_reciprocal,
// q-points in triplets used for summation implemented in
// real_to_reciprocal_elements().
// --sym-fc3q makes them almost equivalent.
static void real_to_reciprocal(lapack_complex_double *fc3_reciprocal,
const double q_vecs[3][3], const double *fc3,
const long is_compact_fc3,
const AtomTriplets *atom_triplets,
const long openmp_at_bands) {
static void real_to_reciprocal_r0_average(lapack_complex_double *fc3_reciprocal,
const double q_vecs[3][3],
const double *fc3,
const long is_compact_fc3,
const AtomTriplets *atom_triplets,
const long openmp_at_bands) {
long i, j, k, l, m, n, ijk;
long num_patom, num_band;
lapack_complex_double pre_phase_factor, fc3_rec_elem[27], fc3_rec;
Expand All @@ -102,10 +167,8 @@ static void real_to_reciprocal(lapack_complex_double *fc3_reciprocal,
k = ijk % num_patom;

pre_phase_factor = get_pre_phase_factor(i, q_vecs, atom_triplets);

real_to_reciprocal_elements(fc3_rec_elem, q_vecs[1], q_vecs[2], fc3,
is_compact_fc3, atom_triplets, i, j, k,
atom_triplets->make_r0_average);
is_compact_fc3, atom_triplets, i, j, k, 1);
for (l = 0; l < 3; l++) {
for (m = 0; m < 3; m++) {
for (n = 0; n < 3; n++) {
Expand All @@ -121,46 +184,40 @@ static void real_to_reciprocal(lapack_complex_double *fc3_reciprocal,
}
}

if (atom_triplets->make_r0_average) {
real_to_reciprocal_elements(fc3_rec_elem, q_vecs[0], q_vecs[2], fc3,
is_compact_fc3, atom_triplets, i, j, k,
2);
for (l = 0; l < 3; l++) {
for (m = 0; m < 3; m++) {
for (n = 0; n < 3; n++) {
// fc3_rec is stored in a way swapping jm <-> il.
fc3_rec = phonoc_complex_prod(
fc3_rec_elem[l * 9 + m * 3 + n], pre_phase_factor);
fc3_reciprocal[(j * 3 + m) * num_band * num_band +
(i * 3 + l) * num_band + k * 3 + n] =
sum_lapack_complex_double(
fc3_reciprocal[(j * 3 + m) * num_band *
num_band +
(i * 3 + l) * num_band + k * 3 +
n],
fc3_rec);
}
// fc3_rec is stored in a way swapping jm <-> il.
pre_phase_factor = get_pre_phase_factor(j, q_vecs, atom_triplets);
real_to_reciprocal_elements(fc3_rec_elem, q_vecs[0], q_vecs[2], fc3,
is_compact_fc3, atom_triplets, j, i, k, 2);
for (l = 0; l < 3; l++) {
for (m = 0; m < 3; m++) {
for (n = 0; n < 3; n++) {
fc3_rec = phonoc_complex_prod(
fc3_rec_elem[m * 9 + l * 3 + n], pre_phase_factor);
fc3_reciprocal[(i * 3 + l) * num_band * num_band +
(j * 3 + m) * num_band + k * 3 + n] =
sum_lapack_complex_double(
fc3_reciprocal[(i * 3 + l) * num_band * num_band +
(j * 3 + m) * num_band + k * 3 + n],
fc3_rec);
}
}
}

real_to_reciprocal_elements(fc3_rec_elem, q_vecs[1], q_vecs[0], fc3,
is_compact_fc3, atom_triplets, i, j, k,
3);
for (l = 0; l < 3; l++) {
for (m = 0; m < 3; m++) {
for (n = 0; n < 3; n++) {
// fc3_rec is stored in a way swapping kn <-> il.
fc3_rec = phonoc_complex_prod(
fc3_rec_elem[l * 9 + m * 3 + n], pre_phase_factor);
fc3_reciprocal[(k * 3 + n) * num_band * num_band +
(j * 3 + m) * num_band + i * 3 + l] =
sum_lapack_complex_double(
fc3_reciprocal[(k * 3 + n) * num_band *
num_band +
(j * 3 + m) * num_band + i * 3 +
l],
fc3_rec);
}
// fc3_rec is stored in a way swapping kn <-> il.
pre_phase_factor = get_pre_phase_factor(k, q_vecs, atom_triplets);
real_to_reciprocal_elements(fc3_rec_elem, q_vecs[1], q_vecs[0], fc3,
is_compact_fc3, atom_triplets, k, j, i, 3);
for (l = 0; l < 3; l++) {
for (m = 0; m < 3; m++) {
for (n = 0; n < 3; n++) {
fc3_rec = phonoc_complex_prod(
fc3_rec_elem[n * 9 + m * 3 + l], pre_phase_factor);
fc3_reciprocal[(i * 3 + l) * num_band * num_band +
(j * 3 + m) * num_band + k * 3 + n] =
sum_lapack_complex_double(
fc3_reciprocal[(i * 3 + l) * num_band * num_band +
(j * 3 + m) * num_band + k * 3 + n],
fc3_rec);
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions phono3py/api_phono3py.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,6 @@ def __init__(
self._use_grg = use_grg
self._SNF_coordinates = SNF_coordinates

if not make_r0_average:
warnings.warn(
"Phono3py init parameter of make_r0_average is deprecated. "
"This is always True but exists for backward compatibility.",
DeprecationWarning,
)
self._make_r0_average = make_r0_average

self._cutoff_frequency = cutoff_frequency
Expand Down
64 changes: 37 additions & 27 deletions phono3py/cui/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import phonopy.cui.load_helper as load_helper
from phonopy.harmonic.force_constants import show_drift_force_constants
from phonopy.interface.calculator import get_default_physical_units
from phonopy.structure.atoms import PhonopyAtoms
from phonopy.structure.cells import determinant

from phono3py import Phono3py
Expand All @@ -52,33 +53,36 @@


def load(
phono3py_yaml=None, # phono3py.yaml-like must be the first argument.
supercell_matrix=None,
primitive_matrix=None,
phonon_supercell_matrix=None,
is_nac=True,
calculator=None,
unitcell=None,
supercell=None,
nac_params=None,
unitcell_filename=None,
supercell_filename=None,
born_filename=None,
forces_fc3_filename: Optional[Union[os.PathLike, Sequence]] = None,
forces_fc2_filename: Optional[Union[os.PathLike, Sequence]] = None,
fc3_filename=None,
fc2_filename=None,
fc_calculator=None,
fc_calculator_options=None,
factor=None,
produce_fc=True,
is_symmetry=True,
symmetrize_fc=True,
is_mesh_symmetry=True,
is_compact_fc=False,
use_grg=False,
symprec=1e-5,
log_level=0,
phono3py_yaml: Optional[
Union[str, bytes, os.PathLike]
] = None, # phono3py.yaml-like must be the first argument.
supercell_matrix: Optional[Union[Sequence, np.ndarray]] = None,
primitive_matrix: Optional[Union[Sequence, np.ndarray]] = None,
phonon_supercell_matrix: Optional[Union[Sequence, np.ndarray]] = None,
is_nac: bool = True,
calculator: Optional[str] = None,
unitcell: Optional[PhonopyAtoms] = None,
supercell: Optional[PhonopyAtoms] = None,
nac_params: Optional[dict] = None,
unitcell_filename: Optional[Union[str, bytes, os.PathLike]] = None,
supercell_filename: Optional[Union[str, bytes, os.PathLike]] = None,
born_filename: Optional[Union[str, bytes, os.PathLike]] = None,
forces_fc3_filename: Optional[Union[str, bytes, os.PathLike]] = None,
forces_fc2_filename: Optional[Union[str, bytes, os.PathLike]] = None,
fc3_filename: Optional[Union[str, bytes, os.PathLike]] = None,
fc2_filename: Optional[Union[str, bytes, os.PathLike]] = None,
fc_calculator: Optional[str] = None,
fc_calculator_options: Optional[str] = None,
factor: Optional[float] = None,
produce_fc: bool = True,
is_symmetry: bool = True,
symmetrize_fc: bool = True,
is_mesh_symmetry: bool = True,
is_compact_fc: bool = False,
use_grg: bool = False,
make_r0_average: bool = True,
symprec: float = 1e-5,
log_level: int = 0,
) -> Phono3py:
"""Create Phono3py instance from parameters and/or input files.
Expand Down Expand Up @@ -227,6 +231,11 @@ def load(
cells. Default is False.
use_grg : bool, optional
Use generalized regular grid when True. Default is False.
make_r0_average : bool, optional
fc3 transformation from real to reciprocal space is done
around three atoms and averaged when True. Default is False, i.e.,
only around the first atom. Setting False is for rough compatibility
with v2.x. Default is True.
symprec : float, optional
Tolerance used to find crystal symmetry. Default is 1e-5.
log_level : int, optional
Expand Down Expand Up @@ -297,6 +306,7 @@ def load(
is_symmetry=is_symmetry,
is_mesh_symmetry=is_mesh_symmetry,
use_grg=use_grg,
make_r0_average=make_r0_average,
calculator=calculator,
log_level=log_level,
)
Expand Down
Loading

0 comments on commit 1529da2

Please sign in to comment.