ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
LRI_CV_Tools.hpp
Go to the documentation of this file.
1//=======================
2// AUTHOR : Peize Lin
3// DATE : 2022-10-24
4//=======================
5
6#ifndef LRI_CV_TOOLS_HPP
7#define LRI_CV_TOOLS_HPP
8
9#include "../../source_base/mathzone.h"
10#include "Inverse_Matrix.h"
11#include "LRI_CV_Tools.h"
12#include "RI_Util.h"
13
14#include <RI/global/Global_Func-1.h>
15#include <RI/global/Map_Operator.h>
16#include "../../source_pw/module_pwdft/global.h"
17
18template <typename Tdata>
19RI::Tensor<Tdata> LRI_CV_Tools::cal_I(const RI::Tensor<Tdata>& m) {
21 I.input(m);
23 return I.output();
24}
25
26template <typename Tdata>
27std::vector<std::vector<RI::Tensor<Tdata>>>
28 LRI_CV_Tools::cal_I(const std::vector<std::vector<RI::Tensor<Tdata>>>& ms) {
30 I.input(ms);
32 return I.output({ms[0][0].shape[0], ms[1][0].shape[0]},
33 {ms[0][0].shape[1], ms[0][1].shape[1]});
34}
35
36template <typename Tdata>
37RI::Tensor<Tdata> LRI_CV_Tools::transform_Rm(const RI::Tensor<Tdata>& V) {
38 return V.transpose();
39}
40
41template <typename Tdata>
42std::array<RI::Tensor<Tdata>, 3>
43 LRI_CV_Tools::transform_Rm(const std::array<RI::Tensor<Tdata>, 3>& dV) {
44 return std::array<RI::Tensor<Tdata>, 3>{-dV[0].transpose(),
45 -dV[1].transpose(),
46 -dV[2].transpose()};
47}
48
49template <typename Tdata>
50bool LRI_CV_Tools::exist(const RI::Tensor<Tdata>& V) {
51 return !V.empty();
52}
53
54template <typename T, std::size_t N>
55bool LRI_CV_Tools::exist(const std::array<T, N>& dV) {
56 for (size_t i = 0; i < 3; ++i)
57 if (!dV[i].empty())
58 return true;
59 return false;
60}
61
62template <typename Tdata>
63RI::Tensor<Tdata> LRI_CV_Tools::mul1(const RI::Tensor<Tdata>& t1,
64 const RI::Tensor<Tdata>& t2) {
65 const size_t sa0 = t1.shape[0], sa1 = t2.shape[0], sl0 = t2.shape[1],
66 sl1 = t2.shape[2];
67 return (t1 * t2.reshape({sa1, sl0 * sl1})).reshape({sa0, sl0, sl1});
68}
69template <typename T>
70std::array<T, 3> LRI_CV_Tools::mul1(const std::array<T, 3>& t1, const T& t2) {
71 return std::array<T, 3>{mul1(t1[0], t2), mul1(t1[1], t2), mul1(t1[2], t2)};
72}
73/*
74template<typename T>
75std::array<T,3> LRI_CV_Tools::mul1(
76 const T &t1,
77 const std::array<T,3> &t2)
78{
79 return std::array<T,3>{
80 mul1(t1,t2[0]), mul1(t1,t2[1]), mul1(t1,t2[2]) };
81}
82*/
83
84template <typename Tdata>
85std::vector<RI::Tensor<Tdata>>
86 LRI_CV_Tools::mul2(const std::vector<std::vector<RI::Tensor<Tdata>>>& mat,
87 const std::vector<RI::Tensor<Tdata>>& vec) {
88 const size_t sa0 = vec[0].shape[0], sa1 = vec[1].shape[0],
89 sl0 = vec[0].shape[1], sl1 = vec[0].shape[2];
90 const RI::Tensor<Tdata> vec0 = vec[0].reshape({sa0, sl0 * sl1}),
91 vec1 = vec[1].reshape({sa1, sl0 * sl1});
92 return std::vector<RI::Tensor<Tdata>>{
93 (mat[0][0] * vec0 + mat[0][1] * vec1).reshape({sa0, sl0, sl1}),
94 (mat[1][0] * vec0 + mat[1][1] * vec1).reshape({sa1, sl0, sl1})};
95}
96/*
97template<typename T1, typename T2>
98std::array<T2,3> LRI_CV_Tools::mul2(
99 const std::array<T1,3> &t1,
100 const T2 &t2)
101{
102 return std::array<T2,3>{
103 mul2(t1[0],t2), mul2(t1[1],t2), mul2(t1[2],t2) };
104}
105*/
106template <typename T1, typename T2>
107std::array<T2, 3> LRI_CV_Tools::mul2(const T1& t1,
108 const std::array<T2, 3>& t2) {
109 return std::array<T2, 3>{mul2(t1, t2[0]), mul2(t1, t2[1]), mul2(t1, t2[2])};
110}
111
112template <typename T>
113RI::Tensor<T> LRI_CV_Tools::mul2(const T& t1, const RI::Tensor<T>& t2) {
114 return t1 * t2;
115}
116
117template <typename T, typename TkeyA, typename TkeyB, typename Tvalue>
118std::map<TkeyA, std::map<TkeyB, Tvalue>>
120 const std::map<TkeyA, std::map<TkeyB, Tvalue>>& t2) {
121 std::map<TkeyA, std::map<TkeyB, Tvalue>> res;
122 for (const auto& outerPair: t2) {
123 const TkeyA keyA = outerPair.first;
124 const std::map<TkeyB, Tvalue>& innerMap = outerPair.second;
125 std::map<TkeyB, Tvalue> newInnerMap;
126
127 for (const auto& innerPair: innerMap) {
128 const TkeyB keyB = innerPair.first;
129 const Tvalue value = innerPair.second;
130 newInnerMap[keyB] = mul2(t1, value);
131 }
132
133 res[keyA] = newInnerMap;
134 }
135
136 return res;
137}
138
139/*
140template<typename T, std::size_t N>
141std::array<T,N> LRI_CV_Tools::operator-(const std::array<T,N> &v1, const
142std::array<T,N> &v2)
143{
144 std::array<T,N> v;
145 for(std::size_t i=0; i<N; ++i)
146 v[i] = v1[i] - v2[i];
147 return v;
148}
149template<typename T>
150std::vector<T> LRI_CV_Tools::operator-(const std::vector<T> &v1, const
151std::vector<T> &v2)
152{
153 assert(v1.size()==v2.size());
154 std::vector<T> v(v1.size());
155 for(std::size_t i=0; i<v.size(); ++i)
156 v[i] = v1[i] - v2[i];
157 return v;
158}
159*/
160template <typename T, std::size_t N>
161std::vector<std::array<T, N>>
162 LRI_CV_Tools::minus(const std::vector<std::array<T, N>>& v1,
163 const std::vector<std::array<T, N>>& v2) {
164 assert(v1.size() == v2.size());
165 std::vector<std::array<T, N>> v(v1.size());
166 for (std::size_t i = 0; i < v.size(); ++i)
167 for (std::size_t j = 0; j < N; ++j)
168 v[i][j] = v1[i][j] - v2[i][j];
169 return v;
170}
171
172template <typename TkeyA, typename TkeyB, typename Tvalue, std::size_t N>
173std::map<TkeyA, std::map<TkeyB, std::array<Tvalue, N>>> LRI_CV_Tools::minus(
174 std::map<TkeyA, std::map<TkeyB, std::array<Tvalue, N>>>& v1,
175 std::map<TkeyA, std::map<TkeyB, std::array<Tvalue, N>>>& v2) {
176 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N> v1_order
177 = change_order(std::move(v1));
178 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N> v2_order
179 = change_order(std::move(v2));
180 auto dv = minus(v1_order, v2_order);
181 return change_order(std::move(dv));
182}
183
184template <typename TkeyA, typename TkeyB, typename Tvalue, std::size_t N>
185std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N> LRI_CV_Tools::minus(
186 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N>& v1,
187 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N>& v2) {
188 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N> dv;
189 for (size_t i = 0; i != N; ++i)
190 dv[i] = minus(v1[i], v2[i]);
191 return dv;
192}
193
194template <typename TkeyA, typename TkeyB, typename Tvalue>
195std::map<TkeyA, std::map<TkeyB, Tvalue>>
196 LRI_CV_Tools::minus(std::map<TkeyA, std::map<TkeyB, Tvalue>>& v1,
197 std::map<TkeyA, std::map<TkeyB, Tvalue>>& v2) {
198 assert(v1.size() == v2.size());
199 using namespace RI::Map_Operator;
200 using namespace RI::Array_Operator;
201
202 std::map<TkeyA, std::map<TkeyB, Tvalue>> dv;
203 auto it1 = v1.begin();
204 auto it2 = v2.begin();
205 while (it1 != v1.end() && it2 != v2.end()) {
206 assert(it1->first == it2->first);
207 const TkeyA& keyA = it1->first;
208 const std::map<TkeyB, Tvalue>& map1 = it1->second;
209 const std::map<TkeyB, Tvalue>& map2 = it2->second;
210 dv[keyA] = map1 - map2;
211 ++it1;
212 ++it2;
213 }
214 return dv;
215}
216
217template <typename T, std::size_t N>
218std::vector<std::array<T, N>>
219 LRI_CV_Tools::add(const std::vector<std::array<T, N>>& v1,
220 const std::vector<std::array<T, N>>& v2) {
221 assert(v1.size() == v2.size());
222 std::vector<std::array<T, N>> v(v1.size());
223 for (std::size_t i = 0; i < v.size(); ++i)
224 for (std::size_t j = 0; j < N; ++j)
225 v[i][j] = v1[i][j] + v2[i][j];
226 return v;
227}
228
229template <typename TkeyA, typename TkeyB, typename Tvalue, std::size_t N>
230std::map<TkeyA, std::map<TkeyB, std::array<Tvalue, N>>> LRI_CV_Tools::add(
231 std::map<TkeyA, std::map<TkeyB, std::array<Tvalue, N>>>& v1,
232 std::map<TkeyA, std::map<TkeyB, std::array<Tvalue, N>>>& v2) {
233 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N> v1_order
234 = change_order(std::move(v1));
235 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N> v2_order
236 = change_order(std::move(v2));
237 auto dv = add(v1_order, v2_order);
238 return change_order(std::move(dv));
239}
240
241template <typename TkeyA, typename TkeyB, typename Tvalue, std::size_t N>
242std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N> LRI_CV_Tools::add(
243 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N>& v1,
244 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N>& v2) {
245 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N> dv;
246 for (size_t i = 0; i != N; ++i)
247 dv[i] = add(v1[i], v2[i]);
248 return dv;
249}
250
251template <typename TkeyA, typename TkeyB, typename Tvalue>
252std::map<TkeyA, std::map<TkeyB, Tvalue>>
253 LRI_CV_Tools::add(std::map<TkeyA, std::map<TkeyB, Tvalue>>& v1,
254 std::map<TkeyA, std::map<TkeyB, Tvalue>>& v2) {
255 assert(v1.size() == v2.size());
256 using namespace RI::Map_Operator;
257 using namespace RI::Array_Operator;
258
259 std::map<TkeyA, std::map<TkeyB, Tvalue>> dv;
260 auto it1 = v1.begin();
261 auto it2 = v2.begin();
262 while (it1 != v1.end() && it2 != v2.end()) {
263 assert(it1->first == it2->first);
264 const TkeyA& keyA = it1->first;
265 const std::map<TkeyB, Tvalue>& map1 = it1->second;
266 const std::map<TkeyB, Tvalue>& map2 = it2->second;
267 dv[keyA] = map1 + map2;
268 ++it1;
269 ++it2;
270 }
271 return dv;
272}
273
274template <typename T, std::size_t N>
275std::array<T, N> LRI_CV_Tools::negative(const std::array<T, N>& v_in) {
276 std::array<T, N> v_out;
277 for (std::size_t i = 0; i < N; ++i)
278 v_out[i] = -v_in[i];
279 return v_out;
280}
281
282template <typename Tdata>
283RI::Tensor<Tdata> LRI_CV_Tools::transpose12(const RI::Tensor<Tdata>& c_in) {
284 RI::Tensor<Tdata> c_out({c_in.shape[0], c_in.shape[2], c_in.shape[1]});
285 for (size_t i0 = 0; i0 < c_in.shape[0]; ++i0)
286 for (size_t i1 = 0; i1 < c_in.shape[1]; ++i1)
287 for (size_t i2 = 0; i2 < c_in.shape[2]; ++i2)
288 c_out(i0, i2, i1) = c_in(i0, i1, i2);
289 return c_out;
290}
291
292template <typename T, std::size_t N>
293std::array<T, N> LRI_CV_Tools::transpose12(const std::array<T, N>& c_in) {
294 std::array<T, N> c_out;
295 for (size_t i = 0; i < N; ++i)
296 c_out[i] = transpose12(c_in[i]);
297 return c_out;
298}
299
300template <typename T, std::size_t N>
301std::array<std::vector<T>, N>
302 LRI_CV_Tools::change_order(std::vector<std::array<T, N>>&& ds_in) {
303 std::array<std::vector<T>, N> ds;
304 for (int ix = 0; ix < N; ++ix) {
305 ds[ix].resize(ds_in.size());
306 for (int iv = 0; iv < ds_in.size(); ++iv)
307 ds[ix][iv] = std::move(ds_in[iv][ix]);
308 }
309 return ds;
310}
311
312template <typename T, std::size_t N>
313std::vector<std::array<T, N>>
314 LRI_CV_Tools::change_order(std::array<std::vector<T>, N>&& ds_in) {
315 std::vector<std::array<T, N>> ds(ds_in[0].size());
316 for (int ix = 0; ix < N; ++ix) {
317 assert(ds.size() == ds_in[ix].size());
318 for (int iv = 0; iv < ds.size(); ++iv)
319 ds[iv][ix] = std::move(ds_in[ix][iv]);
320 }
321 return ds;
322}
323
324template <typename T, std::size_t N>
325std::array<std::vector<std::vector<T>>, N> LRI_CV_Tools::change_order(
326 std::vector<std::vector<std::array<T, N>>>&& ds_in) {
327 std::array<std::vector<std::vector<T>>, N> ds;
328 for (int ix = 0; ix < N; ++ix) {
329 ds[ix].resize(ds_in.size());
330 for (int i0 = 0; i0 < ds_in.size(); ++i0) {
331 ds[ix][i0].resize(ds_in[i0].size());
332 for (int i1 = 0; i1 < ds_in[i0].size(); ++i1)
333 ds[ix][i0][i1] = std::move(ds_in[i0][i1][ix]);
334 }
335 }
336 return ds;
337}
338
339template <typename TkeyA, typename TkeyB, typename Tvalue, std::size_t N>
340std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N>
342 std::map<TkeyA, std::map<TkeyB, std::array<Tvalue, N>>>&& ds_in) {
343 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N> ds;
344 for (auto& ds_A: ds_in)
345 for (auto& ds_B: ds_A.second)
346 for (int ix = 0; ix < N; ++ix)
347 ds[ix][ds_A.first][ds_B.first] = std::move(ds_B.second[ix]);
348 return ds;
349}
350
351template <typename TkeyA, typename TkeyB, typename Tvalue, std::size_t N>
352std::map<TkeyA, std::map<TkeyB, std::array<Tvalue, N>>>
354 std::array<std::map<TkeyA, std::map<TkeyB, Tvalue>>, N>&& ds_in) {
355 std::map<TkeyA, std::map<TkeyB, std::array<Tvalue, N>>> ds;
356 for (int ix = 0; ix < N; ++ix)
357 for (auto& ds_A: ds_in[ix])
358 for (auto& ds_B: ds_A.second)
359 ds[ds_A.first][ds_B.first][ix] = std::move(ds_B.second);
360 return ds;
361}
362
363template <typename Tcell>
364std::array<Tcell, 3> LRI_CV_Tools::cal_latvec_range(const double& rcut_times,
365 const UnitCell &ucell,
366 const std::vector<double>& orb_cutoff) {
367 double Rcut_max = 0;
368 for(int T=0; T<ucell.ntype; ++T)
369 Rcut_max = std::max(Rcut_max, orb_cutoff[T]);
371 std::array<ModuleBase::Vector3<double>,3>{ucell.a1, ucell.a2, ucell.a3});
372 const ModuleBase::Vector3<double> latvec_times = Rcut_max * rcut_times / (proj * ucell.lat0);
373 const ModuleBase::Vector3<Tcell> latvec_times_ceil = {static_cast<Tcell>(std::ceil(latvec_times.x)),
374 static_cast<Tcell>(std::ceil(latvec_times.y)),
375 static_cast<Tcell>(std::ceil(latvec_times.z))};
376 const ModuleBase::Vector3<Tcell> period = 2 * latvec_times_ceil + ModuleBase::Vector3<Tcell>{1,1,1};
377 return std::array<Tcell,3>{period.x, period.y, period.z};
378}
379
380template<typename TA, typename Tcell, typename Tdata>
381std::map<int,std::map<int,std::map<Abfs::Vector3_Order<double>,RI::Tensor<Tdata>>>>
383 const UnitCell &ucell,
384 const std::map<TA,std::map<std::pair<TA,std::array<Tcell,3>>,RI::Tensor<Tdata>>> &CVs)
385{
386 std::map<int,std::map<int,std::map<Abfs::Vector3_Order<double>,RI::Tensor<Tdata>>>> CVws;
387 for(const auto &CVs_A : CVs)
388 {
389 const TA iat0 = CVs_A.first;
390 const int it0 = ucell.iat2it[iat0];
391 const int ia0 = ucell.iat2ia[iat0];
392 const ModuleBase::Vector3<double> tau0 = ucell.atoms[it0].tau[ia0];
393 for(const auto &CVs_B : CVs_A.second)
394 {
395 const TA iat1 = CVs_B.first.first;
396 const int it1 = ucell.iat2it[iat1];
397 const int ia1 = ucell.iat2ia[iat1];
398 const std::array<int,3> &cell1 = CVs_B.first.second;
399 const ModuleBase::Vector3<double> tau1 = ucell.atoms[it1].tau[ia1];
400 const Abfs::Vector3_Order<double> R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*ucell.latvec);
401 CVws[it0][it1][R_delta] = CVs_B.second;
402 }
403 }
404 return CVws;
405}
406
407template <typename TA, typename Tcell, typename Tdata>
408std::map<int, std::map<int, std::map<Abfs::Vector3_Order<double>, std::array<RI::Tensor<Tdata>, 3>>>> LRI_CV_Tools::
409 get_dCVws(const UnitCell& ucell,
410 const std::map<TA, std::map<std::pair<TA, std::array<Tcell, 3>>, std::array<RI::Tensor<Tdata>, 3>>>& dCVs)
411{
412 std::map<int, std::map<int, std::map<Abfs::Vector3_Order<double>, std::array<RI::Tensor<Tdata>, 3>>>> dCVws;
413 for (const auto& dCVs_A: dCVs)
414 {
415 const TA iat0 = dCVs_A.first;
416 const int it0 = ucell.iat2it[iat0];
417 const int ia0 = ucell.iat2ia[iat0];
418 const ModuleBase::Vector3<double> tau0 = ucell.atoms[it0].tau[ia0];
419 for (const auto& dCVs_B: dCVs_A.second)
420 {
421 const TA iat1 = dCVs_B.first.first;
422 const int it1 = ucell.iat2it[iat1];
423 const int ia1 = ucell.iat2ia[iat1];
424 const std::array<int, 3>& cell1 = dCVs_B.first.second;
425 const ModuleBase::Vector3<double> tau1 = ucell.atoms[it1].tau[ia1];
426 const Abfs::Vector3_Order<double> R_delta
427 = -tau0 + tau1 + (RI_Util::array3_to_Vector3(cell1) * ucell.latvec);
428 dCVws[it0][it1][R_delta] = dCVs_B.second;
429 }
430 }
431 return dCVws;
432}
433
434template <typename T, std::size_t N>
435void LRI_CV_Tools::init_elem(std::array<RI::Tensor<T>, N>& data,
436 const size_t ndim0,
437 const size_t ndim1) {
438 for (size_t i = 0; i < N; ++i) {
439 data[i] = RI::Tensor<T>({ndim0, ndim1});
440 }
441}
442
443template <typename T, std::size_t N>
444void LRI_CV_Tools::add_elem(std::array<T, N>& data,
445 const T& val,
446 const T& frac) {
447 for (size_t i = 0; i < N; ++i)
448 data[i] += frac * val;
449}
450
451template <typename T, std::size_t N>
452void LRI_CV_Tools::add_elem(std::array<RI::Tensor<T>, N>& data,
453 const int lmp,
454 const int lmq,
455 const std::array<T, N>& val,
456 const T& frac) {
457 for (size_t i = 0; i < N; ++i) {
458 data[i](lmp, lmq) += frac * val[i];
459 }
460}
461
462template <typename T, std::size_t N>
463void LRI_CV_Tools::add_elem(std::array<RI::Tensor<T>, N>& data,
464 const int lmp0,
465 const int lmq0,
466 const std::array<RI::Tensor<T>, N>& val,
467 const int lmp1,
468 const int lmq1,
469 const T& frac) {
470 for (size_t i = 0; i < N; ++i) {
471 data[i](lmp0, lmq0) += frac * val[i](lmp1, lmq1);
472 }
473}
474
475template <typename Tout, typename Tin>
476RI::Tensor<Tout> LRI_CV_Tools::convert(RI::Tensor<Tin>&& data) {
477 return RI::Global_Func::convert<Tout>(data);
478}
479
480template <typename Tout, typename Tin, std::size_t N>
481std::array<RI::Tensor<Tout>, N>
482 LRI_CV_Tools::convert(std::array<RI::Tensor<Tin>, N>&& data) {
483 std::array<RI::Tensor<Tout>, N> out;
484 for (size_t i = 0; i != N; ++i)
485 out[i] = RI::Global_Func::convert<Tout>(data[i]);
486 return out;
487}
488
489// template <typename T>
490// RI::Tensor<T> LRI_CV_Tools::check_zero(RI::Tensor<T>&& data) {
491// RI::Tensor<T> result(data.shape);
492
493// const std::size_t rows = data.shape[0];
494// const std::size_t cols = data.shape[1];
495
496// for (std::size_t i = 0; i < rows; ++i) {
497// for (std::size_t j = 0; j < cols; ++j) {
498// result(i, j) = LRI_CV_Tools::check_zero(data(i, j));
499// }
500// }
501
502// return result;
503// }
504
505// template <typename T, std::size_t N>
506// std::array<RI::Tensor<T>, N>
507// LRI_CV_Tools::check_zero(std::array<RI::Tensor<T>, N>&& data) {
508// std::array<RI::Tensor<T>, N> result;
509
510// for (size_t i = 0; i != N; ++i)
511// result[i] = LRI_CV_Tools::check_zero(std::move(data[i]));
512
513// return result;
514// }
515
516
517// dMRs[ipos0][ipos1] = \nabla_{ipos0} M R_{ipos1}
518template<typename TA, typename TC, typename Tdata>
519std::array<std::array<std::map<TA,std::map<std::pair<TA,TC>,RI::Tensor<Tdata>>>,3>,3>
521 const UnitCell &ucell,
522 const std::array<std::map<TA,std::map<std::pair<TA,TC>,RI::Tensor<Tdata>>>,3> &dMs)
523{
524 auto get_R_delta = [&](const TA &iat0, const std::pair<TA,TC> &A1) -> std::array<Tdata,3>
525 {
526 const TA iat1 = A1.first;
527 const TC &cell1 = A1.second;
528 const int it0 = ucell.iat2it[iat0];
529 const int ia0 = ucell.iat2ia[iat0];
530 const int it1 = ucell.iat2it[iat1];
531 const int ia1 = ucell.iat2ia[iat1];
532 const ModuleBase::Vector3<double> tau0 = ucell.atoms[it0].tau[ia0];
533 const ModuleBase::Vector3<double> tau1 = ucell.atoms[it1].tau[ia1];
534 const Abfs::Vector3_Order<double> R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*ucell.latvec);
535 return std::array<Tdata,3>{R_delta.x, R_delta.y, R_delta.z};
536 };
537 constexpr int Npos = 3;
538 std::array<std::array<std::map<TA,std::map<std::pair<TA,TC>,RI::Tensor<Tdata>>>,Npos>,Npos> dMRs;
539 for(int ipos0=0; ipos0<Npos; ++ipos0)
540 {
541 for(int ipos1=0; ipos1<Npos; ++ipos1)
542 {
543 for(const auto &dMs_A : dMs[ipos0])
544 {
545 const TA iat0 = dMs_A.first;
546 for(const auto &dMs_B : dMs_A.second)
547 {
548 const std::pair<TA,TC> A1 = dMs_B.first;
549 const RI::Tensor<Tdata> &dM = dMs_B.second;
550 const std::array<Tdata,3> R_delta = get_R_delta(iat0, A1);
551 dMRs[ipos0][ipos1][iat0][A1] = dM * R_delta[ipos1];
552 }
553 }
554 }
555 }
556 return dMRs;
557}
558
559#endif
Definition abfs-vector3_order.h:16
std::vector< ModuleBase::Vector3< double > > tau
Definition atom_spec.h:36
Definition Inverse_Matrix.h:13
void cal_inverse(const Method &method)
Definition Inverse_Matrix.hpp:15
void input(const RI::Tensor< Tdata > &m)
Definition Inverse_Matrix.hpp:63
RI::Tensor< Tdata > output() const
Definition Inverse_Matrix.hpp:117
static ModuleBase::Vector3< T > latvec_projection(const std::array< ModuleBase::Vector3< T >, 3 > &latvec)
Definition mathzone.h:167
3 elements vector
Definition vector3.h:22
T x
Definition vector3.h:24
T y
Definition vector3.h:25
T z
Definition vector3.h:26
Definition unitcell.h:16
int *& iat2it
Definition unitcell.h:47
Atom * atoms
Definition unitcell.h:18
double & lat0
Definition unitcell.h:28
ModuleBase::Matrix3 & latvec
Definition unitcell.h:35
int & ntype
Definition unitcell.h:45
ModuleBase::Vector3< double > & a2
Definition unitcell.h:36
ModuleBase::Vector3< double > & a3
Definition unitcell.h:36
int *& iat2ia
Definition unitcell.h:48
ModuleBase::Vector3< double > & a1
Definition unitcell.h:36
#define N
Definition exp.cpp:24
#define T
Definition exp.cpp:237
std::vector< std::array< T, N > > add(const std::vector< std::array< T, N > > &v1, const std::vector< std::array< T, N > > &v2)
Definition LRI_CV_Tools.hpp:219
std::map< int, std::map< int, std::map< Abfs::Vector3_Order< double >, RI::Tensor< Tdata > > > > get_CVws(const UnitCell &ucell, const std::map< TA, std::map< std::pair< TA, std::array< Tcell, 3 > >, RI::Tensor< Tdata > > > &CVs)
Definition LRI_CV_Tools.hpp:382
std::array< std::vector< T >, N > change_order(std::vector< std::array< T, N > > &&ds_in)
Definition LRI_CV_Tools.hpp:302
RI::Tensor< Tdata > transpose12(const RI::Tensor< Tdata > &c_in)
Definition LRI_CV_Tools.hpp:283
std::map< int, std::map< int, std::map< Abfs::Vector3_Order< double >, std::array< RI::Tensor< Tdata >, 3 > > > > get_dCVws(const UnitCell &ucell, const std::map< TA, std::map< std::pair< TA, std::array< Tcell, 3 > >, std::array< RI::Tensor< Tdata >, 3 > > > &dCVs)
Definition LRI_CV_Tools.hpp:409
std::vector< RI::Tensor< Tdata > > mul2(const std::vector< std::vector< RI::Tensor< Tdata > > > &mat, const std::vector< RI::Tensor< Tdata > > &vec)
Definition LRI_CV_Tools.hpp:86
std::array< Tcell, 3 > cal_latvec_range(const double &rcut_times, const UnitCell &ucell, const std::vector< double > &orb_cutoff)
Definition LRI_CV_Tools.hpp:364
RI::Tensor< Tout > convert(RI::Tensor< Tin > &&data)
Definition LRI_CV_Tools.hpp:476
std::vector< std::array< T, N > > minus(const std::vector< std::array< T, N > > &v1, const std::vector< std::array< T, N > > &v2)
Definition LRI_CV_Tools.hpp:162
void init_elem(Tdata &data, const size_t ndim0, const size_t ndim1)
Definition LRI_CV_Tools.h:178
void add_elem(Tdata &data, const Tdata &val, const Tdata &frac)
Definition LRI_CV_Tools.h:186
RI::Tensor< Tdata > mul1(const RI::Tensor< Tdata > &t1, const RI::Tensor< Tdata > &t2)
Definition LRI_CV_Tools.hpp:63
std::array< int, 3 > TC
Definition LRI_CV_Tools.h:132
std::array< std::array< std::map< TA, std::map< std::pair< TA, TC >, RI::Tensor< Tdata > > >, 3 >, 3 > cal_dMRs(const UnitCell &ucell, const std::array< std::map< TA, std::map< std::pair< TA, TC >, RI::Tensor< Tdata > > >, 3 > &dMs)
Definition LRI_CV_Tools.hpp:520
RI::Tensor< Tdata > transform_Rm(const RI::Tensor< Tdata > &V)
Definition LRI_CV_Tools.hpp:37
bool exist(const RI::Tensor< Tdata > &V)
Definition LRI_CV_Tools.hpp:50
RI::Tensor< Tdata > cal_I(const RI::Tensor< Tdata > &m)
Definition LRI_CV_Tools.hpp:19
std::array< T, N > negative(const std::array< T, N > &v_in)
Definition LRI_CV_Tools.hpp:275
ModuleBase::Vector3< Tcell > array3_to_Vector3(const std::array< Tcell, 3 > &v)
Definition RI_Util.h:38