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

[swak4Foam] Run time correlation calculation along a plane using swak4foam

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By manuc
  • 1 Post By gschaider

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 24, 2018, 05:31
Default Run time correlation calculation along a plane using swak4foam
  #1
Senior Member
 
Manu Chakkingal
Join Date: Feb 2016
Location: Delft, Netherlands
Posts: 129
Rep Power: 10
manuc is on a distinguished road
Hello All

I am interested to monitor the value of my field at center of my geometry and create a field at each time step, which is equal to the product of the field at that location with the value of the field at the center of the domain (calculation of correlation).
Code:
 C(x,y,z,t) =T(x,y,z,t)* T(x0,y0,z0,t)
I access a specific point (x0,y0,z0) and use it in expressionfield with the help of the thread below
groovyBC and probe measurement


Now I would like to calculate the product of the velocity (y component) at the sensor1 (see below) with the Y-velocity in a particular plane

What I tried
Create a cloud point.
Code:
functions
   	{    

		createMeasurement 
		{ 
			type createSampledSet; 
			outputControl outputTime; 
			outputInterval 1; 
			setName sensor1; 
			set  { 
					type cloud; 
					axis xyz; 
					points ( 
					(0.01 0.05 0.05) 
					); 
          		 }      
		 }
......
Try1: Create a 3Dfield with the calculation that I need. i.e. multiplying the value from cloudpoint with U.y in the whole domain
Code:
UpCorr
            {
             functionObjectLibs ("libswakFunctionObjects.so");
			 type              expressionField;
 			 outputControl     timeStep;
                 outputInterval    1;
                 variables         ("UpL{set'sensor1}=(U-            							UMean);");   
                 expression        "U.y*UpL.y";
                 fieldName         UpCorr;
                 verbose           true;
                 autowrite         true;

            }
The issue is I only need to do the above calculation at a single plane. But now I am forced to save/calculate for a 3D field.
What I tried and failed
Create a plane as in swakexpression tutorials calculation but try with type expressionfield .
Code:
functions
{
....
UpCorr2
		 {
    		 functionObjectLibs ("libswakFunctionObjects.so");
                 type        expressionField;
    			 valueType   surface;
    			 surfaceName aperturePlane;
   			 surface
    				 {
     				     type             plane;
       			     basePoint        (0.01 0.05 0.05);
        			     normalVector     (0 1 0);
                          interpolate       true;
                      }   
                 variables         ("UpL{set'sensor1}=(U-            							UMean);");   
                 expression         "U.y*UpL.y";
                fieldName           UpCorr2;
                outputControlMode   timeStep;
                outputInterval      1;
                verbose             true;
                autowrite         true;

            }
....
}
But this creates a 3D scalarfield. What I expect is just a 2D field (just for the plane). Can someone help me to do it just for the plane

Thanks in advance
Luttappy likes this.
__________________
Regards
Manu

Last edited by manuc; December 27, 2018 at 06:52.
manuc is offline   Reply With Quote

Old   December 27, 2018, 13:10
Default
  #2
Member
 
Kristjan
Join Date: Apr 2017
Location: Slovenia
Posts: 36
Rep Power: 9
krikre is on a distinguished road
If I'm getting this right, you're trying to post-process during runtime. Why not sample the fileld in the points you're interested in and do all the post-processing in python afterwards?
krikre is offline   Reply With Quote

Old   December 27, 2018, 13:23
Default
  #3
Senior Member
 
Manu Chakkingal
Join Date: Feb 2016
Location: Delft, Netherlands
Posts: 129
Rep Power: 10
manuc is on a distinguished road
Yes.What you understood is right. But I am interested in timeaveraged correlation.
<C(x+r,y,z,t)>=<C(x0,y0,z0,t).C(x+r,y,z,t)>

For this I need to calculate runtime timeaveraged of the correlation field. If I understand correctly , if I need to do the same in python I need to save a lot of time Instances
__________________
Regards
Manu
manuc is offline   Reply With Quote

Old   December 27, 2018, 15:28
Default
  #4
Member
 
Kristjan
Join Date: Apr 2017
Location: Slovenia
Posts: 36
Rep Power: 9
krikre is on a distinguished road
Sorry for not going into your swak dictionaries but it seems to me you didn't try the sampling thing which is the simples, I think. Here's what I'd do first and later look for better ways to do it.


1. Sample the the field you're interested in.
https://www.openfoam.com/documentati...e/userse21.php
Google other sources.
grep through $FOAM_TUTORIALS


After your simulation is finished, you should have a directory named "postProcessing" in your case directory. Somewhere in there there will be a TXT file with time sequences of your field for all the xyz points you specified.


2. Write the python script. import numpy. Point numpy to the TXT file with genfromtxt
https://www.numpy.org/devdocs/refere...enfromtxt.html


You should now have a matrix with the time in your first column and field values in other columns. Might get a bit tricky with the vector components. You might either remove all of the parenthesis "()" or read the field with some other utility. See PyFoam. But you should be able to reach a point where you have a matrix with i going through the time intances and j going through your space locations. You'll also want to read a txt file with the xyz coodinates where i is the label of your point and j in [0, 1, 2] is the xyz of that point. You should now be able to calculate all the averages, derivatives, intergrals etc. much more easily than coding with swak. This should work for 100 or 1000 spatial points and let's say 10k time steps. Start with fewer points, fewer time steps, then improve the procedure.
krikre is offline   Reply With Quote

Old   December 27, 2018, 15:47
Default
  #5
Senior Member
 
Manu Chakkingal
Join Date: Feb 2016
Location: Delft, Netherlands
Posts: 129
Rep Power: 10
manuc is on a distinguished road
Thanks for the message. I didn't find any tutorial yet which could do expression calculation with sampling along a plane. I don't want the calculation to happen in the whole domain which is costly. I want the correlation to be calculated in the plane interested. Use the temporal average of correlation along the plane or a line in that plane as convergence criteria. So I need to monitor in runtime and can't calculate it after simulation. What i need is to ensure the second order statistics - two point correlation, is statistically steady, which demands the calculation along the plane in runtime. I tried to use functionobject " calculateglobalvariables" . It does calculate the field at every time step only at the plane that I am interested in. But I couldn't manage to calculate it's time average during runtime. Of course , I can calculate once the simulation is complete using MATLAB or python,but then I can't use it as a convergence criteria.

What you suggest is about plotting the data I have at the end as a graph. What I am interested is monitoring this graph during runtime to ensure the statistics is converged. Hope I have made clear on what I am interested. Any suggestion in this direction would be really nice.
Regards
Manu
__________________
Regards
Manu
manuc is offline   Reply With Quote

Old   December 29, 2018, 18:37
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by manuc View Post
Thanks for the message. I didn't find any tutorial yet which could do expression calculation with sampling along a plane. I don't want the calculation to happen in the whole domain which is costly. I want the correlation to be calculated in the plane interested. Use the temporal average of correlation along the plane or a line in that plane as convergence criteria. So I need to monitor in runtime and can't calculate it after simulation. What i need is to ensure the second order statistics - two point correlation, is statistically steady, which demands the calculation along the plane in runtime. I tried to use functionobject " calculateglobalvariables" . It does calculate the field at every time step only at the plane that I am interested in. But I couldn't manage to calculate it's time average during runtime. Of course , I can calculate once the simulation is complete using MATLAB or python,but then I can't use it as a convergence criteria.

What you suggest is about plotting the data I have at the end as a graph. What I am interested is monitoring this graph during runtime to ensure the statistics is converged. Hope I have made clear on what I am interested. Any suggestion in this direction would be really nice.
Regards
Manu

Calculations on a sampledSurface can be done with swakExpression with "valueType surface;". It is not possible to write out the whole surface values. Only accumulations (min, max, average, median ...). There is a functionObject dumpSwakExpression that would write out all the values (but without the spatial information9



If you want to use an expression as a convergence criterion then the functionObject writeAndEndIfSwakExpression is your friend. Time averaging can be done with storedVariables



An elaborate example for convergence checking with swak4Foam can be found in https://openfoamwiki.net/images/7/7b...onTraining.pdf


If you are really hardcore there is also the possiblity to use the python-integration



Sorry for being a bit cryptic but technically I'm on holiday
manuc likes this.
__________________
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   December 30, 2018, 07:14
Default
  #7
Senior Member
 
Manu Chakkingal
Join Date: Feb 2016
Location: Delft, Netherlands
Posts: 129
Rep Power: 10
manuc is on a distinguished road
Dear sir
Thanks for the reply.
Regards
Manu
__________________
Regards
Manu
manuc is offline   Reply With Quote

Reply

Tags
correlations, run-time processing, swak4foam, turbulence analysis


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
How to export time series of variables for one point? mary mor OpenFOAM Post-Processing 8 July 19, 2017 10:54
plot over time fferroni OpenFOAM Post-Processing 7 June 8, 2012 07:56
calculation diverge after continue to run zhajingjing OpenFOAM 0 April 28, 2010 04:35
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 18:07
Warning 097- AB Siemens 6 November 15, 2004 04:41


All times are GMT -4. The time now is 18:11.