accelerInt  v0.1
phiAHessenberg.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <complex.h>
8 
9 #include "header.h"
10 #include "lapack_dfns.h"
11 #include "complexInverse.h"
12 #include "solver_options.h"
13 #include "solver_props.h"
14 
15 extern double complex poles[N_RA];
16 extern double complex res[N_RA];
17 
27 int phi2Ac_variable(const int m, const double* A, const double c, double* phiA) {
28 
29  //allocate arrays
30  int ipiv[STRIDE] = {0};
31  double complex invA[STRIDE * STRIDE];
32  int info = 0;
33 
34  for (int i = 0; i < m; ++i) {
35 
36  for (int j = 0; j < m; ++j) {
37  phiA[i + j*STRIDE] = 0.0;
38  }
39  }
40 
41 
42  for (int q = 0; q < N_RA; q += 2) {
43 
44  // init invA
45  for (int i = 0; i < m; ++i) {
46  for (int j = 0; j < m; ++j) {
47  // A - theta * I
48  if (i == j) {
49  invA[i + j * STRIDE] = c * A[i + j*STRIDE] - poles[q];
50  } else {
51  invA[i + j * STRIDE] = c * A[i + j*STRIDE];
52  }
53  }
54  }
55 
56  // takes care of (A * c - poles(q) * I)^-1
57  getComplexInverseHessenberg (m, invA, ipiv, &info);
58 
59  if (info != 0)
60  return info;
61 
62 
63  for (int i = 0; i < m; ++i) {
64 
65  for (int j = 0; j < m; ++j) {
66  phiA[i + j*STRIDE] += 2.0 * creal((res[q] / (poles[q] * poles[q])) * invA[i + j * STRIDE]);
67  }
68  }
69  }
70 
71  return 0;
72 }
73 
83 int phiAc_variable(const int m, const double* A, const double c, double* phiA) {
84 
85  //allocate arrays
86  int ipiv[STRIDE] = {0};
87  double complex invA[STRIDE * STRIDE];
88  int info = 0;
89 
90  for (int i = 0; i < m; ++i) {
91 
92  for (int j = 0; j < m; ++j) {
93  phiA[i + j*STRIDE] = 0.0;
94  }
95  }
96 
97 
98  for (int q = 0; q < N_RA; q += 2) {
99 
100  // init invA
101  for (int i = 0; i < m; ++i) {
102  for (int j = 0; j < m; ++j) {
103  // A - theta * I
104  if (i == j) {
105  invA[i + j * STRIDE] = c * A[i + j*STRIDE] - poles[q];
106  } else {
107  invA[i + j * STRIDE] = c * A[i + j*STRIDE];
108  }
109  }
110  }
111 
112  // takes care of (A * c - poles(q) * I)^-1
113  getComplexInverseHessenberg (m, invA, ipiv, &info);
114 
115  if (info != 0)
116  return info;
117 
118 
119  for (int i = 0; i < m; ++i) {
120 
121  for (int j = 0; j < m; ++j) {
122  phiA[i + j*STRIDE] += 2.0 * creal((res[q] / poles[q]) * invA[i + j * STRIDE]);
123  }
124  }
125  }
126 
127  return 0;
128 }
129 
140 int expAc_variable(const int m, const double* A, const double c, double* phiA) {
141 
142  //allocate arrays
143  int ipiv[STRIDE] = {0};
144  double complex invA[STRIDE * STRIDE];
145  int info = 0;
146 
147  for (int i = 0; i < m; ++i) {
148 
149  for (int j = 0; j < m; ++j) {
150  phiA[i + j*STRIDE] = 0.0;
151  }
152  }
153 
154 
155  for (int q = 0; q < N_RA; q += 2) {
156 
157  // compute transpose and multiply with constant
158  for (int i = 0; i < m; ++i) {
159  for (int j = 0; j < m; ++j) {
160  // A - theta * I
161  if (i == j) {
162  invA[i + j*STRIDE] = c * A[i + j*STRIDE] - poles[q];
163  } else {
164  invA[i + j*STRIDE] = c * A[i + j*STRIDE];
165  }
166  }
167  }
168 
169  // takes care of (A * c - poles(q) * I)^-1
170  getComplexInverseHessenberg (m, invA, ipiv, &info);
171 
172  if (info != 0)
173  return info;
174 
175 
176  for (int i = 0; i < m; ++i) {
177 
178  for (int j = 0; j < m; ++j) {
179  phiA[i + j*STRIDE] += 2.0 * creal(res[q] * invA[i + j*STRIDE]);
180  }
181  }
182  }
183 
184  return 0;
185 }
double complex poles[N_RA]
An example header file that defines system size and other required methods for integration of the van...
void getComplexInverseHessenberg(const int n, double complex *__restrict__ A, int *__restrict__ ipiv, int *__restrict__ info)
getComplexInverseHessenberg computes the inverse of an upper Hessenberg matrix A using a LU factoriza...
int expAc_variable(const int m, const double *A, const double c, double *phiA)
Compute the zeroth order Phi (exponential) matrix function. This is the regular matrix exponential...
#define N_RA
#define STRIDE
the matrix dimensions
A file generated by Scons that specifies various options to the solvers.
int phiAc_variable(const int m, const double *A, const double c, double *phiA)
Compute the first order Phi (exponential) matrix function.
int phi2Ac_variable(const int m, const double *A, const double c, double *phiA)
Compute the 2nd order Phi (exponential) matrix function.
External lapack routine definitions.
Header definitions for LU factorization routines.
simple convenience file to include the correct solver properties file
double complex res[N_RA]