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] Using regular expressions on multi-line output (https://www.cfd-online.com/Forums/openfoam-community-contributions/143886-using-regular-expressions-multi-line-output.html)

GerhardHolzinger November 5, 2014 03:39

Using regular expressions on multi-line output
 
I want to plot the output values of the force function object. However, in my current installation (OF-2.3.x) the force function object produces multiline output.

In my example I apply the force function object on two patches. How can I write a regular expression for pyFoamPlotWatcher or -Runner that extracts the correct values?

Code:

forces forceRotor output:
    sum of forces:
        pressure : (4.96081e-09 -5.11743e-11 -0.000116436)
        viscous  : (4.97137e-13 -1.13776e-12 6.15157e-08)
        porous  : (0 0 0)
    sum of moments:
        pressure : (7.7971e-11 3.93148e-10 -0.0360825)
        viscous  : (6.43907e-14 1.0728e-14 -4.57924e-05)
        porous  : (0 0 0)

forces forceStator output:
    sum of forces:
        pressure : (-6.20745e-08 7.22842e-08 7.44833e-05)
        viscous  : (4.96527e-14 -2.59452e-14 2.79123e-09)
        porous  : (0 0 0)
    sum of moments:
        pressure : (-6.05447e-09 -6.97223e-09 -3.86287e-07)
        viscous  : (2.41672e-15 5.02503e-15 1.78738e-10)
        porous  : (0 0 0)


gschaider November 5, 2014 04:46

Quote:

Originally Posted by GerhardHolzinger (Post 517426)
I want to plot the output values of the force function object. However, in my current installation (OF-2.3.x) the force function object produces multiline output.

In my example I apply the force function object on two patches. How can I write a regular expression for pyFoamPlotWatcher or -Runner that extracts the correct values?

Code:

forces forceRotor output:
    sum of forces:
        pressure : (4.96081e-09 -5.11743e-11 -0.000116436)
        viscous  : (4.97137e-13 -1.13776e-12 6.15157e-08)
        porous  : (0 0 0)
    sum of moments:
        pressure : (7.7971e-11 3.93148e-10 -0.0360825)
        viscous  : (6.43907e-14 1.0728e-14 -4.57924e-05)
        porous  : (0 0 0)

forces forceStator output:
    sum of forces:
        pressure : (-6.20745e-08 7.22842e-08 7.44833e-05)
        viscous  : (4.96527e-14 -2.59452e-14 2.79123e-09)
        porous  : (0 0 0)
    sum of moments:
        pressure : (-6.05447e-09 -6.97223e-09 -3.86287e-07)
        viscous  : (2.41672e-15 5.02503e-15 1.78738e-10)
        porous  : (0 0 0)


Multi-Line is not possible out of the box. PyFoam looks for efficiency reasons at one line at a time. There is something called "phases" that I introduced for multi-region cases. With something like (doing this from memory
Code:

switchForce {
    type phase;
    idNr 1;
    expr "forces (.+) output:";
}

you could make PyFoam distinguish between the two forces. The problem is that inside the phase there are still two different "phases" (forces and moments) and this concept doesn't nest. Don't see a way around this that doesn't involve modifying or sub-classing RegExpLineAnalyzer to do something like this
Code:

forces {
  type dynamic;
  multiLine 9;
  expr " <long ugly RegExp> ";
}

(store the last 9 lines and match against them)

GerhardHolzinger November 5, 2014 07:54

I "solved" the problem by not using pyFoam and I am aware that this is kind of a terrible thing to say.

I figured out, that the functionObject writes the results (forces & moments) in *.dat files in the postProcessing folder. I use then this files to plot the moments with gnuplot.


However, the problem still persists, e.g. for stuff that the solver computes directly and prints to Terminal via
Code:

Info << "some stuff = " << someStuff << endl;
.
There, I do not have the luxury of some *.dat files that are created for me.

gschaider November 5, 2014 10:38

Quote:

Originally Posted by GerhardHolzinger (Post 517494)
I "solved" the problem by not using pyFoam and I am aware that this is kind of a terrible thing to say.

I figured out, that the functionObject writes the results (forces & moments) in *.dat files in the postProcessing folder. I use then this files to plot the moments with gnuplot.


However, the problem still persists, e.g. for stuff that the solver computes directly and prints to Terminal via
Code:

Info << "some stuff = " << someStuff << endl;
.
There, I do not have the luxury of some *.dat files that are created for me.

Create a Ticket/Feature-Request at https://sourceforge.net/p/openfoam-e...ticketspyfoam/ (something like "multiline regular expression matching")

I usually don't do feature-requests from non-customers but you're just using up the credit you created with publishing your "book"


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