lammps-sys 0.6.0

Generates bindings to LAMMPS' C interface (with optional builds from source)
Documentation
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/*
 *_________________________________________________________________________*
 *      POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE     *
 *      DESCRIPTION: SEE READ-ME                                           *
 *      FILE NAME: matrixfun.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 "matrixfun.h"
#include <cmath>
#include "fastmatrixops.h"
#include <cstdlib>

using namespace std;

//
//  Create a new matrix
//

VirtualMatrix* NewMatrix(int type){
  switch( MatrixType(type) )
    {
      case MATRIX : return new Matrix;
      case COLMATRIX : return new ColMatrix;
      case ROWMATRIX : return new RowMatrix;		
      case MAT3X3 : return new Mat3x3;
		case MAT4X4 : return new Mat4x4;
      case VECT3 : return new Vect3;
		case VECT4 : return new Vect4;
      default  : return 0; // error!
    }
}

//
// Transpose
//

Matrix T(const VirtualMatrix& A){
	int numrows = A.GetNumRows();
	int numcols = A.GetNumCols();
	Matrix C(numcols,numrows);
	for(int i=0;i<numcols;i++)
		for(int j=0;j<numrows;j++)
			C.BasicSet(i,j,A.BasicGet(j,i));
	return C;
}

Mat3x3 T(const Mat3x3& A){
	Mat3x3 C;
	C.elements[0][0] = A.elements[0][0];
	C.elements[1][1] = A.elements[1][1];
	C.elements[2][2] = A.elements[2][2];

	C.elements[0][1] = A.elements[1][0];
	C.elements[0][2] = A.elements[2][0];
	C.elements[1][2] = A.elements[2][1];

	C.elements[1][0] = A.elements[0][1];
	C.elements[2][0] = A.elements[0][2];
	C.elements[2][1] = A.elements[1][2];
	return C;
}

Mat6x6 T(const Mat6x6& A){
	Mat6x6 C;
	int i,j;
	for(i=0;i<6;i++)
		for(j=0;j<6;j++)
			C.elements[i][j] = A.elements[j][i];

	return C;
}

Matrix T(const Vect3& A){
	Matrix C(1,3);
	C.BasicSet(0,0,A.elements[0]);
	C.BasicSet(0,1,A.elements[1]);
	C.BasicSet(0,2,A.elements[2]);

	return C;
}

Matrix T(const Vect6& A){
	Matrix C(1,6);
	C.BasicSet(0,0,A.elements[0]);
	C.BasicSet(0,1,A.elements[1]);
	C.BasicSet(0,2,A.elements[2]);
	C.BasicSet(0,3,A.elements[3]);
	C.BasicSet(0,4,A.elements[4]);
	C.BasicSet(0,5,A.elements[5]);

	return C;
}

RowMatrix T(const VirtualColMatrix &A){
	int numele = A.GetNumRows();
	RowMatrix C(numele);
	for(int i=0;i<numele;i++)
		C.BasicSet(i,A.BasicGet(i));
	return C;
}

ColMatrix T(const VirtualRowMatrix &A){
	int numele = A.GetNumCols();
	ColMatrix C(numele);
	for(int i=0;i<numele;i++)
		C.BasicSet(i,A.BasicGet(i));
	return C;
}

//
// Symmetric Inverse
//

Matrix SymInverse(Matrix &A){
	int r = A.GetNumRows();
	Matrix C(r,r);
	Matrix LD(r,r);
	Matrix I(r,r);
	I.Zeros();
	for(int i=0;i<r;i++) I.BasicSet(i,i,1.0);
	FastLDLT(A,LD);
	FastLDLTSubs(LD,I,C);
	return C;
}

Mat6x6 SymInverse(Mat6x6 &A){
	Mat6x6 C;
	Mat6x6 LD;
	Mat6x6 I;
	I.Zeros();
	for(int i=0;i<6;i++) I.BasicSet(i,i,1.0);
	FastLDLT(A,LD);
	FastLDLTSubs(LD,I,C);
	return C;
}

//
// Inverse
//

Matrix Inverse(Matrix& A){
	int r = A.GetNumRows();
	int indx[10000];
	Matrix LU(r,r);
	Matrix I(r,r);
	Matrix C(r,r);
	I.Zeros();
	for(int i=0;i<r;i++) I.BasicSet(i,i,1.0);
	FastLU(A,LU,indx);
	FastLUSubs(LU,I,C,indx);
	return C;
}

Mat3x3 Inverse(Mat3x3& A){
	int indx[10000];
	Mat3x3 LU;
	Matrix I(3,3);
	Matrix C(3,3);
	I.Zeros();
	for(int i=0;i<3;i++) I.BasicSet(i,i,1.0);
	FastLU(A,LU,indx);
	FastLUSubs(LU,I,C,indx);
	return C;
}

Mat4x4 Inverse(Mat4x4& A){
	int indx[10000];
	Mat4x4 LU;
	Matrix I(4,4);
	Matrix C(4,4);
	I.Zeros();
	for(int i=0;i<4;i++) I.BasicSet(i,i,1.0);
	FastLU(A,LU,indx);
	FastLUSubs(LU,I,C,indx);
	return C;
}

Mat6x6 Inverse(Mat6x6& A){
	int indx[10000];
	Mat6x6 LU;
	Matrix I(6,6);
	Matrix C(6,6);
	I.Zeros();
	for(int i=0;i<6;i++) I.BasicSet(i,i,1.0);
	FastLU(A,LU,indx);
	FastLUSubs(LU,I,C,indx);
	return C;
}

//
// overloaded addition
//

Matrix operator+ (const VirtualMatrix &A, const VirtualMatrix &B){      // addition
	int Arows,Acols,Brows,Bcols;
	Arows = A.GetNumRows();
	Acols = A.GetNumCols();
	Brows = B.GetNumRows();
	Bcols = B.GetNumCols();

	if( !((Arows == Brows) && (Acols == Bcols)) ){
		cerr << "Dimesion mismatch in matrix addition" << endl;
		exit(1);
	}

	Matrix C(Arows,Acols);

	for(int i=0;i<Arows;i++)
		for(int j=0;j<Acols;j++)
			C.BasicSet(i,j,A.BasicGet(i,j) + B.BasicGet(i,j));

	return C;
}

//
// overloaded subtraction
//

Matrix operator- (const VirtualMatrix &A, const VirtualMatrix &B){      // subtraction
	int Arows,Acols,Brows,Bcols;
	Arows = A.GetNumRows();
	Acols = A.GetNumCols();
	Brows = B.GetNumRows();
	Bcols = B.GetNumCols();

	if( !((Arows == Brows) && (Acols == Bcols)) ){
		cerr << "Dimesion mismatch in matrix addition" << endl;
		exit(1);
	}

	Matrix C(Arows,Acols);

	for(int i=0;i<Arows;i++)
		for(int j=0;j<Acols;j++)
			C.BasicSet(i,j,A.BasicGet(i,j) - B.BasicGet(i,j));

	return C;
}

//
// overloaded matrix multiplication
//

Matrix operator* (const VirtualMatrix &A, const VirtualMatrix &B){      // multiplication
	int Arows,Acols,Brows,Bcols;
	Arows = A.GetNumRows();
	Acols = A.GetNumCols();
	Brows = B.GetNumRows();
	Bcols = B.GetNumCols();

	if(Acols != Brows){
		cerr << "Dimesion mismatch in matrix multiplication" << endl;
		exit(1);
	}

	Matrix C(Arows,Bcols);
	C.Zeros();

	for(int i=0;i<Arows;i++)
		for(int j=0;j<Bcols;j++)
			for(int k=0;k<Brows;k++)
				C.BasicIncrement(i,j, A.BasicGet(i,k) * B.BasicGet(k,j) );

	return C;
}

//
// overloaded scalar multiplication
//

Matrix operator* (const VirtualMatrix &A, double b){    // multiplication
	Matrix C = A;
	C *= b;
	return C;
}

Matrix operator* (double b, const VirtualMatrix &A){    // multiplication
	Matrix C = A;  
	C *= b;
	return C;
}

//
// overloaded negative
//

Matrix operator- (const VirtualMatrix& A){  // negative
	int r = A.GetNumRows();
	int c = A.GetNumCols();
	Matrix C(r,c);

	for(int i=0;i<r;i++)
		for(int j=0;j<c;j++)
			C.BasicSet(i,j,-A.BasicGet(i,j));

	return C;
}

//
// Cross product (friend of Vect3)
//

Vect3 Cross(Vect3& a, Vect3& b){
	return CrossMat(a)*b;
}

//
// Cross Matrix (friend of Vect3 & Mat3x3)
//

Mat3x3 CrossMat(Vect3& a){
	Mat3x3 C;
	C.Zeros();
	C.elements[0][1] = -a.elements[2];
	C.elements[1][0] = a.elements[2];
	C.elements[0][2] = a.elements[1];
	C.elements[2][0] = -a.elements[1];
	C.elements[1][2] = -a.elements[0];
	C.elements[2][1] = a.elements[0];

	return C;
}

//
// Stack
//

Matrix Stack(VirtualMatrix& A, VirtualMatrix& B){
	int m,na,nb;
	m = A.GetNumCols();
	if( m != B.GetNumCols()){
		cerr << "Error: cannot stack matrices of differing column dimension" << endl;
		exit(0);
	}
	na = A.GetNumRows();
	nb = B.GetNumRows();

	Matrix C(na+nb,m);

	for(int i=0;i<na;i++){
		for(int j=0;j<m;j++){
			C.BasicSet(i,j,A.BasicGet(i,j));
		}
	}

	for(int i=0;i<nb;i++){
		for(int j=0;j<m;j++){
			C.BasicSet(i+na,j,B.BasicGet(i,j));
		}
	}

	return C;
}

//Hstack

Matrix HStack(VirtualMatrix& A, VirtualMatrix& B){
	int m,na,nb;
	m = A.GetNumRows();
	if( m != B.GetNumRows()){
		cerr << "Error: cannot stack matrices of differing row dimension" << endl;
		exit(0);
	}
	na = A.GetNumCols();
	nb = B.GetNumCols();

	Matrix C(m,na+nb);

	for(int i=0;i<m;i++){
		for(int j=0;j<na;j++){
			C.BasicSet(i,j,A.BasicGet(i,j));
		}
	}

	for(int i=0;i<m;i++){
		for(int j=0;j<nb;j++){
			C.BasicSet(i,j+na,B.BasicGet(i,j));
		}
	}

	return C;
}

//
//

void Set6DAngularVector(Vect6& v6, Vect3& v3){
	v6.elements[0] = v3.elements[0];
	v6.elements[1] = v3.elements[1];
	v6.elements[2] = v3.elements[2];
}

void Set6DLinearVector(Vect6& v6, Vect3& v3){
	v6.elements[3] = v3.elements[0];
	v6.elements[4] = v3.elements[1];
	v6.elements[5] = v3.elements[2];
}