| 1 | //
 | 
|---|
| 2 | // symop.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 | SymmetryOperation::SymmetryOperation()
 | 
|---|
| 39 | {
 | 
|---|
| 40 |   zero();
 | 
|---|
| 41 | }
 | 
|---|
| 42 | 
 | 
|---|
| 43 | SymmetryOperation::SymmetryOperation(const SymmetryOperation &so)
 | 
|---|
| 44 | {
 | 
|---|
| 45 |   for (int i=0; i<3; i++) {
 | 
|---|
| 46 |     for (int j=0; j<3; j++) {
 | 
|---|
| 47 |       d[i][j] = so.d[i][j];
 | 
|---|
| 48 |     }
 | 
|---|
| 49 |   }
 | 
|---|
| 50 | }
 | 
|---|
| 51 | 
 | 
|---|
| 52 | SymmetryOperation::~SymmetryOperation()
 | 
|---|
| 53 | {
 | 
|---|
| 54 | }
 | 
|---|
| 55 | 
 | 
|---|
| 56 | SymmetryOperation
 | 
|---|
| 57 | SymmetryOperation::operate(const SymmetryOperation& r) const
 | 
|---|
| 58 | {
 | 
|---|
| 59 |   SymmetryOperation ret;
 | 
|---|
| 60 |   for (int i=0; i < 3; i++)
 | 
|---|
| 61 |     for (int j=0; j < 3; j++) {
 | 
|---|
| 62 |       double t=0;
 | 
|---|
| 63 |       for (int k=0; k < 3; k++)
 | 
|---|
| 64 |         t += r.d[i][k]*d[k][j];
 | 
|---|
| 65 |       ret.d[i][j] = t;
 | 
|---|
| 66 |     }
 | 
|---|
| 67 |   return ret;
 | 
|---|
| 68 | }
 | 
|---|
| 69 | 
 | 
|---|
| 70 | SymmetryOperation
 | 
|---|
| 71 | SymmetryOperation::transform(const SymmetryOperation& r) const
 | 
|---|
| 72 | {
 | 
|---|
| 73 |   int i,j,k;
 | 
|---|
| 74 |   SymmetryOperation ret,foo;
 | 
|---|
| 75 |   
 | 
|---|
| 76 |   // foo = r * d
 | 
|---|
| 77 |   for (i=0; i < 3; i++) {
 | 
|---|
| 78 |     for (j=0; j < 3; j++) {
 | 
|---|
| 79 |       double t=0;
 | 
|---|
| 80 |       for (k=0; k < 3; k++)
 | 
|---|
| 81 |         t += r.d[i][k] * d[k][j];
 | 
|---|
| 82 |       foo.d[i][j] = t;
 | 
|---|
| 83 |     }
 | 
|---|
| 84 |   }
 | 
|---|
| 85 | 
 | 
|---|
| 86 |   // ret = (r*d)*r~ = foo*r~
 | 
|---|
| 87 |   for (i=0; i < 3; i++) {
 | 
|---|
| 88 |     for (j=0; j < 3; j++) {
 | 
|---|
| 89 |       double t=0;
 | 
|---|
| 90 |       for (k=0; k < 3; k++)
 | 
|---|
| 91 |         t += foo.d[i][k]*r.d[j][k];
 | 
|---|
| 92 |       ret.d[i][j]=t;
 | 
|---|
| 93 |     }
 | 
|---|
| 94 |   }
 | 
|---|
| 95 | 
 | 
|---|
| 96 |   return ret;
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | // Clockwise rotation by 2pi/n degrees
 | 
|---|
| 100 | void
 | 
|---|
| 101 | SymmetryOperation::rotation(int n)
 | 
|---|
| 102 | {
 | 
|---|
| 103 |   double theta = (n) ? 2.0*M_PI/n : 2.0*M_PI;
 | 
|---|
| 104 |   rotation(theta);
 | 
|---|
| 105 | }
 | 
|---|
| 106 | 
 | 
|---|
| 107 | // Clockwise rotation by theta degrees
 | 
|---|
| 108 | void
 | 
|---|
| 109 | SymmetryOperation::rotation(double theta)
 | 
|---|
| 110 | {
 | 
|---|
| 111 |   zero();
 | 
|---|
| 112 | 
 | 
|---|
| 113 |   double ctheta = cos(theta);
 | 
|---|
| 114 |   double stheta = sin(theta);
 | 
|---|
| 115 | 
 | 
|---|
| 116 |   d[0][0] = ctheta;
 | 
|---|
| 117 |   d[0][1] = stheta;
 | 
|---|
| 118 |   d[1][0] = -stheta;
 | 
|---|
| 119 |   d[1][1] = ctheta;
 | 
|---|
| 120 |   d[2][2] = 1.0;
 | 
|---|
| 121 | }
 | 
|---|
| 122 | 
 | 
|---|
| 123 | void
 | 
|---|
| 124 | SymmetryOperation::transpose()
 | 
|---|
| 125 | {
 | 
|---|
| 126 |   for (int i=1; i<3; i++) {
 | 
|---|
| 127 |     for (int j=0; j<i; j++) {
 | 
|---|
| 128 |       double tmp = d[i][j];
 | 
|---|
| 129 |       d[i][j] = d[j][i];
 | 
|---|
| 130 |       d[j][i] = tmp;
 | 
|---|
| 131 |     }
 | 
|---|
| 132 |   }
 | 
|---|
| 133 | }
 | 
|---|
| 134 | 
 | 
|---|
| 135 | void
 | 
|---|
| 136 | SymmetryOperation::print(ostream& os) const
 | 
|---|
| 137 | {
 | 
|---|
| 138 |   os << indent << "        1          2          3\n"
 | 
|---|
| 139 |      << indent << "  1  "
 | 
|---|
| 140 |      << scprintf("%10.7f ", d[0][0])
 | 
|---|
| 141 |      << scprintf("%10.7f ", d[0][1])
 | 
|---|
| 142 |      << scprintf("%10.7f ", d[0][2]) << endl
 | 
|---|
| 143 |      << indent << "  2  "
 | 
|---|
| 144 |      << scprintf("%10.7f ", d[1][0])
 | 
|---|
| 145 |      << scprintf("%10.7f ", d[1][1])
 | 
|---|
| 146 |      << scprintf("%10.7f ", d[1][2]) << endl
 | 
|---|
| 147 |      << indent << "  3  "
 | 
|---|
| 148 |      << scprintf("%10.7f ", d[2][0])
 | 
|---|
| 149 |      << scprintf("%10.7f ", d[2][1])
 | 
|---|
| 150 |      << scprintf("%10.7f ", d[2][2]) << endl << endl;
 | 
|---|
| 151 | }
 | 
|---|
| 152 | 
 | 
|---|
| 153 | /////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 154 | 
 | 
|---|
| 155 | // Local Variables:
 | 
|---|
| 156 | // mode: c++
 | 
|---|
| 157 | // c-file-style: "ETS"
 | 
|---|
| 158 | // End:
 | 
|---|