Skip to content

Commit c72176b

Browse files
committed
Format
1 parent ae86721 commit c72176b

12 files changed

+587
-522
lines changed

include/dftd_cblas.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ inline int BLAS_Add_Mat_x_Mat(
100100
const double alpha
101101
) {
102102
// check for size 0 matrices
103-
if (A.cols == 0 || A.rows == 0 || B.cols == 0 || B.rows == 0 || C.cols == 0 || C.rows == 0)
103+
if (A.cols == 0 || A.rows == 0 || B.cols == 0 || B.rows == 0 || C.cols == 0 ||
104+
C.rows == 0)
104105
exit(EXIT_FAILURE);
105106

106107
// check for transpositions
@@ -150,7 +151,7 @@ inline int BLAS_Add_Mat_x_Mat(
150151
C.cols
151152
);
152153
}; // B transposed
153-
} // A not transposed
154+
} // A not transposed
154155
else {
155156
if (!TransposeB) {
156157
// check dimensions for C=AT*B

include/dftd_damping.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ namespace dftd4 {
3636
* @param latm Switch for D4-ATM (true) or D4-MBD (false) parameters.
3737
* @returns Exit status.
3838
*/
39-
extern int
40-
d4par(const std::string func, dftd4::dparam &par, bool latm = true);
39+
extern int d4par(const std::string func, dftd4::dparam &par, bool latm = true);
4140

4241
} // namespace dftd4

include/dftd_matrix.h

+163-163
Original file line numberDiff line numberDiff line change
@@ -26,189 +26,189 @@ namespace dftd4 {
2626

2727
// Define a vector
2828
template <class T> class TVector {
29-
public:
30-
int N; // Dimension of the vector
31-
int ElementSize; // Size of each element in the vector
32-
T *p; // The pointer to the vector
33-
34-
TVector() {
35-
N = 0;
36-
p = nullptr;
37-
ElementSize = sizeof(T);
38-
}
39-
~TVector() {
40-
if (p != nullptr) Delete();
41-
}
42-
void NewVector(int VectorLength) {
43-
if (VectorLength < 0) { std::exit(EXIT_FAILURE); }
44-
if (p != nullptr && N == VectorLength) {
45-
Init();
46-
} else {
47-
Delete();
48-
if (VectorLength == 0) { return; }
49-
// get new memory
50-
p = new T[VectorLength];
51-
if (!p) { std::exit(EXIT_FAILURE); }
52-
N = VectorLength;
53-
Init();
29+
public:
30+
int N; // Dimension of the vector
31+
int ElementSize; // Size of each element in the vector
32+
T *p; // The pointer to the vector
33+
34+
TVector() {
35+
N = 0;
36+
p = nullptr;
37+
ElementSize = sizeof(T);
5438
}
55-
}
56-
57-
// alias for NewVector
58-
void New(int VectorLength) { return NewVector(VectorLength); }
59-
void NewVec(int VectorLength) { return NewVector(VectorLength); }
60-
61-
void Delete() {
62-
if (p != nullptr && N != 0) { delete[] p; }
63-
p = nullptr;
64-
N = 0;
65-
}
66-
void CopyVec(const TVector &v) {
67-
long int mem;
68-
if (N != v.N) {
69-
Delete();
70-
New(v.N);
39+
~TVector() {
40+
if (p != nullptr) Delete();
7141
}
72-
if (v.N == 0) return;
73-
mem = (long int)N * ElementSize;
74-
std::memcpy(p, v.p, mem);
75-
}
76-
void Init() {
77-
if (p != nullptr) {
78-
long int mem = (long int)N * ElementSize;
79-
std::memset(p, 0, mem);
42+
void NewVector(int VectorLength) {
43+
if (VectorLength < 0) { std::exit(EXIT_FAILURE); }
44+
if (p != nullptr && N == VectorLength) {
45+
Init();
46+
} else {
47+
Delete();
48+
if (VectorLength == 0) { return; }
49+
// get new memory
50+
p = new T[VectorLength];
51+
if (!p) { std::exit(EXIT_FAILURE); }
52+
N = VectorLength;
53+
Init();
54+
}
8055
}
81-
}
8256

83-
void Print(char name[]) {
84-
printf("Vector printed: %s (%d)\n", name, N);
85-
for (int i = 0; i < N; i++) {
86-
printf("%+23.15e\n", p[i]);
57+
// alias for NewVector
58+
void New(int VectorLength) { return NewVector(VectorLength); }
59+
void NewVec(int VectorLength) { return NewVector(VectorLength); }
60+
61+
void Delete() {
62+
if (p != nullptr && N != 0) { delete[] p; }
63+
p = nullptr;
64+
N = 0;
65+
}
66+
void CopyVec(const TVector &v) {
67+
long int mem;
68+
if (N != v.N) {
69+
Delete();
70+
New(v.N);
71+
}
72+
if (v.N == 0) return;
73+
mem = (long int)N * ElementSize;
74+
std::memcpy(p, v.p, mem);
75+
}
76+
void Init() {
77+
if (p != nullptr) {
78+
long int mem = (long int)N * ElementSize;
79+
std::memset(p, 0, mem);
80+
}
8781
}
88-
printf("\n");
89-
}
9082

91-
inline T &operator()(int i) { return p[i]; }
92-
inline const T &operator()(int i) const { return p[i]; }
93-
inline T &operator[](int i) { return p[i]; }
94-
inline const T &operator[](int i) const { return p[i]; }
83+
void Print(char name[]) {
84+
printf("Vector printed: %s (%d)\n", name, N);
85+
for (int i = 0; i < N; i++) {
86+
printf("%+23.15e\n", p[i]);
87+
}
88+
printf("\n");
89+
}
90+
91+
inline T &operator()(int i) { return p[i]; }
92+
inline const T &operator()(int i) const { return p[i]; }
93+
inline T &operator[](int i) { return p[i]; }
94+
inline const T &operator[](int i) const { return p[i]; }
9595
};
9696

9797
// Define a normal matrix
9898
template <class T> class TMatrix {
99-
public:
100-
int rows, cols; // dimensions
101-
int ElementSize; // Size of elements in matrix
102-
T *p; // pointer to dynamic memory
103-
104-
TMatrix() {
105-
cols = 0;
106-
rows = 0;
107-
p = nullptr;
108-
ElementSize = sizeof(T);
109-
}
110-
~TMatrix() {
111-
if (p != nullptr) Delete();
112-
}
113-
114-
void NewMatrix(int r, int c) {
115-
if (r < 0 || c < 0) std::exit(EXIT_FAILURE);
116-
if (p != nullptr && r == rows && c == cols) {
117-
Init();
118-
} else {
119-
long int mem = (long int)r * (long int)c;
120-
if (p != nullptr) Delete(); // Eventually delete old matrix
121-
122-
if (mem == 0) return; // don't touch pointer if no memory is allocated
123-
124-
p = new T[mem];
125-
if (!p) std::exit(EXIT_FAILURE);
126-
rows = r;
127-
cols = c;
128-
Init();
99+
public:
100+
int rows, cols; // dimensions
101+
int ElementSize; // Size of elements in matrix
102+
T *p; // pointer to dynamic memory
103+
104+
TMatrix() {
105+
cols = 0;
106+
rows = 0;
107+
p = nullptr;
108+
ElementSize = sizeof(T);
109+
}
110+
~TMatrix() {
111+
if (p != nullptr) Delete();
112+
}
113+
114+
void NewMatrix(int r, int c) {
115+
if (r < 0 || c < 0) std::exit(EXIT_FAILURE);
116+
if (p != nullptr && r == rows && c == cols) {
117+
Init();
118+
} else {
119+
long int mem = (long int)r * (long int)c;
120+
if (p != nullptr) Delete(); // Eventually delete old matrix
121+
122+
if (mem == 0) return; // don't touch pointer if no memory is allocated
123+
124+
p = new T[mem];
125+
if (!p) std::exit(EXIT_FAILURE);
126+
rows = r;
127+
cols = c;
128+
Init();
129+
}
130+
return;
129131
}
130-
return;
131-
}
132-
133-
void NewMatrix(const TMatrix &v) { NewMatrix(v.rows, v.cols); }
134-
135-
// alias for NewMatrix
136-
void New(int r, int c) { return NewMatrix(r, c); }
137-
void NewMat(int r, int c) { return NewMatrix(r, c); }
138-
139-
void Delete() {
140-
if (p != nullptr && rows * cols != 0) { delete[] p; }
141-
rows = 0;
142-
cols = 0;
143-
p = nullptr;
144-
}
145-
146-
void Init() {
147-
long int mem;
148-
if (p != nullptr) {
149-
mem = (long int)cols * (long int)rows * ElementSize;
150-
std::memset(p, 0, mem);
132+
133+
void NewMatrix(const TMatrix &v) { NewMatrix(v.rows, v.cols); }
134+
135+
// alias for NewMatrix
136+
void New(int r, int c) { return NewMatrix(r, c); }
137+
void NewMat(int r, int c) { return NewMatrix(r, c); }
138+
139+
void Delete() {
140+
if (p != nullptr && rows * cols != 0) { delete[] p; }
141+
rows = 0;
142+
cols = 0;
143+
p = nullptr;
151144
}
152-
}
153-
154-
void Transpose() {
155-
T x;
156-
int i, j;
157-
158-
if (p != nullptr) {
159-
if (rows == cols) {
160-
for (i = 0; i < rows; i++) {
161-
for (j = 0; j < i; j++) {
162-
x = p[i * cols + j];
163-
p[i * cols + j] = p[j * cols + i];
164-
p[j * cols + i] = x;
165-
} // j
166-
} // i
167-
} // if NxN
168-
else {
169-
// for non-square matrix, we need an additional copy
170-
TMatrix<T> temp;
171-
temp.CopyMat(*this);
172-
NewMatrix(cols, rows);
173-
for (i = 0; i < rows; i++) {
174-
for (j = 0; j < cols; j++) {
175-
p[i * cols + j] = temp.p[j * cols + i];
176-
} // j
177-
} // i
145+
146+
void Init() {
147+
long int mem;
148+
if (p != nullptr) {
149+
mem = (long int)cols * (long int)rows * ElementSize;
150+
std::memset(p, 0, mem);
178151
}
179-
} // if data is loaded
180-
} // for NxN matrices transpose elements
152+
}
153+
154+
void Transpose() {
155+
T x;
156+
int i, j;
157+
158+
if (p != nullptr) {
159+
if (rows == cols) {
160+
for (i = 0; i < rows; i++) {
161+
for (j = 0; j < i; j++) {
162+
x = p[i * cols + j];
163+
p[i * cols + j] = p[j * cols + i];
164+
p[j * cols + i] = x;
165+
} // j
166+
} // i
167+
} // if NxN
168+
else {
169+
// for non-square matrix, we need an additional copy
170+
TMatrix<T> temp;
171+
temp.CopyMat(*this);
172+
NewMatrix(cols, rows);
173+
for (i = 0; i < rows; i++) {
174+
for (j = 0; j < cols; j++) {
175+
p[i * cols + j] = temp.p[j * cols + i];
176+
} // j
177+
} // i
178+
}
179+
} // if data is loaded
180+
} // for NxN matrices transpose elements
181181

182-
void CopyMat(const TMatrix &m) {
183-
long int mem;
182+
void CopyMat(const TMatrix &m) {
183+
long int mem;
184184

185-
if ((m.rows != rows) || (m.cols != cols)) {
186-
Delete();
187-
New(m.rows, m.cols);
185+
if ((m.rows != rows) || (m.cols != cols)) {
186+
Delete();
187+
New(m.rows, m.cols);
188+
}
189+
mem = (long int)rows * (long int)cols * ElementSize;
190+
if (mem == 0) return;
191+
std::memcpy(p, m.p, mem);
188192
}
189-
mem = (long int)rows * (long int)cols * ElementSize;
190-
if (mem == 0) return;
191-
std::memcpy(p, m.p, mem);
192-
}
193-
194-
void Print(const char name[] = "unknown") {
195-
printf("Matrix printed: %s (%d, %d)\n", name, rows, cols);
196-
for (int i = 0; i < rows; i++) {
197-
for (int j = 0; j < cols; j++) {
198-
printf("%+23.15e", p[i * cols + j]);
199-
if (j == cols - 1) {
200-
printf("\n");
201-
} else {
202-
printf(" ");
193+
194+
void Print(const char name[] = "unknown") {
195+
printf("Matrix printed: %s (%d, %d)\n", name, rows, cols);
196+
for (int i = 0; i < rows; i++) {
197+
for (int j = 0; j < cols; j++) {
198+
printf("%+23.15e", p[i * cols + j]);
199+
if (j == cols - 1) {
200+
printf("\n");
201+
} else {
202+
printf(" ");
203+
}
203204
}
204205
}
206+
printf("\n");
205207
}
206-
printf("\n");
207-
}
208208

209-
inline T &operator()(int i, int j) { return p[i * cols + j]; }
210-
inline const T &operator()(int i, int j) const { return p[i * cols + j]; }
211-
inline T *operator[](int i) { return p + i * cols; }
209+
inline T &operator()(int i, int j) { return p[i * cols + j]; }
210+
inline const T &operator()(int i, int j) const { return p[i * cols + j]; }
211+
inline T *operator[](int i) { return p + i * cols; }
212212
};
213213

214214
} // namespace dftd4

include/dftd_model.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,10 @@ class TD4Model {
7676

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

79-
extern inline double
80-
weight_cn(double wf, double cn, double cnref);
79+
extern inline double weight_cn(double wf, double cn, double cnref);
8180

82-
extern inline double
83-
zeta(double a, double c, double qref, double qmod);
84-
extern inline double
85-
dzeta(double a, double c, double qref, double qmod);
81+
extern inline double zeta(double a, double c, double qref, double qmod);
82+
extern inline double dzeta(double a, double c, double qref, double qmod);
8683

8784
extern int get_max_ref(const TMolecule &mol, int &mref);
8885

0 commit comments

Comments
 (0)