PSCF v1.2
SpaceSymmetry.h
1#ifndef PRDC_SPACE_SYMMETRY_H
2#define PRDC_SPACE_SYMMETRY_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/math/IntVec.h>
12#include <util/math/Rational.h>
13#include <util/containers/FMatrix.h>
14#include <util/containers/FArray.h>
15#include <util/format/Int.h>
16
17#include <iostream>
18
19namespace Pscf {
20namespace Prdc {
21
22 using namespace Util;
23
24 template <int D> class SpaceSymmetry;
25
26 // Non-member function declarations
27
36 template <int D>
37 bool operator == (const SpaceSymmetry<D>& A, const SpaceSymmetry<D>& B);
38
47 template <int D>
48 bool operator != (const SpaceSymmetry<D>& A, const SpaceSymmetry<D>& B);
49
58 template <int D>
59 SpaceSymmetry<D>
60 operator * (const SpaceSymmetry<D>& A, const SpaceSymmetry<D>& B);
61
73 template <int D>
74 IntVec<D> operator * (const SpaceSymmetry<D>& S, const IntVec<D>& V);
75
87 template <int D>
88 IntVec<D> operator * (const IntVec<D>& V, const SpaceSymmetry<D>& S);
89
98 template <int D>
99 std::ostream& operator << (std::ostream& out, const SpaceSymmetry<D>& A);
100
109 template <int D>
110 std::istream& operator >> (std::istream& in, SpaceSymmetry<D>& A);
111
137 template <int D>
138 class SpaceSymmetry
139 {
140
141 public:
142
145
148
155
159 SpaceSymmetry(const SpaceSymmetry<D>& other);
160
165
169 void normalize();
170
182 void shiftOrigin(Translation const & origin);
183
188
193
197 int determinant() const;
198
205 int& R(int i, int j);
206
213 int R(int i, int j) const;
214
220 Rational& t(int i);
221
227 Rational t(int i) const;
228
229 // Static method
230
234 static const SpaceSymmetry<D>& identity();
235
236 private:
237
245 Rotation R_;
246
250 Translation t_;
251
252 // Static member variables
253
255 static SpaceSymmetry<D> identity_;
256
258 static bool hasIdentity_;
259
261 static void makeIdentity();
262
263 // friends:
264
265 friend
266 bool operator == <> (const SpaceSymmetry<D>& A,
267 const SpaceSymmetry<D>& B);
268
269 friend
270 bool operator != <> (const SpaceSymmetry<D>& A,
271 const SpaceSymmetry<D>& B);
272
273 friend
276 const SpaceSymmetry<D>& B);
277
278 friend
280 const SpaceSymmetry<D>& S);
281
282 friend
284
285 friend
286 std::ostream& operator << <> (std::ostream& out,
287 const SpaceSymmetry<D>& A);
288
289 friend
290 std::istream& operator >> <> (std::istream& in,
292
293 };
294
295 // Explicit specialization of members
296
297 template <>
299
300 template <>
302
303 template <>
305
306 template <>
308
309 template <>
311
312 template <>
314
315 // Inline method definitions
316
317 template <int D>
318 inline
320 { return !(A == B); }
321
322 /*
323 * Return an element of the matrix by reference.
324 */
325 template <int D>
326 inline
327 int& SpaceSymmetry<D>::R(int i, int j)
328 { return R_(i, j); }
329
330 /*
331 * Return an element of the matrix by value
332 */
333 template <int D>
334 inline
335 int SpaceSymmetry<D>::R(int i, int j) const
336 { return R_(i, j); }
337
338 /*
339 * Return an element of the translation vector by reference.
340 */
341 template <int D>
342 inline
344 { return t_[i]; }
345
346 /*
347 * Return an element of the translation vector by value
348 */
349 template <int D>
350 inline
352 { return t_[i]; }
353
354 /*
355 * Return the identity symmetry operation.
356 */
357 template <int D>
358 inline
360 {
361 if (!hasIdentity_) makeIdentity();
362 return identity_;
363 }
364
365 // Friend function template definitions
366
367 /*
368 * Equality operator.
369 */
370 template <int D>
372 {
373 int i, j;
374 for (i = 0; i < D; ++i) {
375 if (A.t_[i] != B.t_[i]) {
376 return false;
377 }
378 for (j = 0; j < D; ++j) {
379 if (A.R_(i, j) != B.R_(i,j)) {
380 return false;
381 }
382 }
383 }
384 return true;
385 }
386
387 /*
388 * Group multipication operator for SpaceSymmetry<D> objects.
389 */
390 template <int D>
393 {
395 int i, j, k;
396
397 // Compute rotation matrix (matrix product)
398 for (i = 0; i < D; ++i) {
399 for (j = 0; j < D; ++j) {
400 C.R_(i, j) = 0;
401 for (k = 0; k < D; ++k) {
402 C.R_(i, j) += A.R_(i, k)*B.R_(k, j);
403 }
404 }
405 }
406
407 // Compute translation vector
408 for (i = 0; i < D; ++i) {
409 C.t_[i] = A.t_[i];
410 }
411 for (i = 0; i < D; ++i) {
412 for (j = 0; j < D; ++j) {
413 C.t_[i] += A.R_(i, j)*B.t_[j];
414 }
415 }
416 C.normalize();
417
418 return C;
419 }
420
421 /*
422 * Matrix / IntVec<D> multiplication.
423 */
424 template <int D>
426 {
427 IntVec<D> U;
428 int i, j;
429 for (i = 0; i < D; ++i) {
430 U[i] = 0;
431 for (j = 0; j < D; ++j) {
432 U[i] += S.R_(i,j)*V[j];
433 }
434 }
435 return U;
436 }
437
438 /*
439 * IntVec<D> / Matrix multiplication.
440 */
441 template <int D>
443 {
444 IntVec<D> U;
445 int i, j;
446 for (i = 0; i < D; ++i) {
447 U[i] = 0;
448 for (j = 0; j < D; ++j) {
449 U[i] += V[j]*S.R_(j,i);
450 }
451 }
452 return U;
453 }
454
455 /*
456 * Output stream inserter for a SpaceSymmetry<D>.
457 */
458 template <int D>
459 std::ostream& operator << (std::ostream& out, const SpaceSymmetry<D>& A)
460 {
461 int i, j;
462 for (i = 0; i < D; ++i) {
463 for (j = 0; j < D; ++j) {
464 out << " " << Int(A.R_(i,j),2);
465 }
466 out << std::endl;
467 }
468 for (i = 0; i < D; ++i) {
469 out << " " << A.t_[i];
470 }
471 out << std::endl;
472 return out;
473 }
474
475 /*
476 * Input stream extractor for a SpaceSymmetry<D>.
477 */
478 template <int D>
479 std::istream& operator >> (std::istream& in, SpaceSymmetry<D>& A)
480 {
481 int i, j;
482 for (i = 0; i < D; ++i) {
483 for (j = 0; j < D; ++j) {
484 in >> A.R_(i,j);
485 }
486 }
487 for (i = 0; i < D; ++i) {
488 in >> A.t_[i];
489 }
490 return in;
491 }
492
493 // Define static members
494 template<int D>
496
497 template<int D>
499
500
501 #ifndef PRDC_SPACE_SYMMETRY_TPP
502 // Suppress implicit instantiation
503 extern template class SpaceSymmetry<1>;
504 extern template class SpaceSymmetry<2>;
505 extern template class SpaceSymmetry<3>;
506 #endif
507
508}
509}
510#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
A SpaceSymmetry represents a crystallographic space group symmetry.
friend std::istream & operator>>(std::istream &in, SpaceSymmetry< D > &A)
Input stream extractor for a SpaceSymmetry<D>
SpaceSymmetry< D > inverse() const
Compute and return the inverse of this symmetry element.
friend bool operator!=(const SpaceSymmetry< D > &A, const SpaceSymmetry< D > &B)
Are two SpaceSymmetry objects not equivalent?
static const SpaceSymmetry< D > & identity()
Return the identity element.
int determinant() const
Compute and return the determinant of the rotation matrix.
friend bool operator==(const SpaceSymmetry< D > &A, const SpaceSymmetry< D > &B)
Are two SpaceSymmetry objects equivalent?
FMatrix< int, D, D > Rotation
Typedef for matrix used to represent point group operation.
FArray< Rational, D > Translation
Typedef for vector used to represent fractional translation.
SpaceSymmetry< D >::Rotation inverseRotation() const
Compute and return the inverse of the rotation matrix.
friend SpaceSymmetry< D > operator*(const SpaceSymmetry< D > &A, const SpaceSymmetry< D > &B)
Return the product A*B of two symmetry objects.
SpaceSymmetry< D > & operator=(const SpaceSymmetry< D > &other)
Assignment operator.
Rational & t(int i)
Return a component of the translation by reference.
void normalize()
Shift components of translation to [0,1).
int & R(int i, int j)
Return an element of the matrix by reference.
void shiftOrigin(Translation const &origin)
Shift the origin of space used in the coordinate system.
SpaceSymmetry()
Default constructor.
A fixed size (static) contiguous array template.
Definition FArray.h:47
Fixed Size Matrix.
Definition FMatrix.h:29
Wrapper for an int, for formatted ostream output.
Definition Int.h:37
A Rational number (a ratio of integers).
Definition Rational.h:34
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.
Rational operator*(Rational const &a, Rational const &b)
Compute product of rationals.
Definition Rational.h:573
bool operator==(Polynomial< T > const &a, Polynomial< T > const &b)
Equality operator for polynomials.
Definition Polynomial.h:675
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition Pair.h:57
bool operator!=(Polynomial< T > const &a, Polynomial< T > const &b)
Inequality operator for polynomials.
Definition Polynomial.h:694