forked from richloft/RBF-FD-Prototype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfstraka.c
121 lines (88 loc) · 2.81 KB
/
fstraka.c
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
#include <NS.h>
extern NS_struct* NS;
void fstraka( const fType t, const fType* restrict S, fType* restrict K){
const int U_SV_ID = 0;
const int W_SV_ID = 1;
const int TH_SV_ID = 2;
const int PI_SV_ID = 3;
// Dimensions
const int NNodes = NS->NNodes;
const int NState = NS->NState;
const int NNbrs = NS->NNbrs;
const int NNbrs_Padded = NS->NNbrs_Padded;
// planetary variables
const fType g = NS->g; //
const fType Cp = NS->Cp; //
const fType Cv = NS->Cv; //
const fType Rd = NS->Rd; //
const fType mu = NS->mu; //
const fType thbar = NS->Ts; // background temperature from Straka test case
fType dpibar_dz = - g/(Cp*thbar);
fType *pibar = NS->pibar;
// stencil and derivative operators
const int* idx = NS->idx;
const fType* Dx = NS->Dx;
const fType* Dz = NS->Dz;
const fType* L = NS->L;
for(int i=0; i<NNodes; i++){
// initialize temporary variables for spatial differentiation at respective node
fType u = 0.0;
fType w = 0.0;
fType th = 0.0;
fType pi = 0.0;
fType du_dx = 0.0;
fType dw_dx = 0.0;
fType dth_dx = 0.0;
fType dpi_dx = 0.0;
fType du_dz = 0.0;
fType dw_dz = 0.0;
fType dth_dz = 0.0;
fType dpi_dz = 0.0;
fType Lu = 0.0;
fType Lw = 0.0;
fType Lth = 0.0;
for (int j = 0; j < NNbrs; j++) {
int dm_lind = i*NNbrs_Padded + j;
int inbr = idx[dm_lind];
int iu = U_SV_ID + NState*inbr;
int iw = W_SV_ID + NState*inbr;
int ith = TH_SV_ID + NState*inbr;
int ipi = PI_SV_ID + NState*inbr;
u = S[iu];
w = S[iw];
th = S[ith];
pi = S[ipi];
// get neighbor node's state vars
// update sums
du_dx += Dx[dm_lind] * u;
dw_dx += Dx[dm_lind] * w;
dpi_dx += Dx[dm_lind] * pi;
dth_dx += Dx[dm_lind] * th;
du_dz += Dz[dm_lind] * u;
dw_dz += Dz[dm_lind] * w;
dpi_dz += Dz[dm_lind] * pi;
dth_dz += Dz[dm_lind] * th;
Lu += L[dm_lind] * u;
Lw += L[dm_lind] * w;
Lth += L[dm_lind] * th;
}
int iu = U_SV_ID + NState*i;
int iw = W_SV_ID + NState*i;
int ith = TH_SV_ID + NState*i;
int ipi = PI_SV_ID + NState*i;
u = S[iu];
w = S[iw];
th = S[ith];
pi = S[ipi];
fType rhs_u = - u * du_dx - w * du_dz - Cp*(thbar+th)*dpi_dx + mu*Lu;
fType rhs_w = - u * dw_dx - w * du_dz - Cp*(thbar+th)*dpi_dz + (g/thbar)*th + mu*Lw;
fType rhs_th = - u * dth_dx - w * dth_dz + mu*Lth;
fType rhs_pi = - u * dpi_dx - w * (dpibar_dz + dpi_dz) - (Rd/Cv)*(pibar[i]+pi)*(du_dx + dw_dz);
// ----------------------------------------------------
// evaluate projections and apply hyperviscosity
K[iu] = rhs_u;
K[iw] = rhs_w;
K[ith] = rhs_th;
K[ipi] = rhs_pi;
}
}