Skip to content

Commit b827591

Browse files
committed
1. add class Filter_Atom_Symmetry
1 parent d9f652e commit b827591

File tree

6 files changed

+116
-10
lines changed

6 files changed

+116
-10
lines changed

include/RI/physics/Exx.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class Exx
3434
const std::array<Tatom_pos,Ndim> &latvec,
3535
const std::array<Tcell,Ndim> &period);
3636

37+
void set_symmetry(
38+
const bool flag_symmetry,
39+
const std::map<std::pair<TA,TA>, std::set<TC>> &irreducible_sector);
40+
3741
void set_Cs(
3842
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
3943
const Tdata_real &threshold_C,

include/RI/physics/Exx.hpp

Lines changed: 13 additions & 0 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,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#pragma once
2+
3+
#include "../ri/Filter_Atom.h"
4+
#include "Symmetry_Filter.h"
5+
6+
namespace RI
7+
{
8+
9+
template<typename TA, typename TC, typename Tdata>
10+
class Filter_Atom_Symmetry: public Filter_Atom<TA, std::pair<TA, TC>>
11+
{
12+
public:
13+
using TAC = std::pair<TA, TC>;
14+
15+
Filter_Atom_Symmetry(
16+
const TC& period,
17+
const std::map<std::pair<TA,TA>, std::set<TC>>& irsec)
18+
:symmetry(period, irsec){}
19+
20+
virtual bool filter_for1(const Label::ab_ab& label, const TA& A1) const override
21+
{
22+
switch (label)
23+
{
24+
case Label::ab_ab::a0b0_a2b1: case Label::ab_ab::a0b0_a2b2:
25+
return !this->symmetry.is_I_in_irreducible_sector(A1);
26+
default:
27+
return false;
28+
}
29+
}
30+
virtual bool filter_for1(const Label::ab_ab& label, const TAC& A1) const override
31+
{
32+
switch (label)
33+
{
34+
case Label::ab_ab::a0b0_a1b1:
35+
return !this->symmetry.is_I_in_irreducible_sector(A1.first);
36+
case Label::ab_ab::a0b0_a1b2:
37+
return !this->symmetry.is_J_in_irreducible_sector(A1.first);
38+
default:
39+
return false;
40+
}
41+
}
42+
43+
virtual bool filter_for32(const Label::ab_ab& label, const TA& A1, const TAC& A2, const TAC& A3) const override
44+
{
45+
switch (label)
46+
{
47+
case Label::ab_ab::a0b0_a2b1: case Label::ab_ab::a0b0_a2b2:
48+
return !this->symmetry.in_irreducible_sector(A1, A3);
49+
default:
50+
return false;
51+
}
52+
}
53+
virtual bool filter_for32(const Label::ab_ab& label, const TAC& A1, const TA& A2, const TAC& A3) const override
54+
{
55+
switch (label)
56+
{
57+
case Label::ab_ab::a0b0_a1b2:
58+
return !this->symmetry.in_irreducible_sector(A3, A1);
59+
default:
60+
return false;
61+
}
62+
}
63+
virtual bool filter_for32(const Label::ab_ab& label, const TAC& A1, const TAC& A2, const TAC& A3) const override
64+
{
65+
switch (label)
66+
{
67+
case Label::ab_ab::a0b0_a1b1:
68+
return !this->symmetry.in_irreducible_sector(A1, A3);
69+
default:
70+
return false;
71+
}
72+
}
73+
74+
public: // private
75+
Symmetry_Filter<TA,TC,Tdata> symmetry;
76+
};
77+
78+
}

include/RI/symmetry/Symmetry_Filter.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1+
#pragma once
2+
3+
#include "../global/Array_Operator.h"
4+
15
#include <array>
26
#include <map>
37
#include <set>
4-
#include <tuple>
8+
59
#define NO_SEC_RETURN_TRUE if(this->irreducible_sector_.empty()) return true;
6-
#include "../global/Array_Operator.h"
10+
711
namespace RI
812
{
9-
using namespace Array_Operator;
10-
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
13+
template<typename TA, typename TC, typename Tdata>
1114
class Symmetry_Filter
1215
{
13-
using TC = std::array<Tcell, Ndim>;
1416
using TAC = std::pair<TA, TC>;
15-
1617
using TIJ = std::pair<TA, TA>;
1718
using TIJR = std::pair<TIJ, TC>;
1819
using Tsec = std::map<TIJ, std::set<TC>>;
19-
public:
20+
21+
public:
2022
Symmetry_Filter(const TC& period_in, const Tsec& irsec)
2123
:period(period_in), irreducible_sector_(irsec) {}
2224
bool in_irreducible_sector(const TA& Aa, const TAC& Ab) const
2325
{
2426
NO_SEC_RETURN_TRUE;
27+
using namespace Array_Operator;
2528
const TIJ& ap = { Aa, Ab.first };
2629
if (irreducible_sector_.find(ap) != irreducible_sector_.end())
2730
if (irreducible_sector_.at(ap).find(Ab.second % this->period) != irreducible_sector_.at(ap).end())
@@ -31,6 +34,7 @@ namespace RI
3134
bool in_irreducible_sector(const TAC& Aa, const TAC& Ab) const
3235
{
3336
NO_SEC_RETURN_TRUE;
37+
using namespace Array_Operator;
3438
const TC dR = (Ab.second - Aa.second) % this->period;
3539
const std::pair<TA, TA> ap = { Aa.first, Ab.first };
3640
if (irreducible_sector_.find(ap) != irreducible_sector_.end())
@@ -60,9 +64,12 @@ namespace RI
6064
{
6165
return { {I.first,J.first}, (J.second - I.second) % this->period };
6266
}
63-
private:
64-
const Tsec& irreducible_sector_;
67+
68+
public: // private:
6569
const TC& period;
70+
const Tsec& irreducible_sector_;
6671
};
6772

68-
}
73+
}
74+
75+
#undef NO_SEC_RETURN_TRUE

include/RI/symmetry/Symmetry_Rotation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#pragma once
2+
13
#include <RI/global/Tensor.h>
4+
25
namespace RI
36
{
47
namespace Sym

unittests/physics/Exx-test.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Exx_Test
1818

1919
RI::Exx<int,int,1,Tdata> exx;
2020
exx.set_parallel(MPI_COMM_WORLD, {{1,{0}},{2,{4}}}, {}, {1});
21+
exx.set_symmetry(false, {});
2122
exx.set_Cs({}, 1E-4);
2223
exx.set_Vs({}, 1E-4);
2324
exx.set_Ds({}, 1E-4);

0 commit comments

Comments
 (0)