Skip to content

Commit 528041b

Browse files
committed
Feature: add ModuleIO::write_libxc_r()
1 parent 516fb64 commit 528041b

File tree

9 files changed

+385
-16
lines changed

9 files changed

+385
-16
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ OBJS_IO=input_conv.o\
504504
write_dipole.o\
505505
td_current_io.o\
506506
write_wfc_r.o\
507+
write_libxc_r.o\
507508
output_log.o\
508509
output_mat_sparse.o\
509510
para_json.o\

source/module_esolver/esolver_fp.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "module_parameter/parameter.h"
99
#include "module_io/rhog_io.h"
1010
#include "module_io/cif_io.h"
11+
#include "module_io/write_libxc_r.h"
1112

1213
namespace ModuleESolver
1314
{
@@ -251,7 +252,19 @@ void ESolver_FP::after_scf(const int istep)
251252
&(GlobalC::ucell),
252253
this->pelec->pot->get_fixed_v());
253254
}
254-
}
255+
256+
if(PARAM.inp.out_xc_r[0]>=0)
257+
{
258+
ModuleIO::write_libxc_r(
259+
PARAM.inp.out_xc_r[0],
260+
XC_Functional::get_func_id(),
261+
this->pw_rhod->nrxx, // number of real-space grid
262+
GlobalC::ucell.omega, // volume of cell
263+
GlobalC::ucell.tpiba,
264+
&this->chr,
265+
this);
266+
}
267+
}
255268
}
256269

257270
void ESolver_FP::init_after_vc(const Input_para& inp, UnitCell& cell)

source/module_io/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ list(APPEND objects
2626
write_dipole.cpp
2727
td_current_io.cpp
2828
write_wfc_r.cpp
29+
write_libxc_r.cpp
2930
output_log.cpp
3031
para_json.cpp
3132
parse_args.cpp

source/module_io/cube_io.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ extern void write_cube(
4949
const int out_fermi = 1); // mohan add 2007-10-17
5050

5151

52+
// when MPI:
53+
// read file as order (ixy,iz) to data[ixy*nz+iz]
54+
// when serial:
55+
// read file as order (ixy,iz) to data[iz*nxy+ixy]
5256
extern void read_cube_core_match(
5357
std::ifstream &ifs,
5458
#ifdef __MPI
@@ -73,18 +77,30 @@ extern void read_cube_core_mismatch(
7377
const int ny_read,
7478
const int nz_read);
7579

80+
#ifdef __MPI
81+
// when MPI:
82+
// write data[ixy*nplane+iz*nld] to file as order (ixy,iz)
7683
extern void write_cube_core(
7784
std::ofstream &ofs_cube,
78-
#ifdef __MPI
7985
const int bz,
8086
const int nbz,
8187
const int nplane,
8288
const int startz_current,
83-
#endif
8489
const double*const data,
8590
const int nxy,
8691
const int nz,
92+
const int nld,
8793
const int n_data_newline);
94+
#else
95+
// when serial:
96+
// write data[iz*nxy+ixy] to file as order (ixy,iz)
97+
extern void write_cube_core(
98+
std::ofstream &ofs_cube,
99+
const double*const data,
100+
const int nxy,
101+
const int nz,
102+
const int n_data_newline);
103+
#endif
88104

89105
/**
90106
* @brief The trilinear interpolation method

source/module_io/read_input_item_output.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ void ReadInput::item_output()
7676
read_sync_bool(input.out_wfc_r);
7777
this->add_item(item);
7878
}
79+
{
80+
Input_Item item("out_xc_r");
81+
item.annotation = "if >=0, output the derivatives of exchange correlation in realspace, second parameter controls the precision";
82+
item.read_value = [](const Input_Item& item, Parameter& para) {
83+
size_t count = item.get_size();
84+
std::vector<int> out_xc_r(count); // create a placeholder vector
85+
std::transform(item.str_values.begin(), item.str_values.end(), out_xc_r.begin(), [](std::string s) { return std::stoi(s); });
86+
std::cout<<out_xc_r[0]<<"\t"<<out_xc_r[1]<<std::endl;
87+
// assign non-negative values to para.input.out_xc_r
88+
std::copy(out_xc_r.begin(), out_xc_r.end(), para.input.out_xc_r.begin());
89+
std::cout<<para.input.out_xc_r[0]<<"\t"<<para.input.out_xc_r[1]<<std::endl;
90+
};
91+
sync_intvec(input.out_xc_r, 2, -1);
92+
this->add_item(item);
93+
}
7994
{
8095
Input_Item item("printe");
8196
item.annotation = "Print out energy for each band for every printe steps";

source/module_io/write_cube.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void ModuleIO::write_cube(
127127
}
128128

129129
#ifdef __MPI
130-
ModuleIO::write_cube_core(ofs_cube, bz, nbz, nplane, startz_current, data, nx*ny, nz, 6);
130+
ModuleIO::write_cube_core(ofs_cube, bz, nbz, nplane, startz_current, data, nx*ny, nz, 1, 6);
131131
#else
132132
ModuleIO::write_cube_core(ofs_cube, data, nx*ny, nz, 6);
133133
#endif
@@ -140,28 +140,25 @@ void ModuleIO::write_cube(
140140
/// for cube file
141141
ofs_cube.close();
142142
}
143-
144-
return;
145143
}
146144

147145

146+
#ifdef __MPI
147+
148148
void ModuleIO::write_cube_core(
149149
std::ofstream &ofs_cube,
150-
#ifdef __MPI
151150
const int bz,
152151
const int nbz,
153152
const int nplane,
154153
const int startz_current,
155-
#endif
156154
const double*const data,
157155
const int nxy,
158156
const int nz,
157+
const int nld,
159158
const int n_data_newline)
160159
{
161160
ModuleBase::TITLE("ModuleIO", "write_cube_core");
162161

163-
#ifdef __MPI
164-
165162
const int my_rank = GlobalV::MY_RANK;
166163
const int my_pool = GlobalV::MY_POOL;
167164
const int rank_in_pool = GlobalV::RANK_IN_POOL;
@@ -176,7 +173,6 @@ void ModuleIO::write_cube_core(
176173

177174
// num_z: how many planes on processor 'ip'
178175
std::vector<int> num_z(nproc_in_pool, 0);
179-
180176
for (int iz = 0; iz < nbz; iz++)
181177
{
182178
const int ip = iz % nproc_in_pool;
@@ -230,7 +226,7 @@ void ModuleIO::write_cube_core(
230226
// mohan change to rho_save on 2012-02-10
231227
// because this can make our next restart calculation lead
232228
// to the same scf_thr as the one saved.
233-
zpiece[ixy] = data[ixy * nplane + iz - startz_current];
229+
zpiece[ixy] = data[ixy * nplane + (iz - startz_current) * nld];
234230
}
235231
}
236232
// case 2: > first part rho: send the rho to
@@ -239,7 +235,7 @@ void ModuleIO::write_cube_core(
239235
{
240236
for (int ixy = 0; ixy < nxy; ixy++)
241237
{
242-
zpiece[ixy] = data[ixy * nplane + iz - startz_current];
238+
zpiece[ixy] = data[ixy * nplane + (iz - startz_current) * nld];
243239
}
244240
MPI_Send(zpiece.data(), nxy, MPI_DOUBLE, 0, tag, POOL_WORLD);
245241
}
@@ -281,7 +277,18 @@ void ModuleIO::write_cube_core(
281277
/// for cube file
282278
}
283279
MPI_Barrier(MPI_COMM_WORLD);
284-
#else
280+
}
281+
282+
#else // #ifdef __MPI
283+
284+
void ModuleIO::write_cube_core(
285+
std::ofstream &ofs_cube,
286+
const double*const data,
287+
const int nxy,
288+
const int nz,
289+
const int n_data_newline)
290+
{
291+
ModuleBase::TITLE("ModuleIO", "write_cube_core");
285292
for (int ixy = 0; ixy < nxy; ixy++)
286293
{
287294
for (int iz = 0; iz < nz; iz++)
@@ -295,5 +302,6 @@ void ModuleIO::write_cube_core(
295302
}
296303
ofs_cube << "\n";
297304
}
298-
#endif
299-
}
305+
}
306+
307+
#endif // #ifdef __MPI

0 commit comments

Comments
 (0)