Skip to content

Commit b9b2c6f

Browse files
committed
Merge branch 'filter'
2 parents d54f831 + c9456c0 commit b9b2c6f

File tree

19 files changed

+535
-35
lines changed

19 files changed

+535
-35
lines changed

include/RI/global/Tensor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Tensor
4545
inline T& operator() (const std::size_t i0, const std::size_t i1, const std::size_t i2, const std::size_t i3) const;
4646

4747
Tensor transpose() const;
48+
Tensor dagger() const;
4849

4950
// ||d||_p = (|d_1|^p+|d_2|^p+...)^{1/p}
5051
// if(p==std::numeric_limits<double>::max()) ||d||_max = max_i |d_i|

include/RI/global/Tensor.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ Tensor<T> Tensor<T>::transpose() const
178178
return t;
179179
}
180180

181+
template<typename T>
182+
Tensor<T> Tensor<T>::dagger() const
183+
{
184+
assert(this->shape.size() == 2);
185+
Tensor<T> t({ this->shape[1], this->shape[0] });
186+
for (std::size_t i0 = 0; i0 < this->shape[0]; ++i0)
187+
for (std::size_t i1 = 0; i1 < this->shape[1]; ++i1)
188+
t(i1, i0) = std::conj((*this)(i0, i1));
189+
return t;
190+
}
191+
181192
template<typename T>
182193
Global_Func::To_Real_t<T> Tensor<T>::norm(const double p) const
183194
{

include/RI/parallel/Parallel_LRI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Parallel_LRI
4949
virtual const std::vector<TAC>& get_list_Ab01(const TA &Aa01, const TAC &Aa2) const =0;
5050
virtual const std::vector<TAC>& get_list_Ab2 (const TA &Aa01, const TAC &Aa2, const TAC &Ab01) const =0;
5151

52+
virtual ~Parallel_LRI()=default;
53+
5254
struct List_A
5355
{
5456
std::vector<TA > a01;

include/RI/physics/Exx.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <mpi.h>
1414
#include <array>
1515
#include <map>
16+
#include <set>
1617

1718
namespace RI
1819
{
@@ -34,6 +35,10 @@ class Exx
3435
const std::array<Tatom_pos,Ndim> &latvec,
3536
const std::array<Tcell,Ndim> &period);
3637

38+
void set_symmetry(
39+
const bool flag_symmetry,
40+
const std::map<std::pair<TA,TA>, std::set<TC>> &irreducible_sector);
41+
3742
void set_Cs(
3843
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
3944
const Tdata_real &threshold_C,
@@ -75,9 +80,11 @@ class Exx
7580
const std::array<std::string,5> &save_names_suffix={"","","","",""}); // "Cs","Vs","Ds","dCRs","dVRs"
7681

7782
std::map<TA, std::map<TAC, Tensor<Tdata>>> Hs;
83+
std::array<std::array< std::map<TA, std::map<TAC, Tensor<Tdata>>> ,2>,Npos> dHs;
84+
std::array<std::array< std::map<TA, std::map<TAC, Tensor<Tdata>>> ,Npos>,Npos> dHRs;
7885
Tdata energy = 0;
7986
std::array<std::map<TA,Tdata>,Ndim> force;
80-
Tensor<Tdata> stress;
87+
Tensor<Tdata> stress = Tensor<Tdata>({Npos, Npos});
8188

8289
Exx_Post_2D<TA,TC,Tdata> post_2D;
8390

@@ -98,6 +105,14 @@ class Exx
98105
};
99106
Flag_Finish flag_finish;
100107

108+
struct Flag_Save_Result
109+
{
110+
bool Hs=true;
111+
bool dHs=false;
112+
bool dHRs=false;
113+
};
114+
Flag_Save_Result flag_save_result;
115+
101116
MPI_Comm mpi_comm;
102117
std::map<TA,Tatom_pos> atoms_pos;
103118
std::array<Tatom_pos,Ndim> latvec;

include/RI/physics/Exx.hpp

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../ri/Cell_Nearest.h"
1010
#include "../ri/Label.h"
1111
#include "../global/Map_Operator.h"
12+
#include "./symmetry/Filter_Atom_Symmetry.h"
1213

1314
#include <cassert>
1415

@@ -35,6 +36,18 @@ void Exx<TA,Tcell,Ndim,Tdata>::set_parallel(
3536
this->post_2D.set_parallel(this->mpi_comm, this->atoms_pos, this->period);
3637
}
3738

39+
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
40+
void Exx<TA,Tcell,Ndim,Tdata>::set_symmetry(
41+
const bool flag_symmetry,
42+
const std::map<std::pair<TA,TA>, std::set<TC>> &irreducible_sector)
43+
{
44+
if(flag_symmetry)
45+
this->lri.filter_atom = std::make_shared<Filter_Atom_Symmetry<TA,TC,Tdata>>(
46+
this->period, irreducible_sector);
47+
else
48+
this->lri.filter_atom = std::make_shared<Filter_Atom<TA,TAC>>();
49+
}
50+
3851
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
3952
void Exx<TA,Tcell,Ndim,Tdata>::set_Cs(
4053
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
@@ -214,6 +227,9 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_Hs(
214227
this->energy = this->post_2D.cal_energy(
215228
this->post_2D.saves["Ds_"+save_names_suffix[2]],
216229
this->post_2D.set_tensors_map2(this->Hs) );
230+
231+
if(!this->flag_save_result.Hs)
232+
this->Hs.clear();
217233
}
218234

219235
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
@@ -234,7 +250,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_force(
234250
std::map<TA,Tdata> force_ipos;
235251

236252
{
237-
std::map<TA,std::map<TAC,Tensor<Tdata>>> dHs;
253+
this->dHs[ipos][0].clear();
238254

239255
this->lri.data_ab_name[Label::ab::a ] = "dCs_"+std::to_string(ipos)+"_"+save_names_suffix[3];
240256
this->lri.data_ab_name[Label::ab::a0b0] = "Vs_"+save_names_suffix[1];
@@ -243,13 +259,13 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_force(
243259
this->lri.cal_loop3(
244260
{Label::ab_ab::a0b0_a1b1,
245261
Label::ab_ab::a0b0_a1b2,},
246-
dHs,
262+
this->dHs[ipos][0],
247263
-1.0);
248264

249265
this->lri.cal_loop3(
250266
{Label::ab_ab::a0b0_a2b1,
251267
Label::ab_ab::a0b0_a2b2},
252-
dHs,
268+
this->dHs[ipos][0],
253269
1.0);
254270

255271
this->lri.data_ab_name[Label::ab::a ] = "Cs_"+save_names_suffix[0];
@@ -258,55 +274,61 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_force(
258274
this->lri.cal_loop3(
259275
{Label::ab_ab::a0b0_a2b2,
260276
Label::ab_ab::a0b0_a2b1},
261-
dHs,
277+
this->dHs[ipos][0],
262278
1.0);
263279

264280
this->post_2D.cal_force(
265281
this->post_2D.saves["Ds_"+save_names_suffix[2]],
266-
this->post_2D.set_tensors_map2(std::move(dHs)),
282+
this->post_2D.set_tensors_map2(this->dHs[ipos][0]),
267283
true,
268284
force_ipos );
269285

270-
// mul(D)
271-
// this->Fs[ipos] = this->post_2D.cal_F(dHs);
272-
// this->stress[ipos] = this->post_2D.cal_sttress(dHs);
273-
// this->Fs[ipos][I] = \sum_J \sum_{i,j} dHs(i,j) * D(i,j)
286+
//mul(D)
287+
//this->Fs[ipos] = this->post_2D.cal_F(dHs);
288+
//this->stress[ipos] = this->post_2D.cal_sttress(dHs);
289+
//this->Fs[ipos][I] = \sum_J \sum_{i,j} dHs(i,j) * D(i,j)
290+
291+
if(!this->flag_save_result.dHs)
292+
this->dHs[ipos][0].clear();
274293
}
275294

276295
{
277-
std::map<TA,std::map<TAC,Tensor<Tdata>>> dHs;
296+
this->dHs[ipos][1].clear();
278297

279298
this->lri.cal_loop3(
280299
{Label::ab_ab::a0b0_a2b2,
281300
Label::ab_ab::a0b0_a1b2},
282-
dHs,
283-
1.0);
301+
this->dHs[ipos][1],
302+
-1.0);
284303

285304
this->lri.data_ab_name[Label::ab::a0b0] = "Vs_"+save_names_suffix[1];
286305
this->lri.data_ab_name[Label::ab::b ] = "dCs_"+std::to_string(ipos)+"_"+save_names_suffix[3];
287306

288307
this->lri.cal_loop3(
289308
{Label::ab_ab::a0b0_a1b1,
290309
Label::ab_ab::a0b0_a2b1},
291-
dHs,
292-
1.0);
310+
this->dHs[ipos][1],
311+
-1.0);
293312

294313
this->lri.cal_loop3(
295314
{Label::ab_ab::a0b0_a1b2,
296315
Label::ab_ab::a0b0_a2b2},
297-
dHs,
298-
-1.0);
316+
this->dHs[ipos][1],
317+
1.0);
299318

300319
this->post_2D.cal_force(
301320
this->post_2D.saves["Ds_"+save_names_suffix[2]],
302-
this->post_2D.set_tensors_map2(std::move(dHs)),
321+
this->post_2D.set_tensors_map2(this->dHs[ipos][1]),
303322
false,
304323
force_ipos );
305324

306-
// mul(D)
307-
// this->Fs[ipos] -= this->post_2D.cal_F(dHs);
308-
// this->stress[ipos] -= this->post_2D.cal_sttress(dHs);
309-
// this->Fs[ipos][J] = \sum_I \sum_{i,j} dHs(i,j) * D(i,j)
325+
//mul(D)
326+
//this->Fs[ipos] -= this->post_2D.cal_F(dHs);
327+
//this->stress[ipos] -= this->post_2D.cal_sttress(dHs);
328+
//this->Fs[ipos][J] = \sum_I \sum_{i,j} dHs(i,j) * D(i,j)
329+
330+
if(!this->flag_save_result.dHs)
331+
this->dHs[ipos][1].clear();
310332
}
311333
this->force[ipos] = this->post_2D.reduce_force(force_ipos);
312334
} // end for(ipos)
@@ -331,7 +353,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_stress(
331353
for(std::size_t ipos0=0; ipos0<Npos; ++ipos0)
332354
for(std::size_t ipos1=0; ipos1<Npos; ++ipos1)
333355
{
334-
std::map<TA,std::map<TAC,Tensor<Tdata>>> dHs;
356+
this->dHRs[ipos0][ipos1].clear();
335357

336358
this->lri.data_ab_name[Label::ab::a ] = "dCRs_"+std::to_string(ipos0)+"_"+std::to_string(ipos1)+"_"+save_names_suffix[3];
337359
this->lri.data_ab_name[Label::ab::a0b0] = "Vs_"+save_names_suffix[1];
@@ -340,7 +362,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_stress(
340362
this->lri.cal_loop3(
341363
{Label::ab_ab::a0b0_a1b1,
342364
Label::ab_ab::a0b0_a2b1},
343-
dHs,
365+
this->dHRs[ipos0][ipos1],
344366
1.0);
345367

346368
this->lri.data_ab_name[Label::ab::a ] = "Cs_"+save_names_suffix[0];
@@ -349,7 +371,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_stress(
349371
this->lri.cal_loop3(
350372
{Label::ab_ab::a0b0_a1b1,
351373
Label::ab_ab::a0b0_a2b1},
352-
dHs,
374+
this->dHRs[ipos0][ipos1],
353375
1.0);
354376

355377
this->lri.data_ab_name[Label::ab::a0b0] = "Vs_"+save_names_suffix[1];
@@ -358,12 +380,15 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_stress(
358380
this->lri.cal_loop3(
359381
{Label::ab_ab::a0b0_a1b1,
360382
Label::ab_ab::a0b0_a2b1},
361-
dHs,
383+
this->dHRs[ipos0][ipos1],
362384
1.0);
363385

364-
this->stress(ipos0,ipos1) = post_2D.cal_energy(
365-
this->post_2D.saves["Ds_"+save_names_suffix[2]],
366-
this->post_2D.set_tensors_map2(dHs));
386+
this->stress(ipos0,ipos1) = post_2D.cal_energy(
387+
this->post_2D.saves["Ds_"+save_names_suffix[2]],
388+
this->post_2D.set_tensors_map2(this->dHRs[ipos0][ipos1]));
389+
390+
if(!this->flag_save_result.dHRs)
391+
this->dHRs[ipos0][ipos1].clear();
367392
}
368393
}
369394

include/RI/physics/Exx_Post_2D.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void Exx_Post_2D<TA,TC,Tdata>::cal_force(
9696
if(flag_add)
9797
force[E_map_A.first] += E_map_B.second;
9898
else
99-
force[std::get<0>(E_map_B.first)] -= E_map_B.second;
99+
force[std::get<0>(E_map_B.first)] += E_map_B.second;
100100
}
101101

102102
template<typename TA, typename TC, typename Tdata>

include/RI/physics/GW.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <mpi.h>
1414
#include <array>
1515
#include <map>
16+
#include <set>
1617

1718
namespace RI
1819
{
@@ -34,6 +35,10 @@ class G0W0
3435
const std::array<Tatom_pos,Ndim> &latvec,
3536
const std::array<Tcell,Ndim> &period);
3637

38+
void set_symmetry(
39+
const bool flag_symmetry,
40+
const std::map<std::pair<TA,TA>, std::set<TC>> &irreducible_sector);
41+
3742
void set_Cs(
3843
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
3944
const Tdata_real &threshold_C);

include/RI/physics/GW.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "GW.h"
88
#include "../ri/Label.h"
9+
#include "./symmetry/Filter_Atom_Symmetry.h"
910

1011
namespace RI
1112
{
@@ -30,6 +31,18 @@ void G0W0<TA,Tcell,Ndim,Tdata>::set_parallel(
3031
// this->post_2D.set_parallel(this->mpi_comm, this->atoms_pos, this->period);
3132
}
3233

34+
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
35+
void G0W0<TA,Tcell,Ndim,Tdata>::set_symmetry(
36+
const bool flag_symmetry,
37+
const std::map<std::pair<TA,TA>, std::set<TC>> &irreducible_sector)
38+
{
39+
if(flag_symmetry)
40+
this->lri.filter_atom = std::make_shared<Filter_Atom_Symmetry<TA,TC,Tdata>>(
41+
this->period, irreducible_sector);
42+
else
43+
this->lri.filter_atom = std::make_shared<Filter_Atom<TA,TAC>>();
44+
}
45+
3346
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
3447
void G0W0<TA,Tcell,Ndim,Tdata>::set_Cs(
3548
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,

include/RI/physics/RPA.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <mpi.h>
1313
#include <array>
1414
#include <map>
15+
#include <set>
1516

1617
namespace RI
1718
{
@@ -20,7 +21,8 @@ template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
2021
class RPA
2122
{
2223
public:
23-
using TAC = std::pair<TA,std::array<Tcell,Ndim>>;
24+
using TC = std::array<Tcell,Ndim>;
25+
using TAC = std::pair<TA,TC>;
2426
using Tdata_real = Global_Func::To_Real_t<Tdata>;
2527
using Tatom_pos = std::array<double,Ndim>; // tmp
2628

@@ -30,6 +32,10 @@ class RPA
3032
const std::array<Tatom_pos,Ndim> &latvec,
3133
const std::array<Tcell,Ndim> &period);
3234

35+
void set_symmetry(
36+
const bool flag_symmetry,
37+
const std::map<std::pair<TA,TA>, std::set<TC>> &irreducible_sector);
38+
3339
void set_Cs(
3440
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
3541
const Tdata_real &threshold_C);

include/RI/physics/RPA.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "RPA.h"
99
#include "../ri/Label.h"
1010
#include "../global/Map_Operator.h"
11+
#include "./symmetry/Filter_Atom_Symmetry.h"
1112

1213
#include <cassert>
1314

@@ -27,6 +28,18 @@ void RPA<TA,Tcell,Ndim,Tdata>::set_parallel(
2728
this->flag_finish.stru = true;
2829
}
2930

31+
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
32+
void RPA<TA,Tcell,Ndim,Tdata>::set_symmetry(
33+
const bool flag_symmetry,
34+
const std::map<std::pair<TA,TA>, std::set<TC>> &irreducible_sector)
35+
{
36+
if(flag_symmetry)
37+
this->lri.filter_atom = std::make_shared<Filter_Atom_Symmetry<TA,TC,Tdata>>(
38+
this->period, irreducible_sector);
39+
else
40+
this->lri.filter_atom = std::make_shared<Filter_Atom<TA,TAC>>();
41+
}
42+
3043
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
3144
void RPA<TA,Tcell,Ndim,Tdata>::set_Cs(
3245
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,

0 commit comments

Comments
 (0)