Liquid Diffusion Model

Liquid Diffusion Model preview image

2 collaborators

Redpanda Joshua Abraham (Author)
Darren Nguyen (Team member)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.1.0 • Viewed 860 times • Downloaded 29 times • Run 0 times
Download the 'Liquid Diffusion Model' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This model primarily simulates the qualittative relationship between liquid diffusion and temperature (K). The model begins with one drop of colored dye at the top of the world which diffuses, or spreads, slowly throughout the clear, in this simulation white, water.

HOW IT WORKS

This model utilizes several key procedures and global variables in order to function:

  • [turtle-dyecolor] is a global defined as the color of the dye. This variable allows the hidden turtle(s) in motion within the world to change their respective patch color to that of the predefined global.

  • [dye-color] & [true-color] are two patches-own variables that allow the patches to change their color. At each [go] iteration, the patches beneath the turtles adopt the [turtle-dyecolor] as their own dyecolor. However, because the [diffuse] command lowers the variable of color, which in turn darkens the color, it is important to invert the numbers. Using equations found for each predefined color, [dye-color] is converted to [true-color] and then [true-color] is set as the new patch color in order to allow proper color diffusion.

  • [temperature] is the main variable that alters how diffusion is carried out. It affects the [direction] and [hatch-rate] of each turtle. Higher temperatures lead to more variability in direction and more frequent splitting, or hatching, of turtles.

  • [color-choice] is defined in the User interface (UI) and defines aesthetic color of the dye. Within the code, this leads the [check-color-change-factor] procedure to define the [color-change-factor]. This factor allows the constants within the code to increase or decrease by multiples of 10 in order to properly adjust color coefficients. For example, selecting orange, which is one set of ten data values away from base color red, creates a [color-change-factor] of 1. This leads the [turtle-dye-color] to increase in value during the set-up by a factor of 1 x 10, giving an orange dye color instead of base red.

  • [dye trials] on the UI defines how many turtles are currently dying the world in the given color.

HOW TO USE IT

(1) Choose a color in the [color-choice] input. (2) Select a temperature in the appropriate slider. Optional: Alter the turtle speed and the diffusion rate. (3) Click [setup]. (4) Click [go].

At any point during the model, the "go" button can be deslected to stop the model manually.

As the model runs, changing the color will yeild values that alter the overall dye color incorrectly and provide miscolored dye.

THINGS TO NOTICE

As the simulation is running, notice how the dye gradually splits into multiple trails. Also notice how, over time, the dye decreases in saturation. How does this represent diffusion?

THINGS TO TRY

1) Compare the maximum temperature and minimum temperature? How does directionality of the dye change?

2) How does diffusion rate affect the final visual result?

3) Change the [turtle-speed] to 0.5, the minimum. How does this affect the final visual result?

EXTENDING THE MODEL

A weakness in the accuracy of this model is the lack of depreciation of the dye trails over time, leading to an unlimited concentration of dye over a large span of time. Extending the model can include the decrease in the initial concentration of dye.

To make the code more complicated, this model can become mathematical using a matlab extension that calculates gradient of diffusion. More simply, this model can also be upgraded by streamlining color choice procedures to allow a wider array of color choice.

Lastly, this model can become more complex by allowing the user to define the medium in which the dye runs. For example, instead of pure water, the dye can run inside salt water.

NETLOGO FEATURES

Note the use of [globals] at the top of the code to define variables not present in the user interface.

The cornerstone of this model is the singular use of [diffuse] which allows the patches to spread its [dye-color] to their eight surrounding patches.

RELATED MODELS

This model is based on Uri Wilensky's "Diffusion Graphics" model which simulates temperature diffusion. In particular, this liquid diffusion simulation borrows Wilensky's turtle to patch variable exchange, which gives the [turtle-dyecolor] to patches in the form of [dye-color].

CREDITS AND REFERENCES

Programmed by: Joshua Abraham and Darren Nguyen Teacher: Mr. Reese Tracy High School IB Physics Period 1

Credit to NetLogo program and for the "Diffusion Graphics" model for fractions of this simulation's code:

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

patches-own [ 
  dye-color                                                       ;Variable to adopt dye color from turtles
  true-color ]                                                    ;Output variable from "dye-color" which creates patch color
turtles-own [
  true-speed ]                                                    ;Speed of turtles
globals [ 
  direction                                                       ;Variable for variablity in direction
  hatch-rate                                                      ;Frequency of hatching/spreading dye trails
  color-change-factor                                             ;Variable to alter color constants
  turtle-dyecolor]                                                ;Variable to dye patches a color

to setup
  clear-all                                                       ;Clears all entities and resets all patches
  check-color-change-factor                                       ;Executes the function "check-color-change-factor"
  set turtle-dyecolor (19 + (10 * color-change-factor))           ;Sets the turtle-dyecolor relative to the the color-change-factor
  set-default-shape turtles "circle"                              ;Sets the default shape for all turtles to "circle"
  ask patches [set dye-color (10.1 + (10 * color-change-factor))] ;Sets the default background to the corresponding white color
  ask turtles [set true-speed turtle-speed]                       ;Transfers the slider variable to the turtles-own

  create-turtles 1                                                ;Creates 1 turtle as a dye source
  [ setxy 0 48                                                    ;Sets the coordinates of the turtle to 0 on the x-axis and 48 and the y-axis
    set heading 180                                               ;Sets the heading of the turtle so that it faces down
    hide-turtle                                                   ;Hides the turtles so that only the diffusion pattern that it creates is apparent
    set dye-color (19 + (10 * color-change-factor)) ]             ;Sets the dye-color, an attribute of the patches, relative to the color-change-factor
  heat-check                                                      ;Executes the heat-check function, which sets variables relative to temperature
  invert-dyecolor                                                 ;Executes the invert-dyecolor function, which inverts the values of patch color that is created by the "diffuse" command
  recolor-patches                                                 ;Executes the recolor-patches function, which colors patches based off of the true-color variable
  reset-ticks
end 

to check-color-change-factor
  if color-choice = "red" 
    [set color-change-factor 0]                                   ;If the color-choice is red, then the value of the color-change-factor is set to 0
  if color-choice = "orange"
    [set color-change-factor 1]                                   ;If the color-choice is orange, then the value of the color-change factor is set to 1
  if color-choice = "green"
    [set color-change-factor 4]                                   ;If the color-choice is green, then the value of the color-change factor is set to 4
  if color-choice = "blue"
    [set color-change-factor 9]                                   ;If the color-choice is blue, then the value of the color-change factor is set to 9
  if color-choice = "magenta"
    [set color-change-factor 11]                                  ;If the color-choice is magenta, then the value of the color-change factor is set to 11
  if color-choice = "grey"
    [set color-change-factor -1]                                  ;If the color-choice is grey, then the value of the color-change factor is set to -1
end 

to heat-check
  set direction (temperature - 295)                               ;Sets the direction, a global variable, relative to the temperature as defined by the slider
  set hatch-rate ((temperature * .19) - 50)                       ;Sets the hatch-rate, a variable that determines the rate at which turtles multiply, relative to the temperature
end 

to go
  heat-check                                                      ;Executes the heat-check function, which sets variables relative to temperature
  
  ask turtles [ if turtle-dyecolor < [dye-color] of patch-here    ;If the turtle lands on a patch that is lighter than its turtle-dyecolor value, it dies
     [die]]
  
  ask turtles [ set dye-color turtle-dyecolor ]                   ;The turtle sets the dye-color of the patch that it is on to its turtle-dyecolor
  
  if ticks mod 10 = 0 [ask turtles [                              ;If the remainder ticks divided by 10 is 0, then the turtle-dyecolor is decreased by .01
    set turtle-dyecolor turtle-dyecolor - .01] ]
  ask turtles [if turtle-dyecolor < 
    (12 + (10 * color-change-factor))                             ;If the turtle-dyecolor is less than a value determined by the color-change-factor then the turtle-dyecolor will be set to that value
    [set turtle-dyecolor 12 + (10 * color-change-factor)] ]
 
  ask turtles [                                                   ;Asks the turtles to rotate a random amount that is determined by the variable, direction
    fd turtle-speed]                                              ;Asks turtles to move by the value of turtle-speed as determined by the slider
  
  if ticks > 10 [ ask turtles [                                   ;If ticks are greater than 10
    rt random direction - random direction] ]                     ;turtles will move a random direction right or left

  diffuse dye-color diffusion-rate                                ;Diffuses the value of dye-color accross nearby patches at the rate determined by the diffusion-rate slider
  invert-dyecolor                                                 ;Executes the invert-dyecolor function, which inverts the values of patch color that is created by the "diffuse" command
  recolor-patches                                                 ;Executes the recolor-patches function, which colors patches based off of the true-color variable
  spread                                                          ;Executes the spread function, which randomly hatches turtles at a determined rate
  tick                                                            ;Makes a tick pass
  wait .1                                                         ;Waits a tenth of a second
end 

to invert-dyecolor
  if color-choice = "red"                                         ;Sets the value of true-color in relation to dye-color if the color-choice is red
    [ask patches 
      [set true-color (0 - dye-color) + 30] ] 
  if color-choice = "orange"                                      ;Sets the value of true-color in relation to dye-color if the color-choice is orange
    [ask patches 
      [set true-color (0 - dye-color) + 50] ]
  if color-choice = "green"                                       ;Sets the value of true-color in relation to dye-color if the color-choice is green
    [ask patches 
      [set true-color (0 - dye-color) + 110] ]
  if color-choice = "blue"                                        ;Sets the value of true-color in relation to dye-color if the color-choice is blue
    [ask patches 
      [set true-color (0 - dye-color) + 210] ]
  if color-choice = "magenta"                                     ;Sets the value of true-color in relation to dye-color if the color-choice is magenta
    [ask patches 
      [set true-color (0 - dye-color) + 250] ]
  if color-choice = "grey"                                        ;Sets the value of true-color in relation to dye-color if the color-choice is grey
    [ask patches 
      [set true-color (0 - dye-color) + 10] ]
end 

to recolor-patches  
  ask patches [ set pcolor true-color ]                           ;color patches according to true-color
end 

to spread
  if random 100 < hatch-rate [ask turtles [hatch 1                ;If the hatch-rate is less than the randomly generated value, create one turtle
    [ set heading (heading + random 40 - random 40)]]]            ;with random heading
  ask turtles [if count turtles > 100                             ;If there are more than 100 turtles, then turtles will die until there are 100 or less turtles
    [die] ]
end 

There is only one version of this model, created over 9 years ago by Joshua Abraham.

Attached files

File Type Description Last updated
Liquid Diffusion Model.png preview Preview for 'Liquid Diffusion Model' over 9 years ago, by Joshua Abraham Download

This model does not have any ancestors.

This model does not have any descendants.