Skip to content

Commit

Permalink
Format (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinfriede authored Sep 27, 2024
1 parent ae86721 commit 2a727c4
Show file tree
Hide file tree
Showing 12 changed files with 587 additions and 522 deletions.
5 changes: 3 additions & 2 deletions include/dftd_cblas.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ inline int BLAS_Add_Mat_x_Mat(
const double alpha
) {
// check for size 0 matrices
if (A.cols == 0 || A.rows == 0 || B.cols == 0 || B.rows == 0 || C.cols == 0 || C.rows == 0)
if (A.cols == 0 || A.rows == 0 || B.cols == 0 || B.rows == 0 || C.cols == 0 ||
C.rows == 0)
exit(EXIT_FAILURE);

// check for transpositions
Expand Down Expand Up @@ -150,7 +151,7 @@ inline int BLAS_Add_Mat_x_Mat(
C.cols
);
}; // B transposed
} // A not transposed
} // A not transposed
else {
if (!TransposeB) {
// check dimensions for C=AT*B
Expand Down
3 changes: 1 addition & 2 deletions include/dftd_damping.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace dftd4 {
* @param latm Switch for D4-ATM (true) or D4-MBD (false) parameters.
* @returns Exit status.
*/
extern int
d4par(const std::string func, dftd4::dparam &par, bool latm = true);
extern int d4par(const std::string func, dftd4::dparam &par, bool latm = true);

} // namespace dftd4
326 changes: 163 additions & 163 deletions include/dftd_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,189 +26,189 @@ namespace dftd4 {

// Define a vector
template <class T> class TVector {
public:
int N; // Dimension of the vector
int ElementSize; // Size of each element in the vector
T *p; // The pointer to the vector

TVector() {
N = 0;
p = nullptr;
ElementSize = sizeof(T);
}
~TVector() {
if (p != nullptr) Delete();
}
void NewVector(int VectorLength) {
if (VectorLength < 0) { std::exit(EXIT_FAILURE); }
if (p != nullptr && N == VectorLength) {
Init();
} else {
Delete();
if (VectorLength == 0) { return; }
// get new memory
p = new T[VectorLength];
if (!p) { std::exit(EXIT_FAILURE); }
N = VectorLength;
Init();
public:
int N; // Dimension of the vector
int ElementSize; // Size of each element in the vector
T *p; // The pointer to the vector

TVector() {
N = 0;
p = nullptr;
ElementSize = sizeof(T);
}
}

// alias for NewVector
void New(int VectorLength) { return NewVector(VectorLength); }
void NewVec(int VectorLength) { return NewVector(VectorLength); }

void Delete() {
if (p != nullptr && N != 0) { delete[] p; }
p = nullptr;
N = 0;
}
void CopyVec(const TVector &v) {
long int mem;
if (N != v.N) {
Delete();
New(v.N);
~TVector() {
if (p != nullptr) Delete();
}
if (v.N == 0) return;
mem = (long int)N * ElementSize;
std::memcpy(p, v.p, mem);
}
void Init() {
if (p != nullptr) {
long int mem = (long int)N * ElementSize;
std::memset(p, 0, mem);
void NewVector(int VectorLength) {
if (VectorLength < 0) { std::exit(EXIT_FAILURE); }
if (p != nullptr && N == VectorLength) {
Init();
} else {
Delete();
if (VectorLength == 0) { return; }
// get new memory
p = new T[VectorLength];
if (!p) { std::exit(EXIT_FAILURE); }
N = VectorLength;
Init();
}
}
}

void Print(char name[]) {
printf("Vector printed: %s (%d)\n", name, N);
for (int i = 0; i < N; i++) {
printf("%+23.15e\n", p[i]);
// alias for NewVector
void New(int VectorLength) { return NewVector(VectorLength); }
void NewVec(int VectorLength) { return NewVector(VectorLength); }

void Delete() {
if (p != nullptr && N != 0) { delete[] p; }
p = nullptr;
N = 0;
}
void CopyVec(const TVector &v) {
long int mem;
if (N != v.N) {
Delete();
New(v.N);
}
if (v.N == 0) return;
mem = (long int)N * ElementSize;
std::memcpy(p, v.p, mem);
}
void Init() {
if (p != nullptr) {
long int mem = (long int)N * ElementSize;
std::memset(p, 0, mem);
}
}
printf("\n");
}

inline T &operator()(int i) { return p[i]; }
inline const T &operator()(int i) const { return p[i]; }
inline T &operator[](int i) { return p[i]; }
inline const T &operator[](int i) const { return p[i]; }
void Print(char name[]) {
printf("Vector printed: %s (%d)\n", name, N);
for (int i = 0; i < N; i++) {
printf("%+23.15e\n", p[i]);
}
printf("\n");
}

inline T &operator()(int i) { return p[i]; }
inline const T &operator()(int i) const { return p[i]; }
inline T &operator[](int i) { return p[i]; }
inline const T &operator[](int i) const { return p[i]; }
};

// Define a normal matrix
template <class T> class TMatrix {
public:
int rows, cols; // dimensions
int ElementSize; // Size of elements in matrix
T *p; // pointer to dynamic memory

TMatrix() {
cols = 0;
rows = 0;
p = nullptr;
ElementSize = sizeof(T);
}
~TMatrix() {
if (p != nullptr) Delete();
}

void NewMatrix(int r, int c) {
if (r < 0 || c < 0) std::exit(EXIT_FAILURE);
if (p != nullptr && r == rows && c == cols) {
Init();
} else {
long int mem = (long int)r * (long int)c;
if (p != nullptr) Delete(); // Eventually delete old matrix

if (mem == 0) return; // don't touch pointer if no memory is allocated

p = new T[mem];
if (!p) std::exit(EXIT_FAILURE);
rows = r;
cols = c;
Init();
public:
int rows, cols; // dimensions
int ElementSize; // Size of elements in matrix
T *p; // pointer to dynamic memory

TMatrix() {
cols = 0;
rows = 0;
p = nullptr;
ElementSize = sizeof(T);
}
~TMatrix() {
if (p != nullptr) Delete();
}

void NewMatrix(int r, int c) {
if (r < 0 || c < 0) std::exit(EXIT_FAILURE);
if (p != nullptr && r == rows && c == cols) {
Init();
} else {
long int mem = (long int)r * (long int)c;
if (p != nullptr) Delete(); // Eventually delete old matrix

if (mem == 0) return; // don't touch pointer if no memory is allocated

p = new T[mem];
if (!p) std::exit(EXIT_FAILURE);
rows = r;
cols = c;
Init();
}
return;
}
return;
}

void NewMatrix(const TMatrix &v) { NewMatrix(v.rows, v.cols); }

// alias for NewMatrix
void New(int r, int c) { return NewMatrix(r, c); }
void NewMat(int r, int c) { return NewMatrix(r, c); }

void Delete() {
if (p != nullptr && rows * cols != 0) { delete[] p; }
rows = 0;
cols = 0;
p = nullptr;
}

void Init() {
long int mem;
if (p != nullptr) {
mem = (long int)cols * (long int)rows * ElementSize;
std::memset(p, 0, mem);

void NewMatrix(const TMatrix &v) { NewMatrix(v.rows, v.cols); }

// alias for NewMatrix
void New(int r, int c) { return NewMatrix(r, c); }
void NewMat(int r, int c) { return NewMatrix(r, c); }

void Delete() {
if (p != nullptr && rows * cols != 0) { delete[] p; }
rows = 0;
cols = 0;
p = nullptr;
}
}

void Transpose() {
T x;
int i, j;

if (p != nullptr) {
if (rows == cols) {
for (i = 0; i < rows; i++) {
for (j = 0; j < i; j++) {
x = p[i * cols + j];
p[i * cols + j] = p[j * cols + i];
p[j * cols + i] = x;
} // j
} // i
} // if NxN
else {
// for non-square matrix, we need an additional copy
TMatrix<T> temp;
temp.CopyMat(*this);
NewMatrix(cols, rows);
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
p[i * cols + j] = temp.p[j * cols + i];
} // j
} // i

void Init() {
long int mem;
if (p != nullptr) {
mem = (long int)cols * (long int)rows * ElementSize;
std::memset(p, 0, mem);
}
} // if data is loaded
} // for NxN matrices transpose elements
}

void Transpose() {
T x;
int i, j;

if (p != nullptr) {
if (rows == cols) {
for (i = 0; i < rows; i++) {
for (j = 0; j < i; j++) {
x = p[i * cols + j];
p[i * cols + j] = p[j * cols + i];
p[j * cols + i] = x;
} // j
} // i
} // if NxN
else {
// for non-square matrix, we need an additional copy
TMatrix<T> temp;
temp.CopyMat(*this);
NewMatrix(cols, rows);
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
p[i * cols + j] = temp.p[j * cols + i];
} // j
} // i
}
} // if data is loaded
} // for NxN matrices transpose elements

void CopyMat(const TMatrix &m) {
long int mem;
void CopyMat(const TMatrix &m) {
long int mem;

if ((m.rows != rows) || (m.cols != cols)) {
Delete();
New(m.rows, m.cols);
if ((m.rows != rows) || (m.cols != cols)) {
Delete();
New(m.rows, m.cols);
}
mem = (long int)rows * (long int)cols * ElementSize;
if (mem == 0) return;
std::memcpy(p, m.p, mem);
}
mem = (long int)rows * (long int)cols * ElementSize;
if (mem == 0) return;
std::memcpy(p, m.p, mem);
}

void Print(const char name[] = "unknown") {
printf("Matrix printed: %s (%d, %d)\n", name, rows, cols);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%+23.15e", p[i * cols + j]);
if (j == cols - 1) {
printf("\n");
} else {
printf(" ");

void Print(const char name[] = "unknown") {
printf("Matrix printed: %s (%d, %d)\n", name, rows, cols);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%+23.15e", p[i * cols + j]);
if (j == cols - 1) {
printf("\n");
} else {
printf(" ");
}
}
}
printf("\n");
}
printf("\n");
}

inline T &operator()(int i, int j) { return p[i * cols + j]; }
inline const T &operator()(int i, int j) const { return p[i * cols + j]; }
inline T *operator[](int i) { return p + i * cols; }
inline T &operator()(int i, int j) { return p[i * cols + j]; }
inline const T &operator()(int i, int j) const { return p[i * cols + j]; }
inline T *operator[](int i) { return p + i * cols; }
};

} // namespace dftd4
9 changes: 3 additions & 6 deletions include/dftd_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,10 @@ class TD4Model {

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

extern inline double
weight_cn(double wf, double cn, double cnref);
extern inline double weight_cn(double wf, double cn, double cnref);

extern inline double
zeta(double a, double c, double qref, double qmod);
extern inline double
dzeta(double a, double c, double qref, double qmod);
extern inline double zeta(double a, double c, double qref, double qmod);
extern inline double dzeta(double a, double c, double qref, double qmod);

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

Expand Down
Loading

0 comments on commit 2a727c4

Please sign in to comment.