1#include "../../include/cuda_utils/linalg.cuh"
6 if (x < 0) {
return -1; }
7 else if (x > 0) {
return 1; }
11 __device__
int stressIndex(
int particleIndex,
int row,
int col)
19 for (i = 0; i <
DIM; i++) {
20 for (j = 0; j <
DIM; j++) {
21 dst[i][j] = src[i][j];
30 for (i = 0; i <
DIM; i++) {
31 for (j = 0; j <
DIM; j++) {
35 for (i = 0; i <
DIM; i++) {
36 for (j = 0; j <
DIM; j++) {
48 for (i = 0; i <
DIM; i++) {
49 for (j = 0; j <
DIM; j++) {
54 for (i = 0; i <
DIM; i++) {
55 for (j = 0; j <
DIM; j++) {
56 for (k = 0; k <
DIM; k++) {
57 vprime[i][j] += A[i][k] * B[k][j];
61 for (i = 0; i <
DIM; i++) {
62 for (j = 0; j <
DIM; j++) {
63 C[i][j] = vprime[i][j];
71 for (i = 0; i <
DIM; i++) {
72 for (j = 0; j <
DIM; j++) {
73 for (k = 0; k <
DIM; k++) {
74 C[i][j] += A[i][k]*B[k][j];
82 for (i = 0; i <
DIM; i++) {
83 for (j = 0; j <
DIM; j++) {
97 for (i = 0; i <
DIM; i++) {
98 for (j = 0; j <
DIM; j++) {
124 for (i = 0; i <
DIM; i++)
125 for (j = 0; j <
DIM; j++)
126 mprime[i][j] = m[i][j];
129 mprime[e][e] = c * c * m[e][e] + s * s * m[f][f] - 2 * s * c * m[e][f];
130 mprime[f][f] = c * c * m[f][f] + s * s * m[e][e] + 2 * s * c * m[e][f];
131 mprime[e][f] = (c * c - s * s) * m[e][f] + s * c * (m[e][e] - m[f][f]);
132 mprime[f][e] = mprime[e][f];
136 for (i = 0; i <
DIM; i++) {
137 if (i == f || i == e)
139 mprime[e][i] = c * m[i][e] - s * m[i][f];
140 mprime[i][e] = mprime[e][i];
141 mprime[f][i] = c * m[i][f] + s * m[i][e];
142 mprime[i][f] = mprime[f][i];
146 for (i = 0; i <
DIM; i++)
147 for (j = 0; j <
DIM; j++)
148 m[i][j] = mprime[i][j];
170 c = s = t = thta = 0.0;
173#define EPS_JACOBI 1e-10
175 for (i = 0; i <
DIM; i++) {
176 for (j = 0; j <
DIM; j++) {
177 diagM[i][j] = M[i][j];
187 printf(
"No maximum element found.\n");
191 thta = (diagM[f][f] - diagM[e][e]) / (2 * diagM[e][f]);
212 for (i = 0; i <
DIM; i++) {
213 eigenvalues[i] = diagM[i][i];
234 c = s = t = thta = 0.0;
239#define EPS_JACOBI 1e-10
241 for (i = 0; i <
DIM; i++)
242 for (j = 0; j <
DIM; j++)
243 diagM[i][j] = M[i][j];
249 printf(
"No maximum element found.\n");
253 thta = (diagM[f][f] - diagM[e][e]) / (2 * diagM[e][f]);
266 max_ev = diagM[0][0];
267 for (i = 1; i <
DIM; i++) {
268 if (diagM[i][i] > max_ev) {
269 max_ev = diagM[i][i];
276 return a * d - c * b;
293 inverted[0*
DIM+0] = det*d;
294 inverted[0*
DIM+1] = -det*b;
295 inverted[1*
DIM+0] = -det*c;
296 inverted[1*
DIM+1] = det*a;
298 det = m[0 *
DIM + 0] * (m[1 *
DIM + 1] * m[2 *
DIM + 2] - m[2 *
DIM + 1] * m[1 *
DIM + 2])
299 - m[0 *
DIM + 1] * (m[1 *
DIM + 0] * m[2 *
DIM + 2] - m[1 *
DIM + 2] * m[2 *
DIM + 0])
300 + m[0 *
DIM + 2] * (m[1 *
DIM + 0] * m[2 *
DIM + 1] - m[1 *
DIM + 1] * m[2 *
DIM + 0]);
304 if (det < 1e-8)
return -1;
307 inverted[0*
DIM+0] = (m[1*
DIM+ 1] * m[2*
DIM+ 2] - m[2*
DIM+ 1] * m[1*
DIM+ 2]) * det;
308 inverted[0*
DIM+1] = (m[0*
DIM+ 2] * m[2*
DIM+ 1] - m[0*
DIM+ 1] * m[2*
DIM+ 2]) * det;
309 inverted[0*
DIM+2] = (m[0*
DIM+ 1] * m[1*
DIM+ 2] - m[0*
DIM+ 2] * m[1*
DIM+ 1]) * det;
310 inverted[1*
DIM+0] = (m[1*
DIM+ 2] * m[2*
DIM+ 0] - m[1*
DIM+ 0] * m[2*
DIM+ 2]) * det;
311 inverted[1*
DIM+1] = (m[0*
DIM+ 0] * m[2*
DIM+ 2] - m[0*
DIM+ 2] * m[2*
DIM+ 0]) * det;
312 inverted[1*
DIM+2] = (m[1*
DIM+ 0] * m[0*
DIM+ 2] - m[0*
DIM+ 0] * m[1*
DIM+ 2]) * det;
313 inverted[2*
DIM+0] = (m[1*
DIM+ 0] * m[2*
DIM+ 1] - m[2*
DIM+ 0] * m[1*
DIM+ 1]) * det;
314 inverted[2*
DIM+1] = (m[2*
DIM+ 0] * m[0*
DIM+ 1] - m[0*
DIM+ 0] * m[2*
DIM+ 1]) * det;
315 inverted[2*
DIM+2] = (m[0*
DIM+ 0] * m[1*
DIM+ 1] - m[1*
DIM+ 0] * m[0*
DIM+ 1]) * det;
__device__ int calculateAllEigenvalues(real M[DIM][DIM], real eigenvalues[DIM], real v[DIM][DIM])
Computes all eigenvalues and eigenvectors of the symmetric matrix M.
__device__ int maxMatrix(real M[DIM][DIM], int *e, int *f, real *elmax)
Returns the indices of the greatest non-diagonal element of the matrix M.
__device__ int stressIndex(int particleIndex, int row, int col)
map [i][j] to [i*DIM*DIM+j] for the tensors
__device__ real calculateMaxEigenvalue(real M[DIM][DIM])
Computes the eigenvalues of the symmetric matrix M.
__device__ void transposeMatrix(real m[DIM][DIM])
Transpose matrix.
__device__ void copyMatrix(real src[DIM][DIM], real dst[DIM][DIM])
Deep copy of matrix.
__device__ int sign(real x)
Get sign of floating point variable.
__device__ real det2x2(real a, real b, real c, real d)
Determinant of a 2x2 matrix.
__device__ void multiplyMatrix(real A[DIM][DIM], real B[DIM][DIM], real C[DIM][DIM])
__device__ int invertMatrix(real *m, real *inverted)
Invert matrix.
__device__ void rotateMatrix(volatile real m[DIM][DIM], volatile real c, volatile real s, volatile int e, volatile int f)
Rotate matrix.
__device__ void multiply(real A[][DIM], real B[][DIM], real C[][DIM])
__device__ void identityMatrix(real A[DIM][DIM])
Return identity matrix.
__device__ real sqrt(real a)
Square root of a floating point value.
__device__ real abs(real a)
Absolute value of a floating point value.
__device__ real max(real a, real b)
Maximum value out of two floating point values.
#define DIM
Dimension of the problem.