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

How to compute the gradient of a scalar as a post-processing

Register Blogs Community New Posts Updated Threads Search

Like Tree12Likes
  • 5 Post By santiagomarquezd
  • 1 Post By eysteinn
  • 6 Post By gschaider

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 25, 2010, 06:06
Default How to compute the gradient of a scalar as a post-processing
  #1
New Member
 
Join Date: Mar 2009
Posts: 29
Rep Power: 17
ayoros is on a distinguished road
Hi foamers,

For some reasons, I need to compute the laplacian of a scalar, which is the divergency of the gradient of this scalar, as a post-processing.

Thanks to foamCalc tool, I found the div operator and the magGrad operator ; but I'm struggling to find the grad operator. I suppose that if foamCalc can compute magGrad, ha can as well compute and write grad, but my poor knowledge in coding doesn't help me here.

Does anyone know how to write the gradient of a scalar as a post-processing ?

The answer may be simple, but as for now I didn't find it.

Cheers,
Fabien
ayoros is offline   Reply With Quote

Old   February 11, 2011, 05:43
Default
  #2
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 16
Andrea_85 is on a distinguished road
Hi ayoros,

Have you found any solution? I got the same problem with interfoam. I need the gradient of alpha1 (3 components, not the absolute value) in all the cell.

Thanks

andrea
Andrea_85 is offline   Reply With Quote

Old   February 11, 2011, 22:53
Default
  #3
Senior Member
 
santiagomarquezd's Avatar
 
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24
santiagomarquezd will become famous soon enough
Hi guys, decompress the gzip tarball in your $HOME/OpenFOAM/<user>/applications directory and do wmake. It'll allow you to use solutionGradient post-process tool in your case directory that will give you the gradient of field T for each timestep. Change the code (line 74) to whatever scalarField you want. The gradient will be stored in gradient volVectorField

Enjoy!
Attached Files
File Type: gz solutionGradient.gz (4.2 KB, 663 views)
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D.
Research Scientist
Research Center for Computational Methods (CIMEC) - CONICET/UNL
Tel: 54-342-4511594 Int. 7032
Colectora Ruta Nac. 168 / Paraje El Pozo
(3000) Santa Fe - Argentina.
http://www.cimec.org.ar
santiagomarquezd is offline   Reply With Quote

Old   August 4, 2011, 10:17
Default
  #4
New Member
 
Join Date: May 2009
Posts: 1
Rep Power: 0
oegerus is on a distinguished road
Dear FOAMers,

i compiled the solutionGradient-tool and switched the temperatur T to U, but Openfoam brings up this errormessage:
______________________________________________
--> FOAM FATAL IO ERROR:
cannot open file

file: /home/OpenFOAM/oeg-1.7.1/run/test/0/gradient at line 0.

From function regIOobject::readStream()
in file db/regIOobject/regIOobjectRead.C at line 61.

FOAM exiting
_______________________________________________

I tried the original file, but still the same Error occurred.
Im not sure where the problem is, can somebody please help me

Thx
Oeg
oegerus is offline   Reply With Quote

Old   October 10, 2011, 11:56
Default
  #5
Member
 
Eysteinn Helgason
Join Date: Sep 2009
Location: Gothenburg, Sweden
Posts: 53
Rep Power: 17
eysteinn is on a distinguished road
Quote:
Originally Posted by oegerus View Post
Dear FOAMers,

i compiled the solutionGradient-tool and switched the temperatur T to U, but Openfoam brings up this errormessage:
______________________________________________
--> FOAM FATAL IO ERROR:
cannot open file

file: /home/OpenFOAM/oeg-1.7.1/run/test/0/gradient at line 0.

From function regIOobject::readStream()
in file db/regIOobject/regIOobjectRead.C at line 61.

FOAM exiting
_______________________________________________

I tried the original file, but still the same Error occurred.
Im not sure where the problem is, can somebody please help me

Thx
Oeg
If you still have this problem ( or someone else ..... )

You need to add a file in your latest time directory called gradient.
In your case the easiest way would be to copy your U file and
lower the dimensions for length by 1 ( second value in the dimensions)
wiedangel likes this.
eysteinn is offline   Reply With Quote

Old   December 20, 2012, 14:56
Default 0/gradient file
  #6
New Member
 
Jeff Freeman
Join Date: Mar 2012
Posts: 9
Rep Power: 14
jeff.freeman is on a distinguished road
Quote:
Originally Posted by eysteinn View Post
If you still have this problem ( or someone else ..... )

You need to add a file in your latest time directory called gradient.
In your case the easiest way would be to copy your U file and
lower the dimensions for length by 1 ( second value in the dimensions)
Hi Eysteinn,

Could you please describe the 0/gradient file that we need to make when using your tool? I've tried using solutionGradient after modifying it for rho so that I can plot a numerical Schlieren image. I followed the following steps in making the 0/gradient file:
  1. Copying 0/rho and renaming it 0/gradient,
  2. Changing the dimension from [1 -3 0 0 0 0 0] to [1 -4 0 0 0 0 0]
  3. Changing its class (line 12) from volScalarField to volVectorField. I did this because i received an error when first running it after step 2 suggesting that I should call it volVectorField.
Even after all that, I get the following error:
-----------------------------------------------------------------------------------------------------

--> FOAM FATAL ERROR:
Attempt to cast type N4Foam5token8CompoundINS_4ListIdEEEE to type N4Foam5token8CompoundINS_4ListINS_6VectorIdEEEEEE

From function dynamicCast<To>(From&)
in file /opt/openfoam211/src/OpenFOAM/lnInclude/typeInfo.H at line 93.

FOAM aborting
-----------------------------------------------------------------------------------------------------


A more complete description and possibly a sample case would be very much appreciated. Thank you for your help,


-Jeff
jeff.freeman is offline   Reply With Quote

Old   January 11, 2013, 04:37
Default
  #7
Member
 
Eysteinn Helgason
Join Date: Sep 2009
Location: Gothenburg, Sweden
Posts: 53
Rep Power: 17
eysteinn is on a distinguished road
Quote:
Originally Posted by jeff.freeman View Post
Hi Eysteinn,

Could you please describe the 0/gradient file that we need to make when using your tool? I've tried using solutionGradient after modifying it for rho so that I can plot a numerical Schlieren image. I followed the following steps in making the 0/gradient file:
  1. Copying 0/rho and renaming it 0/gradient,
  2. Changing the dimension from [1 -3 0 0 0 0 0] to [1 -4 0 0 0 0 0]
  3. Changing its class (line 12) from volScalarField to volVectorField. I did this because i received an error when first running it after step 2 suggesting that I should call it volVectorField.
Even after all that, I get the following error:
-----------------------------------------------------------------------------------------------------

--> FOAM FATAL ERROR:
Attempt to cast type N4Foam5token8CompoundINS_4ListIdEEEE to type N4Foam5token8CompoundINS_4ListINS_6VectorIdEEEEEE

From function dynamicCast<To>(From&)
in file /opt/openfoam211/src/OpenFOAM/lnInclude/typeInfo.H at line 93.

FOAM aborting
-----------------------------------------------------------------------------------------------------


A more complete description and possibly a sample case would be very much appreciated. Thank you for your help,


-Jeff
Sorry for the late answer . . . holidays.

Have you managed to solve this?

/Eysteinn
eysteinn is offline   Reply With Quote

Old   January 11, 2013, 07:30
Default
  #8
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 jeff.freeman View Post
Hi Eysteinn,

Could you please describe the 0/gradient file that we need to make when using your tool? I've tried using solutionGradient after modifying it for rho so that I can plot a numerical Schlieren image. I followed the following steps in making the 0/gradient file:
  1. Copying 0/rho and renaming it 0/gradient,
  2. Changing the dimension from [1 -3 0 0 0 0 0] to [1 -4 0 0 0 0 0]
  3. Changing its class (line 12) from volScalarField to volVectorField. I did this because i received an error when first running it after step 2 suggesting that I should call it volVectorField.
Even after all that, I get the following error:
-----------------------------------------------------------------------------------------------------

--> FOAM FATAL ERROR:
Attempt to cast type N4Foam5token8CompoundINS_4ListIdEEEE to type N4Foam5token8CompoundINS_4ListINS_6VectorIdEEEEEE

From function dynamicCast<To>(From&)
in file /opt/openfoam211/src/OpenFOAM/lnInclude/typeInfo.H at line 93.

FOAM aborting
-----------------------------------------------------------------------------------------------------


A more complete description and possibly a sample case would be very much appreciated. Thank you for your help,


-Jeff
Wow. I'm impressed. All this to calculate the gradient of rho (or U)? I do that with

funkySetFields -latestTime -create -field gradRho -expression "grad(rho)"

(adaption for U is trivial)
__________________
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   January 11, 2013, 10:41
Thumbs up
  #9
Member
 
Eysteinn Helgason
Join Date: Sep 2009
Location: Gothenburg, Sweden
Posts: 53
Rep Power: 17
eysteinn is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Wow. I'm impressed. All this to calculate the gradient of rho (or U)? I do that with

funkySetFields -latestTime -create -field gradRho -expression "grad(rho)"

(adaption for U is trivial)
obviously much simpler solution
eysteinn is offline   Reply With Quote

Old   January 11, 2013, 10:54
Default
  #10
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 eysteinn View Post
obviously much simpler solution
But not as much fun (==challenge) I'm afraid
__________________
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   January 11, 2013, 13:28
Default
  #11
New Member
 
Jeff Freeman
Join Date: Mar 2012
Posts: 9
Rep Power: 14
jeff.freeman is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Wow. I'm impressed. All this to calculate the gradient of rho (or U)? I do that with

funkySetFields -latestTime -create -field gradRho -expression "grad(rho)"

(adaption for U is trivial)
Thanks for the tip!

I'm in the process of acquiring swak4Foam so that I can use funkySetFields. Unfortunately, there seems to be a copyright issue going on with openFoam-extend on SourceForge and I am unable to download the program (either through svn or via tarball). Does anybody know an alternate way of getting the program?

Cheers,
Jeff
jeff.freeman is offline   Reply With Quote

Old   January 11, 2013, 15:15
Default
  #12
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 jeff.freeman View Post
Thanks for the tip!

I'm in the process of acquiring swak4Foam so that I can use funkySetFields. Unfortunately, there seems to be a copyright issue going on with openFoam-extend on SourceForge and I am unable to download the program (either through svn or via tarball). Does anybody know an alternate way of getting the program?

Cheers,
Jeff
Yep. The Mercurial-repository on of-extend which holds the development version is still available (they only shut down the inferior VCS git and SVN ). Just in case I pushed a copy to BitBucket.

Usually the development version I pushed to a public repository only has finished features (so WHAT is there should work) but occasionally I broke stuff without knowing it. The releases are more thoroughly checked.

If you don't want to live on the bleeding edge: the webinterface at bitbucket allows downloading the sources in the state of the last release. That would be

The version for OpenFOAM 2.x
https://bitbucket.org/bgschaid/swak4...0.2.1_v2.x.zip
For OpenFOAM 1.x
https://bitbucket.org/bgschaid/swak4...sion_0.2.1.zip

If you chose to use one of these links and it worked for you could you please gibe me feedback and I'll add the links to the Wiki-page (or you can add 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   January 15, 2013, 00:00
Default
  #13
New Member
 
Jeff Freeman
Join Date: Mar 2012
Posts: 9
Rep Power: 14
jeff.freeman is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Yep. The Mercurial-repository on of-extend which holds the development version is still available (they only shut down the inferior VCS git and SVN ). Just in case I pushed a copy to BitBucket.

Usually the development version I pushed to a public repository only has finished features (so WHAT is there should work) but occasionally I broke stuff without knowing it. The releases are more thoroughly checked.

If you don't want to live on the bleeding edge: the webinterface at bitbucket allows downloading the sources in the state of the last release. That would be

The version for OpenFOAM 2.x
https://bitbucket.org/bgschaid/swak4...0.2.1_v2.x.zip
For OpenFOAM 1.x
https://bitbucket.org/bgschaid/swak4...sion_0.2.1.zip

If you chose to use one of these links and it worked for you could you please gibe me feedback and I'll add the links to the Wiki-page (or you can add them)

Hi Bernhard,

Sorry for the late reply; I had some other things come up. I began with the link for the version associated with OpenFOAM 2.x, but I underestimated how long it would take to install. When my terminal stopped outputting information for a (seemingly) long time, I canceled it and tried the development version from Mercurial. After seeing that it was the same, I gave it some more patience. It installed without any problems and preliminary uses (i.e. gradients of rho and U) are working just fine. I can't wait to find out what else this tool comes with!

Thanks,
Jeff
jeff.freeman is offline   Reply With Quote

Old   January 15, 2013, 04:23
Default
  #14
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 jeff.freeman View Post
Hi Bernhard,

Sorry for the late reply; I had some other things come up. I began with the link for the version associated with OpenFOAM 2.x, but I underestimated how long it would take to install. When my terminal stopped outputting information for a (seemingly) long time, I canceled it and tried the development version from Mercurial. After seeing that it was the same, I gave it some more patience. It installed without any problems and preliminary uses (i.e. gradients of rho and U) are working just fine. I can't wait to find out what else this tool comes with!

Thanks,
Jeff
The problem is the compilation of the grammars. The C++-files which are generated by bison are quite complex and if the compiler tries to optimize them it uses quite a lot of memory (i've seen memory usages in the order of GB). Now if WM_NCOMPROCS is set to a high values (usually in the order of the cores) and all grammars are compiled at the same time then memory can be exhausted and the machine starts swaping. Which may be what happened to you
__________________
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   January 15, 2013, 11:56
Default
  #15
New Member
 
Jeff Freeman
Join Date: Mar 2012
Posts: 9
Rep Power: 14
jeff.freeman is on a distinguished road
Quote:
Originally Posted by gschaider View Post
The problem is the compilation of the grammars. The C++-files which are generated by bison are quite complex and if the compiler tries to optimize them it uses quite a lot of memory (i've seen memory usages in the order of GB). Now if WM_NCOMPROCS is set to a high values (usually in the order of the cores) and all grammars are compiled at the same time then memory can be exhausted and the machine starts swaping. Which may be what happened to you
I'm not very familiar with most of what you just said, so I can't really be sure. From my point of view, it seemed like both versions that I tried installing (from bison and then from Mercurial) behaved the same way. Only the second time I had more patience. If I understood correctly, it needed to make a bunch of libraries and that took quite some time. I didn't time it, but I think it was roughly 1 hour to install.
jeff.freeman is offline   Reply With Quote

Old   August 7, 2015, 05:48
Default
  #16
Senior Member
 
Freedom
Join Date: May 2014
Posts: 209
Rep Power: 13
wenxu is on a distinguished road
Dear Santiago,

Do you know how to implement gradient explicit in a solver? That means we do not use the schemes in the OF, but code them directly in solver.

I want to calculate the gradient explicitly for special use. ----I want to implement sign distance function into OF. mag(Grad(phi)) =1
wenxu is offline   Reply With Quote

Old   March 21, 2018, 07:02
Default
  #17
Senior Member
 
Join Date: Sep 2015
Location: Singapore
Posts: 102
Rep Power: 11
usv001 is on a distinguished road
Hello Foamers,

For those who don't have funkySetFields, here's the grad function implemented through foamCalc.

Steps
  1. Untar the attachment to the src/postProcessing/foamCalcFunctions/field/ directory.
  2. Add the entry 'field/grad/grad.C' to src/postProcessing/foamCalcFunctions/Make/files.
  3. Compile with wmake from foamCalcFunctions directory.
  4. Run using command "foamCalc grad <fieldName>"

Hope this helps.

Regards,
USV
Attached Files
File Type: gz grad.tar.gz (6.3 KB, 66 views)
usv001 is offline   Reply With Quote

Reply


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
dieselFoam problem!! trying to introduce a new heat transfer model vivek070176 OpenFOAM Programming & Development 10 December 24, 2014 00:48
post processing for KIVA dirga Main CFD Forum 5 April 23, 2009 11:58
Gradient of Scalar calculation in 3D BFCskew grids james T Phoenics 0 March 28, 2007 08:12
Post Processing in FEM Abhijit Tilak Main CFD Forum 0 April 26, 2004 12:59
How to compute gradient for non-orthogonal grids? Paul Hsieh Main CFD Forum 3 November 11, 2003 05:52


All times are GMT -4. The time now is 16:37.