75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
|
|
package fluid
|
||
|
|
|
||
|
|
import "math"
|
||
|
|
|
||
|
|
type CellType int
|
||
|
|
|
||
|
|
const (
|
||
|
|
CellTypeFluid = iota
|
||
|
|
CellTypeAir
|
||
|
|
CellTypeSolid
|
||
|
|
CellTypeMax
|
||
|
|
)
|
||
|
|
|
||
|
|
type VelocityField struct {
|
||
|
|
Dimensions FieldVector //in meters
|
||
|
|
Numcells int
|
||
|
|
Nx, Ny int //number of cells in x, y
|
||
|
|
H float32 //field spacing, in meters
|
||
|
|
InvH float32
|
||
|
|
U, V []float32 //field components < u(x,y), v(x,y) >
|
||
|
|
PrevU, PrevV []float32 //previous field components < u(x,y), v(x,y) >
|
||
|
|
DU, DV []float32 //weighted sums for components < u(x,y), v(x,y) >
|
||
|
|
S []float32 //fluid cell scales
|
||
|
|
CellType []float32 //type of cell
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewVelocityField(dimensions FieldVector, spacing float32) *VelocityField {
|
||
|
|
vf := &VelocityField{
|
||
|
|
Dimensions: dimensions,
|
||
|
|
H: spacing,
|
||
|
|
InvH: 1 / spacing,
|
||
|
|
}
|
||
|
|
|
||
|
|
vf.Initialize()
|
||
|
|
return vf
|
||
|
|
}
|
||
|
|
|
||
|
|
func (vf *VelocityField) Initialize() {
|
||
|
|
|
||
|
|
vf.Nx = int(math.Floor(float64(vf.Dimensions.X/vf.H))) + 1
|
||
|
|
vf.Ny = int(math.Floor(float64(vf.Dimensions.Y/vf.H))) + 1
|
||
|
|
|
||
|
|
cellcount := vf.Nx * vf.Ny
|
||
|
|
|
||
|
|
vf.Numcells = cellcount
|
||
|
|
|
||
|
|
vf.U = make([]float32, cellcount)
|
||
|
|
vf.V = make([]float32, cellcount)
|
||
|
|
vf.PrevU = make([]float32, cellcount)
|
||
|
|
vf.PrevV = make([]float32, cellcount)
|
||
|
|
vf.DU = make([]float32, cellcount)
|
||
|
|
vf.DV = make([]float32, cellcount)
|
||
|
|
vf.S = make([]float32, cellcount)
|
||
|
|
vf.CellType = make([]float32, cellcount)
|
||
|
|
|
||
|
|
for i := 0; i < vf.Nx; i++ {
|
||
|
|
for j := 0; j < vf.Ny; j++ {
|
||
|
|
var stype float32 = CellTypeAir //port, code corrected
|
||
|
|
//var stype float32 = 1 //10mp value, claims fluid but isn't
|
||
|
|
//var stype float32 = CellTypeSolid //port, with 10mp intent
|
||
|
|
if i == 0 || i == vf.Nx-1 || j == 0 {
|
||
|
|
stype = CellTypeFluid //port, code corrected
|
||
|
|
//stype = 0 //10mp value, claims solid but isn't
|
||
|
|
//stype = CellTypeFluid //port, with 10mp intent
|
||
|
|
}
|
||
|
|
vf.S[i*vf.Ny+j] = stype
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
func (vf *VelocityField) GetIndex(i, j int) int {
|
||
|
|
return i*vf.Ny + j
|
||
|
|
}
|