化学平衡

化学平衡 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 75 times • Downloaded 3 times • 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). Chemical Equilibrium. School of Chemistry and Chemical Engineering, Shaanxi Normal University.

breed [mode7_no2_t  mode7_no2]
breed [mode7_n2o4_t mode7_n2o4]
breed [mode7_square_t mode7_square]
breed [mode7_he_t mode7_he]

globals[
  float_y
  old_float_y
  count_no2
  count_no2_new
  count_n2o4
  figure_x
  figure_one_flag
  figure_Up_T_flag
  figure_Down_T_flag
  figure_add_P_flag
  figure_delete_P_flag
  figure_add_V_flag
  figure_add_in_flag
  figure_add_cat_flag
  figure_c_actant_flag
  figure_c_resultant_flag

  temp_ticks
  Q
  K
  V
  SL_1
  SL_2
]

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

  ;;初始化海龟
  set-default-shape mode7_no2_t  "no2"
  set-default-shape mode7_n2o4_t   "n2o4"
  set-default-shape mode7_square_t  "square"
  set-default-shape mode7_he_t "he"

  ;;初始化活塞位置
  set float_y 0
  set old_float_y 0
  create_float

  ;;初始化turtle
  create-mode7_no2_t 100[
    setxy random-xcor random((min-pycor + 2) - (float_y - 2)) + (float_y - 2)
    set size 2
  ]

  set K 0.885
  set V 100
  set count_no2 count mode7_no2_t
  set SL_1 0
  set SL_2 0
  set figure_one_flag 0
  set figure_Up_T_flag 0
  set figure_x 0
  reset-ticks
end 

to go
  if ticks mod 5000 = 0[
    turtles_action
    reactivity
  ]
  change_float_set
  set count_no2 count mode7_no2_t
  set count_n2o4 count mode7_n2o4_t

  update_figure

  tick
end 

to update_figure
  if ticks mod 200 = 0[
    if figure_one_flag = 0[
      ifelse ticks <= 810000 [
        set SL_2 ((sqrt ticks) / 18)
        set SL_1 (100 - SL_2)
      ]
      [set figure_one_flag 1]
    ]
    ;;升高温度按键按下
    if figure_Up_T_flag = 1[
      ifelse figure_x < 2500[
        set SL_1 ((sqrt figure_x)  + 60)
        set SL_2 (220 - SL_1)
        set figure_x (figure_x + 1)
      ][
        set figure_Up_T_flag 0
        if temp_ticks = 0[
          set temp_ticks ticks
        ]
      ]
    ]
    ;;降低温度按键按下
    if figure_Down_T_flag = 1[
      ifelse figure_x < 2500[
        set SL_2 ((sqrt figure_x) * 0.3 + 10)
        set SL_1 (50 - SL_2)
        set figure_x (figure_x + 1)
      ][
        set figure_Down_T_flag 0
        if temp_ticks = 0[
          set temp_ticks ticks
        ]
      ]
    ]
    ;;增大压强按键按下
    if figure_add_P_flag = 1[
      ifelse figure_x < 2500[
        set SL_2 ((sqrt figure_x) + 60)
        set SL_1 (220 - SL_2)
        set figure_x (figure_x + 1)
      ][
        set figure_add_P_flag 0
        if temp_ticks = 0[
          set temp_ticks ticks
        ]
      ]
    ]
    ;;减少压强按键按下
    if figure_delete_P_flag = 1[
      ifelse figure_x < 2500[
        set SL_1 ((sqrt figure_x) * 0.3 + 10)
        set SL_2 (50 - SL_1)
        set figure_x (figure_x + 1)
      ][
        set figure_delete_P_flag 0
        if temp_ticks = 0[
          set temp_ticks ticks
        ]
      ]
    ]
    ;;恒压充入按键按下
    if figure_add_in_flag = 1[
      ifelse figure_x < 2500[
        set SL_1 ((sqrt figure_x) * 0.3 + 10)
        set SL_2 (50 - SL_1)
        set figure_x (figure_x + 1)
      ][
        set figure_add_in_flag 0
        if temp_ticks = 0[
          set temp_ticks ticks
        ]
      ]
    ]
    ;;figure_c_actant_flag 增大反应物浓度
    if figure_c_actant_flag = 1[
      ifelse figure_x < 2500[
        set SL_2 ((sqrt figure_x)  + 50)
        set SL_1 (200 - SL_2)
        set figure_x (figure_x + 1)
      ][
        set figure_c_actant_flag 0
        if temp_ticks = 0[
          set temp_ticks ticks
        ]
      ]
    ]
    ;;figure_c_actant_flag 减小反应物浓度
    if figure_c_actant_flag = 2[
      ifelse figure_x < 2500[
        set SL_1 ((sqrt figure_x) * 0.3 + 20)
        set SL_2 (70 - SL_1)
        set figure_x (figure_x + 1)
      ][
        set figure_c_actant_flag 0
        if temp_ticks = 0[
          set temp_ticks ticks
        ]
      ]
    ]
    ;;figure_c_actant_flag 增大生成物浓度
    if figure_c_resultant_flag = 1[
      ifelse figure_x < 2500[
        set SL_1 ((sqrt figure_x)  + 50)
        set SL_2 (200 - SL_1)
        set figure_x (figure_x + 1)
      ][
        set figure_c_resultant_flag 0
        if temp_ticks = 0[
          set temp_ticks ticks
        ]
      ]
    ]
    ;;figure_c_actant_flag 减小生成物浓度
    if figure_c_resultant_flag = 2[
      ifelse figure_x < 2500[
        set SL_2 ((sqrt figure_x) * 0.3 + 20)
        set SL_1 (70 - SL_2)
        set figure_x (figure_x + 1)
      ][
        set figure_c_resultant_flag 0
        if temp_ticks = 0[
          set temp_ticks ticks
        ]
      ]
    ]
  ]
end 

;;turtle不规则移动

to turtles_action
  ask mode7_no2_t [
    ifelse (ycor >= (min-pycor + 2)) and (ycor <= float_y - 2) [
          set heading random 360
     ][
      ;;碰下面
      if (ycor >= (float_y - 2))[
        set heading 180
        ]
      ;;碰上面
      if (ycor <= (min-pycor + 2))[
        set heading 0
        ]
    ]
    fd 1
  ]
  ask mode7_n2o4_t [
    ifelse (ycor >= (min-pycor + 2)) and (ycor <= float_y - 2) [
          set heading random 360
     ][
      ;;碰下面
      if (ycor >= (float_y - 2))[
        set heading 180
        ]
      ;;碰上面
      if (ycor <= (min-pycor + 2))[
        set heading 0
        ]
    ]
    fd 1
  ]
  ask mode7_he_t[
    ifelse (ycor >= (min-pycor + 2)) and (ycor <= float_y - 2) [
          set heading random 360
     ][
      ;;碰下面
      if (ycor >= (float_y - 2))[
        set heading 180
        ]
      ;;碰上面
      if (ycor <= (min-pycor + 2))[
        set heading 0
        ]
    ]
    fd 1
  ]
end 

;;创建盖子

to create_float
  let result []
  let current-value min-pxcor
  while [current-value <= max-pxcor] [
    create-mode7_square_t 1 [
      setxy current-value  float_y ; 根据坐标对生成乌龟
      set size 1.3  ; 可根据需要设置乌龟颜色
    ]
    set current-value current-value + 1
  ]
  create-mode7_square_t 1 [
    setxy 0  (float_y + 1) ; 根据坐标对生成乌龟
    set size 1.3  ; 可根据需要设置乌龟颜色
  ]
  create-mode7_square_t 1 [
    setxy 1  (float_y + 1) ; 根据坐标对生成乌龟
    set size 1.3  ; 可根据需要设置乌龟颜色
  ]
  create-mode7_square_t 1 [
    setxy -1  (float_y + 1) ; 根据坐标对生成乌龟
    set size 1.3  ; 可根据需要设置乌龟颜色
  ]
end 

;;改变盖子的位置

to change_float_set
  if ticks mod 10000 = 0[
    if old_float_y < float_y and float_y <= (max-pycor - 1)[
      ask mode7_square_t[
        set heading 360   ; 设置朝向为正上方
        forward 1        ; 向前移动一格
      ]
      set old_float_y (old_float_y + 1)
    ]
    if old_float_y > float_y and float_y > min-pycor[
      ask mode7_square_t[
        set heading 180   ; 设置朝向为正上方
        forward 1        ; 向前移动一格
      ]
      set old_float_y (old_float_y - 1 )
    ]
  ]
end 

;;n2o4 和 no2相互反应

to reactivity
  let create_number 0

  set Q ((count mode7_n2o4_t / V) / ((count mode7_no2_t / V) ^ 2) )
  if Q < (K - 0.03) [
    ask patches [
      let nearby-turtles_count count turtles in-radius 1
      let nearby-turtles turtles-here
      let to_n2o4_flag 0
      let to_no2_flag 0
      if nearby-turtles_count >= 2 [
        if random-float 1.0 < 0.6 [
          ask nearby-turtles[
            if breed = mode7_no2_t[
              set to_n2o4_flag (to_n2o4_flag + 1)
            ]
            if breed = mode7_n2o4_t[
              set to_no2_flag (to_no2_flag + 1)
            ]
          ]
          if to_n2o4_flag >= 2[
            if random-float 1.0 < 0.6 [
              let first_mode7_no2_t one-of turtles in-radius 1 with [breed = mode7_no2_t]
              ask first_mode7_no2_t [
                set breed mode7_n2o4_t
                set size 2
              ]
              let second_mode7_no2_t one-of turtles in-radius 1 with [breed = mode7_no2_t]
              ask second_mode7_no2_t[
                die
              ]
            ]
          ]
          if to_no2_flag >= 2[
            if random-float 1.0 < 0.01 [
              let first_mode7_n2o4_t one-of turtles in-radius 1 with [breed = mode7_n2o4_t]
              ask first_mode7_n2o4_t [
                set breed mode7_no2_t
                set size 2
              ]
              let second_mode7_n2o4_t one-of turtles in-radius 1 with [breed = mode7_n2o4_t]
              ask second_mode7_n2o4_t[
                set breed mode7_no2_t
                set size 2
              ]
              set create_number (create_number + 2)
            ]
          ]
           stop
        ]
      ]
    ]
    if create_number != 0 [
      create-mode7_no2_t create_number[
        setxy random-xcor random((min-pycor + 2) - (float_y - 2)) + (float_y - 2)
        set size 2
      ]
      set create_number 0
    ]
  ]

  if  Q > (K - 0.03) and Q < (K + 0.03)[
    ask patches [
      let nearby-turtles_count count turtles in-radius 1
      let nearby-turtles turtles-here
      let to_n2o4_flag 0
      let to_no2_flag 0
      if nearby-turtles_count >= 2 [
        if random-float 1.0 < 0.1 [
          ask nearby-turtles[
            if breed = mode7_no2_t[
              set to_n2o4_flag (to_n2o4_flag + 1)
            ]
            if breed = mode7_n2o4_t[
              set to_no2_flag (to_no2_flag + 1)
            ]
          ]
          if to_n2o4_flag >= 2[
            let first_mode7_no2_t one-of turtles in-radius 1 with [breed = mode7_no2_t]
            ask first_mode7_no2_t [
              set breed mode7_n2o4_t
              set size 2
            ]
            let second_mode7_no2_t one-of turtles in-radius 1 with [breed = mode7_no2_t]
            ask second_mode7_no2_t[
              die
            ]
          ]
          if to_no2_flag >= 2[
            let first_mode7_n2o4_t one-of turtles in-radius 1 with [breed = mode7_n2o4_t]
            ask first_mode7_n2o4_t [
              set breed mode7_no2_t
              set size 2
            ]
            let second_mode7_n2o4_t one-of turtles in-radius 1 with [breed = mode7_n2o4_t]
            ask second_mode7_n2o4_t[
              set breed mode7_no2_t
              set size 2
            ]
            set create_number (create_number + 2)
          ]
          stop
        ]
      ]
    ]
    if create_number != 0 [
      create-mode7_no2_t create_number[
        setxy random-xcor random((min-pycor + 2) - (old_float_y - 2)) + (old_float_y - 2)
        set size 2
      ]
      set create_number 0
    ]
  ]

  if Q > (K + 0.03)  [
    let x 0
    let y 0
    ask patches [
      let nearby-turtles_count count turtles in-radius 1
      let nearby-turtles turtles-here
      let to_n2o4_flag 0
      let to_no2_flag 0
      if nearby-turtles_count >= 2 [
        if random-float 1.0 < 0.6 [
          ask nearby-turtles[
            if breed = mode7_no2_t[
              set to_n2o4_flag (to_n2o4_flag + 1)
            ]
            if breed = mode7_n2o4_t[
              set to_no2_flag (to_no2_flag + 1)
            ]
          ]
          if to_n2o4_flag >= 2[
            if random-float 1.0 < 0.01 [
              let first_mode7_no2_t one-of turtles in-radius 1 with [breed = mode7_no2_t]
              ask first_mode7_no2_t [
                set breed mode7_n2o4_t
                set size 2
              ]
              let second_mode7_no2_t one-of turtles in-radius 1 with [breed = mode7_no2_t]
              ask second_mode7_no2_t[
                die
              ]
            ]
          ]
          if to_no2_flag >= 2[
            if random-float 1.0 < 0.6 [
              let first_mode7_n2o4_t one-of turtles in-radius 1 with [breed = mode7_n2o4_t]
              ask first_mode7_n2o4_t [
                set x xcor
                set y ycor
                set breed mode7_no2_t
                set size 2
              ]
              let second_mode7_n2o4_t one-of turtles in-radius 1 with [breed = mode7_n2o4_t]
              ask second_mode7_n2o4_t[
                set breed mode7_no2_t
                set size 2
              ]
              set create_number (create_number + 2)
            ]
          ]
           stop
        ]
      ]
    ]
    if create_number != 0 [
      create-mode7_no2_t create_number[
        setxy x y
        set size 2
      ]
      set create_number 0
    ]
  ]

  if figure_one_flag = 1[

  ]
end 

;to V_1
;  if ticks mod 500 = 0[
;    set count_no2_new count mode7_no2_t
;    let derta count_no2_new - count_no2
;    set SL_1 ((derta / 500) / 2 )
;    set count_no2 count_no2_new
;  ]
;end

;;上升温度按键

to up_T
end 

;;降低温度按键

to down_T
end 

;;恒容充入按键

to add_V
  set figure_add_V_flag 1
  set temp_ticks ticks
  create-mode7_he_t 50[
    setxy random-xcor random((min-pycor + 2) - (float_y - 2)) + (float_y - 2)
    set size 2
  ]
end 

;;恒压充入按键

to add_P
  set figure_add_in_flag 1
   create-mode7_he_t 50[
    setxy random-xcor random((min-pycor + 2) - (float_y - 2)) + (float_y - 2)
    set size 2
  ]
  set float_y 20
  set V 150
end 

;;执行按键

to c_actant_action
  if c_actant > 0 [
    set figure_c_actant_flag 1
    create-mode7_no2_t c_actant[
      setxy random-xcor random((min-pycor + 2) - (float_y - 2)) + (float_y - 2)
      set size 2
    ]
  ]
  if c_actant < 0 [
    set figure_c_actant_flag 2
    let turtle_mode7_no2_t n-of (c_actant * -1) mode7_no2_t
    ask turtle_mode7_no2_t [
      die
    ]
  ]
end 

to c_resultant_action
  if c_resultant > 0 [
    set figure_c_resultant_flag 1
    create-mode7_n2o4_t c_resultant[
      setxy random-xcor random((min-pycor + 2) - (float_y - 2)) + (float_y - 2)
      set size 2
    ]
  ]
  if c_resultant < 0 [
    set figure_c_resultant_flag 2
    let turtle_mode7_n2o4_t n-of (c_resultant * -1) mode7_n2o4_t
    ask turtle_mode7_n2o4_t [
      die
    ]
  ]
end 

to add_cat
 set figure_add_cat_flag 1
 set SL_1 70
 set SL_2 70
 set temp_ticks ticks
end 

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

Attached files

File Type Description Last updated
化学平衡.png preview Preview for '化学平衡' 7 months ago, by Ying Li Download

This model does not have any ancestors.

This model does not have any descendants.