Class: GrayScott::Model
- Inherits:
-
Object
- Object
- GrayScott::Model
- 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
-
#f ⇒ Object
Returns the value of attribute f.
-
#k ⇒ Object
Returns the value of attribute k.
-
#u ⇒ Object
Returns the value of attribute u.
-
#v ⇒ Object
Returns the value of attribute v.
Instance Method Summary collapse
- #clear ⇒ Object
- #immune_surveillance ⇒ Object
-
#initialize(width: 256, height: 256) ⇒ Model
constructor
A new instance of Model.
- #update ⇒ Object
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
#f ⇒ Object
Returns the value of attribute f.
17 18 19 |
# File 'lib/gray_scott/model.rb', line 17 def f @f end |
#k ⇒ Object
Returns the value of attribute k.
17 18 19 |
# File 'lib/gray_scott/model.rb', line 17 def k @k end |
#u ⇒ Object
Returns the value of attribute u.
17 18 19 |
# File 'lib/gray_scott/model.rb', line 17 def u @u end |
#v ⇒ Object
Returns the value of attribute v.
17 18 19 |
# File 'lib/gray_scott/model.rb', line 17 def v @v end |
Instance Method Details
#clear ⇒ Object
33 34 35 36 |
# File 'lib/gray_scott/model.rb', line 33 def clear u.fill 1.0 v.fill 0.0 end |
#immune_surveillance ⇒ Object
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 |
#update ⇒ Object
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 |