提取log文件中的一些信息


  • 管理员

    
    Courant Number mean: 0.143461 max: 0.780362
    deltaT = 0.000740741
    Time = 0.502963
    
    Weighted Re = 9.08136, weighted breakage frequency = 0
    MULES limit is done
    MULES: Solving for alpha.oil
    MULES: Solving for alpha.water
    oil fraction, min, max = 0.003 0.000631032 0.00359543
    water fraction, min, max = 0.997 0.996405 0.999369
    Phase-sum volume fraction, min, max = 1 1 1
    DILUPBiCGStab:  Solving for n, Initial residual = 0.000902233, Final residual = 1.49928e-09, No Iterations 1
        Inconsistency value, average, min, max = 2.52405e-11 -0.000617714 0.00282076
        Droplet diameter max, min, mean = 0.0002, 0.0002, 0.0002
    MULES limit is done
    MULES: Solving for alpha.oil
    MULES: Solving for alpha.water
    oil fraction, min, max = 0.003 0.000631032 0.00359535
    water fraction, min, max = 0.997 0.996405 0.999369
    Phase-sum volume fraction, min, max = 1 1 1
    DILUPBiCGStab:  Solving for n, Initial residual = 0.000901165, Final residual = 1.49419e-09, No Iterations 1
        Inconsistency value, average, min, max = 2.51988e-11 -0.000617713 0.00282694
        Droplet diameter max, min, mean = 0.0002, 0.0002, 0.0002
    Constructing momentum equations
    oil min/max T 300 - 300
    water min/max T 300 - 300
    GAMG:  Solving for p_rgh, Initial residual = 1, Final residual = 0.00559932, No Iterations 6
    GAMG:  Solving for p_rgh, Initial residual = 1, Final residual = 0.00565399, No Iterations 6
    GAMGPCG:  Solving for p_rgh, Initial residual = 1, Final residual = 3.20997e-08, No Iterations 15
    DILUPBiCGStab:  Solving for epsilon.water, Initial residual = 0.000218679, Final residual = 6.3486e-09, No Iterations 2
    DILUPBiCGStab:  Solving for k.water, Initial residual = 0.000310738, Final residual = 1.00525e-09, No Iterations 2
    ExecutionTime = 91.01 s
    
    
    Courant Number mean: 0.14345 max: 0.780081
    deltaT = 0.000740741
    Time = 0.503704
    
    Weighted Re = 9.07954, weighted breakage frequency = 0
    MULES limit is done
    MULES: Solving for alpha.oil
    MULES: Solving for alpha.water
    oil fraction, min, max = 0.003 0.000631032 0.00359535
    water fraction, min, max = 0.997 0.996405 0.999369
    Phase-sum volume fraction, min, max = 1 1 1
    DILUPBiCGStab:  Solving for n, Initial residual = 0.000900074, Final residual = 1.47821e-09, No Iterations 1
        Inconsistency value, average, min, max = 2.51619e-11 -0.000617711 0.00283307
        Droplet diameter max, min, mean = 0.0002, 0.0002, 0.0002
    MULES limit is done
    MULES: Solving for alpha.oil
    MULES: Solving for alpha.water
    oil fraction, min, max = 0.003 0.000631032 0.00359527
    water fraction, min, max = 0.997 0.996405 0.999369
    Phase-sum volume fraction, min, max = 1 1 1
    DILUPBiCGStab:  Solving for n, Initial residual = 0.000899041, Final residual = 1.47284e-09, No Iterations 1
        Inconsistency value, average, min, max = 2.51262e-11 -0.00061771 0.00283924
        Droplet diameter max, min, mean = 0.0002, 0.0002, 0.0002
    Constructing momentum equations
    oil min/max T 300 - 300
    water min/max T 300 - 300
    GAMG:  Solving for p_rgh, Initial residual = 1, Final residual = 0.00559881, No Iterations 6
    GAMG:  Solving for p_rgh, Initial residual = 1, Final residual = 0.00565348, No Iterations 6
    GAMGPCG:  Solving for p_rgh, Initial residual = 1, Final residual = 3.20563e-08, No Iterations 15
    DILUPBiCGStab:  Solving for epsilon.water, Initial residual = 0.000217858, Final residual = 6.31719e-09, No Iterations 2
    DILUPBiCGStab:  Solving for k.water, Initial residual = 0.00030924, Final residual = 9.97882e-10, No Iterations 2
    ExecutionTime = 91.12 s
    
    
    Courant Number mean: 0.143439 max: 0.779868
    deltaT = 0.000740741
    Time = 0.504444
    
    Weighted Re = 9.07807, weighted breakage frequency = 0
    MULES limit is done
    MULES: Solving for alpha.oil
    MULES: Solving for alpha.water
    oil fraction, min, max = 0.003 0.000631032 0.00359526
    water fraction, min, max = 0.997 0.996405 0.999369
    Phase-sum volume fraction, min, max = 1 1 1
    DILUPBiCGStab:  Solving for n, Initial residual = 0.000897968, Final residual = 1.45572e-09, No Iterations 1
        Inconsistency value, average, min, max = 2.50956e-11 -0.000617709 0.00284538
        Droplet diameter max, min, mean = 0.0002, 0.0002, 0.0002
    MULES limit is done
    MULES: Solving for alpha.oil
    MULES: Solving for alpha.water
    oil fraction, min, max = 0.003 0.000631032 0.00359518
    water fraction, min, max = 0.997 0.996405 0.999369
    Phase-sum volume fraction, min, max = 1 1 1
    DILUPBiCGStab:  Solving for n, Initial residual = 0.000896997, Final residual = 1.44647e-09, No Iterations 1
        Inconsistency value, average, min, max = 2.50645e-11 -0.000617707 0.00285154
        Droplet diameter max, min, mean = 0.0002, 0.0002, 0.0002
    Constructing momentum equations
    oil min/max T 300 - 300
    water min/max T 300 - 300
    GAMG:  Solving for p_rgh, Initial residual = 1, Final residual = 0.00559871, No Iterations 6
    GAMG:  Solving for p_rgh, Initial residual = 1, Final residual = 0.00565306, No Iterations 6
    GAMGPCG:  Solving for p_rgh, Initial residual = 1, Final residual = 3.20133e-08, No Iterations 15
    DILUPBiCGStab:  Solving for epsilon.water, Initial residual = 0.000217072, Final residual = 6.28692e-09, No Iterations 2
    DILUPBiCGStab:  Solving for k.water, Initial residual = 0.000307752, Final residual = 9.91092e-10, No Iterations 2
    ExecutionTime = 91.23 s
    
    
    

    各位大佬,这是上面的log文件,我想从中提取几个关键的值:

    • Time = 0.000576911里面的0.000576911
    • Inconsistency value, average, min, max = -1.34441e-17 -0.000583605 0.000718129里面的0.000718129

    目前我使用这个语句:

    awk '{if($0~"Inconsist") print}' log
    

    可以提取出来一部分,但是达不到我的需求。我最终想要的是两列数据,类似:

    0.000576911  0.000718129
    

    上面是一行的,第一列Time,第二列是后面那个

    有没有大佬会搞这个?



  • 大佬,我用的matlab,不知道大佬用不用,写了个简短的字符串处理,读取log文件,文件名aaa.log。查找Time=后的数据和Inconsistency value, average, min, max后面的数据,然后输出到data.txt,第一列时间,第二列是那个数据。用大佬提供的这三个时间步的log信息试了下,应该没啥问题。只是每个时间步Inconsistency value这个有两组,我取的第二组。

    clear;
    clc;
    
    filein=['aaa.log'];
    fidin=fopen(filein,'r');
    ansn=zeros(500000,1);
    anst=zeros(500000,1);
    totn=0;
    tott=0;
    
    line=0;
    flagn=0;
    flagt=0;
    
    
    while ~feof(fidin) % 判断是否为文件末尾  
        line=line+1;
        temp=fgetl(fidin); % 从文件读行
        if flagn ==2 
            flagn=0;
        end
        flagt=0;
        str = deblank(temp);
        s = regexp(str,  '\s+', 'split');
        if length(s) <=2 
            continue;
        end
        if (strcmp(s{2},'Inconsistency')) && (strcmp(s{3},'value,'))
            flagn=flagn+1;
        end 
        if (strcmp(s{1},'Time')) && (strcmp(s{2},'='))
            flagt=1;
        end 
        if (flagn==2)
            ss = char(s{10});
            sss=str2double(ss);
            totn=totn+1;
            ansn(totn) = sss;
        end
        if (flagt>0)
            ss = char(s{3});
            sss=str2double(ss);
            tott=tott+1;
            anst(tott) = sss;
        end 
    end
    
    fclose(fidin);
    fid=fopen('data.txt','wt');
    for i=1:tott
    fprintf(fid, '%.6f %.8f\n',anst(i),ansn(i));
    end
    fclose(fid);
    

    输出的数据:
    0.502963 0.00282694
    0.503704 0.00283924
    0.504444 0.00285154


  • 教授

    @李东岳

    提供一个思路,one liner

    paste <(cat log  | grep '^Time' | awk '{print $3}') <(cat log | grep 'Inconsistency' | awk '{print $9}')
    

    paste 的作用本是将文件内容按列拼接,但是也可以将标准输入来进行拼接,输入的内容可以是来自其他命令。这里是将 Time 和 Inconsistency对应的内容分别提取出来,然后按列拼接。不过这里每个 Time 下面有两个 Inconsistency 的值,所以上面命令拼接处理的应该还不是楼主最终想要的,仅是一个思路。



  • 很实用的提问,mark下!


  • 管理员

    各位简直就是大佬中的大佬 厉害厉害 :chitang:


Log in to reply
 


CFD中文网 | 东岳流体学术 | 东岳流体商业 | 吉ICP备20003622号-1