CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (http://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   How to compute the gradient of a scalar as a post-processing (http://www.cfd-online.com/Forums/openfoam-post-processing/79478-how-compute-gradient-scalar-post-processing.html)

ayoros August 25, 2010 05:06

How to compute the gradient of a scalar as a post-processing
 
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

Andrea_85 February 11, 2011 05:43

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

santiagomarquezd February 11, 2011 22:53

1 Attachment(s)
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!

oegerus August 4, 2011 09:17

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

eysteinn October 10, 2011 10:56

Quote:

Originally Posted by oegerus (Post 318873)
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)

jeff.freeman December 20, 2012 14:56

0/gradient file
 
Quote:

Originally Posted by eysteinn (Post 327341)
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

eysteinn January 11, 2013 04:37

Quote:

Originally Posted by jeff.freeman (Post 398455)
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

gschaider January 11, 2013 07:30

Quote:

Originally Posted by jeff.freeman (Post 398455)
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)

eysteinn January 11, 2013 10:41

Quote:

Originally Posted by gschaider (Post 401350)
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 :)

gschaider January 11, 2013 10:54

Quote:

Originally Posted by eysteinn (Post 401384)
obviously much simpler solution :)

But not as much fun (==challenge) I'm afraid

jeff.freeman January 11, 2013 13:28

Quote:

Originally Posted by gschaider (Post 401350)
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

gschaider January 11, 2013 15:15

Quote:

Originally Posted by jeff.freeman (Post 401425)
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)

jeff.freeman January 15, 2013 00:00

Quote:

Originally Posted by gschaider (Post 401436)
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

gschaider January 15, 2013 04:23

Quote:

Originally Posted by jeff.freeman (Post 401864)
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

jeff.freeman January 15, 2013 11:56

Quote:

Originally Posted by gschaider (Post 401896)
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.

wenxu August 7, 2015 04:48

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


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