-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolverCG.h
142 lines (126 loc) · 4.5 KB
/
SolverCG.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* @file LidDrivenCavity.h
*
* High-Performance Computing 2023-24
*
* Header file of LidDrivenCavity.cpp
*
* Define all public classes and private variables
*
*/
#pragma once
#include "LidDrivenCavity.h"
/**
* @brief The SolverCG class solves a linear system using the Conjugate Gradient method.
*/
class SolverCG
{
public:
/**
* @brief Creates solverCG class. Allocates dynamic memory.
*
* @param pNx Number of grid points in the x-direction.
* @param pNy Number of grid points in the y-direction.
* @param pdx Spacing in the x-direction.
* @param pdy Spacing in the y-direction.
*/
SolverCG(int pNx, int pNy, double pdx, double pdy);
/**
* @brief Destructs solverCG class. Deletes dynamic memory on the SolverCG class.
*/
~SolverCG();
/**
* @brief Solves a linear system using the Conjugate Gradient method.
*
* @param b Right-hand side of the linear system.
* @param x Initial guess for the solution, updated with the result.
* @param solver Reference to the LidDrivenCavity object.
*/
void Solve(double* b, double* x, LidDrivenCavity& solver);
/**
* @brief Function to extract a column from a matrix.
*
* This function extracts a column from a given matrix and stores it in an array.
*
* @param matrix Pointer to the matrix.
* @param columnIdx Index of the column to be extracted.
* @param column Pointer to the array where the column will be stored.
*/
void get_column(double* matrix, int columnIdx, double* column);
/**
* @brief Function to extract a column from a matrix.
*
* This function extracts a column from a given matrix and stores it in an array.
*
* @param matrix Pointer to the matrix.
* @param columnIdx Index of the column to be extracted.
* @param column Pointer to the array where the column will be stored.
*/
void get_row(double* matrix, int rowIdx, double* row);
/**
* @brief Function to update a column of a matrix.
*
* This function updates a column of a given matrix with the values from an array.
*
* @param matrix Pointer to the matrix.
* @param columnIdx Index of the column to be updated.
* @param column Pointer to the array containing the new column values.
*/
void update_column(double* matrix, int columnIdx, double* column);
/**
* @brief Function to update a row of a matrix.
*
* This function updates a row of a given matrix with the values from an array.
*
* @param matrix Pointer to the matrix.
* @param rowIdx Index of the row to be updated.
* @param row Pointer to the array containing the new row values.
*/
void update_row(double* matrix, int rowIdx, double* row);
/**
* @brief Reduces a matrix by removing boundary elements.
*
* This function reduces a matrix by removing boundary elements, such as the first and last rows and columns,
* and stores the result in another matrix.
*
* @param matrixIn Pointer to the input matrix.
* @param matrixOut Pointer to the output matrix where the reduced matrix will be stored.
*/
void reduce_Matrix(double* matrixIn, double* matrixOut);
private:
double dx; /**< Spacing in the x-direction. */
double dy; /**< Spacing in the y-direction. */
int Nx; /**< Number of grid points in the x-direction. */
int Ny; /**< Number of grid points in the y-direction. */
double* r; /**< Residual vector. */
double* p; /**< Search direction vector. */
double* z; /**< Preconditioned search direction vector. */
double* t; /**< Temporal vector. */
double* b_reduced; /**< Reduced right-hand side vector. */
double* r_reduced; /**< Reduced residual vector. */
double* t_reduced; /**< Reduced temporal vector. */
double* p_reduced; /**< Reduced search direction vector. */
double* z_reduced; /**< Reduced preconditioned search direction vector. */
/**
* @brief Applies the discretized Laplacian operator to the input vector.
*
* @param in Input vector.
* @param out Output vector.
*/
void ApplyOperator(double* p, double* t);
/**
* @brief Applies preconditioning to the input vector.
*
* @param in Input vector.
* @param out Output vector.
*/
void Precondition(double* p, double* t);
/**
* @brief Imposes boundary condition.
*
* Boudary values equal zero.
*
* @param inout Inout vector to which BC are applied.
*/
void ImposeBC(double* p);
};