Skip to content

Commit 3ec87b8

Browse files
authored
Minor cleanup (#18)
- Remove unused LAPACK/BLAS functions - add some more documentation - format
1 parent 963fdc5 commit 3ec87b8

9 files changed

+538
-592
lines changed

Diff for: .clang-format

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ BasedOnStyle: LLVM
44
AccessModifierOffset: 2
55
ConstructorInitializerIndentWidth: 2
66
ContinuationIndentWidth: 2
7+
IndentAccessModifiers: true
78
IndentWidth: 2
89
IndentWrappedFunctionNames: true
910
TabWidth: 2
@@ -23,3 +24,4 @@ AllowShortIfStatementsOnASingleLine: AllIfsAndElse
2324

2425
AlignOperands: true
2526
AllowAllArgumentsOnNextLine: true
27+
InsertTrailingCommas: Wrapped

Diff for: include/dftd_cblas.h

+29-54
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424

2525
namespace dftd4 {
2626

27+
/**
28+
* @brief General matrix vector multiplication (`C = alpha * A * V + C`).
29+
*
30+
* @param C Result vector C. Modified in-place.
31+
* @param A Matrix A.
32+
* @param V Vector V.
33+
* @param Transpose Specifies whether to transpose matrix A.
34+
* @param alpha Scaling factor for the product of matrix A and vector X.
35+
* @return Exit code
36+
*/
2737
inline int BLAS_Add_Mat_x_Vec(
2838
TVector<double> &C,
2939
TMatrix<double> &A,
@@ -70,34 +80,18 @@ inline int BLAS_Add_Mat_x_Vec(
7080
return EXIT_FAILURE;
7181
};
7282

73-
inline void BLAS_Add_Mat_x_Vec(
74-
double *C,
75-
const double *A,
76-
const double *B,
77-
const int rows,
78-
const int cols,
79-
const bool Transpose,
80-
const double alpha,
81-
const double beta
82-
) {
83-
if (Transpose) {
84-
cblas_dgemv(
85-
CblasRowMajor, CblasTrans, rows, cols, alpha, A, cols, B, 1, beta, C, 1
86-
);
87-
} else {
88-
cblas_dgemv(
89-
CblasRowMajor, CblasNoTrans, rows, cols, alpha, A, cols, B, 1, beta, C, 1
90-
);
91-
};
92-
};
93-
94-
inline double
95-
BLAS_Vec_x_Vec(const TVector<double> &A, const TVector<double> &B) {
96-
if (A.N != B.N) exit(EXIT_FAILURE);
97-
return cblas_ddot(A.N, A.p, 1, B.p, 1);
98-
};
9983

100-
/// C = alpha * A * B + C
84+
/**
85+
* @brief General matrix-matrix multiplication (`C = alpha * A * B + C`).
86+
*
87+
* @param C Result matrix C. Modified in-place.
88+
* @param A Matrix A.
89+
* @param B Matrix B.
90+
* @param TransposeA Specifies whether to transpose matrix A.
91+
* @param TransposeB Specifies whether to transpose matrix B.
92+
* @param alpha Scaling factor for the product of matrix A and matrix B.
93+
* @return Exit code.
94+
*/
10195
inline int BLAS_Add_Mat_x_Mat(
10296
TMatrix<double> &C,
10397
const TMatrix<double> &A,
@@ -209,37 +203,19 @@ inline int BLAS_Add_Mat_x_Mat(
209203
return EXIT_SUCCESS;
210204
};
211205

212-
// Linear equation solver
213-
inline int BLAS_LINEQ(TMatrix<double> &a, TMatrix<double> &b, int m) {
214-
lapack_int info, n, nrhs;
215-
lapack_int *ipiv;
216-
217-
if (a.rows != a.cols) return EXIT_FAILURE;
218-
219-
n = a.rows;
220-
nrhs = m;
221-
222-
a.Transpose();
223-
b.Transpose();
224-
225-
ipiv = new lapack_int[n];
226-
227-
info = LAPACKE_dgesv(LAPACK_COL_MAJOR, n, nrhs, a.p, n, ipiv, b.p, n);
228-
229-
delete[] ipiv;
230-
231-
a.Transpose();
232-
b.Transpose();
233-
234-
return info;
235-
}
236-
206+
/**
207+
* @brief Compute inverse of a matrix using LU decomposition.
208+
*
209+
* @param a Matrix a.
210+
* @return Exit code.
211+
*/
237212
inline int BLAS_InvertMatrix(TMatrix<double> &a) {
238213
if (a.rows != a.cols) { return EXIT_FAILURE; }
239214

240215
lapack_int info;
241216
lapack_int *ipiv = new lapack_int[a.rows];
242217

218+
// LU factorization of a general m-by-n matrix
243219
info = LAPACKE_dgetrf(
244220
LAPACK_ROW_MAJOR,
245221
(lapack_int)a.rows,
@@ -248,13 +224,12 @@ inline int BLAS_InvertMatrix(TMatrix<double> &a) {
248224
(lapack_int)a.cols,
249225
ipiv
250226
);
251-
252227
if (info != 0) { return EXIT_FAILURE; }
253228

229+
// Inverse of an LU-factored general matrix
254230
info = LAPACKE_dgetri(
255231
LAPACK_ROW_MAJOR, (lapack_int)a.rows, a.p, (lapack_int)a.cols, ipiv
256232
);
257-
258233
if (info != 0) { return EXIT_FAILURE; }
259234

260235
delete[] ipiv;

Diff for: include/dftd_dispersion.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
namespace dftd4 {
2929

3030
class dparam {
31-
public:
32-
double s6;
33-
double s8;
34-
double s10;
35-
double s9;
36-
double a1;
37-
double a2;
38-
int alp;
31+
public:
32+
double s6;
33+
double s8;
34+
double s10;
35+
double s9;
36+
double a1;
37+
double a2;
38+
int alp;
3939
};
4040

4141
/**
@@ -46,16 +46,16 @@ class dparam {
4646
* @param par DFT-D4 parameters.
4747
* @param d4 Base D4 dispersion model.
4848
* @param cutoff Real-space cutoffs for CN and dispersion.
49-
* @param energy Dispersion energy.
50-
* @param GRAD Dispersion gradient.
49+
* @param energy Dispersion energy (inout).
50+
* @param GRAD Dispersion gradient (inout).
5151
* @return Exit status.
5252
*/
5353
extern int get_dispersion(
5454
const TMolecule &mol,
5555
const int charge,
56-
TD4Model &d4,
56+
const TD4Model &d4,
5757
const dparam &par,
58-
TCutoff cutoff,
58+
const TCutoff cutoff,
5959
double &energy,
6060
double *GRAD
6161
);

Diff for: include/dftd_model.h

+36-36
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,49 @@
2323

2424
namespace dftd4 {
2525

26-
// Default weighting factor for coordination number interpolation
27-
static const double wf_default = 6.0;
28-
2926
// Default maximum charge scaling height for partial charge extrapolation
3027
static const double ga_default = 3.0;
3128

3229
// Default charge scaling steepness for partial charge extrapolation
3330
static const double gc_default = 2.0;
3431

32+
// Default weighting factor for coordination number interpolation
33+
static const double wf_default = 6.0;
34+
3535
class TD4Model {
36-
public:
37-
double wf;
38-
double ga;
39-
double gc;
40-
41-
explicit TD4Model(
42-
double wf_scale = wf_default,
43-
double ga_scale = ga_default,
44-
double gc_scale = gc_default
45-
);
46-
47-
int weight_references(
48-
const TMolecule &mol,
49-
const TVector<double> &cn,
50-
const TVector<double> &q,
51-
TMatrix<double> &gwvec,
52-
TMatrix<double> &dgwdcn,
53-
TMatrix<double> &dgwdq,
54-
bool lgrad = false
55-
);
56-
57-
int get_atomic_c6(
58-
const TMolecule &mol,
59-
const TMatrix<double> &gwvec,
60-
const TMatrix<double> &dgwdcn,
61-
const TMatrix<double> &dgwdq,
62-
TMatrix<double> &c6,
63-
TMatrix<double> &dc6dcn,
64-
TMatrix<double> &dc6dq,
65-
bool lgrad = false
66-
);
67-
68-
int set_refalpha_eeq(const TMolecule &mol, TMatrix<double> &alpha);
36+
public:
37+
double ga;
38+
double gc;
39+
double wf;
40+
41+
explicit TD4Model(
42+
double ga_scale = ga_default,
43+
double gc_scale = gc_default,
44+
double wf_scale = wf_default
45+
);
46+
47+
int weight_references(
48+
const TMolecule &mol,
49+
const TVector<double> &cn,
50+
const TVector<double> &q,
51+
TMatrix<double> &gwvec,
52+
TMatrix<double> &dgwdcn,
53+
TMatrix<double> &dgwdq,
54+
bool lgrad = false
55+
) const;
56+
57+
int get_atomic_c6(
58+
const TMolecule &mol,
59+
const TMatrix<double> &gwvec,
60+
const TMatrix<double> &dgwdcn,
61+
const TMatrix<double> &dgwdq,
62+
TMatrix<double> &c6,
63+
TMatrix<double> &dc6dcn,
64+
TMatrix<double> &dc6dq,
65+
bool lgrad = false
66+
) const;
67+
68+
int set_refalpha_eeq(const TMolecule &mol, TMatrix<double> &alpha) const;
6969
};
7070

7171
extern inline double trapzd(const double a[23], const double b[23]);

0 commit comments

Comments
 (0)