-
Notifications
You must be signed in to change notification settings - Fork 0
/
graetz_residual_functions.cpp
138 lines (110 loc) · 3.89 KB
/
graetz_residual_functions.cpp
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
// graetz_residual_functions.cpp
//
// For use with: graetz_problem_conduct.cpp
//
// Zachary Cotman
//
// 11/21/2018
//
// These functions are used to calculate the residuals of the
// iterative solver
#include <fstream>
#include <cmath>
using namespace std; // meh
#include <gsl/gsl_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_spmatrix.h>
//#include <gsl/gsl_splinalg.h>
//#include "graetz_problem_conduct.h"
//***********************************************************************************
// Function Prototypes
double res_interior
(const int N, const int M, const double A, const double B,
const gsl_vector * C, const gsl_vector * D, const gsl_matrix * T);
double res_bottom
(const int N, const int M, const double A, const double B,
const gsl_vector * C, const gsl_vector * D, const gsl_matrix * T);
double res_lastline
(const int N, const int M, const double A, const double B,
const gsl_vector * C, const gsl_vector * D, const gsl_matrix * T);
double res_corner
(const int N, const int M, const double A, const double B,
const gsl_vector * C, const gsl_vector * D, const gsl_matrix * T);
//***********************************************************************************
// Function Definitions
double res_interior (const int N, const int M, const double A, const double B,
const gsl_vector * C, const gsl_vector * D, const gsl_matrix * T)
{
double res = 0;
double res_tot = 0;
double Cj = 0;
double Dj = 0;
for(int i = 1; i < N-1; ++i){
for(int j = 1; j < M-1; ++j){
Cj = gsl_vector_get(C, j);
Dj = gsl_vector_get(D, j);
res = (Cj - A) *gsl_matrix_get(T, j-1, i) +
(2.*(A + B)+Dj)*gsl_matrix_get(T, j, i) +
(-Cj - A) *gsl_matrix_get(T, j+1, i) -
(B + Dj) *gsl_matrix_get(T, j, i-1) -
B *gsl_matrix_get(T, j, i+1);
res_tot += res*res;
}
}
return res_tot;
}
//***********************************************************************************
double res_bottom (const int N, const int M, const double A, const double B,
const gsl_vector * C, const gsl_vector * D, const gsl_matrix * T)
{
double res = 0;
double res_tot = 0;
int j = M; j = 0;
double Cj = gsl_vector_get(C, j);
double Dj = gsl_vector_get(D, j);
j = 0;
for(int i = 1; i < N-1; ++i){
res = (4.*A + 2.*B + Dj)*gsl_matrix_get(T, j, i) +
-4.*A *gsl_matrix_get(T, j+1, i) -
(B + Dj) *gsl_matrix_get(T, j, i-1) -
B *gsl_matrix_get(T, j, i+1);
res_tot += res*res;
}
return res_tot;
}
//***********************************************************************************
double res_lastline (const int N, const int M, const double A, const double B,
const gsl_vector * C, const gsl_vector * D, const gsl_matrix * T)
{
double res = 0;
double res_tot = 0;
double Cj = 0;
double Dj = 0;
int i = N-1;
for(int j = 1; j < M-1; ++j){
Cj = gsl_vector_get(C, j);
Dj = gsl_vector_get(D, j);
res = (Cj - A) *gsl_matrix_get(T, j-1, i) +
(2.*(A + B)+Dj)*gsl_matrix_get(T, j, i) +
(-Cj - A) *gsl_matrix_get(T, j+1, i) -
2.*(B + Dj) *gsl_matrix_get(T, j, i-1);
res_tot += res*res;
}
return res_tot;
}
//***********************************************************************************
double res_corner (const int N, const int M, const double A, const double B,
const gsl_vector * C, const gsl_vector * D, const gsl_matrix * T)
{
double res = 0;
double res_tot = 0;
int i = N-1;
int j = M-M; j = 0;
double Cj = gsl_vector_get(C, j);
double Dj = gsl_vector_get(D, j);
res = (4.*A + 2.*B + Dj)*gsl_matrix_get(T, j, i) +
-4.*A *gsl_matrix_get(T, j+1, i) -
2.*(B + Dj) *gsl_matrix_get(T, j, i-1);
res_tot = res*res;
return res_tot;
}