Skip to content

Commit 5cb72aa

Browse files
committed
v1.68 fixed the bug on the first and update charge and B0_prev in the CELL::Q model
1 parent 8a802db commit 5cb72aa

25 files changed

+6625
-120
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ Note tat a NIL `compute pe/atom_GA` with the compute name of `__Electro_Control_
4242

4343
**Otherwise**, copy all files in the `src_mod` folder to `src` and edit the`src\MAKE\OPTION\Makefile.XXX `. Then, type `make XXX` in the `src` folder. Here, **Makefile.intel_cpu_intelmpi** is also provided in `misc` folder as an example for installation configuration.
4444

45-
Note that the default **single** precision of the FFTW setup is not higher enough for constant potential simulation that results in the order of error of 1e-6. To improve the accuracy, we suggests to switch to **double** precision using the macro of `-DFFT_DOUBLE`. Thus, if the error of `undefined reference to 'LAMMPS_NS::FFT3d::compute(double*, double*, int)'` is encountered, type `make clean-XXX` to remove the existing **single** precision FFTW library and recompile it.
45+
Note that the default **single** precision of the FFTW setup is not higher enough for constant potential simulation that results in the order of error of 1e-6. To improve the accuracy, we suggests to switch to **double** precision using the macro of `-DFFT_DOUBLE`. Thus, if the error of `undefined reference to 'LAMMPS_NS::FFT3d::compute(double*, double*, int)'` is encountered, type `make no-KSPACE;
46+
make yes-KSPACE` to recompile the existing *kspace* code compiled with **single** precision FFTW library.
4647

4748
## Syntax: pair_style lj/cut/point/long
4849

makefile

Lines changed: 7 additions & 1 deletion
Large diffs are not rendered by default.

src_mod/debug_func.cpp

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,29 @@
1515
#include <cstdio>
1616
#include <unistd.h>
1717

18-
namespace LAMMPS_NS {
18+
namespace LAMMPS_NS
19+
{
1920

20-
void print_vec(double *arr, int N, const char *name) {
21+
void print_vec(double* arr, int N, const char* name)
22+
{
2123
printf(" %s = ", name);
2224
for (int i = 0; i < N; ++i) {
2325
printf("%12.10g ", arr[i]);
2426
}
2527
printf("\n");
2628
}
2729

28-
double norm_mat(double *mat, int N) {
30+
void print_vec(int* arr, int N, const char* name)
31+
{
32+
printf(" %s = ", name);
33+
for (int i = 0; i < N; ++i) {
34+
printf("%d ", arr[i]);
35+
}
36+
printf("\n");
37+
}
38+
39+
double norm_mat(double* mat, int N)
40+
{
2941
double res = 0;
3042
for (int i = 0; i < N; ++i) {
3143
res += mat[i] * mat[i];
@@ -36,55 +48,61 @@ double norm_mat(double *mat, int N) {
3648
return sqrt(res);
3749
}
3850

39-
double norm_mat_p(double *mat, int N, const char *info) {
51+
double norm_mat_p(double* mat, int N, const char* info)
52+
{
4053
double value = norm_mat(mat, N);
4154
printf("%3s %.16g with size = %d\n", info, value, N);
4255
return value;
4356
}
4457

45-
void write_mat(const double *const ptr, int N, const char *name) {
46-
FILE *outa = fopen(name, "wb");
58+
void write_mat(const double* const ptr, int N, const char* name)
59+
{
60+
FILE* outa = fopen(name, "wb");
4761
printf("write as %s with size = %d\n", name, N);
48-
if (ptr == NULL)
49-
printf("the input ptr is NULL.\n");
62+
if (ptr == NULL) printf("the input ptr is NULL.\n");
5063
fwrite(ptr, sizeof(double), N, outa);
5164
fclose(outa);
5265
}
5366

54-
double hash_vec(double *mat, int N) {
67+
double hash_vec(double* mat, int N)
68+
{
5569
double res = 0, inv_N = 1 / double(N);
5670
for (int i = 0; i < N; ++i) {
5771
res += (mat[i] + i * inv_N) * (mat[i] + i * inv_N);
5872
}
5973
return sqrt(res);
6074
}
6175

62-
double hash_vec(int *mat, int N) {
76+
double hash_vec(int* mat, int N)
77+
{
6378
double res = 0, inv_N = 1 / double(N);
6479
for (int i = 0; i < N; ++i) {
6580
res += (mat[i] + i * inv_N) * (mat[i] + i * inv_N);
6681
}
6782
return sqrt(res);
6883
}
6984

70-
double *load_mat(int N, const char *name) {
71-
double *ptr = (double *)malloc(sizeof(double) * N);
72-
FILE *infile = fopen(name, "r");
73-
int result = fread(ptr, sizeof(double), N, infile);
85+
double* load_mat(int N, const char* name)
86+
{
87+
double* ptr = (double*)malloc(sizeof(double) * N);
88+
FILE* infile = fopen(name, "r");
89+
int result = fread(ptr, sizeof(double), N, infile);
7490
if (result != N) {
7591
printf("cannot read %d double from %s\n", N, name);
7692
}
7793
return ptr;
7894
}
7995

80-
void print_hash(double *arr, int N, const char *name) {
96+
void print_hash(double* arr, int N, const char* name)
97+
{
8198
printf(" %s = ", name);
82-
double hash = hash_vec(arr, N);
99+
double hash = hash_vec(arr, N);
83100
double normal = norm_mat(arr, N);
84101
printf("hash = %12.10g, Norm. = %12.10g Size = %d\n", hash, normal, N);
85102
}
86103

87-
void eext(int n) {
104+
void eext(int n)
105+
{
88106
printf("LOG: exit with %d\n", n);
89107
fflush(stdout);
90108
sleep(n);

src_mod/debug_func.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
#define CONP_GA_DEBUG_FUNC_H
1212

1313
#ifndef CONP_NO_DEBUG
14-
namespace LAMMPS_NS {
14+
namespace LAMMPS_NS
15+
{
1516

16-
void print_vec(double *arr, int N, const char *name);
17-
double norm_mat(double *mat, int N);
18-
double norm_mat_p(double *mat, int N, const char *info);
19-
void write_mat(const double *const ptr, int N, const char *name);
20-
double hash_vec(double *mat, int N);
21-
double hash_vec(int *mat, int N);
22-
double *load_mat(int N, const char *name);
23-
void print_hash(double *arr, int N, const char *name);
17+
void print_vec(double* arr, int N, const char* name);
18+
void print_vec(int* arr, int N, const char* name);
19+
double norm_mat(double* mat, int N);
20+
double norm_mat_p(double* mat, int N, const char* info);
21+
void write_mat(const double* const ptr, int N, const char* name);
22+
double hash_vec(double* mat, int N);
23+
double hash_vec(int* mat, int N);
24+
double* load_mat(int N, const char* name);
25+
void print_hash(double* arr, int N, const char* name);
2426
void eext(int n);
2527

2628
} // namespace LAMMPS_NS

src_mod/electro_control_GA.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void Electro_Control_GA::setup()
164164
if (kspace) {
165165
kspace_conp_Flag = true;
166166
if (me == 0) {
167-
utils::logmesg(lmp, "[ConpGA] using optimized electrostatic solver: %s\n", kspace->type_name());
167+
utils::logmesg(lmp, "[ConpGA] using optimized electrostatic solver: {}\n", kspace->type_name());
168168
}
169169
kspace->electro = this;
170170
kspace->DEBUG_LOG_LEVEL = DEBUG_LOG_LEVEL;
@@ -181,6 +181,8 @@ void Electro_Control_GA::setup()
181181

182182
int* Electro_Control_GA::setup_comm(int* all_ghostGA_ind)
183183
{
184+
if (me == 0) utils::logmesg(lmp, "[ConpGA] Setup inner communicator\n");
185+
184186
int nprocs = comm->nprocs;
185187
std::map<int, int> tag_to_proc;
186188
const int* const localGA_tag = &FIX->localGA_tag.front();
@@ -490,22 +492,23 @@ void Electro_Control_GA::calc_GA_potential(STAT cl_stat_new, STAT ek_stat_new, S
490492
// OP: {0, NIL}, {1: PE->Potential}, {2: Potential->PE}
491493
// printf("ek_stat = %d\n", ek_stat);
492494
if (me == 0 && DEBUG_LOG_LEVEL > 1)
493-
utils::logmesg(lmp, "[Debug] U<=>POT conv. {cl: {}=>{}} {ek: {}=>{}} sum_op {}\n", cl_stat, cl_stat_new, ek_stat, ek_stat_new, sum_op);
495+
utils::logmesg(lmp, "[Debug] U<=>POT conv. {{cl: {}=>{}}} {{ek: {}=>{}}} sum_op {}\n", cl_stat, cl_stat_new, ek_stat, ek_stat_new, sum_op);
494496

495497
if (sum_op != SUM_OP::BOTH) {
496498
int cl_op = (3 + static_cast<int>(cl_stat_new) - static_cast<int>(cl_stat)) % 3;
497499
int ek_op = (3 + static_cast<int>(ek_stat_new) - static_cast<int>(ek_stat)) % 3;
498500
bool sum_op_flag = sum_op == SUM_OP::ON;
499501
if (sum_op_flag && cl_stat_new != ek_stat_new) {
500502
if (me == 0)
501-
utils::logmesg(lmp, "Sum between cl{{}: {}} vs ek{{}: {}}\n", cl_stat, name_stat[static_cast<int>(cl_stat)], ek_stat,
503+
utils::logmesg(lmp, "Sum between cl{{{}: {}}} vs ek{{{}: {}}}\n", cl_stat, name_stat[static_cast<int>(cl_stat)], ek_stat,
502504
name_stat[static_cast<int>(ek_stat)]);
503505
error->all(FLERR, "inconsistent sum type!");
504506
}
505507
conv_GA_potential(cl_op, ek_op, sum_op_flag);
506508
ek_stat = ek_stat_new;
507509
cl_stat = cl_stat_new;
508510
} else {
511+
// SUM_OP::BOTH
509512
conv_GA_potential_both(cl_stat, ek_stat);
510513
cl_stat = STAT::E;
511514
ek_stat = STAT::POT;
@@ -846,4 +849,12 @@ Electro_Control_GA::~Electro_Control_GA()
846849
memory->sfree(sendlist);
847850
memory->sfree(recvlist);
848851
}
852+
if (pair != NULL) {
853+
pair->DEBUG_LOG_LEVEL = 0;
854+
pair->electro = nullptr;
855+
}
856+
if (kspace_conp_Flag == true && kspace != nullptr) {
857+
kspace->DEBUG_LOG_LEVEL = 0;
858+
kspace->electro = nullptr;
859+
}
849860
}

src_mod/electro_control_GA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class Electro_Control_GA : protected Pointers {
9595
} else
9696
return kspace->type_name();
9797
}
98+
STAT get_ek_stat() { return ek_stat; }
99+
STAT get_cl_stat() { return cl_stat; }
98100

99101
/*
100102
virtual void compute_vector(bigint *, double *) = 0;

0 commit comments

Comments
 (0)