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