水解平衡

水解平衡 preview image

1 collaborator

Default-person Ying Li (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.4.0 • Viewed 40 times • Downloaded 1 time • Run 0 times
Download the '水解平衡' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

; Li Ying created this module at Shaanxi Normal University in 2024. If you mention this model in a publication, we ask that you include the citations below.
;Ying, L. (2024). Hydrolysis Equilibrium. School of Chemistry and Chemical Engineering, Shaanxi Normal University.
breed [mode4_h20_t mode4_h20]
breed [mode4_h_t  mode4_h]
breed [mode4_oh_t  mode4_oh]
breed [mode4_na_t  mode4_na]
breed [mode4_cl_t  mode4_cl]
breed [mode4_nh4_t  mode4_nh4]
breed [mode4_nh3h2o_t  mode4_nh3h20]
breed [mode4_ac_t  mode4_ac]
breed [mode4_hac_t  mode4_hac]
breed [mode4_nacl_t  mode4_nacl]
breed [mode4_naac_t  mode4_naac]
breed [mode4_nh4cl_t  mode4_nh4cl]
breed [mode4_nh4ac_t  mode4_nh4ac]

globals[
  Init_water
  add_flag
  ch3coona_flag
  nh4cl_flag
  Up_T_flag
  Down_T_flag
  Down_T_figure_flag
  add_CH3C00Na_flag
  add_CH3C00Na_figure_flag
  add_water_flag
  add_water_figure_flag
  add_acid_flag
  add_acid_figure_flag
  add_base_flag
  add_base_figure_flag
  update_figure_flag
  h2o_count
  h_count
  oh_count
  na_count
  cl_count
  ac_count
  hac_count
  nh4_count
  nh3h2o_count

  plot1
  plot2
  plot3
  plot4
  plot5
  plot6
]

to setup
  clear-all
  ;设置画布颜色白色
  ask patches [
    set pcolor white
  ]

  ;初始化海龟
  set-default-shape mode4_h20_t "h20"
  set-default-shape mode4_h_t "h"
  set-default-shape mode4_oh_t "oh"
  set-default-shape mode4_na_t "na"
  set-default-shape mode4_cl_t "cl"
  set-default-shape mode4_nh4_t "nh4"
  set-default-shape mode4_nh3h2o_t "nh3h20"
  set-default-shape mode4_ac_t "ac"
  set-default-shape mode4_hac_t "hac"
  set-default-shape mode4_nacl_t "nacl"
  set-default-shape mode4_naac_t "naac"
  set-default-shape mode4_nh4cl_t "nh4cl"
  set-default-shape mode4_nh4ac_t "nh4ac"

  create-mode4_h20_t (20)
  [
    setxy random-xcor random-ycor
    set size 2
  ]

  set Init_water 0
  set add_flag 0
  set ch3coona_flag 0
  set nh4cl_flag 0
  set Down_T_flag 0
  set update_figure_flag 0
  set add_CH3C00Na_flag 0
  set add_water_flag 0
  set add_acid_flag 0
  set add_base_flag 0
  set Up_T_flag 0
  set Down_T_figure_flag 0
  set add_CH3C00Na_figure_flag 0
  set add_water_figure_flag 0
  set add_acid_figure_flag 0
  set add_base_figure_flag 0

  reset-ticks
end 

to go
  if ticks mod 300 = 0 [
    if Init_water = 0[
      ;;初始化水分解
      Hydrolytic_separation
    ]
    if Init_water != 0[
      if add_flag = 1[
        salt_separation
      ]
        update_figure
    ]

    ask turtles
    [ fd 1                                        ;; move turtles around randomly
      rt random 360
      lt random 360 ]

    if  (salt = "NaCl")[
      set h2o_count count mode4_h20_t
      set h_count count mode4_h_t
      set oh_count count mode4_oh_t
      set cl_count count mode4_cl_t
      set na_count count mode4_na_t
    ]
    if  (salt = "CH3COONa")[
      set h2o_count count mode4_h20_t
      set h_count count mode4_h_t
      set oh_count count mode4_oh_t
      set ac_count count mode4_ac_t
      set na_count count mode4_na_t
      set hac_count count mode4_hac_t
    ]
    if  (salt = "NH4Cl")[
      set h2o_count count mode4_h20_t
      set h_count count mode4_h_t
      set oh_count count mode4_oh_t
      set nh4_count count mode4_nh4_t
      set cl_count count mode4_cl_t
      set nh3h2o_count count mode4_nh3h2o_t
    ]
    if  (salt = "CH3COONH4")[
      set h2o_count count mode4_h20_t
      set h_count count mode4_h_t
      set oh_count count mode4_oh_t
      set ac_count count mode4_ac_t
      set hac_count count mode4_hac_t
      set nh3h2o_count count mode4_nh3h2o_t
      set nh4_count count mode4_nh4_t
    ]

  ]
  tick
end 

to update_figure
  let update_figure_one_turtle_flag 0
  if add_flag = 2 [
    if  (salt = "CH3COONa")[
      if update_figure_flag = 0[
        if count mode4_ac_t > 10 [
          let x 0
          let y 0
          ask mode4_ac_t [
            if update_figure_one_turtle_flag = 0[
              let meeting-mode4_h_t mode4_h_t in-radius 10
              if count meeting-mode4_h_t > 0 [
                ; 在半径2的范围内相遇时,创建新的turtle
                let turtles-here-mode4_ac_t turtles with [breed = mode4_ac_t]
                let turtles-here-mode4_h_t turtles with [breed = mode4_h_t]
                let turtle_mode4_ac_t one-of turtles-here-mode4_ac_t in-radius 2
                let turtle_mode4_h_t one-of turtles-here-mode4_h_t in-radius 2
                if turtle_mode4_ac_t != nobody and turtle_mode4_h_t != nobody [
                  ask turtle_mode4_ac_t [
                    set breed mode4_hac_t
                    set size 2
                  ]
                  ; 删除原来的mode4_h_t turtle
                  ask turtle_mode4_h_t [
                    die
                  ]
                  if count mode4_h_t = 0[
                    let mode4_h20_t_molecule one-of turtles with [breed = mode4_h20_t]
                    ask mode4_h20_t_molecule [
                      set x xcor
                      set y ycor
                    ];;创建一个oh
                    set ch3coona_flag 1
                    ask mode4_h20_t_molecule [
                      set breed mode4_h_t
                      set size 2
                    ];;创建一个oh
                  ]
                  set update_figure_one_turtle_flag 1
                ]
              ]
            ]
          ]
          if ch3coona_flag != 0[
            create-mode4_oh_t (ch3coona_flag)
            [
              setxy x y
              set size 2
            ]
            set ch3coona_flag 0
          ]
        ]
        if count mode4_ac_t = 10 [
          set update_figure_flag 1
        ]
      ]
    ]
    if  (salt = "NH4Cl")[
      if count mode4_nh4_t > 10 [
        let x 0
        let y 0
        ask mode4_nh4_t [
          if update_figure_one_turtle_flag = 0[
            let meeting-mode4_oh_t mode4_oh_t in-radius 10
            if count meeting-mode4_oh_t > 0 [
              ; 在半径2的范围内相遇时,创建新的turtle
              let turtles-here-mode4_nh4_t turtles with [breed = mode4_nh4_t]
              let turtles-here-mode4_oh_t turtles with [breed = mode4_oh_t]
              let turtle_mode4_nh4_t one-of turtles-here-mode4_nh4_t in-radius 2
              let turtle_mode4_oh_t one-of turtles-here-mode4_oh_t in-radius 2
              if turtle_mode4_nh4_t != nobody and turtle_mode4_oh_t != nobody [
                ask turtle_mode4_nh4_t [
                  set breed mode4_nh3h2o_t
                  set size 2
                ]
                ; 删除原来的mode4_h_t turtle
                ask turtle_mode4_oh_t [
                  die
                ]
                if count mode4_oh_t = 0[
                  let mode4_h20_t_molecule one-of turtles with [breed = mode4_h20_t]
                  ask mode4_h20_t_molecule [
                    set x xcor
                    set y ycor
                  ];;创建一个h
                  set nh4cl_flag 1
                  ask mode4_h20_t_molecule [
                    set breed mode4_oh_t
                    set size 2
                  ]
                ]
                set update_figure_one_turtle_flag 1
              ]
            ]
          ]
        ]
        if nh4cl_flag != 0[
          create-mode4_h_t (nh4cl_flag)
          [
            setxy x y
            set size 2
          ]
          set nh4cl_flag 0
        ]
      ]
    ]
    if  (salt = "CH3COONH4")[
      if count mode4_ac_t > 5 [
        let x 0
        let y 0
        ask mode4_ac_t [
          if update_figure_one_turtle_flag = 0[
            let meeting-mode4_h_t mode4_h_t in-radius 10
            if count meeting-mode4_h_t > 0 [
              ; 在半径2的范围内相遇时,创建新的turtle
              let turtles-here-mode4_ac_t turtles with [breed = mode4_ac_t]
              let turtles-here-mode4_h_t turtles with [breed = mode4_h_t]
              let turtle_mode4_ac_t one-of turtles-here-mode4_ac_t in-radius 2
              let turtle_mode4_h_t one-of turtles-here-mode4_h_t in-radius 2
              if turtle_mode4_ac_t != nobody and turtle_mode4_h_t != nobody [
                ask turtle_mode4_ac_t [
                  set breed mode4_hac_t
                  set size 2
                ]
                ; 删除原来的mode4_h_t turtle
                ask turtle_mode4_h_t [
                  die
                ]
                if count mode4_h_t = 0[
                  let mode4_h20_t_molecule one-of turtles with [breed = mode4_h20_t]
                  ask mode4_h20_t_molecule [
                    set x xcor
                    set y ycor
                  ];;创建一个oh
                  set ch3coona_flag 1
                  ask mode4_h20_t_molecule [
                    set breed mode4_h_t
                    set size 2
                  ];;创建一个oh
                ]
                set update_figure_one_turtle_flag 1
              ]
            ]
          ]
        ]
        if ch3coona_flag != 0[
          create-mode4_oh_t (ch3coona_flag)
          [
            setxy x y
            set size 2
          ]
          set ch3coona_flag 0
        ]
      ]
      if count mode4_nh4_t > 5 [
        let x 0
        let y 0
        ask mode4_nh4_t [
          if update_figure_one_turtle_flag = 0[
            let meeting-mode4_oh_t mode4_oh_t in-radius 10
            if count meeting-mode4_oh_t > 0 [
              ; 在半径2的范围内相遇时,创建新的turtle
              let turtles-here-mode4_nh4_t turtles with [breed = mode4_nh4_t]
              let turtles-here-mode4_oh_t turtles with [breed = mode4_oh_t]
              let turtle_mode4_nh4_t one-of turtles-here-mode4_nh4_t in-radius 2
              let turtle_mode4_oh_t one-of turtles-here-mode4_oh_t in-radius 2
              if turtle_mode4_nh4_t != nobody and turtle_mode4_oh_t != nobody [
                ask turtle_mode4_nh4_t [
                  set breed mode4_nh3h2o_t
                  set size 2
                ]
                ; 删除原来的mode4_h_t turtle
                ask turtle_mode4_oh_t [
                  die
                ]
                if count mode4_oh_t = 0[
                  let mode4_h20_t_molecule one-of turtles with [breed = mode4_h20_t]
                  ask mode4_h20_t_molecule [
                    set x xcor
                    set y ycor
                  ];;创建一个h
                  set nh4cl_flag 1
                  ask mode4_h20_t_molecule [
                    set breed mode4_oh_t
                    set size 2
                  ]
                ]
                set update_figure_one_turtle_flag 1
              ]
            ]
          ]
        ]
        if nh4cl_flag != 0[
          create-mode4_h_t (nh4cl_flag)
          [
            setxy x y
            set size 2
          ]
          set nh4cl_flag 0
        ]
      ]
    ]
  ]
end 

;;水的解离

to Hydrolytic_separation
  let temp_number count mode4_h20_t
  if temp_number >= 17[
    if ticks mod 3000 = 0 [
      let mode4_h20_t_molecule one-of turtles with [breed = mode4_h20_t]
      ;;将一个水分子变成h
      ask mode4_h20_t_molecule [
        set breed mode4_h_t
        set size 2
      ];;创建一个oh
      create-mode4_oh_t (1)
      [
        setxy random-xcor random-ycor
        set size 2
      ]
    ]
  ]
  if temp_number = 17[
   set Init_water 1
  ]
end 

;;加入盐分解

to salt_separation
  if ticks mod 2000 = 0 [
    let turtle_xys []  ; 创建一个空列表来存储坐标对
    if  (salt = "NaCl")[
      ask mode4_nacl_t [
        let xys list xcor ycor  ; 创建一个包含当前乌龟坐标对的列表
        set turtle_xys lput xys turtle_xys  ; 将当前乌龟的坐标对添加到列表中
      ]
      foreach turtle_xys [
        xy ->
        create-mode4_na_t 1 [
          setxy (item 0 xy) (item 1 xy)  ; 根据坐标对生成乌龟
          set size 2  ; 可根据需要设置乌龟颜色
        ]
      ]
      ask mode4_nacl_t [
        set breed mode4_cl_t
        set size 2
      ]
    ]
    if  (salt = "CH3COONa")[
      ask mode4_naac_t [
        let xys list xcor ycor  ; 创建一个包含当前乌龟坐标对的列表
        set turtle_xys lput xys turtle_xys  ; 将当前乌龟的坐标对添加到列表中
      ]
      foreach turtle_xys [
        xy ->
        create-mode4_na_t 1 [
          setxy (item 0 xy) (item 1 xy)  ; 根据坐标对生成乌龟
          set size 2  ; 可根据需要设置乌龟颜色
        ]
      ]
      ask mode4_naac_t [
        set breed mode4_ac_t
        set size 2
      ]
    ]
    if  (salt = "NH4Cl")[
      ask mode4_nh4cl_t [
        let xys list xcor ycor  ; 创建一个包含当前乌龟坐标对的列表
        set turtle_xys lput xys turtle_xys  ; 将当前乌龟的坐标对添加到列表中
      ]
      foreach turtle_xys [
        xy ->
        create-mode4_cl_t 1 [
          setxy (item 0 xy) (item 1 xy)  ; 根据坐标对生成乌龟
          set size 2  ; 可根据需要设置乌龟颜色
        ]
      ]
      ask mode4_nh4cl_t [
        set breed mode4_nh4_t
        set size 2
      ]
    ]
    if  (salt = "CH3COONH4")[
      ask mode4_nh4ac_t [
        let xys list xcor ycor  ; 创建一个包含当前乌龟坐标对的列表
        set turtle_xys lput xys turtle_xys  ; 将当前乌龟的坐标对添加到列表中
      ]
      foreach turtle_xys [
        xy ->
        create-mode4_nh4_t 1 [
          setxy (item 0 xy) (item 1 xy)  ; 根据坐标对生成乌龟
          set size 2  ; 可根据需要设置乌龟颜色
        ]
      ]
      ask mode4_nh4ac_t [
        set breed mode4_ac_t
        set size 2
      ]
    ]
    set add_flag 2
  ]
end 

;;对应升温按键

to Up_T
  set Up_T_flag 1
  if ticks mod 300 = 0 [
    if  (salt = "CH3COONa")[
      let temp_change 0
      if temp_change = 0[
        if count mode4_ac_t > 8 [
          let x 0
          let y 0
          ask mode4_ac_t [
            if temp_change = 0[
              let meeting-mode4_h_t mode4_h_t in-radius 10
              if count meeting-mode4_h_t > 0 [
                ; 在半径2的范围内相遇时,创建新的turtle
                let turtles-here-mode4_ac_t turtles with [breed = mode4_ac_t]
                let turtles-here-mode4_h_t turtles with [breed = mode4_h_t]
                let turtle_mode4_ac_t one-of turtles-here-mode4_ac_t in-radius 4
                let turtle_mode4_h_t one-of turtles-here-mode4_h_t in-radius 4
                if turtle_mode4_ac_t != nobody and turtle_mode4_h_t != nobody [
                  ask turtle_mode4_ac_t [
                    set breed mode4_hac_t
                    set size 2
                  ]
                  ; 删除原来的mode4_h_t turtle
                  ask turtle_mode4_h_t [
                    die
                  ]
                  if count mode4_h_t = 0[
                    let mode4_h20_t_molecule one-of turtles with [breed = mode4_h20_t]
                    ask mode4_h20_t_molecule [
                      set x xcor
                      set y ycor
                    ];;创建一个oh
                    set ch3coona_flag 1
                    ask mode4_h20_t_molecule [
                      set breed mode4_h_t
                      set size 2
                    ];;创建一个oh
                  ]
                  set temp_change 1
                ]
              ]
            ]
          ]
          if ch3coona_flag != 0[
            create-mode4_oh_t (ch3coona_flag)
            [
              setxy x y
              set size 2
            ]
            set ch3coona_flag 0
          ]
        ]
      ]
    ]
  ]
end 

;;对应降温按键

to Down_T
  set Down_T_figure_flag 1
  if  (salt = "CH3COONa")[
    if Down_T_flag = 0[
      if ticks mod 300 = 0 [
        let turtle_xys []  ; 创建一个空列表来存储坐标对
        let turtle_mode4_hac_t n-of 2 mode4_hac_t
        ask turtle_mode4_hac_t [
          let xys list xcor ycor  ; 创建一个包含当前乌龟坐标对的列表
          set turtle_xys lput xys turtle_xys  ; 将当前乌龟的坐标对添加到列表中
          set breed mode4_ac_t
          set size 2
        ]
        foreach turtle_xys [
          xy ->
          create-mode4_h_t 1 [
            setxy (item 0 xy) (item 1 xy)  ; 根据坐标对生成乌龟
            set size 2  ; 可根据需要设置乌龟颜色
          ]
        ]
        if count mode4_ac_t = 12[
          set Down_T_flag 1
        ]
      ]
    ]
    if Down_T_flag != 2[
      ask mode4_oh_t [
        let meeting-mode4_h_t mode4_h_t in-radius 10
        if count meeting-mode4_h_t > 0 [
          ; 在半径2的范围内相遇时,创建新的turtle
          let turtles-here-mode4_oh_t turtles with [breed = mode4_oh_t]
          let turtles-here-mode4_h_t turtles with [breed = mode4_h_t]
          let turtle_mode4_oh_t one-of turtles-here-mode4_oh_t in-radius 2
          let turtle_mode4_h_t one-of turtles-here-mode4_h_t in-radius 2
          if turtle_mode4_oh_t != nobody and turtle_mode4_h_t != nobody [
            if Down_T_flag != 2[
              ask turtle_mode4_oh_t [
                set breed mode4_h20_t
                set size 2
              ]
              ; 删除原来的mode4_h_t turtle
              ask turtle_mode4_h_t [
                die
              ]
              if count mode4_h20_t = 11[
                set Down_T_flag 2
              ]
            ]
          ]
        ]
      ]
    ]
  ]
end 

;;对应加入CH3COONa按键

to add_CH3C00Na
  set add_CH3C00Na_figure_flag 1
  ;控制时间
  if  (salt = "CH3COONa")[
    if ticks mod 300 = 0 [
      if add_CH3C00Na_flag = 0[
        create-mode4_naac_t 5 [
          setxy random-xcor random-ycor  ; 根据坐标对生成乌龟
          set size 2  ; 可根据需要设置乌龟颜色
        ]
        set add_CH3C00Na_flag 1
      ]
      if count mode4_naac_t > 0 [
        let x 0
        let y 0
        let turtle_mode4_naac_t n-of 1 mode4_naac_t
        ask turtle_mode4_naac_t[
          set x xcor
          set y ycor
          set breed mode4_ac_t
          set size 2
        ]
        create-mode4_na_t 1
        [
          setxy x y
          set size 2
        ]
      ]
      if add_CH3C00Na_flag = 1[
        ask mode4_h_t [
          let meeting-mode4_ac_t mode4_ac_t in-radius 10
          if count meeting-mode4_ac_t > 0 [
            ; 在半径2的范围内相遇时,创建新的turtle
            let turtles-here-mode4_ac_t turtles with [breed = mode4_ac_t]
            let turtles-here-mode4_h_t turtles with [breed = mode4_h_t]
            let turtle_mode4_ac_t one-of turtles-here-mode4_ac_t in-radius 2
            let turtle_mode4_h_t one-of turtles-here-mode4_h_t in-radius 2
            if turtle_mode4_ac_t != nobody and turtle_mode4_h_t != nobody [
              if add_CH3C00Na_flag = 1[
                ask turtle_mode4_h_t [
                  set breed mode4_hac_t
                  set size 2
                ]
                ; 删除原来的mode4_h_t turtle
                ask turtle_mode4_ac_t [
                  die
                ]
                set add_CH3C00Na_flag 2
              ]
            ]
          ]
        ]
      ]
      if add_CH3C00Na_flag = 2[
        let x 0
        let y 0
        let turtle_mode4_h2o_t n-of 1 mode4_h20_t
        ask turtle_mode4_h2o_t[
          set x xcor
          set y ycor
          set breed mode4_h_t
          set size 2
        ]
        create-mode4_oh_t 1
        [
          setxy x y
          set size 2
        ]
        set add_CH3C00Na_flag 3
      ]
    ]
  ]
end 

;;对应加水按键

to add_water
  set add_water_figure_flag 1
  if  (salt = "CH3COONa")[
    if ticks mod 300 = 0 [
      if add_water_flag = 0 [
        create-mode4_h20_t 10
        [
          setxy random-xcor random-ycor  ; 根据坐标对生成乌龟
          set size 2  ; 可根据需要设置乌龟颜色
        ]
        set add_water_flag 1
      ]
      if add_water_flag = 1[
        ask mode4_h_t [
          let meeting-mode4_ac_t mode4_ac_t in-radius 10
          if count meeting-mode4_ac_t > 0 [
            ; 在半径2的范围内相遇时,创建新的turtle
            let turtles-here-mode4_ac_t turtles with [breed = mode4_ac_t]
            let turtles-here-mode4_h_t turtles with [breed = mode4_h_t]
            let turtle_mode4_ac_t one-of turtles-here-mode4_ac_t in-radius 2
            let turtle_mode4_h_t one-of turtles-here-mode4_h_t in-radius 2
            if turtle_mode4_ac_t != nobody and turtle_mode4_h_t != nobody [
              if add_water_flag = 1[
                ask turtle_mode4_h_t [
                  set breed mode4_hac_t
                  set size 2
                ]
                ; 删除原来的mode4_h_t turtle
                ask turtle_mode4_ac_t [
                  die
                ]
                set add_water_flag 2
              ]
            ]
          ]
        ]
      ]
      if add_water_flag = 2
      [
        let x 0
        let y 0
        let turtle_mode4_h2o_t n-of 1 mode4_h20_t
        ask turtle_mode4_h2o_t[
          set x xcor
          set y ycor
          set breed mode4_h_t
          set size 2
        ]
        create-mode4_oh_t 1
        [
          setxy x y
          set size 2
        ]
        set add_water_flag 3
      ]
    ]
  ]
end 

;;对应加酸按键

to add_acid
  set add_acid_figure_flag 1
  if  (salt = "CH3COONa")[
    if ticks mod 300 = 0 [
      if add_acid_flag = 0[
        create-mode4_h_t 3
        [
          setxy random-xcor random-ycor  ; 根据坐标对生成乌龟
          set size 2  ; 可根据需要设置乌龟颜色
        ]
        set add_acid_flag 1
      ]

      ;h + oh -> h2o
      if add_acid_flag = 1[
        ask mode4_oh_t [
          let meeting-mode4_h_t mode4_h_t in-radius 10
          if count meeting-mode4_h_t > 0 [
            ; 在半径2的范围内相遇时,创建新的turtle
            let turtles-here-mode4_oh_t turtles with [breed = mode4_oh_t]
            let turtles-here-mode4_h_t turtles with [breed = mode4_h_t]
            let turtle_mode4_oh_t one-of turtles-here-mode4_oh_t in-radius 2
            let turtle_mode4_h_t one-of turtles-here-mode4_h_t in-radius 2
            if turtle_mode4_oh_t != nobody and turtle_mode4_h_t != nobody [
              if count mode4_oh_t != 9[
                ask turtle_mode4_oh_t [
                  set breed mode4_h20_t
                  set size 2
                ]
                ; 删除原来的mode4_h_t turtle
                ask turtle_mode4_h_t [
                  die
                ]
                if count mode4_oh_t = 9[
                  set add_acid_flag 2
                ]
              ]
            ]
          ]
        ]
      ]
      ;ac + h -> hac
      if add_acid_flag = 2[
        ask mode4_h_t [
          let meeting-mode4_ac_t mode4_ac_t in-radius 10
          if count meeting-mode4_ac_t > 0 [
            ; 在半径2的范围内相遇时,创建新的turtle
            let turtles-here-mode4_ac_t turtles with [breed = mode4_ac_t]
            let turtles-here-mode4_h_t turtles with [breed = mode4_h_t]
            let turtle_mode4_ac_t one-of turtles-here-mode4_ac_t in-radius 2
            let turtle_mode4_h_t one-of turtles-here-mode4_h_t in-radius 2
            if turtle_mode4_ac_t != nobody and turtle_mode4_h_t != nobody [
              if add_acid_flag = 2[
                ask turtle_mode4_h_t [
                  set breed mode4_hac_t
                  set size 2
                ]
                ; 删除原来的mode4_h_t turtle
                ask turtle_mode4_ac_t [
                  die
                ]
                set add_acid_flag 3
              ]
            ]
          ]
        ]
      ]
      ;h2o -> h + oh
      if add_acid_flag = 3[
        let x 0
        let y 0
        let turtle_mode4_h2o_t n-of 1 mode4_h20_t
        ask turtle_mode4_h2o_t[
          set x xcor
          set y ycor
          set breed mode4_h_t
          set size 2
        ]
        create-mode4_oh_t 1
        [
          setxy x y
          set size 2
        ]
        set add_acid_flag 4
      ]
    ]
  ]
end 

;;对应加碱按键

to add_base
  set add_base_figure_flag 1
  if  (salt = "CH3COONa")[
    if ticks mod 300 = 0 [
      if add_base_flag = 0[
        create-mode4_oh_t 3
        [
          setxy random-xcor random-ycor  ; 根据坐标对生成乌龟
          set size 2  ; 可根据需要设置乌龟颜色
        ]
        set add_base_flag 1
      ]

      ;2 oh + 2 hac -> 2 h2o + 2 ac
      if add_base_flag = 1[
        ask mode4_oh_t [
          let meeting-mode4_hac_t mode4_ac_t in-radius 10
          if count meeting-mode4_hac_t > 0 [
            ; 在半径2的范围内相遇时,创建新的turtle
            let turtles-here-mode4_oh_t turtles with [breed = mode4_oh_t]
            let turtles-here-mode4_hac_t turtles with [breed = mode4_hac_t]
            let turtle_mode4_oh_t one-of turtles-here-mode4_oh_t in-radius 2
            let turtle_mode4_hac_t one-of turtles-here-mode4_hac_t in-radius 2
            if turtle_mode4_oh_t != nobody and turtle_mode4_hac_t != nobody [
              if count mode4_oh_t != 12[
                ask turtle_mode4_oh_t [
                  set breed mode4_h20_t
                  set size 2
                ]
                ; 删除原来的mode4_h_t turtle
                ask turtle_mode4_hac_t [
                  set breed mode4_ac_t
                  set size 2
                ]
                if count mode4_oh_t = 12[
                  set add_base_flag 2
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  ]
end 

;;对应加入按键

to add
  if add_flag = 0[
    if  (salt = "NaCl")[
      create-mode4_nacl_t (20)
      [
        setxy random-xcor random-ycor
        set size 2
      ]
    ]
    if  (salt = "CH3COONa")[
      create-mode4_naac_t (20)
      [
        setxy random-xcor random-ycor
        set size 2
      ]
    ]
    if  (salt = "NH4Cl")[
      create-mode4_nh4cl_t (20)
      [
        setxy random-xcor random-ycor
        set size 2
      ]
    ]
    if  (salt = "CH3COONH4")[
      create-mode4_nh4ac_t (20)
      [
        setxy random-xcor random-ycor
        set size 2
      ]
    ]
    set add_flag  1
  ]
end 

There is only one version of this model, created 3 months ago by Ying Li.

Attached files

File Type Description Last updated
水解平衡.png preview Preview for '水解平衡' 3 months ago, by Ying Li Download

This model does not have any ancestors.

This model does not have any descendants.