TiledArray  0.7.0
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/madness.h>
30 #include <TiledArray/error.h>
31 
32 namespace TiledArray {
33 
35 
76  class Irrep {
77 
79  std::unique_ptr<unsigned int[]> data_;
80  unsigned int degree_;
82 
83  public:
84 
85  Irrep() = delete;
86  Irrep(Irrep&&) = default;
87  ~Irrep() = default;
88  Irrep& operator=(Irrep&&) = default;
89 
90  Irrep(const Irrep& other) :
91  data_(std::make_unique<unsigned int[]>(other.degree_ << 1)),
92  degree_(other.degree_)
93  {
94  std::copy_n(other.data_.get(), other.degree_ << 1, data_.get());
95  }
96 
98  Irrep(const std::initializer_list<unsigned int>& mu,
99  const std::initializer_list<unsigned int>& M) :
100  data_(std::make_unique<unsigned int[]>(M.size() << 1u)), degree_(M.size())
101  {
102  TA_ASSERT(mu.size() > 0ul);
103  TA_ASSERT(M.size() > 0ul);
104  TA_ASSERT(mu.size() <= M.size());
105 
106  // Fill the data of the irrep
107  std::fill(std::copy(mu.begin(), mu.end(), data_.get()), data_.get() + degree_, 0u);
108  std::copy(M.begin(), M.end(), data_.get() + degree_);
109 
110 #ifndef NDEBUG
111  {
112  const unsigned int* MADNESS_RESTRICT const M = data_.get() + degree_;
113  const unsigned int* MADNESS_RESTRICT const mu = data_.get();
114  unsigned int M_max = 0u;
115  unsigned int mu_sum = 0u;
116  for(unsigned int i = 0u; i < degree_; ++i) {
117  // Validate the partition data
118  if(i > 0u)
119  TA_ASSERT(mu[i] <= mu[i - 1u]);
120  mu_sum += mu[i];
121 
122  // Validate the Yamanouchi symbols data
123  TA_ASSERT(M[i] <= (M_max + 1u));
124  M_max = std::max(M[i], M_max);
125  TA_ASSERT(std::count(M, M + degree_, i + 1u) == mu[i]);
126  }
127 
128  // Check that the correct number of elements are in the partition data
129  TA_ASSERT(mu_sum == degree_);
130  }
131 #endif // NDEBUG
132  }
133 
135 
138  Irrep& operator=(const Irrep& other) {
139  if(degree_ != other.degree_) {
140  data_ = std::make_unique<unsigned int[]>(other.degree_ << 1);
141  degree_ = other.degree_;
142  }
143  std::copy_n(other.data_.get(), other.degree_ << 1, data_.get());
144 
145  return *this;
146  }
147 
149 
151  unsigned int degree() const { return degree_; }
152 
154 
157  const unsigned int* data() const { return data_.get(); }
158 
159  }; // class Irrep
160 
161 } // namespace TiledArray
162 
163 #endif // TILEDARRAY_IRREP_H__INCLUDED
Irrep of an symmetric group.
Definition: irrep.h:76
Irrep(const Irrep &other)
Definition: irrep.h:90
STL namespace.
KroneckerDeltaTile< _N >::numeric_type max(const KroneckerDeltaTile< _N > &arg)
size_t size(const DistArray< Tile, Policy > &a)
Definition: utils.h:49
#define TA_ASSERT(a)
Definition: error.h:107
Irrep & operator=(const Irrep &other)
Copy operator.
Definition: irrep.h:138
unsigned int degree() const
Irrep degree accessor.
Definition: irrep.h:151
DistArray< Tile, Policy > copy(const DistArray< Tile, Policy > &a)
Definition: utils.h:58
Irrep & operator=(Irrep &&)=default
Irrep(const std::initializer_list< unsigned int > &mu, const std::initializer_list< unsigned int > &M)
Irrep constructor.
Definition: irrep.h:98
const unsigned int * data() const
Data accessor.
Definition: irrep.h:157