From a2ae9dce64baaa54b3c60aa20bf6526a3bc3f8e7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 9 Feb 2024 06:29:08 -0500 Subject: [PATCH] apply clang-tidy fixes --- tools/phonon/disp.cpp | 6 +-- tools/phonon/dynmat.cpp | 29 ++------------- tools/phonon/green.cpp | 15 ++------ tools/phonon/input.cpp | 8 +--- tools/phonon/interpolate.cpp | 22 +++-------- tools/phonon/kpath.cpp | 12 ++---- tools/phonon/phonon.cpp | 59 +++++++----------------------- tools/phonon/phonopy.cpp | 8 +--- tools/phonon/qnodes.cpp | 4 -- tools/phonon/timer.cpp | 8 +--- tools/phonon/tricubic/tricubic.cpp | 2 +- 11 files changed, 36 insertions(+), 137 deletions(-) diff --git a/tools/phonon/disp.cpp b/tools/phonon/disp.cpp index 79a22aeee4..9cc1b99762 100644 --- a/tools/phonon/disp.cpp +++ b/tools/phonon/disp.cpp @@ -53,7 +53,7 @@ void Phonon::pdisp() #ifdef UseSPG if (method == 1){ #endif - while (1){ + while (true){ for (int i = 0; i < 3; ++i) qstr[i] = qend[i]; printf("\nPlease input the start q-point in unit of B1->B3, q to exit [%g %g %g]: ", qstr[0], qstr[1], qstr[2]); @@ -67,7 +67,7 @@ void Phonon::pdisp() qstr[2] = atof(strtok(NULL, " \t\n\r\f")); } - while ( 1 ){ + while ( true ){ printf("Please input the end q-point in unit of B1->B3: "); input->read_stdin(str); if (count_words(str) >= 3) break; @@ -166,8 +166,6 @@ void Phonon::pdisp() delete []fname; delete qnodes; - -return; } /*----------------------------------------------------------------------------*/ diff --git a/tools/phonon/dynmat.cpp b/tools/phonon/dynmat.cpp index 5994ce703e..bdcce7a3bc 100644 --- a/tools/phonon/dynmat.cpp +++ b/tools/phonon/dynmat.cpp @@ -200,8 +200,6 @@ DynMat::DynMat(int narg, char **arg) // ask for the interpolation method interpolate->set_method(); - - return; } @@ -222,8 +220,6 @@ DynMat::~DynMat() memory->destroy(DM_all); memory->destroy(M_inv_sqrt); delete memory; - - return; } /* ---------------------------------------------------------------------------- @@ -234,10 +230,10 @@ void DynMat::writeDMq(double *q) FILE *fp; // only ask for file name for the first time // other calls will append the result to the file. - if (dmfile == NULL){ + if (dmfile == nullptr){ char str[MAXLINE], *ptr; printf("\n"); - while ( 1 ){ + while ( true ){ printf("Please input the filename to output the DM at selected q: "); input->read_stdin(str); ptr = strtok(str, " \r\t\n\f"); @@ -260,8 +256,6 @@ void DynMat::writeDMq(double *q) } fprintf(fp,"\n"); fclose(fp); - - return; } /* ---------------------------------------------------------------------------- @@ -275,7 +269,6 @@ void DynMat::writeDMq(double *q, const double qr, FILE *fp) for (int j = 0; j < fftdim; ++j) fprintf(fp,"%lg %lg\t", DM_q[i][j].r, DM_q[i][j].i); fprintf(fp,"\n"); - return; } /* ---------------------------------------------------------------------------- @@ -327,8 +320,6 @@ int DynMat::geteigen(double *egv, int flag) void DynMat::getDMq(double *q) { interpolate->execute(q, DM_q[0]); - - return; } /* ---------------------------------------------------------------------------- @@ -339,7 +330,6 @@ void DynMat::getDMq(double *q, double *wt) interpolate->execute(q, DM_q[0]); if (flag_skip && interpolate->UseGamma ) wt[0] = 0.; - return; } /* ---------------------------------------------------------------------------- @@ -359,8 +349,7 @@ void DynMat::car2dir() basis[i][idim] = x[0]*mat[idim] + x[1]*mat[3+idim] + x[2]*mat[6+idim]; } - return; -} + } /* ---------------------------------------------------------------------------- * private method to enforce the acoustic sum rule on force constant matrix at G @@ -463,7 +452,6 @@ void DynMat::EnforceASR() } delete[] egvs; puts("\n================================================================================\n"); - return; } /* ---------------------------------------------------------------------------- @@ -501,7 +489,6 @@ void DynMat::real2rec() for (int j = 0; j < sysdim; ++j) printf("%8.4f ", ibasevec[i*3+j]); } puts("\n================================================================================"); - return; } /* ---------------------------------------------------------------------- @@ -590,8 +577,6 @@ void DynMat::GaussJordan(int n, double *Mat) delete []indxr; delete []indxc; delete []ipiv; - - return; } /* ---------------------------------------------------------------------------- @@ -600,8 +585,6 @@ void DynMat::GaussJordan(int n, double *Mat) void DynMat::reset_interp_method() { interpolate->set_method(); - - return; } /* ---------------------------------------------------------------------------- @@ -644,8 +627,6 @@ void DynMat::ShowVersion() printf(" (__) (_) (_)(__)(__)(_)\\_)(__)(__)\n"); printf("\nPHonon ANAlyzer for Fix-Phonon, version 2.%02d, compiled on %s.\n", VERSION, __DATE__); printf("Reference: https://doi.org/10.1016/j.cpc.2011.04.019\n"); - - return; } /* ---------------------------------------------------------------------------- @@ -696,8 +677,7 @@ void DynMat::Define_Conversion_Factor() printf("sqrt(E/ML^2)/(2*pi) into THz, instead, I set it to 1; you should check the unit\nused by LAMMPS.\n"); eml2f = eml2fc = 1.; } - return; -} + } /* ---------------------------------------------------------------------------- * Private method to output the information read @@ -711,6 +691,5 @@ void DynMat::ShowInfo() printf("System dimension : %d\n", sysdim); printf("Boltzmann constant in used units : %g\n", boltz); puts("================================================================================"); - return; } /* --------------------------------------------------------------------*/ diff --git a/tools/phonon/green.cpp b/tools/phonon/green.cpp index 0f687fd834..63b820dd2c 100644 --- a/tools/phonon/green.cpp +++ b/tools/phonon/green.cpp @@ -65,8 +65,6 @@ Green::Green(const int ntm, const int sdim, const int niter, const double min, c // Get the inverser of the treated hessian by continued fractional method Recursion(); - - return; } /*------------------------------------------------------------------------------ @@ -74,14 +72,12 @@ Green::Green(const int ntm, const int sdim, const int niter, const double min, c *----------------------------------------------------------------------------*/ Green::~Green() { - H = NULL; - ldos = NULL; + H = nullptr; + ldos = nullptr; memory->destroy(alpha); memory->destroy(beta); delete memory; - - return; } /*------------------------------------------------------------------------------ @@ -134,8 +130,6 @@ void Green::Lanczos() delete []vp; delete []v; delete []w; - - return; } /*------------------------------------------------------------------------------ @@ -211,8 +205,6 @@ void Green::Recursion() delete []beta_inf; delete []xmin; delete []xmax; - - return; } /*------------------------------------------------------------------------------ @@ -239,7 +231,6 @@ void Green::recursion() } w += dw; } - return; -} + } /*------------------------------------------------------------------------------*/ diff --git a/tools/phonon/input.cpp b/tools/phonon/input.cpp index c2059043c7..7b496796d0 100644 --- a/tools/phonon/input.cpp +++ b/tools/phonon/input.cpp @@ -7,10 +7,8 @@ * ---------------------------------------------------------------- */ UserInput::UserInput(int flag) { - fp = NULL; + fp = nullptr; if (flag) fp = fopen("script.inp", "w"); - - return; } /* ------------------------------------------------------------------- @@ -19,7 +17,7 @@ UserInput::UserInput(int flag) UserInput::~UserInput() { if (fp) fclose(fp); - fp = NULL; + fp = nullptr; } /* ------------------------------------------------------------------- @@ -29,7 +27,5 @@ void UserInput::read_stdin(char *str) { fgets(str, MAXLINE, stdin); if (fp) fprintf(fp, "%s", str); - - return; } /* ---------------------------------------------------------------- */ diff --git a/tools/phonon/interpolate.cpp b/tools/phonon/interpolate.cpp index 8ea551d1a8..5ce4c55651 100644 --- a/tools/phonon/interpolate.cpp +++ b/tools/phonon/interpolate.cpp @@ -28,8 +28,6 @@ Interpolate::Interpolate(int nx, int ny, int nz, int ndm, doublecomplex **DM) Dfdx = Dfdy = Dfdz = D2fdxdy = D2fdxdz = D2fdydz = D3fdxdydz = NULL; flag_reset_gamma = flag_allocated_dfs = 0; input = NULL; - - return; } /* ---------------------------------------------------------------------------- @@ -106,8 +104,7 @@ void Interpolate::tricubic_init() } n++; } - return; -} + } /* ---------------------------------------------------------------------------- * Deconstructor used to free memory @@ -123,8 +120,6 @@ Interpolate::~Interpolate() memory->destroy(D2fdydz); memory->destroy(D3fdxdydz); delete memory; - - return; } /* ---------------------------------------------------------------------------- @@ -184,8 +179,7 @@ void Interpolate::tricubic(double *qin, doublecomplex *DMq) tricubic_get_coeff(&a[0],&f[0],&dfdx[0],&dfdy[0],&dfdz[0],&d2fdxdy[0],&d2fdxdz[0],&d2fdydz[0],&d3fdxdydz[0]); DMq[idim].i = tricubic_eval(&a[0],x,y,z); } - return; -} + } /* ---------------------------------------------------------------------------- * method to interpolate the DM at an arbitrary q point; @@ -250,8 +244,7 @@ void Interpolate::trilinear(double *qin, doublecomplex *DMq) } } - return; -} + } /* ---------------------------------------------------------------------------- * To invoke the interpolation @@ -263,8 +256,6 @@ void Interpolate::execute(double *qin, doublecomplex *DMq) tricubic(qin, DMq); else // otherwise: trilinear trilinear(qin, DMq); - - return; } /* ---------------------------------------------------------------------------- @@ -274,7 +265,7 @@ void Interpolate::set_method() { char str[MAXLINE]; int im = 1; - if (input == NULL) input = new UserInput(0); + if (input == nullptr) input = new UserInput(0); puts("\n================================================================================"); printf("Which interpolation method would you like to use?\n"); @@ -289,8 +280,6 @@ void Interpolate::set_method() puts("================================================================================\n"); if (which == 1) tricubic_init(); - - return; } /* ---------------------------------------------------------------------------- @@ -316,6 +305,5 @@ void Interpolate::reset_gamma() + (data[im1][idim].r + data[ip1][idim].r) * two3; } - return; -} + } /* ---------------------------------------------------------------------------- */ diff --git a/tools/phonon/kpath.cpp b/tools/phonon/kpath.cpp index 49730b42b6..aa868f2bce 100644 --- a/tools/phonon/kpath.cpp +++ b/tools/phonon/kpath.cpp @@ -64,7 +64,6 @@ kPath::kPath(DynMat *dm, QNodes *qn) for (int j = 0; j < 3; ++j) pos[i][j] = atpos[i][j]; spgnum = spg_get_international(symbol, latvec, (double (*)[3])pos, attyp, num_atom, symprec); memory->destroy(pos); - return; } /* ---------------------------------------------------------------------------- @@ -89,7 +88,6 @@ void kPath::show_info() printf("The space group number of your unit cell is: %d => %s\n", spgnum, symbol); puts("--------------------------------------------------------------------------------"); - return; } /* ---------------------------------------------------------------------------- @@ -102,8 +100,6 @@ kPath::~kPath( ) delete memory; dynmat = NULL; q = NULL; - - return; } /* ---------------------------------------------------------------------------- @@ -2764,15 +2760,14 @@ void kPath::kpath( ) q->nqbin.push_back(nqpt); } - return; -} + } /* ---------------------------------------------------------------------------- * Show the k-path info * ---------------------------------------------------------------------------- */ void kPath::show_path() { - if (q == NULL) return; + if (q == nullptr) return; int nbin = q->ndstr.size(); if (nbin > 0){ puts("\n--------------------------------------------------------------------------------"); @@ -2787,7 +2782,6 @@ void kPath::show_path() puts("--------------------------------------------------------------------------------"); } - return; -} + } /* ---------------------------------------------------------------------------- */ #endif diff --git a/tools/phonon/phonon.cpp b/tools/phonon/phonon.cpp index 06372dcd1b..718f5c43b5 100644 --- a/tools/phonon/phonon.cpp +++ b/tools/phonon/phonon.cpp @@ -96,15 +96,14 @@ Phonon::Phonon(DynMat *dm) else if (job ==-1) dynmat->reset_interp_method(); else break; } - return; -} + } /* ---------------------------------------------------------------------------- * Deconstructor to free memory * ---------------------------------------------------------------------------- */ Phonon::~Phonon() { - dynmat = NULL; + dynmat = nullptr; memory->destroy(wt); memory->destroy(qpts); @@ -120,8 +119,6 @@ Phonon::~Phonon() memory->destroy(atpos); #endif delete memory; - - return; } /* ---------------------------------------------------------------------------- @@ -191,8 +188,6 @@ void Phonon::pdos() // output DOS writeDOS(); - - return; } /* ---------------------------------------------------------------------------- @@ -200,7 +195,7 @@ void Phonon::pdos() * ---------------------------------------------------------------------------- */ void Phonon::writeDOS() { - if (dos == NULL) return; + if (dos == nullptr) return; char str[MAXLINE]; // now to output the phonon DOS @@ -231,8 +226,6 @@ void Phonon::writeDOS() fclose(fp); fname = NULL; - - return; } /* ---------------------------------------------------------------------------- @@ -265,8 +258,7 @@ void Phonon::writeLDOS() fclose(fp); } - return; -} + } /* ---------------------------------------------------------------------------- * Private method to calculate the local phonon DOS via the real space Green's @@ -303,7 +295,7 @@ void Phonon::ldos_rsgf() int ik = 0, nit = MAX(ndim*0.1, MIN(ndim,50)); double eps = 12.; // for Cu with 1000+ atoms, 12 is enough; for small system, eps should be large. - while (1) { + while (true) { int istr, iend, iinc; // ask for relevant info printf("\nThere are %d atoms in each unit cell of your lattice.\n", dynmat->nucell); @@ -401,8 +393,6 @@ void Phonon::ldos_rsgf() } memory->destroy(Hessian); - - return; } /* ---------------------------------------------------------------------------- @@ -412,19 +402,17 @@ void Phonon::dmanyq() { char str[MAXLINE]; double q[3]; - while ( 1 ){ + while ( true ){ printf("Please input the q-point to output the dynamical matrix: "); input->read_stdin(str); if (count_words(str) >= 3) break; } q[0] = atof(strtok(str," \t\n\r\f")); - q[1] = atof(strtok(NULL," \t\n\r\f")); - q[2] = atof(strtok(NULL," \t\n\r\f")); + q[1] = atof(strtok(nullptr," \t\n\r\f")); + q[2] = atof(strtok(nullptr," \t\n\r\f")); dynmat->getDMq(q); dynmat->writeDMq(q); - - return; } /* ---------------------------------------------------------------------------- @@ -436,7 +424,7 @@ void Phonon::vfanyq() double q[3]; double *egvs = new double[ndim]; - while ( 1 ){ + while ( true ){ printf("Please input the q-point to compute the frequencies, q to exit: "); input->read_stdin(str); if (count_words(str) < 3) break; @@ -454,7 +442,6 @@ void Phonon::vfanyq() } delete[] egvs; - return; } /* ---------------------------------------------------------------------------- @@ -471,7 +458,7 @@ void Phonon::vecanyq() if (count_words(str) < 1) strcpy(str,"eigvec.dat"); FILE *fp = fopen(strtok(str," \t\n\r\f"), "w"); - while ( 1 ){ + while ( true ){ printf("Please input the q-point to compute the frequencies, q to exit: "); input->read_stdin(str); if (count_words(str) < 3) break; @@ -504,7 +491,6 @@ void Phonon::vecanyq() fclose(fp); delete[] egvs; eigvec = NULL; - return; } /* ---------------------------------------------------------------------------- @@ -528,7 +514,7 @@ void Phonon::DMdisp() int nq = MAX(MAX(dynmat->nx,dynmat->ny),dynmat->nz)/2; qend[0] = qend[1] = qend[2] = 0.; - while ( 1 ){ + while ( true ){ for (int i = 0; i < 3; ++i) qstr[i] = qend[i]; printf("\nPlease input the start q-point in unit of B1->B3, q to exit [%g %g %g]: ", qstr[0], qstr[1], qstr[2]); @@ -542,7 +528,7 @@ void Phonon::DMdisp() qstr[2] = atof(strtok(NULL," \t\n\r\f")); } - while ( 1 ){ + while ( true ){ printf("Please input the end q-point in unit of B1->B3: "); input->read_stdin(str); if (count_words(str) >= 3) break; @@ -569,8 +555,6 @@ void Phonon::DMdisp() qr -= dq; } fclose(fp); - - return; } /* ---------------------------------------------------------------------------- @@ -605,8 +589,6 @@ void Phonon::smooth(double *array, const int npt) memory->destroy(tmp); memory->destroy(table); - - return; } /* ---------------------------------------------------------------------------- @@ -671,8 +653,6 @@ void Phonon::therm() } while (T > 0.); fclose(fp); - - return; } /* ---------------------------------------------------------------------------- @@ -707,7 +687,7 @@ void Phonon::local_therm() // constants J.s J/K J const double h = 6.62606896e-34, Kb = 1.380658e-23, eV = 1.60217733e-19; double T = dynmat->Tmeasure; - while ( 1 ){ + while ( true ){ printf("\nPlease input the temperature at which to evaluate the local vibrational\n"); printf("thermal properties, non-positive number to exit [%g]: ", T); input->read_stdin(str); @@ -789,8 +769,6 @@ void Phonon::local_therm() } } fclose(fp); - - return; } /* ---------------------------------------------------------------------------- @@ -935,8 +913,6 @@ void Phonon::QMesh() } #endif printf("Your new q-mesh size would be: %d x %d x %d => %d points\n", nx,ny,nz,nq); - - return; } /* ---------------------------------------------------------------------------- @@ -1055,8 +1031,6 @@ void Phonon::ldos_egv() // evaluate the local vibrational thermal properties optionally local_therm(); - - return; } /* ---------------------------------------------------------------------------- @@ -1078,8 +1052,6 @@ void Phonon::ShowCell() for (int i = 0; i < dynmat->nucell; ++i) printf("%4d %12.8f %12.8f %12.8f\n", dynmat->attyp[i], dynmat->basis[i][0], dynmat->basis[i][1], dynmat->basis[i][2]); puts("================================================================================"); - - return; } /* ---------------------------------------------------------------------------- @@ -1112,8 +1084,7 @@ void Phonon::Normalize() } } - return; -} + } /* ---------------------------------------------------------------------------- * Private method to calculate vibrational frequencies for all q-points @@ -1138,8 +1109,6 @@ void Phonon::ComputeAll() } printf("Done!\n"); time->stop(); time->print(); delete time; - - return; } /*------------------------------------------------------------------------------ diff --git a/tools/phonon/phonopy.cpp b/tools/phonon/phonopy.cpp index 2cee319aa7..95a734ea56 100644 --- a/tools/phonon/phonopy.cpp +++ b/tools/phonon/phonopy.cpp @@ -60,8 +60,6 @@ Phonopy::Phonopy(DynMat *dynmat) phonopy(); -return; - } /* ---------------------------------------------------------------------------- @@ -72,8 +70,7 @@ Phonopy::~Phonopy() memory->destroy(mass); memory->destroy(FC_all); delete memory; - dm = NULL; -return; + dm = nullptr; } /* ---------------------------------------------------------------------------- @@ -111,7 +108,6 @@ void Phonopy::write(int flag) } else if (flag == 5){ puts("================================================================================"); } -return; } /* ---------------------------------------------------------------------------- @@ -141,7 +137,6 @@ void Phonopy::get_my_FC() } ++ipt; } -return; } /* ---------------------------------------------------------------------------- @@ -304,7 +299,6 @@ void Phonopy::phonopy() write(5); delete[] type_id; delete[] num_type; - return; } /*------------------------------------------------------------------------------ diff --git a/tools/phonon/qnodes.cpp b/tools/phonon/qnodes.cpp index 32e57f9736..fb1103138b 100644 --- a/tools/phonon/qnodes.cpp +++ b/tools/phonon/qnodes.cpp @@ -11,8 +11,6 @@ QNodes::QNodes() qs.clear(); qe.clear(); nqbin.clear(); - - return; } /* ---------------------------------------------------------------------------- @@ -25,6 +23,4 @@ QNodes::~QNodes() qs.clear(); qe.clear(); nqbin.clear(); - - return; } diff --git a/tools/phonon/timer.cpp b/tools/phonon/timer.cpp index 9ae4e94441..43126d0f55 100644 --- a/tools/phonon/timer.cpp +++ b/tools/phonon/timer.cpp @@ -9,8 +9,6 @@ Timer::Timer() { flag = 0; start(); - - return; } /* ----------------------------------------------------------------------------- @@ -20,7 +18,6 @@ void Timer::start() { t1 = clock(); flag |= 1; - return; } /* ----------------------------------------------------------------------------- @@ -32,8 +29,7 @@ void Timer::stop() t2 = clock(); flag |= 2; } - return; -} + } /* ----------------------------------------------------------------------------- * public function, print the total time used after timer stops @@ -44,8 +40,6 @@ void Timer::print() double cpu_time_used = ((double) (t2 - t1)) / CLOCKS_PER_SEC; printf("Total CPU time used: %g seconds.\n", cpu_time_used); - - return; } /* ----------------------------------------------------------------------------- diff --git a/tools/phonon/tricubic/tricubic.cpp b/tools/phonon/tricubic/tricubic.cpp index 974ed6aa52..dff3227048 100644 --- a/tools/phonon/tricubic/tricubic.cpp +++ b/tools/phonon/tricubic/tricubic.cpp @@ -90,7 +90,7 @@ static void point2xyz(int p, int *x, int *y, int *z) { } } -const char *tricubic_version(void) { +const char *tricubic_version() { return(tricubic_version_stored); }