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 |
|
---|
33 | using namespace std;
|
---|
34 | using namespace sc;
|
---|
35 |
|
---|
36 | /////////////////////////////////////////////////////////////////////////
|
---|
37 |
|
---|
38 | SymRep::SymRep(int i) :
|
---|
39 | n(i)
|
---|
40 | {
|
---|
41 | zero();
|
---|
42 | }
|
---|
43 |
|
---|
44 | SymRep::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 |
|
---|
53 | SymRep::~SymRep()
|
---|
54 | {
|
---|
55 | n=0;
|
---|
56 | }
|
---|
57 |
|
---|
58 | SymRep::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 |
|
---|
75 | SymRep
|
---|
76 | SymRep::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 |
|
---|
98 | SymRep
|
---|
99 | SymRep::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 |
|
---|
135 | void
|
---|
136 | SymRep::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 |
|
---|
147 | void
|
---|
148 | SymRep::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 |
|
---|
161 | void
|
---|
162 | SymRep::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 |
|
---|
175 | void
|
---|
176 | SymRep::rotation(int nt)
|
---|
177 | {
|
---|
178 | double theta = (nt) ? 2.0*M_PI/nt : 2.0*M_PI;
|
---|
179 | rotation(theta);
|
---|
180 | }
|
---|
181 |
|
---|
182 | void
|
---|
183 | SymRep::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 |
|
---|
240 | void
|
---|
241 | SymRep::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 |
|
---|
254 | void
|
---|
255 | SymRep::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 |
|
---|
269 | void
|
---|
270 | SymRep::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:
|
---|