: count-pn (s n -- count ) 2* dup nth-count swap 1+ nth-count 2* + ; : mass-gas (s -- n ) 0 6 0 do i count-pn + loop ; : x-mom-gas (s -- n ) 3 count-pn 0 count-pn - 2* 2 count-pn 4 count-pn + 1 count-pn 5 count-pn + - + ; : y-mom-gas (s -- n ) 4 count-pn 5 count-pn + 1 count-pn 2 count-pn + - ; : count-subcell2 2 activate-subcell *count* ; : mass-tracers (s -- n ) 0 6 0 do i nth-count + loop ; : x-mom-tracers (s -- n ) 3 nth-count 0 nth-count - 2* 2 nth-count 4 nth-count + 1 nth-count 5 nth-count + - + ; : y-mom-tracers (s -- n ) 4 nth-count 5 nth-count + 1 nth-count 2 nth-count + - ; : Print.counts *count* cr ." FHP2 mass: " mass-gas . cr ." x-mom*2: " x-mom-gas . cr ." y-mom*2/sqrt3: " y-mom-gas . cr count-subcell2 cr ." Tracer mass: " mass-tracers . cr ." x-mom*2: " x-mom-tracers . cr ." y-mom*2/sqrt3: " y-mom-tracers . cr ; press C "Count particles and momentum" : shear-space begin-line-io Y 0 ?do i Y 2/ - 2/ dup negate kick x step i read-line kick x step i write-line loop end-line-io ; : Initial.test.pattern 2 io-subcell 0 100 /random>cam 1 io-subcell random>cam 0 io-subcell test-pattern file>cam shear-space 1 steps ; press I "Initialize with test pattern." : count-mom-rule force tracer-sink <> if 0 -> gas then force tracer-sink = -> force ; create-lut count-mom-lut ?rule>table count-mom-rule count-mom-lut : count-x-fraction (s x-mom mass -- ) lut-data count-mom-lut switch-luts count-lut stop x-mom-gas 2/ mass-gas ; : count-tracers step-count @ ." Step #" . count-x-fraction 1 max 100 swap */ ." x-mom =" . ." per 100 particles" cr ; : Show.tracers ['] count-tracers is before-display { tracers messengers force } show-fields colormap tmap show cr ; press T "Show the tracer fluid." : Show.fhp2 ['] noop is before-display 0 show-subcell colormap fmap show ; press F "Show the fhp2 fluid." : Show.mpeg.movie "" run_fhp2flow_mpg "" run_fhp2flow_mpg (exec ; press M "Run mpeg movie showing 45x speedup."