source: ThirdParty/mpqc_open/src/lib/math/symmetry/rep.cc

Candidate_v1.6.1
Last change on this file was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 5.1 KB
Line 
1//
2// rep.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Edward Seidl <seidl@janed.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#include <util/misc/math.h>
29
30#include <math/symmetry/pointgrp.h>
31#include <util/misc/formio.h>
32
33using namespace std;
34using namespace sc;
35
36/////////////////////////////////////////////////////////////////////////
37
38SymRep::SymRep(int i) :
39 n(i)
40{
41 zero();
42}
43
44SymRep::SymRep(const SymmetryOperation& so) :
45 n(3)
46{
47 memset(d,0,sizeof(double)*25);
48 for (int i=0; i < 3; i++)
49 for (int j=0; j < 3; j++)
50 d[i][j] = so[i][j];
51}
52
53SymRep::~SymRep()
54{
55 n=0;
56}
57
58SymRep::operator SymmetryOperation() const
59{
60 if (n != 3) {
61 ExEnv::err0() << indent << "SymRep::operator SymmetryOperation(): "
62 << "trying to cast to symop when n == " << n << endl;
63 abort();
64 }
65
66 SymmetryOperation so;
67
68 for (int i=0; i < 3; i++)
69 for (int j=0; j < 3; j++)
70 so[i][j] = d[i][j];
71
72 return so;
73}
74
75SymRep
76SymRep::operate(const SymRep& r) const
77{
78 if (r.n != n) {
79 ExEnv::err0() << indent << "SymRep::operate(): dimensions don't match: "
80 << r.n << " != " << n << endl;
81 abort();
82 }
83
84 SymRep ret(n);
85
86 for (int i=0; i < n; i++) {
87 for (int j=0; j < n; j++) {
88 double t=0;
89 for (int k=0; k < n; k++)
90 t += r[i][k] * d[k][j];
91 ret[i][j] = t;
92 }
93 }
94
95 return ret;
96}
97
98SymRep
99SymRep::transform(const SymRep& r) const
100{
101 int i,j,k;
102
103 if (r.n != n) {
104 ExEnv::err0() << indent
105 << "SymRep::symm_transform(): dimensions don't match: "
106 << r.n << " != " << n << endl;
107 abort();
108 }
109
110 SymRep ret(n), foo(n);
111
112 // foo = r * d
113 for (i=0; i < n; i++) {
114 for (j=0; j < n; j++) {
115 double t=0;
116 for (k=0; k < n; k++)
117 t += r[i][k] * d[k][j];
118 foo[i][j] = t;
119 }
120 }
121
122 // ret = (r*d)*r~ = foo*r~
123 for (i=0; i < n; i++) {
124 for (j=0; j < n; j++) {
125 double t=0;
126 for (k=0; k < n; k++)
127 t += foo[i][k]*r[j][k];
128 ret[i][j]=t;
129 }
130 }
131
132 return ret;
133}
134
135void
136SymRep::sigma_h()
137{
138 unit();
139
140 if (n==3) {
141 d[2][2] = -1.0;
142 } else if (n==5) {
143 d[3][3] = d[4][4] = -1.0;
144 }
145}
146
147void
148SymRep::sigma_xz()
149{
150 unit();
151
152 if (n==2 || n==3 || n==4) {
153 d[1][1] = -1.0;
154 if (n==4)
155 d[2][2] = -1.0;
156 } else if (n==5) {
157 d[2][2] = d[4][4] = -1.0;
158 }
159}
160
161void
162SymRep::sigma_yz()
163{
164 unit();
165
166 if (n==2 || n==3 || n==4) {
167 d[0][0] = -1.0;
168 if (n==4)
169 d[3][3] = -1.0;
170 } else if (n==5) {
171 d[2][2] = d[3][3] = -1.0;
172 }
173}
174
175void
176SymRep::rotation(int nt)
177{
178 double theta = (nt) ? 2.0*M_PI/nt : 2.0*M_PI;
179 rotation(theta);
180}
181
182void
183SymRep::rotation(double theta)
184{
185 zero();
186
187 double ctheta = cos(theta);
188 double stheta = sin(theta);
189 double c2theta = cos(2*theta);
190 double s2theta = sin(2*theta);
191
192 switch (n) {
193 case 1:
194 d[0][0] = 1.0;
195 break;
196
197 case 3:
198 d[0][0] = ctheta;
199 d[0][1] = stheta;
200 d[1][0] = -stheta;
201 d[1][1] = ctheta;
202 d[2][2] = 1.0;
203 break;
204
205 case 4:
206 case 2:
207 d[0][0] = ctheta;
208 d[0][1] = stheta;
209 d[1][0] = -stheta;
210 d[1][1] = ctheta;
211
212 // this is ok since d is hardwired
213 d[2][2] = c2theta;
214 d[2][3] = -s2theta;
215 d[3][2] = s2theta;
216 d[3][3] = c2theta;
217 break;
218
219 case 5:
220 d[0][0] = 1.0;
221
222 d[1][1] = c2theta;
223 d[1][2] = s2theta;
224 d[2][1] = -s2theta;
225 d[2][2] = c2theta;
226
227 d[3][3] = ctheta;
228 d[3][4] = -stheta;
229 d[4][3] = stheta;
230 d[4][4] = ctheta;
231 break;
232
233 default:
234 ExEnv::err0() << indent << "SymRep::rotation(): n > 5 (" << n << ")\n";
235 abort();
236 }
237
238}
239
240void
241SymRep::c2_x()
242{
243 i();
244
245 if (n==2 || n==3 || n==4) {
246 d[0][0] = 1.0;
247 if (n==4)
248 d[3][3] = 1.0;
249 } else if (n==5) {
250 d[0][0] = d[1][1] = d[4][4] = 1.0;
251 }
252}
253
254void
255SymRep::c2_y()
256{
257 i();
258
259 if (n==2 || n==3 || n==4) {
260 d[1][1] = 1.0;
261 if (n==4)
262 d[2][2] = 1.0;
263 } else if (n==5) {
264 d[0][0] = d[1][1] = d[3][3] = 1.0;
265 }
266}
267
268
269void
270SymRep::print(ostream& os) const
271{
272 int i;
273
274 os << indent;
275 for (i=0; i < n; i++) os << scprintf("%11d",i+1);
276 os << endl;
277
278 for (i=0; i < n; i++) {
279 os << indent << scprintf("%3d ",i+1);
280 for (int j=0; j < n; j++)
281 os << scprintf(" %10.7f",d[i][j]);
282 os << endl;
283 }
284 os << endl;
285}
286
287/////////////////////////////////////////////////////////////////////////////
288
289// Local Variables:
290// mode: c++
291// c-file-style: "ETS"
292// End:
Note: See TracBrowser for help on using the repository browser.