CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [PyFoam] pyFoamPlotWatcher and customRegexp (https://www.cfd-online.com/Forums/openfoam-community-contributions/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 04: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 12: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 04:08

Hi Bernhard,

thanks a lot for the quick reply!

Best regards,
Jan

aerogt3 March 5, 2013 08: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 09: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 13: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 16: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

Sethu June 15, 2015 02:32

PyFoamPlotWatcher to plot min/max "p"
 
Dear all,

Im trying to plot min/max of pressure (p) in my domain using pyFoamPlotwatcher.py along with massflow rate. Im able to plot for massflow rate, but min(p) values are not getting plotted.

My log file looks like this,

//log_file_sample_start//
...
ExecutionTime = 46.73 s ClockTime = 51 s

MassFlows: outlet = 0.000254 inlet = -0.000254
fieldMinMax minmaxdomain output:
min(p) = -9.27757 at position (0.0549444 -0.0108001 -1.09092e-21)
max(p) = 13.3839 at position (0.207022 0.0251462 -1.63172e-21)

min(U) = (9.83972 -1.23842 0) at position (-0.0198086 0.000156695 -2.90727e-21)
max(U) = (10.0882 0.0457922 5.69625e-23) at position (0.000794772 0.00125782 -3.55445e-21)

//log_file_sample_end//


My customRegexp file is written like this,

massFlow
{
accumulation first;
enabled yes;
expr "MassFlows: outlet = (%f%) inlet = (%f%)";
name Custom01_massFlow;
theTitle "Massflow rate";
titles
(
outlet
inlet
);
type regular;
}

min(p)
{
expr "min(p) = (%f%) at position \(%f% %f% %f%\)";
name Custom02_min(p);
theTitle "min_p";
titles
(
min_p
);
type regular;
}


As I mentioned earlier, massflow values are plotted but min(p) value is not getting plotted. Moreover, i didnt receive any error.

Pls give me your suggestions.


Sethu


arieljeds July 19, 2016 10:48

Hi, I'm having trouble using the customRegexp and swak4Foam function objects (following from one of the OFW presentation examples). I'm getting the following error when I try to run a case with some swak4Foam expressions in controlDict and a customRegexp file:

Code:

PyFoam WARNING on line 144 of file /usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Execution/ParallelExecution.py : which can not find a match for waveFoam . Hoping for the best
Traceback (most recent call last):
  File "/usr/local/bin/pyFoamPlotRunner.py", line 5, in <module>
    pkg_resources.run_script('PyFoam==0.6.5', 'pyFoamPlotRunner.py')
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 499, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1235, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/EGG-INFO/scripts/pyFoamPlotRunner.py", line 5, in <module>
    PlotRunner()
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Applications/PlotRunner.py", line 60, in __init__
    **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Applications/PyFoamApplication.py", line 424, in __init__
    result=self.run()
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Applications/PlotRunner.py", line 135, in run
    jobId=self.opts.jobId)
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Execution/GnuplotRunner.py", line 171, in __init__
    plottingImplementation=plottingImplementation)
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Execution/GnuplotRunner.py", line 74, in __init__
    plottingImplementation=plottingImplementation)
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Execution/AnalyzedCommon.py", line 278, in createPlots
    endTime=custom.end))
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/LogAnalysis/RegExpLineAnalyzer.py", line 71, in __init__
    self.exp=re.compile(self.strExp,reFlags)
  File "/usr/lib/python2.7/re.py", line 190, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python2.7/re.py", line 242, in _compile
    raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis
Exception in thread Thread-3 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
  File "/usr/lib/python2.7/threading.py", line 757, in run
  File "/usr/lib/python2.7/threading.py", line 403, in wait
  File "/usr/lib/python2.7/threading.py", line 258, in wait
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

My controlDict is as follows:

Code:

  application                waveFoam;
   
    startFrom                latestTime; //startTime;
   
    startTime                0;
   
    stopAt                endTime;
   
    endTime                300;
   
    deltaT                0.05;
   
    writeControl        adjustableRunTime;
   
    writeInterval        0.5;
   
    purgeWrite                0;
   
    writeFormat                ascii;
   
    writePrecision        6;
   
    writeCompression        off;
   
    timeFormat                general;
   
    timePrecision        6;
   
    runTimeModifiable        true;
   
    adjustTimeStep        yes;
   
    maxCo                0.9; // increase the Co as much as possible
   
    maxAlphaCo                0.9;
   
    maxDeltaT                1;
 
  // **************************************************************************** //
 
 
  libs
  (
          "libOpenFOAM.so"
          "libsimpleSwakFunctionObjects.so"
          "libswakFunctionObjects.so"
          "libgroovyBC.so"
  );
 
  functions
  {

        forces
    {
        type forces;
        functionObjectLibs ("libforces.so");
        patches (cylinder);
        rhoName rho;
        rhoInf 1028;
        CofR (0 0 0);
        outputControl timeStep;//outputTime;//
        outputInterval 100;
        log true;
      }
     
     
      velocityStatistics
      {
     
            type swakExpression;
            verbose true;
            outputControlMode timeStep;
            outputInterval          1;
            valueType        internalField;
            expression        "mag(U)";
            accumulations (
                    weightedQuantile0.1
                    weightedAverage
                    weightedQuantile0.9
                    max
                    );
      }
     
      minStreamFunctionPos
      {
        type        swakExpression;
        verbose true;
        outputControlMode        timeStep;
        outputInterval                1;
        expression "streamF";
        valueType  internalField;
        accumulations (
                    min
                );
        expressions "minPosition(streamF)";
      }
           

  }


And finally my customRegexp file is:

Code:

velocity {
            theTitle  "Velocity statistics";
            expr "Expression velocityStatistics :  weightedQuantile0.1=(.+) weightedAverage=(.+)
                  weightedQuantile0.9=(.+) max=(.+)";
          titles (
                    "10 %"
                    average
                    "90 %"
                    maximum
            );
          ylabel "[m/s]";
}


I can't see an unbalanced paranthesis... can anyone help me on this?

Thanks in advance

RomainBou July 21, 2016 11:34

hello dear friends,

I am trying to plot the output of a faceSource functionObject that computes the total massflow at inlet.

Here is my log for one timestep:
Code:

PIMPLE: iteration 1
DILUPBiCG:  Solving for Ux, Initial residual = 0.0116454, Final residual = 5.6463e-08, No Iterations 2
DILUPBiCG:  Solving for Uy, Initial residual = 0.00353414, Final residual = 3.34245e-09, No Iterations 2
DILUPBiCG:  Solving for Uz, Initial residual = 0.00429777, Final residual = 8.15157e-09, No Iterations 2
GAMG:  Solving for p, Initial residual = 0.0390386, Final residual = 0.000158842, No Iterations 4
time step continuity errors : sum local = 4.00815e-08, global = 3.11859e-13, cumulative = 1.62584e-11
DICPCG:  Solving for PotE, Initial residual = 7.94541e-07, Final residual = 7.94541e-07, No Iterations 0
ExecutionTime = 5.58 s  ClockTime = 6 s

faceSource debit_sortant output:
    sum(inlet) of phi = -0.00164543

I am using pyFoam 0.6.5 and here is my customRegexp file :
Code:

massflowplot
{
  enabled  yes;
  expr    "    sum(inlet) of phi = (%f%)";
  name Custom_flow_plot;
  theTitle "Custom_flow_plot";
  titles
  (
    massflow
  );
  type regular;
}

Then i run
Code:

pyFoamPlotRunner.py mySolver
and it says "Reading regular expressions from /home/romain/OpenFOAM/romain-3.0.1/run/Cuve2_variations/Cuve2Cas1_variation_B/customRegexp".
But it doesn't plot and I don't understand why. Any idea ? Do I have to write something else somewere else ? Is the regexp correct ? thanks a lot for any help !

Mars409 June 13, 2020 11:36

Plotting particles added and escapes
 
Hi All,

How do you get pyFoamPlotWatcher to plot the added particle count and the escape count from solver.log?

The typical time step output for particles look like below:


Time = 0.875

Evolving kinematicCloud

Solving 3-D cloud kinematicCloud
Cloud: kinematicCloud
Current number of parcels = 5045
Current mass in system = 0.00647515
Linear momentum = (-0.002015723 -0.001078755 -0.0004498539)
|Linear momentum| = 0.002330069
Linear kinetic energy = 0.01457947
injector_1:
number of parcels added = 6546
mass introduced = 0.008395572
Parcel fate (number, mass) : patch cyclone_inletX
- escape = 0, 0
- stick = 0, 0
Parcel fate (number, mass) : patch cyclone_outlet
- escape = 1501, 0.001920422
- stick = 0, 0


I wrote a Python script to print to a CSV file and plot it using Gnuplot:

Code:

#!/usr/bin/python

import re
import sys
from subprocess import call

if len(sys.argv) > 1 :
        TEXTFILE = sys.argv[1]
else :
        TEXTFILE = 'solver.log'

if len(sys.argv) > 2 :
    CSVFILE = sys.argv[2]
else :
    CSVFILE = 'timeAddsEscapes.csv'
   
f1=open(CSVFILE, 'w+')

STATE0 = 'TIME'
STATE00 = 'SEARCH_ADDED'
STATE1 = 'SEARCH_OUTLET'
STATE2 = 'SEARCH_ESCAPE'

RE0 = 'Time = (\d+.\d+)'
RE00 = r'.*parcels added\s*=\s*(\d+)'
RE1 = r'\s*Parcel fate.*\:.*outlet$'
RE2 = r'\s*-\s*escape\s*=\s*(\d+)'



state = STATE0

print >>f1, "Time","Added", "Escapes"
with open(TEXTFILE, 'r') as f:
        for line in f:
                if state == STATE0 :
                        pat = RE0
                elif state == STATE00 :
                        pat = RE00
                elif state == STATE1 :
                        pat = RE1
                else :
                        pat = RE2
                match = re.match(pat, line)
                if not match :
                        continue
                #if state == STATE0 or state == STATE2 :
                #print line
                if state == STATE0 :
                        time = float(match.group(1))
                        state = STATE00
                elif state == STATE00 :
                        added = int(match.group(1))
                        state = STATE1
                elif state == STATE1 :
                        state = STATE2
                else :
                        escapes = int(match.group(1))
                        state = STATE0
                        if added > 0 :
                                # print "Time = ", time, " added = ", added, " escapes = ",escapes
                                print >>f1, time, added, escapes
f1.close()

call(["plotEscapes.sh", CSVFILE])

Here's a shell script, called by the name 'plotEscapes.sh' as in the above Python script, to plot the CSV values using Gnuplot:
Code:

#!/bin/bash
if (( $# != 1 )); then
    echo "Illegal number of parameters"
    cat <<EOT
Usage:
    plotEscapes.sh <CSV filename>
EOT
exit
fi


gnuplot -persist << EOT
        set term X11 size 700, 900
        set title 'Particle escapes & Particles added vs Time'
        set xlabel 'Time/s'
        set ylabel 'Particle count'
        set grid
        set multiplot layout 2,1 columnsfirst
        plot for [i=2:3] '$1' using 1:i lt 1 with lines title columnhead at end


        set logscale y
        plot for [i=2:3] '$1' using 1:i lt 2 with lines title columnhead at end
        unset multiplot
EOT



All times are GMT -4. The time now is 19:43.