CASM  1.1.0
A Clusters Approach to Statistical Mechanics
SymGroupRep.cc
Go to the documentation of this file.
2 
3 #include <numeric>
4 
5 #include "casm/casm_io/Log.hh"
8 #include "casm/global/eigen.hh"
10 #include "casm/misc/CASM_math.hh"
11 #include "casm/misc/algorithm.hh"
12 #include "casm/symmetry/Orbit.hh"
16 
17 namespace CASM {
18 
20  : std::vector<SymOpRepresentation *>(RHS.size(), NULL) {
21  (*this) = RHS;
22 }
23 
24 //*******************************************************************************************
25 
27 
28 //*******************************************************************************************
29 
32  clear();
33  if (RHS.size() > 0 && has_valid_master() &&
34  master_group().size() != RHS.size()) {
35  throw std::runtime_error(
36  "Invalid assignment of SymGroupRep. Sizes are incompatible.\n");
37  }
38  resize(RHS.size(), NULL);
39  for (Index i = 0; i < RHS.size(); i++) {
40  if (RHS[i]) set_rep(i, *RHS[i]);
41  }
42  return *this;
43 }
44 
45 //*******************************************************************************************
46 
48  const SymGroupRepID &_rep_ID) {
49  m_master_group = &master;
50  if (_rep_ID.empty() || &(master.representation(_rep_ID)) != this) {
51  throw std::runtime_error(std::string(
52  "SymGroupRep::set_master_group() attempted to assign SymGroupRepID "
53  "that does not match the current SymGroupRep!\n"));
54  }
55  m_rep_ID = _rep_ID;
56  if (size() == 0)
57  std::vector<SymOpRepresentation *>::resize(master.size());
58  else if (size() == master.size()) {
59  for (Index i = 0; i < size(); i++) {
60  if (at(i)) at(i)->set_identifiers(master, m_rep_ID, i);
61  }
62  } else {
63  throw std::runtime_error(
64  std::string("SymGroupRep::set_master_group() passed new master whose "
65  "size is incompatible with the size\n") +
66  "of the current representation.\n");
67  }
68 }
69 
70 //*******************************************************************************************
71 
72 void SymGroupRep::set_rep(const SymOp &base_op,
73  const SymOpRepresentation &new_rep) {
74  if (!has_valid_master()) {
75  err_log() << "CRITICAL ERROR: In SymGroupRep::set_rep(), you are trying to "
76  "assign the representation of a SymOp whose factor_group is "
77  "not specified!\n"
78  << " Exiting...\n";
79  assert(0);
80  exit(1);
81  }
82  if (valid_index(base_op.index())) return set_rep(base_op.index(), new_rep);
83 
84  // else:
85  return set_rep(master_group().find_periodic(base_op), new_rep);
86 }
87 
88 //*******************************************************************************************
89 
91  const SymOpRepresentation &new_rep) {
92  if (!has_valid_master()) {
93  err_log() << "CRITICAL ERROR: In SymGroupRep::set_rep(), you are trying to "
94  "assign the representation of a SymOpRepresentation whose "
95  "factor_group is not specified!\n"
96  << " Exiting...\n";
97  assert(0);
98  exit(1);
99  }
100  if (valid_index(base_op.index()))
101  set_rep(base_op.index(), new_rep);
102  else {
103  err_log() << "CRITICAL ERROR: In SymGroupRep::set_rep(), you are trying to "
104  "assign the representation of a SymOpRepresentation whose "
105  "index is not specified!\n"
106  << " Exiting...\n";
107  assert(0);
108  exit(1);
109  }
110 }
111 
112 //*******************************************************************************************
113 
114 void SymGroupRep::set_rep(Index op_index, const SymOpRepresentation &new_rep) {
115  assert(valid_index(op_index) && op_index < size() &&
116  "In SymGroupRep::set_rep(), reference representation is improperly "
117  "initialized.");
118  if (at(op_index)) {
119  err_log() << "CRITICAL ERROR: In SymGroupRep::set_rep(), representation "
120  "already exists for operation "
121  << op_index << ".\n"
122  << " Exiting...\n";
123  assert(0);
124  exit(1);
125  }
126 
127  SymOpRepresentation *tcopy = new_rep.copy();
128  if (has_valid_master())
129  tcopy->set_identifiers(master_group(), m_rep_ID, op_index);
130 
131  // avoid doing this elsewhere in CASM
132  const_cast<SymOpRepresentation *&>(at(op_index)) = tcopy;
133 }
134 
135 //*******************************************************************************************
136 
138  for (Index i = 0; i < size(); i++) delete at(i);
139  std::vector<SymOpRepresentation *>::clear();
140 }
141 
142 //*******************************************************************************************
143 
145  return at(i)->MatrixXd();
146 }
147 
148 //*******************************************************************************************
149 
151  const SymOpRepresentation &op) const {
152  return at(op.index())->MatrixXd();
153 }
154 
155 //*******************************************************************************************
156 
158  return at(i)->permutation();
159 }
160 
161 //*******************************************************************************************
162 
164  const SymOpRepresentation &op) const {
165  return at(op.index())->permutation();
166 }
167 
168 //*******************************************************************************************
169 
170 //*******************************************************************************************
171 // Calculates new SymGroupRep that is the results of performing coordinate
172 // transformation specified by trans_mat The ROWS of trans_mat are the new basis
173 // vectors in terms of the old such that new_symrep_matrix = trans_mat *
174 // old_symrep_matrix * trans_mat.transpose();
176  const Eigen::MatrixXd &trans_mat) {
177  SymGroupRep new_rep(_rep.master_group());
178  if (!_rep.size()) return new_rep;
179  if (_rep[0] && !(_rep.MatrixXd(0))) {
180  err_log() << "CRITICAL ERROR: Trying to perform matrix transformation on a "
181  "non-matrix SymRep. Exiting...\n";
182  assert(0);
183  exit(1);
184  }
185  Eigen::MatrixXd rightmat;
186  rightmat =
187  trans_mat.transpose()
188  .jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV)
189  .solve(Eigen::MatrixXd::Identity(trans_mat.cols(), trans_mat.cols()))
190  .transpose();
191 
192  for (Index i = 0; i < _rep.size(); i++) {
193  if (!_rep[i]) continue;
194 
195  new_rep.set_rep(i,
196  SymMatrixXd(trans_mat * (*(_rep.MatrixXd(i))) * rightmat));
197  }
198  return new_rep;
199 }
200 
201 } // namespace CASM
SymGroupRep const & representation(SymGroupRepID i) const
Const access of alternate Representations of a SymGroup.
Definition: SymGroup.cc:717
SymGroupRep is an alternative representation of a SymGroup for something other than real space....
Definition: SymGroupRep.hh:31
SymGroupRep & operator=(const SymGroupRep &RHS)
explicit assignment operator Necessary because SymGroupRep directly manages heap-allocated SymOpRepre...
Definition: SymGroupRep.cc:30
const MasterSymGroup & master_group() const
Reference to MasterSymGroup for which this SymGroupRep is a group representation If a MasterSymGroup ...
Definition: SymGroupRep.hh:76
~SymGroupRep()
explicit destructor Necessary because SymGroupRep directly manages heap-allocated SymOpRepresentation...
Definition: SymGroupRep.cc:26
void set_rep(Index op_index, const SymOpRepresentation &new_rep)
Sets the representation of operation at entry 'op_index' of this group representation Throws if this ...
Definition: SymGroupRep.cc:114
SymGroupRepID m_rep_ID
rep_ID is unique identifier of a specific SymGroupRep instantiation
Definition: SymGroupRep.hh:157
bool has_valid_master() const
Returns true if this SymGroupRep has valid pointer to a MasterSymGroup.
Definition: SymGroupRep.hh:86
Eigen::MatrixXd const * MatrixXd(Index i) const
pointer to MatrixXd corresponding to SymOpRepresentation at entry 'i' of this SymGroupRep Returns nul...
Definition: SymGroupRep.cc:144
Permutation const * permutation(Index i) const
pointer to Permutation corresponding to SymOpRepresentation at entry 'i' of this SymGroupRep Returns ...
Definition: SymGroupRep.cc:157
SymGroupRep()=delete
void set_master_group(const MasterSymGroup &master, const SymGroupRepID &_rep_ID)
Assign ma.
Definition: SymGroupRep.cc:47
MasterSymGroup const * m_master_group
Pointer to the home_group that generated this SymGroupRep.
Definition: SymGroupRep.hh:160
Type-safe ID object for communicating and accessing Symmetry representation info.
bool empty() const
Returns true if SymGroupRepID has not been initialized with valid group_index or rep_index.
Generalized symmetry matrix representation for arbitrary dimension Can be used to describe applicatio...
Definition: SymMatrixXd.hh:26
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
SymOpRepresentation is the base class for anything describes a symmetry operation.
virtual SymOpRepresentation * copy() const =0
Make copy of Derived object through Base-class interface.
void set_identifiers(const MasterSymGroup &new_group, SymGroupRepID new_rep_ID)
Change m_master_group and determine op_index.
IdentitySymRepBuilder Identity()
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::MatrixXd MatrixXd
SymGroupRep coord_transformed_copy(SymGroupRep const &_rep, const Eigen::MatrixXd &trans_mat)
Make a copy of representation on vector space 'V' that is transformed into a representation on vector...
Definition: SymGroupRep.cc:175
bool valid_index(Index i)
Definition: definitions.cc:5
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Log & err_log()
Definition: Log.hh:426
Definition: stream_io.hh:24