-
Notifications
You must be signed in to change notification settings - Fork 0
/
LatticeSite.cpp
136 lines (107 loc) · 2.47 KB
/
LatticeSite.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
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
#include <iostream>
#include "LatticeSite.h"
using namespace std;
const int ThermalSite::c[4][2] = {{1,0}, {0,1}, {-1,0}, {0, -1}};
const int VelSite::e[9][2] = {{0,0}, {1,0}, {0,1}, {-1,0}, {0,-1}, {1,1}, {-1,1}, {-1,-1}, {1,-1}};
const double VelSite::w[9] = {4.0/9.0, 1.0/9.0, 1.0/9.0, 1.0/9.0, 1.0/9.0, 1.0/36.0, 1.0/36.0, 1.0/36.0, 1.0/36.0};
LatticeSite::LatticeSite()
{
}
void VelSite::init(SiteType t, double rho, double u[2],
double coef_force_)
{
setType(t);
coef_force = coef_force_;
for (int k=0; k<q; k++)
f[k] = fEq(k, rho, u);
}
void ThermalSite::init(SiteType t, double T, double u[2],
double coef_force_)
{
setType(t);
for (int k=0; k<q; k++)
f[k] = fEq(k, T, u);
}
void LatticeSite::setType(SiteType t)
{
type = t;
}
bool LatticeSite::isSolid()
{
return type == Solid;
}
bool LatticeSite::isFluid()
{
return type == Fluid;
}
VelSite::VelSite()
{
q = 9;
T0 = 0.5;
}
//ThermalSite::ThermalSite(double T0_) : T0(T0_)
ThermalSite::ThermalSite()
{
q = 4;
}
void VelSite::computeRhoAndU(double& rho, double u[2])
{
rho = 0;
for (int k=0; k<q; k++)
{rho += f[k];}
u[0] = 0;
u[1] = 0;
for (int k=0; k<9; k++)
{
u[0] += f[k]*e[k][0];
u[1] += f[k]*e[k][1];
}
u[0] /= rho;
u[1] /= rho;
}
void ThermalSite::computeRhoAndU(double & rho, double u[2])
{
}
void ThermalSite::computeRhoAndU(double &T)
{
T = 0.0;
for (int k=0; k<q; k++)
T += f[k];
}
double VelSite::fEq(int k, double rho, double u[2])
{
double u2 = u[0]*u[0] + u[1]*u[1];
double eu = e[k][0]*u[0] + e[k][1]*u[1];
return rho * w[k] * (1.0 + 3.0*eu + 4.5*eu*eu - 1.5*u2);
}
double ThermalSite::fEq(int k, double T, double u[2])
{
double eu = c[k][0]*u[0] + c[k][1]*u[1];
return (1./4.)*T*(1.0 + 2.*eu);
}
void VelSite::collide(double& rho, double& T, double u[2], double omega)
{
//computeRhoAndU(rho, u);
double eu, a, F;
a = (1.-0.5*omega);
for (int k=0; k<q; k++)
{
//Compute the force from Boussinesq approx
eu = e[k][0]*u[0] + e[k][1]*u[1];
F = rho*coef_force*T;
//force = a * w[k] * (3.*(e[k][1]*F-u[1]*F) + 9.*eu*F);
force = 3.*w[k]*rho*coef_force*T*e[k][1];
f[k]= f[k]*(1.-omega) +fEq(k,rho,u)*omega + force;
// f[k] *= (1.0-omega);
// f[k] += omega*fEq(k, rho, u);
}
}
void ThermalSite::collide(double& rho, double& T, double u[2], double omega)
{
//computeRhoAndU(T);
for (int k=0; k<q; k++)
{
f[k] *= (1.0-omega);
f[k] += omega*fEq(k, T, u);
}
}