Class: GrayScott::Model

Inherits:
Object
  • Object
show all
Includes:
XumoShortHand
Defined in:
lib/gray_scott/model.rb

Overview

Gray-Scott model

Constant Summary collapse

Dx =
0.01
Dt =

Delta t is the change in time for each iteration

1
Du =

diffusion rate for U

2e-5
Dv =

diffusion rate for V

1e-5

Constants included from XumoShortHand

XumoShortHand::SFloat, XumoShortHand::UInt8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: 256, height: 256) ⇒ Model

Returns a new instance of Model.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gray_scott/model.rb', line 19

def initialize(width: 256, height: 256)
  # Feed rate
  @f = 0.04

  # Kill rate
  @k = 0.06

  # concentration of U
  @u = SFloat.ones height, width

  # concentration of V
  @v = SFloat.zeros height, width
end

Instance Attribute Details

#fObject

Returns the value of attribute f.



17
18
19
# File 'lib/gray_scott/model.rb', line 17

def f
  @f
end

#kObject

Returns the value of attribute k.



17
18
19
# File 'lib/gray_scott/model.rb', line 17

def k
  @k
end

#uObject

Returns the value of attribute u.



17
18
19
# File 'lib/gray_scott/model.rb', line 17

def u
  @u
end

#vObject

Returns the value of attribute v.



17
18
19
# File 'lib/gray_scott/model.rb', line 17

def v
  @v
end

Instance Method Details

#clearObject



33
34
35
36
# File 'lib/gray_scott/model.rb', line 33

def clear
  u.fill 1.0
  v.fill 0.0
end

#immune_surveillanceObject



50
51
52
53
54
55
56
# File 'lib/gray_scott/model.rb', line 50

def immune_surveillance
  # clip is better.
  @u[@u.lt 0.00001] = 0.00001
  @u[@u.gt 1] = 1
  @v[@v.lt 0.00001] = 0.00001
  @v[@v.gt 1] = 1
end

#updateObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gray_scott/model.rb', line 38

def update
  l_u = Utils::Math._laplacian2d u, Dx
  l_v = Utils::Math._laplacian2d v, Dx

  uvv = u * v * v
  dudt = Du * l_u - uvv + f * (1.0 - u)
  dvdt = Dv * l_v + uvv - (f + k) * v
  u._ + (Dt * dudt)
  v._ + (Dt * dvdt)
  immune_surveillance
end