accelerInt  v0.1
exponential_linear_algebra.h
Go to the documentation of this file.
1 
10 #ifndef EXPONENTIAL_LINEAR_ALGEBRA_H
11 #define EXPONENTIAL_LINEAR_ALGEBRA_H
12 
13 #include "header.h"
14 #include "solver_options.h"
15 #include "solver_props.h"
16 
17 
19 
27 static inline
28 void matvec_m_by_m (const int m, const double * __restrict__ A,
29  const double * __restrict__ V, double * __restrict__ Av) {
30  //for each row
31 
32  for (int i = 0; i < m; ++i) {
33  Av[i] = A[i] * V[0];
34 
35  //go across a row of A, multiplying by a column
36  for (int j = 1; j < m; ++j) {
37  Av[i] += A[j * STRIDE + i] * V[j];
38  }
39  }
40 }
41 
43 
54 static inline void matvec_m_by_m_plusequal (const int m, const double * __restrict__ A,
55  const double * __restrict__ V, double * __restrict__ Av)
56 {
57  //for each row
58 
59  for (int i = 0; i < m; ++i) {
60  Av[i] = A[i] * V[0];
61 
62  //go across a row of A, multiplying by a column of phiHm
63 
64  for (int j = 1; j < m; ++j) {
65  Av[i] += A[j * STRIDE + i] * V[j];
66  }
67 
68  Av[i] += V[i];
69  }
70 }
71 
83 static inline
84 void matvec_n_by_m_scale (const int m, const double scale,
85  const double * __restrict__ A, const double * __restrict__ V,
86  double * __restrict__ Av) {
87  //for each row
88 
89  for (int i = 0; i < NSP; ++i) {
90  Av[i] = A[i] * V[0];
91 
92  //go across a row of A, multiplying by a column of phiHm
93 
94  for (int j = 1; j < m; ++j) {
95  Av[i] += A[j * NSP + i] * V[j];
96  }
97 
98  Av[i] *= scale;
99  }
100 }
101 
117 static inline
118 void matvec_n_by_m_scale_special (const int m, const double* __restrict__ scale,
119  const double * __restrict__ A, const double** __restrict__ V,
120  double** __restrict__ Av) {
121  //for each row
122  for (int i = 0; i < NSP; ++i) {
123  Av[0][i] = A[i] * V[0][0];
124  Av[1][i] = A[i] * V[1][0];
125  Av[2][i] = A[i] * V[2][0];
126 
127  //go across a row of A, multiplying by a column of phiHm
128 
129  for (int j = 1; j < m; ++j) {
130  Av[0][i] += A[j * NSP + i] * V[0][j];
131  Av[1][i] += A[j * NSP + i] * V[1][j];
132  Av[2][i] += A[j * NSP + i] * V[2][j];
133  }
134 
135  Av[0][i] *= scale[0];
136  Av[1][i] *= scale[1];
137  Av[2][i] = Av[2][i] * scale[2] + V[3][i] + V[4][i];
138  }
139 }
140 
157 static inline
158 void matvec_n_by_m_scale_special2 (const int m, const double* __restrict__ scale,
159  const double* __restrict__ A, const double** __restrict__ V,
160  double** __restrict__ Av) {
161  //for each row
162  for (int i = 0; i < NSP; ++i) {
163  Av[0][i] = A[i] * V[0][0];
164  Av[1][i] = A[i] * V[1][0];
165 
166  //go across a row of A, multiplying by a column of phiHm
167 
168  for (int j = 1; j < m; ++j) {
169  Av[0][i] += A[j * NSP + i] * V[0][j];
170  Av[1][i] += A[j * NSP + i] * V[1][j];
171  }
172 
173  Av[0][i] *= scale[0];
174  Av[1][i] *= scale[1];
175  }
176 }
177 
179 
192 static inline
193 void matvec_n_by_m_scale_add (const int m, const double scale, const double* __restrict__ A,
194  const double* __restrict__ V, double* __restrict__ Av,
195  const double* __restrict__ add) {
196  //for each row
197  for (int i = 0; i < NSP; ++i) {
198  Av[i] = A[i] * V[0];
199 
200  //go across a row of A, multiplying by a column of phiHm
201 
202  for (int j = 1; j < m; ++j) {
203  Av[i] += A[j * NSP + i] * V[j];
204  }
205 
206  Av[i] = Av[i] * scale + add[i];
207  }
208 }
209 
211 
226 static inline
227 void matvec_n_by_m_scale_add_subtract (const int m, const double scale,
228  const double* __restrict__ A, const double* __restrict__ V,
229  double* __restrict__ Av, const double* __restrict__ add,
230  const double* __restrict__ sub) {
231  //for each row
232 
233  for (int i = 0; i < NSP; ++i) {
234  Av[i] = A[i] * V[0];
235 
236  //go across a row of A, multiplying by a column of phiHm
237 
238  for (int j = 1; j < m; ++j) {
239  Av[i] += A[j * NSP + i] * V[j];
240  }
241 
242  Av[i] = Av[i] * scale + 2.0 * add[i] - sub[i];
243  }
244 }
245 
247 
257 static inline
258 void scale (const double* __restrict__ y0, const double* __restrict__ y1, double* __restrict__ sc) {
259 
260  for (int i = 0; i < NSP; ++i) {
261  sc[i] = 1.0 / (ATOL + fmax(fabs(y0[i]), fabs(y1[i])) * RTOL);
262  }
263 }
264 
266 
273 static inline
274 void scale_init (const double* __restrict__ y0, double* __restrict__ sc) {
275 
276  for (int i = 0; i < NSP; ++i) {
277  sc[i] = 1.0 / (ATOL + fabs(y0[i]) * RTOL);
278  }
279 }
280 
282 
292 static inline
293 double sc_norm (const double* __restrict__ nums, const double* __restrict__ sc) {
294  double norm = 0.0;
295 
296  for (int i = 0; i < NSP; ++i) {
297  norm += nums[i] * nums[i] * sc[i] * sc[i];
298  }
299 
300  return sqrt(norm / NSP);
301 }
302 
310 static inline
311 double two_norm(const double* __restrict__ v)
312 {
313  double norm = 0.0;
314 
315  for (int i = 0; i < NSP; ++i) {
316  norm += v[i] * v[i];
317  }
318  return sqrt(norm);
319 }
320 
329 static inline
330 double normalize (const double* __restrict__ v, double* __restrict__ v_out) {
331 
332  double norm = two_norm(v);
333 
334  if (norm == 0)
335  norm = 1;
336 
337  double m_norm = 1.0 / norm;
338 
339 
340  for (int i = 0; i < NSP; ++i) {
341  v_out[i] = v[i] * m_norm;
342  }
343  return norm;
344 }
345 
355 static inline
356 double dotproduct(const double* __restrict__ w, const double* __restrict__ Vm)
357 {
358  double sum = 0;
359 
360  for(int i = 0; i < NSP; i++)
361  {
362  sum += w[i] * Vm[i];
363  }
364  return sum;
365 }
366 
376 static inline void scale_subtract(const double s, const double* __restrict__ Vm, double* __restrict__ w)
377 {
378 
379  for (int i = 0; i < NSP; i++)
380  {
381  w[i] -= s * Vm[i];
382  }
383 }
384 
385 
395 static inline void scale_mult(const double s, const double* __restrict__ w, double* __restrict__ Vm)
396 {
397 
398  for (int i = 0; i < NSP; i++)
399  {
400  Vm[i] = w[i] * s;
401  }
402 }
403 #endif
static void scale_init(const double *__restrict__ y0, double *__restrict__ sc)
Get scaling for weighted norm for the initial timestep (used in krylov process)
An example header file that defines system size and other required methods for integration of the van...
static void scale_mult(const double s, const double *__restrict__ w, double *__restrict__ Vm)
Sets Vm to s * w.
static double sc_norm(const double *__restrict__ nums, const double *__restrict__ sc)
Perform weighted norm.
static void matvec_n_by_m_scale_special2(const int m, const double *__restrict__ scale, const double *__restrict__ A, const double **__restrict__ V, double **__restrict__ Av)
Matrix-vector multiplication of a matrix sized NSPxM and a vector of size Mx1 scaled by a specified f...
#define NSP
The IVP system size.
Definition: header.cuh:20
#define STRIDE
the matrix dimensions
A file generated by Scons that specifies various options to the solvers.
static double dotproduct(const double *__restrict__ w, const double *__restrict__ Vm)
Performs the dot product of the w (NSP x 1) vector with the given subspace vector (NSP x 1) ...
static void matvec_n_by_m_scale_add_subtract(const int m, const double scale, const double *__restrict__ A, const double *__restrict__ V, double *__restrict__ Av, const double *__restrict__ add, const double *__restrict__ sub)
Matrix-vector multiplication of a matrix sized NSPxM and a vector of size Mx1 scaled by a specified f...
static void matvec_m_by_m(const int m, const double *__restrict__ A, const double *__restrict__ V, double *__restrict__ Av)
Matrix-vector multiplication of a matrix sized MxM and a vector Mx1.
#define RTOL
static double normalize(const double *__restrict__ v, double *__restrict__ v_out)
Normalize the input vector using a 2-norm.
#define ATOL
static void matvec_n_by_m_scale_add(const int m, const double scale, const double *__restrict__ A, const double *__restrict__ V, double *__restrict__ Av, const double *__restrict__ add)
Matrix-vector multiplication of a matrix sized NSPxM and a vector of size Mx1 scaled by a specified f...
static void scale_subtract(const double s, const double *__restrict__ Vm, double *__restrict__ w)
Subtracts Vm scaled by s from w.
simple convenience file to include the correct solver properties file
static void scale(const double *__restrict__ y0, const double *__restrict__ y1, double *__restrict__ sc)
Get scaling for weighted norm.
static void matvec_m_by_m_plusequal(const int m, const double *__restrict__ A, const double *__restrict__ V, double *__restrict__ Av)
Matrix-vector plus equals for a matrix of size MxM and vector of size Mx1. That is, it returns (A + I) * v.
static void matvec_n_by_m_scale(const int m, const double scale, const double *__restrict__ A, const double *__restrict__ V, double *__restrict__ Av)
Matrix-vector multiplication of a matrix sized NSPxM and a vector of size Mx1 scaled by a specified f...
static double two_norm(const double *__restrict__ v)
Computes and returns the two norm of a vector.
static void matvec_n_by_m_scale_special(const int m, const double *__restrict__ scale, const double *__restrict__ A, const double **__restrict__ V, double **__restrict__ Av)
Matrix-vector multiplication of a matrix sized NSPxM and a vector of size Mx1 scaled by a specified f...