An open source method of characteristics neutron transport code.
linalg.h
Go to the documentation of this file.
1 
9 /* File: linalg.h */
10 
11 #ifndef LINALG_H_
12 #define LINALG_H_
13 
14 #ifdef __cplusplus
15 #ifdef SWIG
16 #include "Python.h"
17 #endif
18 #include "log.h"
19 #include "Matrix.h"
20 #include "Vector.h"
21 #include "constants.h"
22 #include <math.h>
23 #include <vector>
24 #include <omp.h>
25 #endif
26 
27 
32 
33  /* The Max. prolongation factor of the CMFD */
34  double pf;
35 
36  /* The initial residual of the CMFD eigenvalue problem */
37  double cmfd_res_1;
38 
39  /* The final residual of the CMFD eigenvalue problem */
40  double cmfd_res_end;
41 
42  /* The linear solver residual of the first CMFD eigenvalue iteration */
43  double linear_res_1;
44 
45  /* The linear solver residual of the final CMFD eigenvalue iteration */
46  double linear_res_end;
47 
48  /* The number of the CMFD eigenvalue iterations */
49  int cmfd_iters;
50 
51  /* The number of linear iterations for the first CMFD eigenvalue iteration */
52  int linear_iters_1;
53 
54  /* The number of linear iterations for the final CMFD eigenvalue iteration */
55  int linear_iters_end;
56 
57  /* Constructor initializes convergence statistics to -1 */
58  ConvergenceData() {
59  pf = -1;
60  cmfd_res_1 = -1;
61  cmfd_res_end = -1;
62  linear_res_1 = -1;
63  linear_res_end = -1;
64  cmfd_iters = -1;
65  linear_iters_1 = -1;
66  linear_iters_end = -1;
67  }
68 };
69 
70 
75 
76  int _num_domains_x;
77  int _num_domains_y;
78  int _num_domains_z;
79  int _domain_idx_x;
80  int _domain_idx_y;
81  int _domain_idx_z;
82  int _local_num_x;
83  int _local_num_y;
84  int _local_num_z;
85 
86  /* Sum of the starting CMFD global indexes of a domain, for the color*/
87  int _offset;
88 
89  /* Number of connecting neighbors for each surface cell */
90  int** num_connections;
91 
92  /* Indexes of connecting neighbors for each surface cell */
93  int*** indexes;
94 
95  /* Surface numbers of connecting neighbors for each surface cell */
96  int*** domains;
97 
98  /* Coupling coeffs between connecting neighbors and itself for each
99  surface cell */
100  CMFD_PRECISION*** coupling_coeffs;
101 
102  /* Fluxes of connecting neighbors for each surface cell*/
103  CMFD_PRECISION*** fluxes;
104 
105  /* Buffer for sending/receiving fluxes to/from connecting neighbors */
106  CMFD_PRECISION** buffer;
107 
108  /* Map to the index of the boundary elements */
109  std::map<int, int> mapLocalToSurface;
110 
111  int num_groups;
112  bool stop;
113 #ifdef MPIx
114  MPI_Comm _MPI_cart;
115 #endif
116 };
117 
118 
123 #ifdef MPIx
124 void getCouplingTerms(DomainCommunicator* comm, int color, int*& coupling_sizes,
125  int**& coupling_indexes, CMFD_PRECISION**& coupling_coeffs,
126  CMFD_PRECISION**& coupling_fluxes,
127  CMFD_PRECISION* curr_fluxes, int& offset);
128 #endif
129 
130 double eigenvalueSolve(Matrix* A, Matrix* M, Vector* X, double k_eff,
131  double tol, double SOR_factor=1.5,
132  ConvergenceData* convergence_data = NULL,
133  DomainCommunicator* comm = NULL);
134 bool linearSolve(Matrix* A, Matrix* M, Vector* X, Vector* B, double tol,
135  double SOR_factor=1.5,
136  ConvergenceData* convergence_data = NULL,
137  DomainCommunicator* comm = NULL);
138 bool ddLinearSolve(Matrix* A, Matrix* M, Vector* X, Vector* B, double tol,
139  double SOR_factor, ConvergenceData* convergence_data,
140  DomainCommunicator* comm);
141 void matrixMultiplication(Matrix* A, Vector* X, Vector* B);
142 double computeRMSE(Vector* x, Vector* y, bool integrated,
143  DomainCommunicator* comm = NULL);
144 
145 
152 template<typename T>
153 inline void matrix_transpose(T* matrix, int dim1, int dim2) {
154 
155  std::vector<T> temp(dim1 * dim2);
156 
157  for (int i=0; i < dim1; i++) {
158  for (int j=0; j < dim2; j++)
159  temp[i * dim1 + j] = matrix[j * dim1 + i];
160  }
161 
162  std::copy(temp.begin(), temp.end(), matrix);
163 }
164 
165 #endif /* LINALG_H_ */
Definition: Vector.h:27
Math constants and comparision tolerances.
Verbose iteration information for the CMFD eigenvalue solver.
Definition: linalg.h:31
Structure for communication of fluxes between neighbor domains.
Definition: linalg.h:74
void matrix_transpose(T *matrix, int dim1, int dim2)
Transpose a 2D matrix.
Definition: linalg.h:153
double eigenvalueSolve(Matrix *A, Matrix *M, Vector *X, double k_eff, double tol, double SOR_factor=1.5, ConvergenceData *convergence_data=NULL, DomainCommunicator *comm=NULL)
Get coupling fluxes and other information from neighbors.
Definition: linalg.cpp:25
void matrixMultiplication(Matrix *A, Vector *X, Vector *B)
Performs a matrix vector multiplication.
Definition: linalg.cpp:533
bool ddLinearSolve(Matrix *A, Matrix *M, Vector *X, Vector *B, double tol, double SOR_factor, ConvergenceData *convergence_data, DomainCommunicator *comm)
Solves a linear system using the linear solver above, but makes the loss and streaming matrix diagona...
Definition: linalg.cpp:696
bool linearSolve(Matrix *A, Matrix *M, Vector *X, Vector *B, double tol, double SOR_factor=1.5, ConvergenceData *convergence_data=NULL, DomainCommunicator *comm=NULL)
Solves a linear system using Red-Black Gauss Seidel with successive over-relaxation.
Definition: linalg.cpp:179
A matrix object.
Definition: Matrix.h:26
double computeRMSE(Vector *x, Vector *y, bool integrated, DomainCommunicator *comm=NULL)
Computes the Root Mean Square Error of two Vectors.
Definition: linalg.cpp:583
A vector object.
Utility functions for writing log messages to the screen.