@@ -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(
122123void 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
133132void 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
260259void 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 }
0 commit comments