CG_solver.h
Go to the documentation of this file.
1 //
2 // This file is part of the FFEA simulation package
3 //
4 // Copyright (c) by the Theory and Development FFEA teams,
5 // as they appear in the README.md file.
6 //
7 // FFEA is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // FFEA is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with FFEA. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // To help us fund FFEA development, we humbly ask that you cite
21 // the research papers on the package.
22 //
23 
24 #ifndef CG_SOLVER_H_INCLUDED
25 #define CG_SOLVER_H_INCLUDED
26 
27 #include <stdlib.h>
28 #include <stdio.h>
29 
30 #include "FFEA_return_codes.h"
31 #include "mat_vec_types.h"
33 
34 class CG_solver {
35 public:
36  CG_solver();
37  ~CG_solver();
38 
39  int init(int N, scalar tol, int max_num_iterations);
40 
42 
43  int solve(SparseMatrixFixedPattern *A, scalar *x, scalar *b, int num_iterations);
44 
45 private:
46 
47  int N;
48 
50 
52 
54 
55  scalar *d;
56  scalar *r;
57  scalar *q;
58  scalar *s;
59 
61 
62  scalar residual2();
63 
64  void parallel_vector_add_self(scalar *v1, scalar a, scalar *v2);
65 
66  void parallel_vector_add(scalar *v1, scalar a, scalar *v2);
67 
69 
70  void zero(scalar *v);
71 
73  scalar dot(scalar *a, scalar *b);
74 };
75 
76 #endif
scalar parallel_apply_preconditioner()
Definition: CG_solver.cpp:197
int init(int N, scalar tol, int max_num_iterations)
Definition: CG_solver.cpp:54
int max_num_iterations
Maximum number of iterations before giving up.
Definition: CG_solver.h:51
void parallel_vector_add(scalar *v1, scalar a, scalar *v2)
Definition: CG_solver.cpp:188
scalar residual2()
Definition: CG_solver.cpp:166
scalar * r
Vector needed for use by conjugate gradient solver.
Definition: CG_solver.h:56
scalar * d
Vector needed for use by conjugate gradient solver.
Definition: CG_solver.h:55
void zero(scalar *v)
Definition: CG_solver.cpp:210
~CG_solver()
Definition: CG_solver.cpp:37
static const int x
Definition: rod_math_v9.h:52
scalar dot(scalar *a, scalar *b)
Definition: CG_solver.cpp:216
scalar conjugate_gradient_residual(SparseMatrixFixedPattern *A, scalar *x, scalar *b)
Definition: CG_solver.cpp:149
Definition: SparseMatrixFixedPattern.h:36
CG_solver()
Definition: CG_solver.cpp:26
int solve(SparseMatrixFixedPattern *A, scalar *x, scalar *b)
Definition: CG_solver.cpp:85
Definition: CG_solver.h:34
scalar * inv_M
The preconditioner matrix (inverse of the diagonal)
Definition: CG_solver.h:53
scalar tol
The convergence tolerance threshold.
Definition: CG_solver.h:49
void parallel_vector_add_self(scalar *v1, scalar a, scalar *v2)
Definition: CG_solver.cpp:179
int N
The number of unknowns.
Definition: CG_solver.h:47
scalar * q
Vector needed for use by conjugate gradient solver.
Definition: CG_solver.h:57
double scalar
Definition: mat_vec_types.h:36
scalar * s
Vector needed for use by conjugate gradient solver.
Definition: CG_solver.h:58