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

[PyFoam] pyFoamPlotWatcher and customRegexp

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

Like Tree3Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 15, 2015, 02:32
Default PyFoamPlotWatcher to plot min/max "p"
  #21
New Member
 
sethu
Join Date: Oct 2011
Posts: 7
Rep Power: 12
Sethu is on a distinguished road
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

Sethu is offline   Reply With Quote

Old   July 19, 2016, 10:48
Default
  #22
Senior Member
 
ArielJ
Join Date: Aug 2015
Posts: 127
Rep Power: 9
arieljeds is on a distinguished road
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
arieljeds is offline   Reply With Quote

Old   July 21, 2016, 11:34
Unhappy
  #23
New Member
 
Join Date: Mar 2016
Posts: 14
Rep Power: 8
RomainBou is on a distinguished road
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 !
RomainBou is offline   Reply With Quote

Old   June 13, 2020, 11:36
Default Plotting particles added and escapes
  #24
New Member
 
Join Date: May 2020
Posts: 27
Blog Entries: 1
Rep Power: 4
Mars409 is on a distinguished road
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

Last edited by Mars409; June 17, 2020 at 04:45. Reason: Adding more codes.
Mars409 is offline   Reply With Quote

Reply

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
[PyFoam] First discussion thread about PyFoam braennstroem OpenFOAM Community Contributions 338 March 17, 2022 14:05


All times are GMT -4. The time now is 04:01.