ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
xc3_mock.h
Go to the documentation of this file.
1// I'm mocking FFT here because it is not possible to write
2// unit tests with FFT
3#include <fstream>
4
5namespace ModulePW
6{
7namespace
8{
9// Preserve the shared prefix and use zero for mock outputs without a
10// one-to-one counterpart between real- and reciprocal-space buffers.
11template <typename FPTYPE, typename InputType>
12void mock_real2recip(
13 const InputType *in,
14 std::complex<FPTYPE> *out,
15 const int nrxx,
16 const int nrecip,
17 const bool add,
18 const FPTYPE factor)
19{
20 for (int i = 0; i < nrecip; ++i)
21 {
22 const std::complex<FPTYPE> value = (i < nrxx) ? std::complex<FPTYPE>(in[i]) : std::complex<FPTYPE>(0.0, 0.0);
23 if (add)
24 {
25 out[i] += factor * value;
26 }
27 else
28 {
29 out[i] = value;
30 }
31 }
32}
33
34template <typename FPTYPE>
35void mock_recip2real(
36 const std::complex<FPTYPE> *in,
37 std::complex<FPTYPE> *out,
38 const int nrecip,
39 const int nrxx,
40 const bool add,
41 const FPTYPE factor)
42{
43 for (int i = 0; i < nrxx; ++i)
44 {
45 const std::complex<FPTYPE> value =
46 (i < nrecip) ? -ModuleBase::IMAG_UNIT * in[i] : std::complex<FPTYPE>(0.0, 0.0);
47 if (add)
48 {
49 out[i] += factor * value;
50 }
51 else
52 {
53 out[i] = value;
54 }
55 }
56}
57
58template <typename FPTYPE>
59void mock_recip2real(
60 const std::complex<FPTYPE> *in,
61 FPTYPE *out,
62 const int nrecip,
63 const int nrxx,
64 const bool add,
65 const FPTYPE factor)
66{
67 for (int i = 0; i < nrxx; ++i)
68 {
69 const FPTYPE value = (i < nrecip) ? (-ModuleBase::IMAG_UNIT * in[i]).real() : FPTYPE(0.0);
70 if (add)
71 {
72 out[i] += factor * value;
73 }
74 else
75 {
76 out[i] = value;
77 }
78 }
79}
80} // namespace
81
84
85template <typename FPTYPE>
87 const FPTYPE *in,
88 std::complex<FPTYPE> *out,
89 const bool add,
90 const FPTYPE factor) const
91{
92 mock_real2recip(in, out, nrxx, npw, add, factor);
93}
95 const double *in,
96 std::complex<double> *out,
97 bool add,
98 double factor) const;
99
100template <typename FPTYPE>
102 const std::complex<FPTYPE> *in,
103 std::complex<FPTYPE> *out,
104 const bool add,
105 const FPTYPE factor) const
106{
107 mock_real2recip(in, out, nrxx, npw, add, factor);
108}
109template void PW_Basis::real2recip<double>(
110 const std::complex<double> *in,
111 std::complex<double> *out,
112 const bool add,
113 const double factor) const;
114
115template <typename FPTYPE>
117 const std::complex<FPTYPE> *in,
118 std::complex<FPTYPE> *out,
119 const bool add,
120 const FPTYPE factor) const // in:(nz, ns) ; out(nplane,nx*ny)
121{
122 mock_recip2real(in, out, npw, nrxx, add, factor);
123}
124template void PW_Basis::recip2real(
125 const std::complex<double> *in,
126 std::complex<double> *out,
127 const bool add,
128 const double factor) const;
129
130template <typename FPTYPE>
132 const std::complex<FPTYPE> *in,
133 FPTYPE *out,
134 const bool add,
135 const FPTYPE factor) const
136{
137 mock_recip2real(in, out, npw, nrxx, add, factor);
138}
139template void PW_Basis::recip2real(
140 const std::complex<double> *in,
141 double *out,
142 const bool add,
143 const double factor) const;
144
145template <typename FPTYPE>
147 const std::complex<FPTYPE> *in,
148 std::complex<FPTYPE> *out,
149 const int ik,
150 const bool add,
151 const FPTYPE factor) const // in:(nz, ns) ; out(nplane,nx*ny)
152{
153 mock_recip2real(in, out, npwk[ik], nrxx, add, factor);
154}
155template void PW_Basis_K::recip2real(
156 const std::complex<double> *in,
157 std::complex<double> *out,
158 const int ik,
159 const bool add,
160 const double factor) const;
161
162ModuleBase::Vector3<double> PW_Basis_K::getgpluskcar(int, int) const
163{
164 ModuleBase::Vector3<double> x = {1, 2, 3};
165 return x;
166}
167
168template <typename FPTYPE, typename Device>
170 const Device *ctx,
171 const std::complex<FPTYPE> *in,
172 std::complex<FPTYPE> *out,
173 const int ik,
174 const bool add,
175 const FPTYPE factor) const // in:(nplane,nx*ny) ; out(nz, ns)
176{
177 mock_real2recip(in, out, nrxx, npwk[ik], add, factor);
178}
179template <typename FPTYPE, typename Device>
181 const Device *ctx,
182 const std::complex<FPTYPE> *in,
183 std::complex<FPTYPE> *out,
184 const int ik,
185 const bool add,
186 const FPTYPE factor) const
187{
188 mock_recip2real(in, out, npwk[ik], nrxx, add, factor);
189}
190
192 const base_device::DEVICE_CPU *ctx,
193 const std::complex<double> *in,
194 std::complex<double> *out,
195 const int ik,
196 const bool add,
197 const double factor) const;
199 const base_device::DEVICE_CPU *ctx,
200 const std::complex<double> *in,
201 std::complex<double> *out,
202 const int ik,
203 const bool add,
204 const double factor) const;
205#if __CUDA || __ROCM
207 const base_device::DEVICE_GPU *ctx,
208 const std::complex<double> *in,
209 std::complex<double> *out,
210 const int ik,
211 const bool add,
212 const double factor) const;
213
215 const base_device::DEVICE_GPU *ctx,
216 const std::complex<double> *in,
217 std::complex<double> *out,
218 const int ik,
219 const bool add,
220 const double factor) const;
221#endif
222
223void PW_Basis::initgrids(double, ModuleBase::Matrix3, double) {};
224void PW_Basis::distribute_r() {};
226 double,
227 ModuleBase::Matrix3,
228 int,
229 int,
230 int) {};
231
234} // namespace ModulePW
235
236namespace ModuleBase
237{
238void WARNING_QUIT(const std::string &file, const std::string &description)
239{
240 std::cout << " " << file << " warning : " << description << std::endl;
241 exit(1);
242}
243void WARNING(const std::string &file, const std::string &description) {};
244
245void Matrix3::Identity() {};
246
247IntArray::IntArray(int, int) {};
248IntArray::~IntArray() {};
249
250void TITLE(const std::string &class_function_name, bool disable) {};
251void TITLE(const std::string &class_name, const std::string &function_name, bool disable) {};
252
253} // namespace ModuleBase
254
257
258Charge::Charge() {};
259Charge::~Charge() {};
260
263
266Sep_Cell::Sep_Cell() noexcept {}
267Sep_Cell::~Sep_Cell() noexcept {}
268
269namespace unitcell
270{
271void cal_ux(UnitCell &ucell, const int nspin)
272{
273 ucell.magnet.lsign_ = false;
274
275 ucell.magnet.ux_[0] = 0;
276 ucell.magnet.ux_[1] = 1;
277 ucell.magnet.ux_[2] = 2;
278
279 ucell.magnet.lsign_ = true;
280};
281} // namespace unitcell
282
283namespace Parallel_Reduce
284{
286template <typename T>
287void reduce_all(T &object) {};
288template <typename T>
289void reduce_all(T *object, const int n) {};
290template <typename T>
291void reduce_pool(T &object) {};
292template <typename T>
293void reduce_pool(T *object, const int n) {};
294
295template <>
296void Parallel_Reduce::reduce_pool<double>(double &object)
297{
298#ifdef __MPI
299 double swap = object;
300 MPI_Allreduce(&swap, &object, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
301#endif
302 return;
303}
304template void reduce_all<double>(double &object);
305template void reduce_all<double>(double *object, const int n);
306template void reduce_pool<float>(float &object);
307template void reduce_pool<float>(float *object, const int n);
308template void reduce_pool<double>(double *object, const int n);
309} // namespace Parallel_Reduce
~Charge()
Definition charge.cpp:41
Charge()
Definition charge.cpp:36
bool lsign_
lsign_
Definition magnetism.h:56
double ux_[3]
ux_
Definition magnetism.h:53
Magnetism()
Constructor.
Definition magnetism.cpp:8
~Magnetism()
Destructor.
Definition magnetism.cpp:16
3x3 matrix and related mathamatical operations
Definition matrix3.h:15
void real_to_recip(const Device *ctx, const std::complex< FPTYPE > *in, std::complex< FPTYPE > *out, const int ik, const bool add=false, const FPTYPE factor=1.0) const
Definition xc3_mock.h:169
PW_Basis_K()
Definition pw_basis_k.cpp:12
void recip2real(const std::complex< FPTYPE > *in, FPTYPE *out, const int ik, const bool add=false, const FPTYPE factor=1.0) const
transform reciprocal space to real space
Definition pw_transform_k.cpp:216
~PW_Basis_K()
Definition pw_basis_k.cpp:17
void recip_to_real(const Device *ctx, const std::complex< FPTYPE > *in, std::complex< FPTYPE > *out, const int ik, const bool add=false, const FPTYPE factor=1.0) const
Definition xc3_mock.h:180
int * npwk
Definition pw_basis_k.h:77
ModuleBase::Vector3< double > getgpluskcar(const int ik, const int igl) const
Definition pw_basis_k.cpp:399
int nrxx
Definition pw_basis.h:127
void real2recip(const FPTYPE *in, std::complex< FPTYPE > *out, const bool add=false, const FPTYPE factor=1.0) const
Transform real-valued real-space data to reciprocal-space (gamma-only or non-gamma).
Definition pw_transform.cpp:150
int npw
Definition pw_basis.h:122
PW_Basis()
Definition pw_basis.cpp:11
virtual void distribute_r()
distribute real-space grids to different processors
Definition pw_distributer.cpp:11
virtual void initgrids(const double lat0_in, const ModuleBase::Matrix3 latvec_in, const double gridecut)
Definition pw_init.cpp:23
void recip2real(const std::complex< FPTYPE > *in, FPTYPE *out, const bool add=false, const FPTYPE factor=1.0) const
Transform reciprocal-space to real-valued real-space (gamma-only or non-gamma).
Definition pw_transform.cpp:381
virtual ~PW_Basis()
Definition pw_basis.cpp:23
SepPot()
Definition symm_rho_soc_test.cpp:39
~SepPot()
Definition symm_rho_soc_test.cpp:40
~Sep_Cell() noexcept
Definition symm_rho_soc_test.cpp:42
Sep_Cell() noexcept
Definition symm_rho_soc_test.cpp:41
Provide the basic information about unitcell.
Definition unitcell.h:16
~UnitCell()
Definition symm_rho_soc_test.cpp:36
Magnetism magnet
magnetism Yu Liu 2021-07-03
Definition unitcell.h:170
UnitCell()
Definition symm_rho_soc_test.cpp:35
#define complex
Definition elpa_new.h:28
#define T
Definition exp.cpp:237
int4 i[880]
Definition sincos.cpp:28
double x[440]
Definition sincos.cpp:28
Definition clebsch_gordan_coeff.cpp:8
void WARNING_QUIT(const std::string &, const std::string &)
Combine the functions of WARNING and QUIT.
Definition test_delley.cpp:15
const std::complex< double > IMAG_UNIT(0.0, 1.0)
void WARNING(const std::string &file, const std::string &description)
Print out warning information in warning.log file.
Definition tool_quit_no_exit.cpp:8
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
Definition pw_op.cpp:3
Definition parallel_reduce.h:12
void reduce_all(T &object)
reduce in all process
Definition depend_mock.cpp:14
void reduce_pool< double >(double &object)
Definition depend_mock.cpp:20
void reduce_pool(T &object)
Definition depend_mock.cpp:15
void reduce_all(double &v, const ParaWorld &world)
Definition para_mpi_func.cpp:155
Free functions for extracting atom/orbital info from Atom array.
Definition bcast_cell.cpp:8
void cal_ux(UnitCell &ucell, const int nspin)
Calculate ux for the unit cell.
Definition cal_ux.cpp:18
file(GLOB ATen_CORE_SRCS "*.cpp") set(ATen_CPU_SRCS $
Definition CMakeLists.txt:1