PSCF v1.1
SpaceSymmetry.tpp
1#ifndef PSCF_SPACE_SYMMETRY_TPP
2#define PSCF_SPACE_SYMMETRY_TPP
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 "SpaceSymmetry.h"
12
13namespace Pscf
14{
15
16 using namespace Util;
17
18 /*
19 * Default constructor.
20 */
21 template <int D>
23 : R_(),
24 t_()
25 {
26 int i, j;
27 for (i = 0; i < D; ++i) {
28 t_[i] = 0;
29 for (j = 0; j < D; ++j) {
30 if (i == j) {
31 R_(i, j) = 1;
32 } else {
33 R_(i, j) = 0;
34 }
35 }
36 }
37 }
38
39 /*
40 * Copy constructor.
41 */
42 template <int D>
44 {
45 int i, j;
46 for (i = 0; i < D; ++i) {
47 t_[i] = other.t_[i];
48 for (j = 0; j < D; ++j) {
49 R_(i, j) = other.R_(i,j);
50 }
51 }
52 normalize();
53 }
54
55 /*
56 * Assignment operator.
57 */
58 template <int D>
61 {
62 if (this != &other) {
63 int i, j;
64 for (i = 0; i < D; ++i) {
65 t_[i] = other.t_[i];
66 for (j = 0; j < D; ++j) {
67 R_(i, j) = other.R_(i,j);
68 }
69 }
70 }
71 normalize();
72 return *this;
73 }
74
75 /*
76 * Shift translation to lie in range [0,1).
77 */
78 template <int D>
80 {
81 for (int i = 0; i < D; ++i) {
82 int num = t_[i].num();
83 int den = t_[i].den();
84 UTIL_ASSERT(den > 0);
85 if (den == 1) {
86 num = 0;
87 } else {
88 while (num < 0) {
89 num += den;
90 }
91 while (num >= den) {
92 num -= den;
93 }
94 }
95 if (num != t_[i].num()) {
96 t_[i] = Rational(num, den);
97 }
98 }
99 }
100
101 /*
102 * Make identity (private static method).
103 */
104 template <int D>
106 {
107 int i, j;
108 for (i = 0; i < D; ++i) {
109 identity_.t_[i] = 0;
110 for (j = 0; j < D; ++j) {
111 if (i == j) {
112 identity_.R_(i, j) = 1;
113 } else {
114 identity_.R_(i, j) = 0;
115 }
116 }
117 }
118 }
119
120 /*
121 * Return inverse of this SpaceSymmetry<D>.
122 */
123 template <int D>
125 {
127
128 // Compute inverse of rotation matrix
129 C.R_ = inverseRotation();
130
131 // Compute translation -R^{-1}t
132 int i, j;
133 for (i = 0; i < D; ++i) {
134 C.t_[i] = 0;
135 for (j = 0; j < D; ++j) {
136 C.t_[i] -= C.R_(i, j)*t_[j];
137 }
138 }
139 C.normalize();
140
141 //UTIL_CHECK(C.determinant()*determinant() == 1);
142
143 return C;
144 }
145
146 /*
147 * Shift the origin of the coordinate system.
148 */
149 template <int D>
151 SpaceSymmetry<D>::Translation const & origin)
152 {
153 int i, j;
154 for (i = 0; i < D; ++i) {
155 t_[i] -= origin[i];
156 for (j = 0; j < D; ++j) {
157 t_[i] += R_(i,j)*origin[j];
158 }
159 }
160 normalize();
161 }
162
163}
164#endif
A SpaceSymmetry represents a crystallographic space group symmetry.
void normalize()
Shift components of translation to [0,1).
SpaceSymmetry< D > inverse() const
Compute and return the inverse of this symmetry element.
SpaceSymmetry< D > & operator=(const SpaceSymmetry< D > &other)
Assignment operator.
void shiftOrigin(Translation const &origin)
Shift the origin of space used in the coordinate system.
SpaceSymmetry()
Default constructor.
A Rational number (a ratio of integers).
Definition: Rational.h:34
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition: global.h:75
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1