美文网首页
用Python对OpenFOAM计算结果log文件数据的提取

用Python对OpenFOAM计算结果log文件数据的提取

作者: 平平又无奇 | 来源:发表于2017-12-21 14:36 被阅读201次
    • 一个时间步的log文件显示如下
    Time = 1000
    
    
    Solving 3-D cloud sprayCloud
    
    Cloud: sprayCloud injector: model1
        Added 20000 new parcels
    
    Cloud: sprayCloud
        Current number of parcels       = 104523
        Current mass in system          = 2.44025e+06
        Linear momentum                 = (448.443 3.07731e+07 -4.0631e+06)
       |Linear momentum|                = 3.10402e+07
        Linear kinetic energy           = 2.67875e+08
        model1:
            number of parcels added     = 79980000
            mass introduced             = 1.86726e+09
        Parcel fate (number, mass)
          - escape                      = 390717, 0
          - stick                       = 0, 0
        Temperature min/max             = 301, 301
        Mass transfer phase change      = 0
        D10, D32, Dmax (mu)             = 400, 400, 400
        Liquid penetration 95% mass (m) = 31.2189
    
    diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
    PIMPLE: iteration 1
    GAMG:  Solving for Ux, Initial residual = 0.180739, Final residual = 0.000179812, No Iterations 1
    GAMG:  Solving for Uy, Initial residual = 0.000644012, Final residual = 1.31311e-06, No Iterations 1
    GAMG:  Solving for Uz, Initial residual = 0.000924792, Final residual = 1.35269e-06, No Iterations 1
    DILUPBiCG:  Solving for H2O, Initial residual = 0, Final residual = 0, No Iterations 0
    DILUPBiCG:  Solving for N2, Initial residual = 0.00133494, Final residual = 8.04592e-09, No Iterations 4
    DILUPBiCG:  Solving for h, Initial residual = 0.00114968, Final residual = 6.95384e-05, No Iterations 1
    T gas min/max   = 296.882, 301.877
    GAMG:  Solving for p, Initial residual = 0.00656675, Final residual = 1.67482e-05, No Iterations 3
    diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
    time step continuity errors : sum local = 5.64318e-07, global = -1.53357e-08, cumulative = 0.00182297
    rho max/min : 1.20053 1.12852
    GAMG:  Solving for p, Initial residual = 0.00133588, Final residual = 6.08234e-06, No Iterations 3
    diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
    time step continuity errors : sum local = 2.04937e-07, global = 2.23063e-09, cumulative = 0.00182298
    rho max/min : 1.20033 1.12852
    PIMPLE: iteration 2
    GAMG:  Solving for Ux, Initial residual = 0.0441852, Final residual = 3.2553e-07, No Iterations 2
    GAMG:  Solving for Uy, Initial residual = 8.23501e-05, Final residual = 1.02875e-07, No Iterations 1
    GAMG:  Solving for Uz, Initial residual = 0.000119312, Final residual = 1.05676e-07, No Iterations 1
    DILUPBiCG:  Solving for H2O, Initial residual = 0, Final residual = 0, No Iterations 0
    DILUPBiCG:  Solving for N2, Initial residual = 0.00392789, Final residual = 1.48488e-07, No Iterations 4
    DILUPBiCG:  Solving for h, Initial residual = 0.00132034, Final residual = 3.51496e-07, No Iterations 3
    T gas min/max   = 296.882, 301.876
    GAMG:  Solving for p, Initial residual = 0.000637544, Final residual = 2.7269e-06, No Iterations 3
    diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
    time step continuity errors : sum local = 9.18747e-08, global = -4.31392e-09, cumulative = 0.00182297
    rho max/min : 1.20028 1.12852
    GAMG:  Solving for p, Initial residual = 0.000161301, Final residual = 3.80677e-08, No Iterations 5
    diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
    time step continuity errors : sum local = 1.28259e-09, global = 2.30985e-11, cumulative = 0.00182297
    rho max/min : 1.2003 1.12852
    GAMG:  Solving for k, Initial residual = 0.00180064, Final residual = 7.61412e-09, No Iterations 2
    ExecutionTime = 21472.9 s  ClockTime = 21611 s
    
    • 如上面的运行结果所示,提取每个时间步的Current number of parcels行信息,并写入新的文件
    my_file=open('F:/data/1221/test_1.txt','w')
    for line in open("F:/data/1221/log_43"):  
        if 'Current number of parcels' in line:       
            my_file.write(line) 
    my_file.close()
    
    • 则test_1中部分显示如下

    Current number of parcels = 104388
    Current number of parcels = 104335
    Current number of parcels = 104363
    Current number of parcels = 104465
    Current number of parcels = 104542
    Current number of parcels = 104409
    Current number of parcels = 104656
    Current number of parcels = 104463
    Current number of parcels = 104424
    Current number of parcels = 104503
    Current number of parcels = 104535
    Current number of parcels = 104530
    Current number of parcels = 104502
    Current number of parcels = 104652
    Current number of parcels = 104655
    Current number of parcels = 104633
    Current number of parcels = 104623
    Current number of parcels = 104489
    Current number of parcels = 104681
    Current number of parcels = 104712
    Current number of parcels = 104784
    Current number of parcels = 104763
    Current number of parcels = 104379
    Current number of parcels = 104523
    ......

    • 接下来就可以导入MATLAB画图了:
      数据结果图.png

    相关文章

      网友评论

          本文标题:用Python对OpenFOAM计算结果log文件数据的提取

          本文链接:https://www.haomeiwen.com/subject/pdlawxtx.html