Skip to content

Commit 647fbaf

Browse files
authored
Merge pull request brucefan1983#1395 from tang070205/master
Provide the right advice for expanding your circle of friends
2 parents a7fce38 + f54096e commit 647fbaf

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

doc/gpumd/input_files/kpoints_in.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ or
3838
0 0 0 G
3939
0.5 0 0.5 X
4040
0.625 0.25 0.625 U
41-
#Represents a breakpoint, marking the start of the second path.
41+
4242
0.375 0.375 0.75 K
4343
0 0 0 G
4444
0.5 0.5 0.5 L
@@ -47,4 +47,4 @@ or
4747
4848
Here,
4949
* The first three columns represent the coordinates of high symmetry points. The last column corresponds to names.
50-
* A blank line indicates a breakpoint or the initiation of a second path.
50+
* A blank line must be used to indicate a breakpoint or the start of a second path.

src/phonon/hessian.cu

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Then calculate the dynamical matrices with different k points.
2222
#include "force/force.cuh"
2323
#include "force/force_constant.cuh"
2424
#include "hessian.cuh"
25+
#include "model/box.cuh"
2526
#include "utilities/common.cuh"
2627
#include "utilities/cusolver_wrapper.cuh"
2728
#include "utilities/error.cuh"
@@ -122,17 +123,15 @@ void Hessian::compute(
122123
void Hessian::get_cutoff_from_potential(Force& force)
123124
{
124125
for (const auto& potential : force.potentials) {
125-
if (potential->rc > cutoff) {
126126
cutoff = potential->rc;
127-
}
128127
}
129128
phonon_cutoff = cutoff * 2.0;
130129
printf("Using cutoff for phonon calculations: %g A.\n", phonon_cutoff);
131130
}
132131

133132
void Hessian::create_basis(const std::vector<double>& cpu_mass, size_t N)
134133
{
135-
num_basis = N / (cx * cy * cz);
134+
num_basis = N / (cxyz[0] * cxyz[1] * cxyz[2]);
136135

137136
basis.resize(num_basis);
138137
mass.resize(num_basis);
@@ -201,9 +200,9 @@ void Hessian::create_kpoints(const Box& box)
201200
num_kpoints = (num_kpoints - 1) * 100 + 1;
202201

203202
const Vec3 origin_lattice[3] = {
204-
{box.cpu_h[0] / cx, box.cpu_h[3] / cx, box.cpu_h[6] / cx},
205-
{box.cpu_h[1] / cy, box.cpu_h[4] / cy, box.cpu_h[7] / cy},
206-
{box.cpu_h[2] / cz, box.cpu_h[5] / cz, box.cpu_h[8] / cz}};
203+
{box.cpu_h[0] / cxyz[0], box.cpu_h[3] / cxyz[0], box.cpu_h[6] / cxyz[0]},
204+
{box.cpu_h[1] / cxyz[1], box.cpu_h[4] / cxyz[1], box.cpu_h[7] / cxyz[1]},
205+
{box.cpu_h[2] / cxyz[2], box.cpu_h[5] / cxyz[2], box.cpu_h[8] / cxyz[2]}};
207206
const auto rec_lat = reciprocal_lattice(origin_lattice);
208207

209208
kpoints.resize(num_kpoints * 3);
@@ -258,24 +257,41 @@ void Hessian::create_kpoints(const Box& box)
258257
}
259258

260259
void Hessian::initialize(
261-
const std::vector<double>& cpu_mass, const Box& box, Force& force, size_t N)
260+
const std::vector<double>& cpu_mass, Box& box, Force& force, size_t N)
262261
{
263262
get_cutoff_from_potential(force);
263+
264264
std::ifstream fin("run.in");
265-
std::string key;
266-
if (!(fin >> key && key == "replicate")) {
267-
PRINT_INPUT_ERROR("replicate keyword not found in run.in file.");
265+
std::string line;
266+
bool f_rep = false;
267+
while (std::getline(fin, line)) {
268+
auto tokens = get_tokens(line);
269+
if (!tokens.empty() && tokens[0][0] != '#' && tokens[0] == "replicate") { // 跳过空行和注释行
270+
f_rep = true;
271+
cxyz[0] = get_int_from_token(tokens[1], __FILE__, __LINE__);
272+
cxyz[1] = get_int_from_token(tokens[2], __FILE__, __LINE__);
273+
cxyz[2] = get_int_from_token(tokens[3], __FILE__, __LINE__);
274+
}
275+
break;
268276
}
269-
fin >> cx >> cy >> cz;
270277
fin.close();
278+
if (!f_rep) {
279+
PRINT_INPUT_ERROR("replicate keyword not found in run.in file.");
280+
}
271281

272-
double lattice_lengths[3] = {box.cpu_h[0] / cx, box.cpu_h[4] / cy, box.cpu_h[8] / cz};
273282
int s_c[3] = {1, 1, 1};
274-
for (int i = 0; i < 3; ++i) {
275-
for (int j = 1; j < 100; ++j) {
276-
if (lattice_lengths[i] * j >= cutoff * 4) {
277-
s_c[i] = j;
278-
break;
283+
int stru_pbc[3] = {box.pbc_x, box.pbc_y, box.pbc_z};
284+
double volume = box.get_volume();
285+
for (int i= 0; i < 3; ++i){
286+
double thickness = volume / box.get_area(i);
287+
double ori_thick = thickness / cxyz[i];
288+
printf("thickness in %d direction: %f\n", i, ori_thick);
289+
if (stru_pbc[i]) {
290+
for (int j= 1;j< 100;++j){
291+
if (ori_thick *j>= cutoff *4){
292+
s_c[i] = j;
293+
break;
294+
}
279295
}
280296
}
281297
}

src/phonon/hessian.cuh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Force;
2727
class Hessian
2828
{
2929
private:
30-
size_t cx = 1, cy = 1, cz = 1;
30+
int cxyz[3] = {1, 1, 1};
3131

3232
public:
3333
double displacement = 0.005;
@@ -66,7 +66,7 @@ protected:
6666

6767
void create_basis(const std::vector<double>& cpu_mass, size_t N);
6868
void create_kpoints(const Box& box);
69-
void initialize(const std::vector<double>& cpu_mass, const Box& box, Force& force, size_t N);
69+
void initialize(const std::vector<double>& cpu_mass, Box& box, Force& force, size_t N);
7070
void finalize(void);
7171

7272
void find_H(

0 commit comments

Comments
 (0)