CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   pyFoamPlotWatcher and customRegexp (http://www.cfd-online.com/Forums/openfoam-solving/99189-pyfoamplotwatcher-customregexp.html)

wernsen March 28, 2012 03:46

pyFoamPlotWatcher and customRegexp
 
Hello everybody,

I am having problems plotting of variables out of the logfiles with the help of pyFoam 0.5.5. Neither can I see any plot nor do I get any error while starting the plot.

It would be nice if anyone can help me :)

Thanks

Code:

Custom01
{
  accumulation first;
  enabled yes;
  expr " MassFlows:  inlet = (%f%)  outlet = (%f%)";
  name Custom01_massflow;
  persist no;
  raisit no;
  theTitle "Custom 1 - MassFlows";
  titles
    (
      min
      max
    );
  type regular;
  with lines;
}

My logFile looks like:
Code:

...
MassFlows:  inlet = -0.03416099  outlet = 0.0341609
Time = 597
smoothSolver:  Solving for Ux, Initial residual = 7.440172e-05, Final residual = 3.728601e-06, No Iterations 4
smoothSolver:  Solving for Uy, Initial residual = 0.0001222075, Final residual = 1.202023e-05, No Iterations 3
smoothSolver:  Solving for Uz, Initial residual = 5.190061e-05, Final residual = 4.436034e-06, No Iterations 3
DILUPBiCG:  Solving for h, Initial residual = 6.815629e-05, Final residual = 4.644949e-06, No Iterations 1
GAMG:  Solving for p, Initial residual = 2.698017e-05, Final residual = 1.007462e-06, No Iterations 2
time step continuity errors : sum local = 0.0081001, global = -3.721162e-05, cumulative = 0.4522695
rho max/min : 1.200515 1.06891
smoothSolver:  Solving for omega, Initial residual = 1.341662e-05, Final residual = 1.333425e-06, No Iterations 3
bounding omega, min: -11603.2 max: 6.233842e+07 average: 106296.4
smoothSolver:  Solving for k, Initial residual = 0.0003323861, Final residual = 2.379521e-05, No Iterations 4
bounding k, min: -8.03594e-05 max: 240.341 average: 3.479831
ExecutionTime = 3112.29 s  ClockTime = 3258 s
...


gschaider March 28, 2012 07:49

Quote:

Originally Posted by wernsen (Post 351871)
Hello everybody,

I am having problems plotting of variables out of the logfiles with the help of pyFoam 0.5.5. Neither can I see any plot nor do I get any error while starting the plot.

It would be nice if anyone can help me :)

Thanks

Code:

Custom01
{
  accumulation first;
  enabled yes;
  expr " MassFlows:  inlet = (%f%)  outlet = (%f%)";
  name Custom01_massflow;
  persist no;
  raisit no;
  theTitle "Custom 1 - MassFlows";
  titles
    (
      min
      max
    );
  type regular;
  with lines;
}

My logFile looks like:
Code:

...
MassFlows:  inlet = -0.03416099  outlet = 0.0341609
Time = 597
smoothSolver:  Solving for Ux, Initial residual = 7.440172e-05, Final residual = 3.728601e-06, No Iterations 4
smoothSolver:  Solving for Uy, Initial residual = 0.0001222075, Final residual = 1.202023e-05, No Iterations 3
smoothSolver:  Solving for Uz, Initial residual = 5.190061e-05, Final residual = 4.436034e-06, No Iterations 3
DILUPBiCG:  Solving for h, Initial residual = 6.815629e-05, Final residual = 4.644949e-06, No Iterations 1
GAMG:  Solving for p, Initial residual = 2.698017e-05, Final residual = 1.007462e-06, No Iterations 2
time step continuity errors : sum local = 0.0081001, global = -3.721162e-05, cumulative = 0.4522695
rho max/min : 1.200515 1.06891
smoothSolver:  Solving for omega, Initial residual = 1.341662e-05, Final residual = 1.333425e-06, No Iterations 3
bounding omega, min: -11603.2 max: 6.233842e+07 average: 106296.4
smoothSolver:  Solving for k, Initial residual = 0.0003323861, Final residual = 2.379521e-05, No Iterations 4
bounding k, min: -8.03594e-05 max: 240.341 average: 3.479831
ExecutionTime = 3112.29 s  ClockTime = 3258 s
...


Regular expressions are sensitive to spaces. I'm not 100% percent sure, but the leading spaces in your regexp might be the problem (I don't see them in your log). As far as I remember leading spaces are removed from the log-line before matching, but not from the expression

The way I usually "develop" a regexp is by copying a log-line between "" and then replace the numbers I want to match with (%f%)

wernsen March 28, 2012 08:07

Hello Bernhard,

what a honor to get the answer from the father of pyFoam itself. It is a realy helpfull set of tools. Actually like a swizz knife :D

I found my Problem. I had to delete the space as you adviced and the customRegexp-File have to be placed where the logfile is.

-> now it works greatfull

Thanks Bernhard,
MARTIN

gschaider March 28, 2012 12:01

Quote:

Originally Posted by wernsen (Post 351923)
what a honor to get the answer from the father of pyFoam itself. It is a realy helpfull set of tools. Actually like a swizz knife :D

Thanks. But I think father is the wrong word. I like to think about myself as the sinister mastermind behind PyFoam ;)

Quote:

Originally Posted by wernsen (Post 351923)
I found my Problem. I had to delete the space as you adviced and the customRegexp-File have to be placed where the logfile is.

-> now it works greatfull

Great. If you feel that information that would have helped you to avoid that problem in the first place is missing from the Wiki-page could you be so kind to add it? Thanks

JNSN December 12, 2012 05:45

Hi PyFoamers,

is it possible to skip a value from the expression? E.g. plotting only the outlet value in the above example?

Thanks in advance!
Jan

gschaider December 12, 2012 13:38

Quote:

Originally Posted by JNSN (Post 397097)
Hi PyFoamers,

is it possible to skip a value from the expression? E.g. plotting only the outlet value in the above example?

Thanks in advance!
Jan

Yep. Only pattern groups are being plotted. So instead of

Code:

expr " MassFlows:  inlet = (%f%)  outlet = (%f%)"
write

Code:

expr " MassFlows:  inlet = %f%  outlet = (%f%)"
or

Code:

expr " MassFlows:  inlet = .+  outlet = (%f%)"
would work too

JNSN December 13, 2012 05:08

Hi Bernhard,

thanks a lot for the quick reply!

Best regards,
Jan

aerogt3 March 5, 2013 09:48

Is there any way to plot, on the same graph axes, two variables which are on different lines of the log file? I am having trouble defining multiple expressions in a single graph!

gschaider March 5, 2013 10:09

Quote:

Originally Posted by aerogt3 (Post 411657)
Is there any way to plot, on the same graph axes, two variables which are on different lines of the log file? I am having trouble defining multiple expressions in a single graph!

Yes there is. And it is even described on the Wiki-page: http://openfoamwiki.net/index.php/Co...oam#New_format (look for "type slave")

GerhardHolzinger September 26, 2013 11:45

Additional Information
 
I don't mean to hijack this thread, but I found out, that parentheses make problems with the regexp. I had this line of solver output

Code:

Concentration = 0.0823725  Min(T) = 0.00958365  Max(T) = 0.326796
and tried this regexp

Code:

{"expr":"Concentration = (%f%)  Min(T) = (%f%)  Max(T) = (%f%)","name":"Concentration"}
But it did not work. However, after some trial and error I found out that the parenthesis were causing the problem. So I changed my output accordingly:

Code:

Concentration = 0.0505933  Min T = 0.00492903  Max T = 0.217095
Now this regexp works

Code:

{"expr":"Concentration = (%f%)  Min T = (%f%)  Max T = (%f%)","name":"Concentration","titles":["avg","min","max"]}

gschaider September 26, 2013 13:12

Quote:

Originally Posted by GerhardHolzinger (Post 453758)
I don't mean to hijack this thread, but I found out, that parentheses make problems with the regexp. I had this line of solver output

Code:

Concentration = 0.0823725  Min(T) = 0.00958365  Max(T) = 0.326796
and tried this regexp

Code:

{"expr":"Concentration = (%f%)  Min(T) = (%f%)  Max(T) = (%f%)","name":"Concentration"}
But it did not work. However, after some trial and error I found out that the parenthesis were causing the problem. So I changed my output accordingly:

Code:

Concentration = 0.0505933  Min T = 0.00492903  Max T = 0.217095
Now this regexp works

Code:

{"expr":"Concentration = (%f%)  Min T = (%f%)  Max T = (%f%)","name":"Concentration","titles":["avg","min","max"]}

Parenthesis have a special meaning in regular expressions: they define "groups". PyFoam uses these groups to say "this is important". You can say "I really mean '(' not a group" by escaping with \: \( and \) (BTW: the same is true for [ and ])

I think I wrote this in one of my PyFoam-presentations (but probably not on the Wiki-page)

GerhardHolzinger September 27, 2013 03:58

Thanks for the explanation.

As you say on in the wiki

Quote:

regular expression need some getting used to
So I need to get used to regular expressions. Had nothing to do with them yet.

By the way: In the wiki in section 9.1.2 Information on regular expression both links to summaries on regular expressions are broken.

gschaider September 27, 2013 06:22

Quote:

Originally Posted by GerhardHolzinger (Post 453839)
Thanks for the explanation.

As you say on in the wiki



So I need to get used to regular expressions. Had nothing to do with them yet.

By the way: In the wiki in section 9.1.2 Information on regular expression both links to summaries on regular expressions are broken.

That kind of link is so common (google "regular expression cheat sheet": http://www.cheatography.com/davechil...r-expressions/) that people move it all the time. I'm also not sure whether these cheat sheets are the best place for a beginner. If you find a good link it'd be nice if you replace the old links with it (I'm not an expert on regular expressions but I guess you're nearer to beginner level so you're the better judge what is good for newbies)

emjay December 3, 2014 14:23

Hallo may somebody can help me:

my logFile looks like:

Code:

PIMPLE: converged in 3 iterations
ExecutionTime = 75513.4 s  ClockTime = 75651 s

forces forces output:
    sum of forces:
        pressure : (0.603027 -0.0244227 -4.07056e-21)
        viscous  : (0.060363 0.0116136 -1.30133e-21)
        porous  : (0 0 0)
    sum of moments:
        pressure : (2.66751e-19 -2.65314e-17 -1.75474e-12)
        viscous  : (5.0719e-19 -2.74569e-18 -0.000137971)
        porous  : (0 0 0)

How should my customRegExp should look like, to plot the sum of pressure ans viscous components?
pressure in x : 7.7394e-19
pressure in y : 0.09


Thanl you for your help

gschaider December 3, 2014 17:48

Quote:

Originally Posted by emjay (Post 522347)
Hallo may somebody can help me:

my logFile looks like:

Code:

PIMPLE: converged in 3 iterations
ExecutionTime = 75513.4 s  ClockTime = 75651 s

forces forces output:
    sum of forces:
        pressure : (0.603027 -0.0244227 -4.07056e-21)
        viscous  : (0.060363 0.0116136 -1.30133e-21)
        porous  : (0 0 0)
    sum of moments:
        pressure : (2.66751e-19 -2.65314e-17 -1.75474e-12)
        viscous  : (5.0719e-19 -2.74569e-18 -0.000137971)
        porous  : (0 0 0)

How should my customRegExp should look like, to plot the sum of pressure ans viscous components?
pressure in x : 7.7394e-19
pressure in y : 0.09


Thanl you for your help

Matching this hasn't been possible until last week as the match has to go over multiple lines. Last week PyFoam 0.6.4 came out and if you look at the release notes http://sourceforge.net/p/openfoam-ex...Notes.md#sec-1 then this is now possible.

zfaraday April 22, 2015 14:10

Plot residuals of any region in a multi region solver
 
Hi all!

I apologize for pulling up this old thread but I'm struggling with some issue that I think that fits well in it...

I'm solving some cases with chtMultiRegionSimpleFoam solver with a few solid regions and a fluid one. When I run pyFoamPlotWatcher it only shows the residuals plot for the fluid region. What I would like to study is the residuals for some of the solid regions and after having searched for some info in the net I think that it would be possible by using customRegexp. The problem is that I don't have enough knowledge to tackle it on my own so here comes my question: How should my file look like? The solver's output looks like
Code:

Solving for solid region regionName
DICPCG:  Solving for h, Initial residual = 0.02194378, Final residual = 0.0001580524, No Iterations 4
DICPCG:  Solving for h, Initial residual = 0.01952452, Final residual = 0.0001349324, No Iterations 4
DICPCG:  Solving for h, Initial residual = 0.01921998, Final residual = 0.000115592, No Iterations 4
DICPCG:  Solving for h, Initial residual = 0.01896599, Final residual = 0.0001086326, No Iterations 4
Min/max T:min(T) [0 0 0 1 0 0 0] 937.6767 max(T) [0 0 0 1 0 0 0] 962.7659

and as per what I saw in the wiki page the file should be similar to
Code:

ReactionSpeed
{
  expr "Reaction Speed: (%f%) min (%f%) max";
  name Custom01_Reaction_speed;
  theTitle "Custom 1 - Reaction speed";
  titles
  (
    min
    max
  );
  type regular;
}

but I don't know what I should do in oder to create the proper customRegexp file to be able to plot the residuals for any other region than the fluid one...

Any word of wisdom that can enlighten me about this matter will be much appreciated! :)

Best regards,

Alex

zfaraday April 23, 2015 09:40

After some attempts to make it work I didn't succeed...:(

My attempt was to create a file within the case directory with the name customRegexp as suggested in the wiki. In my case, the file contains the following information:

Code:

alumina_residuals
{
  expr "Solving for solid region alumina\n\nDICPCG:  Solving for h, Initial residual = (%f%), Final residual = .+, No Iterations .+";
  name Custom01_alumina_res;
  theTitle "Custom 1 - Residuals for region alumina";
  titles
  (
    Initial Residuals
  );
  type regular;
}

As one can see, my intention is to plot the initial residual for the last correction step (the third line for the region in the example). I used \n to indicate pyFoam that it must read the line number n in order to pick the information I want to plot. Not sure if I used it correctly (probably not as I'm unexperienced in using regular expressions). I also tried to leave a sapce between the new line characters and the rest of the characters ("region alumina \n \n DICPCG:") but it also gave no outputs...

I'm using pyFoam version 0.6.4 and the order I type in the terminal is:
Code:

pyFoamPlotWatcher.py --silent --progress --no-default log.chtMultiRegionSimpleFoam &
to what the terminal says:
Code:

Reading regular expressions from customRegexp
so it seems that everything is fine. However, no plot is shown...:(

Can anyone give me some advice on how to proceed correctly in order to write the proper regular expression to be able to plot the residuals for any region? I would really appreciate the help given! :)

Best regards,

Alex

zfaraday April 24, 2015 11:45

Residuals plot with vertical axis in logarithmic scale
 
Dear colleagues,

Finally I could manage to solve it (more or less). I get a a residuals plot by using this customRegexp file:

Code:

alumina_residuals
{
  expr "Solving for solid region alumina\nDICPCG:  Solving for h, Initial residual = (%f%), Final residual = .+, No Iterations .+";
  name Custom_alumina_res;
  theTitle "Residuals for region: alumina";
  titles
  (
    "h (1st iter.)"
  );
  type regular;
}

This is the initial residual for the first correction step, I also managed to plot the last correction step but I realized that it makes more sense to plot the first initial residual.

Now I have another problem, the plot shows the residuals using a linear vertical axis instead of a logarithmical axis which is not much useful because I can barely see anything... I tried to add a line in the customRegexp file in order to convert the vertical axis into logarithmic scale using the gnuplot grammar, i.e. set logscale y, but it did nothing, the plot was done in linear scale any way.

How can I plot the residuals with the vertical axis in logarithmic scale? Is it possible to do that?

Many thanks in advance!

Alex

JNSN May 18, 2015 09:37

Code:

  logscale true;

zfaraday May 18, 2015 09:43

Amazing! As simple as that... Thanks!

Regards,

Alex


All times are GMT -4. The time now is 21:38.