\ Bacteria growth and death rules and steps

\.

During the growth phase, bacteria with enough food may spawn and
produce children, which diffuse around -- those that find an empty
spot attach to the growing aggregate and remain fixed.  Those that
don't find a spot before the growth step is over will be deleted.  At
the same time, aggregated bacteria die at a constant rate.

.\

: birth+death-rule

                boundary 0<>            \ no bacteria allowed in boundary
        if                              \ (might be there from init)
                0 -> bacteria
        then
        update

        0 -> child+  0 -> child-
        update

                food 0<> spawn 0<> and
        if
                bacteria -> child+                
        then
        update

                die 0<>
        if
                0 -> bacteria
        then
        update
;
create-lut birth+death-lut  ?rule>table birth+death-rule birth+death-lut

: child-diffuse-rule

                mix 0<> boundary 0= and
        if
                child+ <-> child-
        then
        update

        \ at the top, force child to go down

                boundary food-source =  child- 0<> and
        if
                child- -> child+
                0 -> child-
        then
        update

        \ at the bottom, force child to go up

                boundary substrate =  child+ 0<> and
        if
                child+ -> child-
                0 -> child+
        then
        update

        \ deposit child at empty spot not on boundary

                child+ 0<> child- 0<> or  bacteria 0= and  boundary 0= and
        if
                              child+ -> bacteria
                child+ 0= if  child- -> bacteria  then
                0 -> child+  0 -> child-
        then
        update
;
create-lut child-diffuse-lut  ?rule>table child-diffuse-rule child-diffuse-lut


: birth+death-step

        lut-data birth+death-lut  switch-luts
        lut-src site
        site-src lut
        kick  spawn field random x random y random z
                die field random x random y random z
        run         
;
define-step birth+death-step0   birth+death-step  end-step
define-step birth+death-step1   birth+death-step  end-step


: child-diffuse-step (s axis dir -- )

        is dir
        is axis

        kick  child+ field  dir axis xn
              child- field -dir axis xn
              mix    field random x random y random z
        run         
;

\* Just as in the food-diffusion, we alternate the meaning of + and -
direction to avoid a bias for particles moving in the boundary -- see
comment for food-step.  *\

define-step child-diffusion
        lut-data child-diffuse-lut  switch-luts
        lut-src site
        site-src lut
        
                child-diffuse-period 0
        do
                0  1 child-diffuse-step
                1  1 child-diffuse-step
                2  1 child-diffuse-step
                0 -1 child-diffuse-step
                1  1 child-diffuse-step
                2 -1 child-diffuse-step 
       loop
end-step
