I have a log file having the following output and I have shortened it as it goes to thousands of lines:
Time = 1
smoothSolver: Solving for Ux, Initial residual = 0.230812, Final residual = 0.0134171, No Iterations 2
smoothSolver: Solving for Uy, Initial residual = 0.283614, Final residual = 0.0158797, No Iterations 3
smoothSolver: Solving for Uz, Initial residual = 0.190444, Final residual = 0.016567, No Iterations 2
GAMG: Solving for p, Initial residual = 0.0850116, Final residual = 0.00375608, No Iterations 3
time step continuity errors : sum local = 0.00999678, global = 0.00142109, cumulative = 0.00142109
smoothSolver: Solving for omega, Initial residual = 0.00267604, Final residual = 0.000166675, No Iterations 3
bounding omega, min: -26.6597 max: 18468.7 average: 219.43
smoothSolver: Solving for k, Initial residual = 1, Final residual = 0.0862096, No Iterations 2
ExecutionTime = 4.84 s ClockTime = 5 s
Time = 2
smoothSolver: Solving for Ux, Initial residual = 0.0299872, Final residual = 0.00230507, No Iterations 2
smoothSolver: Solving for Uy, Initial residual = 0.145767, Final residual = 0.00882969, No Iterations 3
smoothSolver: Solving for Uz, Initial residual = 0.0863129, Final residual = 0.00858536, No Iterations 2
GAMG: Solving for p, Initial residual = 0.394189, Final residual = 0.0175138, No Iterations 3
time step continuity errors : sum local = 0.00862823, global = 0.00212477, cumulative = 0.00354587
smoothSolver: Solving for omega, Initial residual = 0.00258475, Final residual = 0.000222705, No Iterations 3
smoothSolver: Solving for k, Initial residual = 0.112805, Final residual = 0.0054572, No Iterations 3
ExecutionTime = 5.9 s ClockTime = 6 s
Time = 3
smoothSolver: Solving for Ux, Initial residual = 0.128298, Final residual = 0.0070293, No Iterations 2
smoothSolver: Solving for Uy, Initial residual = 0.138825, Final residual = 0.0116437, No Iterations 3
smoothSolver: Solving for Uz, Initial residual = 0.0798979, Final residual = 0.00491246, No Iterations 3
GAMG: Solving for p, Initial residual = 0.108748, Final residual = 0.00429273, No Iterations 2
time step continuity errors : sum local = 0.0073211, global = -0.00187909, cumulative = 0.00166678
smoothSolver: Solving for omega, Initial residual = 0.00238456, Final residual = 0.000224435, No Iterations 3
smoothSolver: Solving for k, Initial residual = 0.0529661, Final residual = 0.00280851, No Iterations 3
ExecutionTime = 6.92 s ClockTime = 7 s
I need to extract Time = 1, 2, 3 and corresponding cumulative values using Python's regular expression. More precisely, I need to extract only the values 1, 2, 3 and 0.00142109, 0.00354587, 0.00166678 that corresponds to cumulative at Time = 1,2 and 3 and write to an another file.
Currently, this is what I have:
contCumulative_0_out = open('contCumulative_0', 'w+')
with open(logFile, 'r') as logfile_read:
for line in logfile_read:
line = line.rstrip()
iteration_time = re.findall(r'^Time = ([0-9]+)', line)
print iteration_time
contCumulative_0 = re.search(r'cumulative = ((\d|.)+)', line)
if contCumulative_0:
cumvalue = contCumulative_0.groups(1)
contCumulative_0_out.write('\n'.join(cumvalue))
The variable iteration_time grabs the Time value, however this is not available within the next subsequent if loop and therefore I am unable to combine Time and cumulative to give me 1 0.00142109 in the output file.