2016-10-30 14:58:47 +08:00
|
|
|
/* Copyright (C) 2015 Atsushi Togo */
|
|
|
|
/* All rights reserved. */
|
|
|
|
|
|
|
|
/* This file is part of phonopy. */
|
|
|
|
|
|
|
|
/* Redistribution and use in source and binary forms, with or without */
|
|
|
|
/* modification, are permitted provided that the following conditions */
|
|
|
|
/* are met: */
|
|
|
|
|
|
|
|
/* * Redistributions of source code must retain the above copyright */
|
|
|
|
/* notice, this list of conditions and the following disclaimer. */
|
|
|
|
|
|
|
|
/* * Redistributions in binary form must reproduce the above copyright */
|
|
|
|
/* notice, this list of conditions and the following disclaimer in */
|
|
|
|
/* the documentation and/or other materials provided with the */
|
|
|
|
/* distribution. */
|
|
|
|
|
|
|
|
/* * Neither the name of the phonopy project nor the names of its */
|
|
|
|
/* contributors may be used to endorse or promote products derived */
|
|
|
|
/* from this software without specific prior written permission. */
|
|
|
|
|
|
|
|
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
|
|
|
|
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
|
|
|
|
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
|
|
|
|
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */
|
|
|
|
/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
|
|
|
|
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, */
|
|
|
|
/* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
|
|
|
|
/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER */
|
|
|
|
/* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT */
|
|
|
|
/* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */
|
|
|
|
/* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
|
|
|
/* POSSIBILITY OF SUCH DAMAGE. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
2021-01-26 10:10:19 +08:00
|
|
|
#include "phonoc_array.h"
|
|
|
|
#include "phonoc_utils.h"
|
|
|
|
#include "collision_matrix.h"
|
2016-10-30 14:58:47 +08:00
|
|
|
|
2019-02-04 20:43:11 +08:00
|
|
|
static void get_collision_matrix(double *collision_matrix,
|
|
|
|
const double *fc3_normal_squared,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long num_band0,
|
|
|
|
const long num_band,
|
2019-02-04 20:43:11 +08:00
|
|
|
const double *frequencies,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long (*triplets)[3],
|
|
|
|
const long *triplets_map,
|
|
|
|
const long num_gp,
|
|
|
|
const long *map_q,
|
|
|
|
const long *rot_grid_points,
|
|
|
|
const long num_ir_gp,
|
|
|
|
const long num_rot,
|
2019-02-04 20:43:11 +08:00
|
|
|
const double *rotations_cartesian,
|
|
|
|
const double *g,
|
|
|
|
const double temperature,
|
|
|
|
const double unit_conversion_factor,
|
|
|
|
const double cutoff_frequency);
|
2017-04-08 16:34:34 +08:00
|
|
|
static void
|
2019-02-04 20:43:11 +08:00
|
|
|
get_reducible_collision_matrix(double *collision_matrix,
|
|
|
|
const double *fc3_normal_squared,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long num_band0,
|
|
|
|
const long num_band,
|
2019-02-04 20:43:11 +08:00
|
|
|
const double *frequencies,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long (*triplets)[3],
|
|
|
|
const long *triplets_map,
|
|
|
|
const long num_gp,
|
|
|
|
const long *map_q,
|
2019-02-04 20:43:11 +08:00
|
|
|
const double *g,
|
|
|
|
const double temperature,
|
|
|
|
const double unit_conversion_factor,
|
|
|
|
const double cutoff_frequency);
|
2017-11-19 11:11:35 +08:00
|
|
|
static void get_inv_sinh(double *inv_sinh,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long gp,
|
2018-10-08 20:12:20 +08:00
|
|
|
const double temperature,
|
2017-11-19 11:11:35 +08:00
|
|
|
const double *frequencies,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long triplet[3],
|
|
|
|
const long *triplets_map,
|
|
|
|
const long *map_q,
|
|
|
|
const long num_band,
|
2017-11-19 11:11:35 +08:00
|
|
|
const double cutoff_frequency);
|
2021-02-22 11:46:31 +08:00
|
|
|
static long *create_gp2tp_map(const long *triplets_map,
|
|
|
|
const long num_gp);
|
2017-07-07 15:23:44 +08:00
|
|
|
|
2017-11-19 11:11:35 +08:00
|
|
|
void col_get_collision_matrix(double *collision_matrix,
|
|
|
|
const Darray *fc3_normal_squared,
|
|
|
|
const double *frequencies,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long (*triplets)[3],
|
|
|
|
const long *triplets_map,
|
|
|
|
const long *map_q,
|
|
|
|
const long *rot_grid_points,
|
2017-11-19 11:11:35 +08:00
|
|
|
const double *rotations_cartesian,
|
|
|
|
const double *g,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long num_ir_gp,
|
|
|
|
const long num_gp,
|
|
|
|
const long num_rot,
|
2017-11-19 11:11:35 +08:00
|
|
|
const double temperature,
|
|
|
|
const double unit_conversion_factor,
|
|
|
|
const double cutoff_frequency)
|
2016-10-30 14:58:47 +08:00
|
|
|
{
|
2021-02-22 11:46:31 +08:00
|
|
|
long num_triplets, num_band0, num_band;
|
2016-10-30 14:58:47 +08:00
|
|
|
|
|
|
|
num_triplets = fc3_normal_squared->dims[0];
|
2017-11-16 15:47:37 +08:00
|
|
|
num_band0 = fc3_normal_squared->dims[1];
|
|
|
|
num_band = fc3_normal_squared->dims[2];
|
2016-10-30 14:58:47 +08:00
|
|
|
|
2019-02-04 20:43:11 +08:00
|
|
|
get_collision_matrix(
|
2021-10-12 14:56:14 +08:00
|
|
|
collision_matrix,
|
|
|
|
fc3_normal_squared->data,
|
|
|
|
num_band0,
|
|
|
|
num_band,
|
|
|
|
frequencies,
|
|
|
|
triplets,
|
|
|
|
triplets_map,
|
|
|
|
num_gp,
|
|
|
|
map_q,
|
|
|
|
rot_grid_points,
|
|
|
|
num_ir_gp,
|
|
|
|
num_rot,
|
|
|
|
rotations_cartesian,
|
|
|
|
g + 2 * num_triplets * num_band0 * num_band * num_band,
|
|
|
|
temperature,
|
|
|
|
unit_conversion_factor,
|
|
|
|
cutoff_frequency);
|
2017-04-08 13:40:20 +08:00
|
|
|
}
|
|
|
|
|
2017-11-19 11:11:35 +08:00
|
|
|
void col_get_reducible_collision_matrix(double *collision_matrix,
|
|
|
|
const Darray *fc3_normal_squared,
|
|
|
|
const double *frequencies,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long (*triplets)[3],
|
|
|
|
const long *triplets_map,
|
|
|
|
const long *map_q,
|
2017-11-19 11:11:35 +08:00
|
|
|
const double *g,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long num_gp,
|
2017-11-19 11:11:35 +08:00
|
|
|
const double temperature,
|
|
|
|
const double unit_conversion_factor,
|
|
|
|
const double cutoff_frequency)
|
2017-04-08 13:40:20 +08:00
|
|
|
{
|
2021-02-22 11:46:31 +08:00
|
|
|
long num_triplets, num_band, num_band0;
|
2017-04-08 13:40:20 +08:00
|
|
|
|
|
|
|
num_triplets = fc3_normal_squared->dims[0];
|
2017-11-25 15:56:18 +08:00
|
|
|
num_band0 = fc3_normal_squared->dims[1];
|
2017-04-08 13:40:20 +08:00
|
|
|
num_band = fc3_normal_squared->dims[2];
|
|
|
|
|
2019-02-04 20:43:11 +08:00
|
|
|
get_reducible_collision_matrix(
|
2021-10-12 14:56:14 +08:00
|
|
|
collision_matrix,
|
|
|
|
fc3_normal_squared->data,
|
|
|
|
num_band0,
|
|
|
|
num_band,
|
|
|
|
frequencies,
|
|
|
|
triplets,
|
|
|
|
triplets_map,
|
|
|
|
num_gp,
|
|
|
|
map_q,
|
|
|
|
g + 2 * num_triplets * num_band0 * num_band * num_band,
|
|
|
|
temperature,
|
|
|
|
unit_conversion_factor,
|
|
|
|
cutoff_frequency);
|
2017-04-08 13:40:20 +08:00
|
|
|
}
|
|
|
|
|
2019-02-04 20:43:11 +08:00
|
|
|
static void get_collision_matrix(double *collision_matrix,
|
|
|
|
const double *fc3_normal_squared,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long num_band0,
|
|
|
|
const long num_band,
|
2019-02-04 20:43:11 +08:00
|
|
|
const double *frequencies,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long (*triplets)[3],
|
|
|
|
const long *triplets_map,
|
|
|
|
const long num_gp,
|
|
|
|
const long *map_q,
|
|
|
|
const long *rot_grid_points,
|
|
|
|
const long num_ir_gp,
|
|
|
|
const long num_rot,
|
2019-02-04 20:43:11 +08:00
|
|
|
const double *rotations_cartesian,
|
|
|
|
const double *g,
|
|
|
|
const double temperature,
|
|
|
|
const double unit_conversion_factor,
|
|
|
|
const double cutoff_frequency)
|
2017-04-08 13:40:20 +08:00
|
|
|
{
|
2021-02-22 11:46:31 +08:00
|
|
|
long i, j, k, l, m, n, ti, r_gp;
|
|
|
|
long *gp2tp_map;
|
2017-04-08 13:40:20 +08:00
|
|
|
double collision;
|
|
|
|
double *inv_sinh;
|
|
|
|
|
|
|
|
gp2tp_map = create_gp2tp_map(triplets_map, num_gp);
|
2016-10-30 14:58:47 +08:00
|
|
|
|
2021-04-12 17:24:48 +08:00
|
|
|
#ifdef PHPYOPENMP
|
2017-07-07 15:23:44 +08:00
|
|
|
#pragma omp parallel for private(j, k, l, m, n, ti, r_gp, collision, inv_sinh)
|
2021-04-12 17:24:48 +08:00
|
|
|
#endif
|
2021-10-12 14:56:14 +08:00
|
|
|
for (i = 0; i < num_ir_gp; i++)
|
|
|
|
{
|
|
|
|
inv_sinh = (double *)malloc(sizeof(double) * num_band);
|
|
|
|
for (j = 0; j < num_rot; j++)
|
|
|
|
{
|
2019-02-04 20:43:11 +08:00
|
|
|
r_gp = rot_grid_points[i * num_rot + j];
|
2017-11-19 11:11:35 +08:00
|
|
|
ti = gp2tp_map[triplets_map[r_gp]];
|
|
|
|
get_inv_sinh(inv_sinh,
|
|
|
|
r_gp,
|
|
|
|
temperature,
|
|
|
|
frequencies,
|
2019-02-04 20:43:11 +08:00
|
|
|
triplets[ti],
|
2017-11-19 11:11:35 +08:00
|
|
|
triplets_map,
|
2019-02-04 20:43:11 +08:00
|
|
|
map_q,
|
2017-11-19 11:11:35 +08:00
|
|
|
num_band,
|
|
|
|
cutoff_frequency);
|
2017-07-07 15:23:44 +08:00
|
|
|
|
2021-10-12 14:56:14 +08:00
|
|
|
for (k = 0; k < num_band0; k++)
|
|
|
|
{
|
|
|
|
for (l = 0; l < num_band; l++)
|
|
|
|
{
|
2017-11-14 15:26:09 +08:00
|
|
|
collision = 0;
|
2021-10-12 14:56:14 +08:00
|
|
|
for (m = 0; m < num_band; m++)
|
|
|
|
{
|
2017-11-14 15:26:09 +08:00
|
|
|
collision +=
|
2021-10-12 14:56:14 +08:00
|
|
|
fc3_normal_squared[ti * num_band0 * num_band * num_band +
|
|
|
|
k * num_band * num_band +
|
|
|
|
l * num_band + m] *
|
|
|
|
g[ti * num_band0 * num_band * num_band +
|
|
|
|
k * num_band * num_band +
|
|
|
|
l * num_band + m] *
|
|
|
|
inv_sinh[m] * unit_conversion_factor;
|
2017-11-14 15:26:09 +08:00
|
|
|
}
|
2021-10-12 14:56:14 +08:00
|
|
|
for (m = 0; m < 3; m++)
|
|
|
|
{
|
|
|
|
for (n = 0; n < 3; n++)
|
|
|
|
{
|
2017-11-14 15:26:09 +08:00
|
|
|
collision_matrix[k * 3 * num_ir_gp * num_band * 3 +
|
|
|
|
m * num_ir_gp * num_band * 3 +
|
|
|
|
i * num_band * 3 + l * 3 + n] +=
|
2021-10-12 14:56:14 +08:00
|
|
|
collision * rotations_cartesian[j * 9 + m * 3 + n];
|
2017-11-14 15:26:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-30 14:58:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(inv_sinh);
|
|
|
|
inv_sinh = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(gp2tp_map);
|
|
|
|
gp2tp_map = NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-08 16:34:34 +08:00
|
|
|
static void
|
2019-02-04 20:43:11 +08:00
|
|
|
get_reducible_collision_matrix(double *collision_matrix,
|
|
|
|
const double *fc3_normal_squared,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long num_band0,
|
|
|
|
const long num_band,
|
2019-02-04 20:43:11 +08:00
|
|
|
const double *frequencies,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long (*triplets)[3],
|
|
|
|
const long *triplets_map,
|
|
|
|
const long num_gp,
|
|
|
|
const long *map_q,
|
2019-02-04 20:43:11 +08:00
|
|
|
const double *g,
|
|
|
|
const double temperature,
|
|
|
|
const double unit_conversion_factor,
|
|
|
|
const double cutoff_frequency)
|
2016-10-30 14:58:47 +08:00
|
|
|
{
|
2021-02-22 11:46:31 +08:00
|
|
|
long i, j, k, l, ti;
|
|
|
|
long *gp2tp_map;
|
2016-10-30 14:58:47 +08:00
|
|
|
double collision;
|
|
|
|
double *inv_sinh;
|
|
|
|
|
2017-04-08 13:40:20 +08:00
|
|
|
gp2tp_map = create_gp2tp_map(triplets_map, num_gp);
|
2016-10-30 14:58:47 +08:00
|
|
|
|
2021-04-12 17:24:48 +08:00
|
|
|
#ifdef PHPYOPENMP
|
2016-10-30 14:58:47 +08:00
|
|
|
#pragma omp parallel for private(j, k, l, ti, collision, inv_sinh)
|
2021-04-12 17:24:48 +08:00
|
|
|
#endif
|
2021-10-12 14:56:14 +08:00
|
|
|
for (i = 0; i < num_gp; i++)
|
|
|
|
{
|
|
|
|
inv_sinh = (double *)malloc(sizeof(double) * num_band);
|
2017-11-19 11:11:35 +08:00
|
|
|
ti = gp2tp_map[triplets_map[i]];
|
|
|
|
get_inv_sinh(inv_sinh,
|
|
|
|
i,
|
|
|
|
temperature,
|
|
|
|
frequencies,
|
2019-02-04 20:43:11 +08:00
|
|
|
triplets[ti],
|
2017-11-19 11:11:35 +08:00
|
|
|
triplets_map,
|
2019-02-04 20:43:11 +08:00
|
|
|
map_q,
|
2017-11-19 11:11:35 +08:00
|
|
|
num_band,
|
|
|
|
cutoff_frequency);
|
2016-10-30 14:58:47 +08:00
|
|
|
|
2021-10-12 14:56:14 +08:00
|
|
|
for (j = 0; j < num_band0; j++)
|
|
|
|
{
|
|
|
|
for (k = 0; k < num_band; k++)
|
|
|
|
{
|
2017-11-14 15:26:09 +08:00
|
|
|
collision = 0;
|
2021-10-12 14:56:14 +08:00
|
|
|
for (l = 0; l < num_band; l++)
|
|
|
|
{
|
2017-11-14 15:26:09 +08:00
|
|
|
collision +=
|
2021-10-12 14:56:14 +08:00
|
|
|
fc3_normal_squared[ti * num_band0 * num_band * num_band +
|
|
|
|
j * num_band * num_band +
|
|
|
|
k * num_band + l] *
|
|
|
|
g[ti * num_band0 * num_band * num_band +
|
|
|
|
j * num_band * num_band +
|
|
|
|
k * num_band + l] *
|
|
|
|
inv_sinh[l] * unit_conversion_factor;
|
2017-11-14 15:26:09 +08:00
|
|
|
}
|
|
|
|
collision_matrix[j * num_gp * num_band + i * num_band + k] += collision;
|
2016-10-30 14:58:47 +08:00
|
|
|
}
|
|
|
|
}
|
2017-07-07 15:23:44 +08:00
|
|
|
|
2016-10-30 14:58:47 +08:00
|
|
|
free(inv_sinh);
|
|
|
|
inv_sinh = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(gp2tp_map);
|
|
|
|
gp2tp_map = NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-19 11:11:35 +08:00
|
|
|
static void get_inv_sinh(double *inv_sinh,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long gp,
|
2018-10-08 20:12:20 +08:00
|
|
|
const double temperature,
|
2017-11-19 11:11:35 +08:00
|
|
|
const double *frequencies,
|
2021-02-22 11:46:31 +08:00
|
|
|
const long triplet[3],
|
|
|
|
const long *triplets_map,
|
|
|
|
const long *map_q,
|
|
|
|
const long num_band,
|
2017-11-19 11:11:35 +08:00
|
|
|
const double cutoff_frequency)
|
2016-10-30 14:58:47 +08:00
|
|
|
{
|
2021-02-22 11:46:31 +08:00
|
|
|
long i, gp2;
|
2016-10-30 14:58:47 +08:00
|
|
|
double f;
|
2017-07-07 15:23:44 +08:00
|
|
|
|
2021-03-28 16:11:14 +08:00
|
|
|
/* This assumes the algorithm of get_ir_triplets_at_q_perm_q1q2, */
|
|
|
|
/* where defined triplets_map[gp] == triplets_map[map_q[gp]]. */
|
|
|
|
/* If triplets_map[map_q[gp]] != map_q[gp], q1 and q2 are permuted. */
|
2021-10-12 14:56:14 +08:00
|
|
|
if (triplets_map[gp] == map_q[gp])
|
|
|
|
{
|
2019-02-04 20:43:11 +08:00
|
|
|
gp2 = triplet[2];
|
2021-10-12 14:56:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-04 20:43:11 +08:00
|
|
|
gp2 = triplet[1];
|
2016-10-30 14:58:47 +08:00
|
|
|
}
|
2021-03-28 16:11:14 +08:00
|
|
|
|
2021-10-12 14:56:14 +08:00
|
|
|
for (i = 0; i < num_band; i++)
|
|
|
|
{
|
2016-10-30 14:58:47 +08:00
|
|
|
f = frequencies[gp2 * num_band + i];
|
2021-10-12 14:56:14 +08:00
|
|
|
if (f > cutoff_frequency)
|
|
|
|
{
|
2021-03-15 12:02:18 +08:00
|
|
|
inv_sinh[i] = phonoc_inv_sinh_occupation(f, temperature);
|
2021-10-12 14:56:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-30 14:58:47 +08:00
|
|
|
inv_sinh[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-27 14:37:48 +08:00
|
|
|
/* Symmetrically independent triplets are indexed. */
|
|
|
|
/* Inverse definition of ir_grid_points in get_BZ_triplets_at_q */
|
|
|
|
/* in triplet_grid.c. */
|
2021-02-22 11:46:31 +08:00
|
|
|
static long *create_gp2tp_map(const long *triplets_map,
|
|
|
|
const long num_gp)
|
2016-10-30 14:58:47 +08:00
|
|
|
{
|
2021-03-27 14:37:48 +08:00
|
|
|
long i, num_ir;
|
2021-02-22 11:46:31 +08:00
|
|
|
long *gp2tp_map;
|
2017-07-07 15:23:44 +08:00
|
|
|
|
2021-10-12 14:56:14 +08:00
|
|
|
gp2tp_map = (long *)malloc(sizeof(long) * num_gp);
|
2021-03-27 14:37:48 +08:00
|
|
|
num_ir = 0;
|
2021-10-12 14:56:14 +08:00
|
|
|
for (i = 0; i < num_gp; i++)
|
|
|
|
{
|
|
|
|
if (triplets_map[i] == i)
|
|
|
|
{
|
2021-03-27 14:37:48 +08:00
|
|
|
gp2tp_map[i] = num_ir;
|
|
|
|
num_ir++;
|
2021-10-12 14:56:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* This should not be used. */
|
2021-03-27 14:37:48 +08:00
|
|
|
gp2tp_map[i] = -1;
|
2016-10-30 14:58:47 +08:00
|
|
|
}
|
2021-02-22 11:46:31 +08:00
|
|
|
}
|
2017-07-07 15:23:44 +08:00
|
|
|
|
2016-10-30 14:58:47 +08:00
|
|
|
return gp2tp_map;
|
|
|
|
}
|