File: mat3x3.cpp

package info (click to toggle)
lammps 20220106.git7586adbb6a%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348,064 kB
  • sloc: cpp: 831,421; python: 24,896; xml: 14,949; f90: 10,845; ansic: 7,967; sh: 4,226; perl: 4,064; fortran: 2,424; makefile: 1,501; objc: 238; lisp: 163; csh: 16; awk: 14; tcl: 6
file content (153 lines) | stat: -rw-r--r-- 4,553 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 *_________________________________________________________________________*
 *      POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE     *
 *      DESCRIPTION: SEE READ-ME                                           *
 *      FILE NAME: mat3x3.cpp                                              *
 *      AUTHORS: See Author List                                           *
 *      GRANTS: See Grants List                                            *
 *      COPYRIGHT: (C) 2005 by Authors as listed in Author's List          *
 *      LICENSE: Please see License Agreement                              *
 *      DOWNLOAD: Free at www.rpi.edu/~anderk5                             *
 *      ADMINISTRATOR: Prof. Kurt Anderson                                 *
 *                     Computational Dynamics Lab                          *
 *                     Rensselaer Polytechnic Institute                    *
 *                     110 8th St. Troy NY 12180                           *
 *      CONTACT:        anderk5@rpi.edu                                    *
 *_________________________________________________________________________*/


#include "mat3x3.h"
#include <cstdlib>

using namespace std;

Mat3x3::Mat3x3(){
  numrows = numcols = 3;
}
Mat3x3::~Mat3x3(){
}

Mat3x3::Mat3x3(const Mat3x3& A){
  numrows = numcols = 3;
  elements[0][0] = A.elements[0][0];elements[0][1] = A.elements[0][1];elements[0][2] = A.elements[0][2];
  elements[1][0] = A.elements[1][0];elements[1][1] = A.elements[1][1];elements[1][2] = A.elements[1][2];
  elements[2][0] = A.elements[2][0];elements[2][1] = A.elements[2][1];elements[2][2] = A.elements[2][2];
}

Mat3x3::Mat3x3(const VirtualMatrix& A){
  numrows = numcols = 3;

  // error check
  if( (A.GetNumRows() != 3) || (A.GetNumCols() != 3) ){
    cerr << "illegal matrix size" << endl;
    exit(0);
  }

  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      elements[i][j] = A.BasicGet(i,j);
}

double& Mat3x3::operator_2int(int i, int j){ // array access
  return elements[i-1][j-1];
}

double Mat3x3::Get_2int(int i, int j) const{
  return elements[i-1][j-1];
}

void Mat3x3::Set_2int(int i, int j, double value){
  elements[i-1][j-1] = value;
}

double Mat3x3::BasicGet_2int(int i, int j) const{
  return elements[i][j];
}

void Mat3x3::BasicSet_2int(int i, int j, double value){
  elements[i][j] = value;
}

void Mat3x3::BasicIncrement_2int(int i, int j, double value){
  elements[i][j] += value;
}

void Mat3x3::Const(double value){
  elements[0][0] = elements[0][1] = elements[0][2] = value;
  elements[1][0] = elements[1][1] = elements[1][2] = value;
  elements[2][0] = elements[2][1] = elements[2][2] = value;
}

MatrixType Mat3x3::GetType() const{
  return MAT3X3;
}

istream& Mat3x3::ReadData(istream& c){  //input
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      c >> elements[i][j];
  return c;
}

ostream& Mat3x3::WriteData(ostream& c) const{  //output
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      c << elements[i][j] << ' ';
  return c;
}

void Mat3x3::AssignVM(const VirtualMatrix& A){
  // error check
  if( (A.GetNumRows() != 3) || (A.GetNumCols() != 3) ){
    cerr << "illegal matrix size" << endl;
    exit(0);
  }

  for(int i=0;i<numrows;i++)
    for(int j=0;j<numcols;j++)
      elements[i][j] = A.BasicGet(i,j);
}

Mat3x3& Mat3x3::operator=(const Mat3x3& A){ // assignment operator
  elements[0][0] = A.elements[0][0];elements[0][1] = A.elements[0][1];elements[0][2] = A.elements[0][2];
  elements[1][0] = A.elements[1][0];elements[1][1] = A.elements[1][1];elements[1][2] = A.elements[1][2];
  elements[2][0] = A.elements[2][0];elements[2][1] = A.elements[2][1];elements[2][2] = A.elements[2][2];
  return *this;
}

Mat3x3& Mat3x3::operator=(const VirtualMatrix& A){ // overloaded =
  // error check
  if( (A.GetNumRows() != 3) || (A.GetNumCols() != 3) ){
    cerr << "illegal matrix size" << endl;
    exit(0);
  }

  for(int i=0;i<numrows;i++)
    for(int j=0;j<numcols;j++)
      elements[i][j] = A.BasicGet(i,j);
  return *this;
}

Mat3x3& Mat3x3::operator*=(double b){
  elements[0][0] *= b; elements[0][1] *= b; elements[0][2] *= b;
  elements[1][0] *= b; elements[1][1] *= b; elements[1][2] *= b;
  elements[2][0] *= b; elements[2][1] *= b; elements[2][2] *= b;
  return *this;
}

Mat3x3& Mat3x3::Identity(){
  elements[0][0] = 1.0;
  elements[0][1] = 0.0;
  elements[0][2] = 0.0;

  elements[1][0] = 0.0;
  elements[1][1] = 1.0;
  elements[1][2] = 0.0;

  elements[2][0] = 0.0;
  elements[2][1] = 0.0;
  elements[2][2] = 1.0;

  return *this;
}