-
Notifications
You must be signed in to change notification settings - Fork 7
/
SphPressureTerms.h
152 lines (136 loc) · 6.94 KB
/
SphPressureTerms.h
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
/*
Macros for function:
void SphPressureTermsSym(PARTICLE *p,int nSmooth,NN *nnList,SMF *smf)
in smoothfcn.c
This code is used 3 times. Constrained to use Macros (not functions) because
Macro definitions change between uses as follows:
1) with p and q active
hash define PACTIVE(xxx) xxx
hash define QACTIVE(xxx) xxx
2) with just p active
hash define PACTIVE(xxx) xxx
hash define QACTIVE(xxx)
3) with just q active
hash define PACTIVE(xxx)
hash define QACTIVE(xxx) xxx
All Macros and Variables not defined here are defined in smoothfcn.c
*/
#define DRHODTACTIVE(xxx)
#ifdef FEEDBACKDIFFLIMIT
#define DIFFUSIONLimitTest() (diffSum == 0 || smf->dTime < p->fTimeCoolIsOffUntil || smf->dTime < q->fTimeCoolIsOffUntil)
#else
#define DIFFUSIONLimitTest() (diffSum == 0)
#endif
#define DIFFUSIONBase() double diffSum = (p->diff+q->diff); \
double diffBase = (DIFFUSIONLimitTest() ? 0 : diffSum);
#define MASSDIFFFAC(pother_) 1
#define DIFFUSIONMetalsBase() double diffMetalsBase = 2*smf->dMetalDiffusionCoeff*diffBase \
/(p->fDensity+q->fDensity);
#define DIFFUSIONMass()
#define DIFFUSIONVelocity()
#if defined(UNONCOOL) && !defined(TWOPHASE)
#define DIFFUSIONThermaluHot() \
{ double diffuNc = diffTh*(p->uHotPred-q->uHotPred); \
PACTIVE( p->uHotDotDiff += diffuNc*rq ); \
QACTIVE( q->uHotDotDiff -= diffuNc*rp ); \
}
#else
#define DIFFUSIONThermaluHot()
#endif
/* Default -- thermal diffusion */
#ifdef THERMALCOND
/* Harmonic average coeff */
#define DIFFUSIONThermalCondBase(dt_) double dThermalCondSum = p->fThermalCond + q->fThermalCond; \
double dThermalCond = ( dThermalCondSum <= 0 ? 0 : 4*p->fThermalCond*q->fThermalCond/(dThermalCondSum*p->fDensity*q->fDensity) ); \
if (dThermalCond > 0 && (dt_diff = smf->dtFacDiffusion*ph*ph/(dThermalCond*p->fDensity)) < dt_) dt_ = dt_diff;
#else
#define DIFFUSIONThermalCondBase(dt_) double dThermalCond=0;
#endif
#define DIFFUSIONShockCondBase() double dShockCond = 0;
#define DIFFUSIONShockCond() double dShockCond = 0;
#define DIFFUSIONThermal(dt_) \
{ double diffTh = (2*smf->dThermalDiffusionCoeff*diffBase/(p->fDensity+q->fDensity)); \
double dt_diff, diffu; \
DIFFUSIONThermalCondBase(dt_); \
if (diffTh > 0 && (dt_diff= smf->dtFacDiffusion*ph*ph/(diffTh*p->fDensity)) < dt_) dt_ = dt_diff; \
diffu = (diffTh+dThermalCond+dShockCond)*(p->uPred-q->uPred); \
PACTIVE( p->uDotDiff += diffu*rq*MASSDIFFFAC(q) ); \
QACTIVE( q->uDotDiff -= diffu*rp*MASSDIFFFAC(p) ); \
DIFFUSIONThermaluHot(); }
#define DIFFUSIONMetals() \
{ double diff = diffMetalsBase*(p->fMetals - q->fMetals); \
PACTIVE( p->fMetalsDot += diff*rq*MASSDIFFFAC(q) ); \
QACTIVE( q->fMetalsDot -= diff*rp*MASSDIFFFAC(p) ); }
#ifdef STARFORM
#define DIFFUSIONMetalsOxygen() \
{ double diff = diffMetalsBase*(p->fMFracOxygen - q->fMFracOxygen); \
PACTIVE( p->fMFracOxygenDot += diff*rq*MASSDIFFFAC(q) ); \
QACTIVE( q->fMFracOxygenDot -= diff*rp*MASSDIFFFAC(p) ); }
#define DIFFUSIONMetalsIron() \
{ double diff = diffMetalsBase*(p->fMFracIron - q->fMFracIron); \
PACTIVE( p->fMFracIronDot += diff*rq*MASSDIFFFAC(q) ); \
QACTIVE( q->fMFracIronDot -= diff*rp*MASSDIFFFAC(p) ); }
#else
#define DIFFUSIONMetalsOxygen()
#define DIFFUSIONMetalsIron()
#endif /* STARFORM */
#if defined(VARALPHA) || defined(CULLENDEHNEN)
#define ALPHA (smf->alpha*0.5*(p->alpha+q->alpha))
#define BETA (smf->beta*0.5*(p->alpha+q->alpha))
#else
#define ALPHA (smf->alpha)
#define BETA (smf->beta)
#endif
#define SETDTNEW_PQ(dt_) { if (dt_ < p->dtNew) p->dtNew=dt_; \
if (dt_ < q->dtNew) q->dtNew=dt_; \
if (4*q->dt < p->dtNew) p->dtNew = 4*q->dt; \
if (4*p->dt < q->dtNew) q->dtNew = 4*p->dt; }
#define ARTIFICIALVISCOSITY(visc_,dt_) { absmu = -dvdotdr*smf->a \
/sqrt(nnList[i].fDist2); /* mu multiply by a to be consistent with physical c */ \
if (absmu>p->mumax) p->mumax=absmu; /* mu terms for gas time step */ \
if (absmu>q->mumax) q->mumax=absmu; \
visc_ = (ALPHA*(pc + q->c) + BETA*1.5*absmu); \
dt_ = smf->dtFacCourant*ph/(0.625*(pc + q->c)+0.375*visc_); \
visc_ = SWITCHCOMBINE(p,q)*visc_ \
*absmu/(pDensity + q->fDensity); }
/* Force Calculation between particles p and q */
DRHODTACTIVE( PACTIVE( p->fDivv_PdV -= rq/p->fDivv_Corrector/RHO_DIVV(pDensity,q->fDensity)*dvdotdr; ));
DRHODTACTIVE( QACTIVE( q->fDivv_PdV -= rp/p->fDivv_Corrector/RHO_DIVV(q->fDensity,pDensity)*dvdotdr; ));
DRHODTACTIVE( PACTIVE( p->fDivv_PdVcorr -= rq/RHO_DIVV(pDensity,q->fDensity)*dvdotdr; ));
DRHODTACTIVE( QACTIVE( q->fDivv_PdVcorr -= rp/RHO_DIVV(q->fDensity,pDensity)*dvdotdr; ));
PACTIVE( p->uDotPdV += rq*PRES_PDV(pPoverRho2,qPoverRho2)*dvdotdr; );
QACTIVE( q->uDotPdV += rp*PRES_PDV(qPoverRho2,pPoverRho2)*dvdotdr; );
//if (p->iOrder == 865177) printf("sphp %d: %g %g %g %g\n",p->iOrder,p->u,pPoverRho2,dvdotdr,rq*PRES_PDV(pPoverRho2,qPoverRho2)*dvdotdr );
//if (q->iOrder == 865177) printf("sphq %q: %g %g %g %g\n",q->iOrder,q->u,qPoverRho2,dvdotdr,rp*PRES_PDV(qPoverRho2,pPoverRho2)*dvdotdr );
PACTIVE( Accp = (PRES_ACC(pPoverRho2f,qPoverRho2f)); );
QACTIVE( Accq = (PRES_ACC(qPoverRho2f,pPoverRho2f)); );
//DIFFUSIONShockCondBase();
if (dvdotdr>=0.0) {
dt = smf->dtFacCourant*ph/(2*(pc > q->c ? pc : q->c));
}
else {
ARTIFICIALVISCOSITY(visc,dt); /* Calculate Artificial viscosity terms and associated dt */
PACTIVE( p->uDotAV += rq*(0.5*visc)*dvdotdr; );
QACTIVE( q->uDotAV += rp*(0.5*visc)*dvdotdr; );
PACTIVE( Accp += visc; );
QACTIVE( Accq += visc; );
}
PACTIVE( Accp *= rq*aFac; );/* aFac - convert to comoving acceleration */
QACTIVE( Accq *= rp*aFac; );
PACTIVE( ACCEL(p,0) -= Accp * dx; );
PACTIVE( ACCEL(p,1) -= Accp * dy; );
PACTIVE( ACCEL(p,2) -= Accp * dz; );
QACTIVE( ACCEL(q,0) += Accq * dx; );
QACTIVE( ACCEL(q,1) += Accq * dy; );
QACTIVE( ACCEL(q,2) += Accq * dz; );
DIFFUSIONBase();
DIFFUSIONShockCondBase();
if (dvdotdr < 0.0) {DIFFUSIONShockCond();}
DIFFUSIONThermal(dt);
DIFFUSIONMetalsBase();
DIFFUSIONMetals();
DIFFUSIONMetalsOxygen();
DIFFUSIONMetalsIron();
DIFFUSIONMass();
DIFFUSIONVelocity();
SETDTNEW_PQ(dt);