-
Notifications
You must be signed in to change notification settings - Fork 14
/
RHSoperator.cpp
83 lines (66 loc) · 1.42 KB
/
RHSoperator.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
#include "RHSoperator.h"
template<class T>
RHSOperator<T>::RHSOperator()
{
}
template<class T>
RHSOperator<T>::~RHSOperator()
{
}
template<class T>
Central1D<T>::Central1D(DataStruct<T> &_U,
DataStruct<T> &_mesh,
FluxFunction<T> &_F):
U(_U), mesh(_mesh), F(_F)
{
RHS.setSize(_U.getSize());
}
template<class T>
Central1D<T>::~Central1D()
{
}
template<class T>
void Central1D<T>::evalRHS(DataStruct<T> &Uin)
{
// the BC should be included in the mesh
// momentarily done here by hand
T *dataRHS = RHS.getData();
const T *dataU = Uin.getData();
const T *dataMesh = mesh.getData();
const int len = U.getSize();
for(int j = 0; j < len; j++)
{
T dx;
if(j == 0)
{
dx = dataMesh[len-1] - dataMesh[len-2];
dx += dataMesh[1] - dataMesh[0];
dataRHS[0] = -(F.computeFlux(dataU[1]) - F.computeFlux(dataU[len-2]))/dx;
}
else
{
dx = dataMesh[j+1] - dataMesh[j-1];
dataRHS[j] = -(F.computeFlux(dataU[j+1]) - F.computeFlux(dataU[j-1]))/dx;
}
}
dataRHS[len-1] = dataRHS[0];
}
template<class T>
void Central1D<T>::eval()
{
evalRHS(U);
}
template<class T>
void Central1D<T>::eval(DataStruct<T> &Uin)
{
evalRHS(Uin);
}
template<class T>
DataStruct<T>& Central1D<T>::ref2RHS()
{
return RHS;
}
template class RHSOperator<float>;
template class RHSOperator<double>;
template class Central1D<float>;
template class Central1D<double>;