44 Real reciprocal_space_multiplicity = planewave_basis_.
is_gamma_only() ? 2.0 : 1.0;
48 if (local_gstart == 1) {
49 for (
int species_index = 0;
53 Complex structure_factor_zero(0.0, 0.0);
54 for (
int atom_index = 0; atom_index < crystal_structure_.
number_of_atoms();
58 structure_factor_zero +=
Complex(1.0, 0.0);
60 evloc += (std::conj(charge_density_g[0]) *
62 structure_factor_zero)
66 for (
int g_vector_index = local_gstart;
69 const auto& g_vector = planewave_basis_.
g_vectors()[g_vector_index];
70 Complex local_potential_total(0.0, 0.0);
71 for (
int species_index = 0;
75 Complex structure_factor(0.0, 0.0);
76 for (
int atom_index = 0; atom_index < crystal_structure_.
number_of_atoms();
85 local_potential_total +=
90 reciprocal_space_multiplicity *
91 (std::conj(charge_density_g[g_vector_index]) * local_potential_total).real();
94 for (
int direction_a = 0; direction_a < 3; direction_a++) {
95 result_.
local[direction_a][direction_a] += evloc;
98 Real stress_xx = 0, stress_yx = 0, stress_yy = 0, stress_zx = 0, stress_zy = 0,
102 const auto& g_vector = planewave_basis_.
g_vectors()[g_vector_index];
103 Real g_vector_squared = g_vector.magnitude_squared;
106 Real g_vector_magnitude =
109 Complex derivative_local_potential_times_structure_factor(0.0, 0.0);
110 for (
int species_index = 0;
118 Real derivative_local_potential_d_q =
120 species_index, g_vector_magnitude);
121 Real derivative_local_potential_d_g_squared =
122 derivative_local_potential_d_q / (2.0 * g_vector_magnitude);
124 Complex structure_factor(0.0, 0.0);
125 for (
int atom_index = 0; atom_index < crystal_structure_.
number_of_atoms();
134 derivative_local_potential_times_structure_factor +=
135 derivative_local_potential_d_g_squared * structure_factor;
138 Real stress_partial_contribution = reciprocal_space_multiplicity * 2.0 *
139 (std::conj(charge_density_g[g_vector_index]) *
140 derivative_local_potential_times_structure_factor)
142 stress_xx += stress_partial_contribution * g_vector.g_cart.x * g_vector.g_cart.x;
143 stress_yx += stress_partial_contribution * g_vector.g_cart.y * g_vector.g_cart.x;
144 stress_yy += stress_partial_contribution * g_vector.g_cart.y * g_vector.g_cart.y;
145 stress_zx += stress_partial_contribution * g_vector.g_cart.z * g_vector.g_cart.x;
146 stress_zy += stress_partial_contribution * g_vector.g_cart.z * g_vector.g_cart.y;
147 stress_zz += stress_partial_contribution * g_vector.g_cart.z * g_vector.g_cart.z;
149 result_.
local[0][0] +=
151 result_.
local[1][0] +=
153 result_.
local[1][1] +=
155 result_.
local[2][0] +=
157 result_.
local[2][1] +=
159 result_.
local[2][2] +=