irrep.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2015 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * justus
19  * Department of Chemistry, Virginia Tech
20  *
21  * irrep.h
22  * May 18, 2015
23  *
24  */
25 
26 #ifndef TILEDARRAY_IRREP_H__INCLUDED
27 #define TILEDARRAY_IRREP_H__INCLUDED
28 
29 #include <TiledArray/error.h>
31 
32 namespace TiledArray {
33 
35 
76 class Irrep {
78  std::unique_ptr<unsigned int[]>
79  data_;
80  unsigned int degree_;
82 
83  public:
84  Irrep() = delete;
85  Irrep(Irrep&&) = default;
86  ~Irrep() = default;
87  Irrep& operator=(Irrep&&) = default;
88 
89  Irrep(const Irrep& other)
90  : data_(std::make_unique<unsigned int[]>(other.degree_ << 1)),
91  degree_(other.degree_) {
92  std::copy_n(other.data_.get(), other.degree_ << 1, data_.get());
93  }
94 
96  Irrep(const std::initializer_list<unsigned int>& mu,
97  const std::initializer_list<unsigned int>& M)
98  : data_(std::make_unique<unsigned int[]>(M.size() << 1u)),
99  degree_(M.size()) {
100  TA_ASSERT(mu.size() > 0ul);
101  TA_ASSERT(M.size() > 0ul);
102  TA_ASSERT(mu.size() <= M.size());
103 
104  // Fill the data of the irrep
105  std::fill(std::copy(mu.begin(), mu.end(), data_.get()),
106  data_.get() + degree_, 0u);
107  std::copy(M.begin(), M.end(), data_.get() + degree_);
108 
109 #ifndef NDEBUG
110  {
111  const unsigned int* MADNESS_RESTRICT const M = data_.get() + degree_;
112  const unsigned int* MADNESS_RESTRICT const mu = data_.get();
113  unsigned int M_max = 0u;
114  unsigned int mu_sum = 0u;
115  for (unsigned int i = 0u; i < degree_; ++i) {
116  // Validate the partition data
117  if (i > 0u) TA_ASSERT(mu[i] <= mu[i - 1u]);
118  mu_sum += mu[i];
119 
120  // Validate the Yamanouchi symbols data
121  TA_ASSERT(M[i] <= (M_max + 1u));
122  M_max = std::max(M[i], M_max);
123  TA_ASSERT(std::count(M, M + degree_, i + 1u) == mu[i]);
124  }
125 
126  // Check that the correct number of elements are in the partition data
127  TA_ASSERT(mu_sum == degree_);
128  }
129 #endif // NDEBUG
130  }
131 
133 
136  Irrep& operator=(const Irrep& other) {
137  if (degree_ != other.degree_) {
138  data_ = std::make_unique<unsigned int[]>(other.degree_ << 1);
139  degree_ = other.degree_;
140  }
141  std::copy_n(other.data_.get(), other.degree_ << 1, data_.get());
142 
143  return *this;
144  }
145 
147 
149  unsigned int degree() const { return degree_; }
150 
152 
155  const unsigned int* data() const { return data_.get(); }
156 
157 }; // class Irrep
158 
159 } // namespace TiledArray
160 
161 #endif // TILEDARRAY_IRREP_H__INCLUDED
Irrep(Irrep &&)=default
Irrep of an symmetric group.
Definition: irrep.h:76
#define TA_ASSERT(EXPR,...)
Definition: error.h:39
Irrep(const std::initializer_list< unsigned int > &mu, const std::initializer_list< unsigned int > &M)
Irrep constructor.
Definition: irrep.h:96
KroneckerDeltaTile< _N >::numeric_type max(const KroneckerDeltaTile< _N > &arg)
Irrep(const Irrep &other)
Definition: irrep.h:89
const unsigned int * data() const
Data accessor.
Definition: irrep.h:155
Irrep & operator=(Irrep &&)=default
Irrep & operator=(const Irrep &other)
Copy operator.
Definition: irrep.h:136
unsigned int degree() const
Irrep degree accessor.
Definition: irrep.h:149