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