-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplm.c
More file actions
164 lines (148 loc) · 4.77 KB
/
Copy pathplm.c
File metadata and controls
164 lines (148 loc) · 4.77 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "paul.h"
double get_signed_dp( double , double );
double minmod( double a , double b , double c ){
double m = a;
if( a*b < 0.0 ) m = 0.0;
if( fabs(b) < fabs(m) ) m = b;
if( b*c < 0.0 ) m = 0.0;
if( fabs(c) < fabs(m) ) m = c;
return(m);
}
void plm_phi( struct domain * theDomain ){
struct cell ** theCells = theDomain->theCells;
int Nr = theDomain->Nr;
int Nz = theDomain->Nz;
int * Np = theDomain->Np;
double PLM = theDomain->theParList.PLM;
int i,j,k,q;
for( j=0 ; j<Nr ; ++j ){
for( k=0 ; k<Nz ; ++k ){
int jk = j+Nr*k;
for( i=0 ; i<Np[jk] ; ++i ){
int im = i-1;
if( im == -1 ) im = Np[jk]-1;
int ip = (i+1)%Np[jk];
struct cell * c = &(theCells[jk][i]);
struct cell * cL = &(theCells[jk][im]);
struct cell * cR = &(theCells[jk][ip]);
double dpL = cL->dphi;
double dpC = c->dphi;
double dpR = cR->dphi;
for( q=0 ; q<NUM_Q ; ++q ){
double pL = cL->prim[q];
double pC = c->prim[q];
double pR = cR->prim[q];
double sL = pC - pL;
sL /= .5*( dpC + dpL );
double sR = pR - pC;
sR /= .5*( dpR + dpC );
double sC = pR - pL;
sC /= .5*( dpL + dpR ) + dpC;
c->gradp[q] = minmod( PLM*sL , sC , PLM*sR );
}
}
}
}
}
double get_dA( double * , double * , int );
void plm_trans( struct domain * theDomain , struct face * theFaces , int Nf , int dim ){
struct cell ** theCells = theDomain->theCells;
int Nr = theDomain->Nr;
int Nz = theDomain->Nz;
int * Np = theDomain->Np;
double * r_jph = theDomain->r_jph;
double * z_kph = theDomain->z_kph;
double PLM = theDomain->theParList.PLM;
int i,j,k,q;
//Clear gradients
for( j=0 ; j<Nr ; ++j ){
for( k=0 ; k<Nz ; ++k ){
int jk = j+Nr*k;
for( i=0 ; i<Np[jk] ; ++i ){
memset( theCells[jk][i].grad , 0 , NUM_Q*sizeof(double) );
}
}
}
//Add weighted slopes
int n;
for( n=0 ; n<Nf ; ++n ){
struct face * f = &( theFaces[n] );
double phi = f->cm[1];
struct cell * cL = f->L;
struct cell * cR = f->R;
double dxL = f->dxL;
double dxR = f->dxR;
double phiL = cL->piph - .5*cL->dphi;
double phiR = cR->piph - .5*cR->dphi;
double dpL = get_signed_dp(phi,phiL);
double dpR = get_signed_dp(phiR,phi);
double dA = f->dA;
for( q=0 ; q<NUM_Q ; ++q ){
double WL = cL->prim[q] + dpL*cL->gradp[q];
double WR = cR->prim[q] - dpR*cR->gradp[q];
double S = (WR-WL)/(dxR+dxL);
cL->grad[q] += S*dA;
cR->grad[q] += S*dA;
}
}
//Divide by total weight
for( j=0 ; j<Nr ; ++j ){
for( k=0 ; k<Nz ; ++k ){
int jk = j+Nr*k;
for( i=0 ; i<Np[jk] ; ++i ){
struct cell * c = &(theCells[jk][i]);
double phip = c->piph;
double phim = phip - c->dphi;
double xp[3] = {r_jph[j ],phip,z_kph[k ]};
double xm[3] = {r_jph[j-1],phim,z_kph[k-1]};
if( dim==1 ) xm[0] = r_jph[j];
else xm[2] = z_kph[k];
double dAp = get_dA(xp,xm,dim);
if( dim==1 ){
xp[0] = r_jph[j-1];
xm[0] = r_jph[j-1];
}else{
xp[2] = z_kph[k-1];
xm[2] = z_kph[k-1];
}
double dAm = get_dA(xp,xm,dim);
double dAtot = dAp+dAm;
if( (dim==1 && j==0 ) || (dim==2 && k==0 ) ) dAtot = dAp;
if( (dim==1 && j==Nr-1) || (dim==2 && k==Nz-1) ) dAtot = dAm;
for( q=0 ; q<NUM_Q ; ++q ){
c->grad[q] /= dAtot;
}
}
}
}
//Slope Limiting
for( n=0 ; n<Nf ; ++n ){
struct face * f = &( theFaces[n] );
double phi = f->cm[1];
struct cell * cL = f->L;
struct cell * cR = f->R;
double dxL = f->dxL;
double dxR = f->dxR;
double phiL = cL->piph - .5*cL->dphi;
double phiR = cR->piph - .5*cR->dphi;
double dpL = get_signed_dp(phi,phiL);
double dpR = get_signed_dp(phiR,phi);
for( q=0 ; q<NUM_Q ; ++q ){
double WL = cL->prim[q] + dpL*cL->gradp[q];
double WR = cR->prim[q] - dpR*cR->gradp[q];
double S = (WR-WL)/(dxR+dxL);
double SL = cL->grad[q];
double SR = cR->grad[q];
if( S*SL < 0.0 ){
cL->grad[q] = 0.0;
}else if( fabs(PLM*S) < fabs(SL) ){
cL->grad[q] = PLM*S;
}
if( S*SR < 0.0 ){
cR->grad[q] = 0.0;
}else if( fabs(PLM*S) < fabs(SR) ){
cR->grad[q] = PLM*S;
}
}
}
}