-
Notifications
You must be signed in to change notification settings - Fork 0
/
FDMApproximation.cpp
54 lines (45 loc) · 1.41 KB
/
FDMApproximation.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
/******************************************************************************
* FILE NAME FDMApproximation.cpp
* PURPOSE Finite difference method
*
* SPEC
* NOTES NONE
******************************************************************************/
#include "TaskFunctions.h"
#include "FDMApproximation.h"
void fdm_slau_assembling(const fdm_grid& grid, sparse_matrix& mSM, vector& vRP)
{
double rH2;
int nNode, nI;
std::vector<int> vNeighbours(4);
rH2 = grid.m_rH * grid.m_rH;
// assemble SLAE
for (nNode = 0; nNode < grid.m_nSize; ++nNode)
{
if (grid.node_is_boundary(nNode))
{
// write boundary condition
vRP[nNode] = bound_condition(grid.m_vCoords[nNode]);
mSM.add2(nNode, nNode) = 1.0;
}
else
{
// write finite difference equation
vRP[nNode] = rH2 * right_part(grid.m_vCoords[nNode]);
mSM.add2(nNode, nNode) = 4.0;
grid.get_neighbours(nNode, vNeighbours);
for (nI = 0; nI < 4; ++nI)
{
if (grid.node_is_boundary(vNeighbours[nI]))
{
// take into account boundary condition for SLAE symmetrization
vRP[nNode] -= -1.0 * bound_condition(grid.m_vCoords[vNeighbours[nI]]);
}
else
{
mSM.add2(nNode, vNeighbours[nI]) = -1.0;
}
}
}
}
} // end of fdm_slau_assembling