CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[PyFoam] Using regular expressions on multi-line output

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 5, 2014, 04:39
Default Using regular expressions on multi-line output
  #1
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 305
Rep Power: 24
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
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)
GerhardHolzinger is offline   Reply With Quote

Old   November 5, 2014, 05:46
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,210
Rep Power: 48
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by GerhardHolzinger View Post
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)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   November 5, 2014, 08:54
Default
  #3
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 305
Rep Power: 24
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
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.
GerhardHolzinger is offline   Reply With Quote

Old   November 5, 2014, 11:38
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,210
Rep Power: 48
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by GerhardHolzinger View Post
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"
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Reply

Tags
pyfoamplotwatcher.py, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[OpenFOAM] Take derivative of mean velocity in paraFoam hiuluom ParaView 13 April 26, 2016 07:44
[OpenFOAM] could not open file .vtk in paraview ali_atrian ParaView 8 August 27, 2014 11:31
[OpenFOAM] Annoying issue of automatic "Rescale to Data Range " with paraFoam/paraview 3.12 keepfit ParaView 60 September 18, 2013 04:23
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 02:27
Problems of Duns Codes! Martin J Main CFD Forum 8 August 15, 2003 00:19


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