PFC模仿流感傳染

這里仿照國外的一個數(shù)據(jù)可視化結(jié)果。

利用PFC顆粒流模擬流感的傳染,對比設置隔離和不設置隔離的情況。

在一個位置設置一個感染者,以感染者和別人接觸作為傳染的額方式。

每個人一開始都有一個隨機的初速度,不設置fric和damp等來消耗動能。

未設置任何措施:

dongtu.gif

設置隔離:

dongtugeli.gif

這里還顯示了感染比率和時間的關(guān)系曲線。

沒事做了玩,哈哈

完整代碼:

new
[ball_rad=0.1]
set random 10001
domain extent -10 10
wall generate box -8 8 -4 4
ball generate number 300 radius 0.1  range x [-8+ball_rad] [8-ball_rad] ...
                                            y [-4+ball_rad] [4-ball_rad]
 ball attribute density 2e3 
 
wall create  vertices 3.5 4 3.5 0.2
wall create  vertices 3.5 -4 3.5 -0.2
def add_huanzhe
    huanzhe_pos_x=4
    huanzhe_pos_y=4
    bp=ball.near(4,4)
    ball.group(bp)="huanzhe"
end
@add_huanzhedef add_chu_su_du
    loop foreach bp ball.list
        x_v= math.random.uniform
        y_v=math.random.uniform
       
        x_dir=math.random.uniform-0.5
        y_dir=math.random.uniform-0.5
        ball.vel.x(bp)=x_v*math.sgn(x_dir)
        ball.vel.y(bp)=y_v*math.sgn(y_dir)
    endloop
end
@add_chu_su_du
[huanzhe_count=1]
def gan_ran
    time=mech.age
    loop foreach ct contact.list("ball-ball")
        bp1=contact.end1(ct)
        bp2=contact.end2(ct)
        if ball.isgroup(bp1,"huanzhe")=true then
          
            if ball.isgroup(bp2,"huanzhe")=false then
                ball.group(bp2)="huanzhe"
                huanzhe_count+=1
            endif
        else if ball.isgroup(bp2,"huanzhe")=true then
          
            if ball.isgroup(bp1,"huanzhe")=false  then
                ball.group(bp1)="huanzhe"
                huanzhe_count+=1
               
            endif
        endif       
    endloop
    ganran_ratio=huanzhe_count/300.0  
   
end
cmat default model linear property kn 1e5
set fish callback -1.0 @gan_ran
set mech age 0
history id 1 @time
history id 2 @ganran_ratio[time_record=mech.age]
[baocunpinlv=0.3]
def savefile
   
    if mech.age-time_record > baocunpinlv then
        filename=string.build("jieguo%1",count)
        command
            ;save @filename
            plot bitmap filename @filename
        endcommand
        time_record=mech.age
        count +=1
    endif
   
end
set fish callback -1.0 @savefilesolve time 15

登錄后免費查看全文
立即登錄
App下載
技術(shù)鄰APP
工程師必備
  • 項目客服
  • 培訓客服
  • 平臺客服

TOP

13
8