CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   How to compile a new utility (https://www.cfd-online.com/Forums/openfoam/71026-how-compile-new-utility.html)

rudy December 12, 2009 12:55

How to compile a new utility
 
Hi,
I am new openfoam user and I am not good at programming :eek:. I intend to find grad of a scalar variable which is a solution of my computation :confused:. Initially I used a function "gradient of unstructured variable" from paraFoam but it is giving me some error.So I am trying to make my own utility to calculate gradient of scalar quantity.Now,I guess if I make a new utility i would have to compile it with my solver and for that I am following instructions given in Userguide.I mentioned utilityFunctionObjects lib name in solver/Make/options and then used wmake command from inside solver dir. I guess it goes on well and ultimately yields a messege that solver is uptodate,but when i use the new utility command name from inside case directory it says command is not found.Can anyone please tell me what exact steps I should take to compile my newly defined utility file with the intended solver.
Thanks and regards,
rudy.

AlanR December 12, 2009 20:29

Rudy,

Some searching through the OF forums will turn up a number of links to courses, tutorials, etc that cover programming and customizing applications. Here's a link that may be helpful: http://www.openfoamworkshop.org/2009...ngTutorial.pdf. A recent thread has an excellent list of links. http://www.cfd-online.com/Forums/ope...thingelse.html. Learning Foam is challenging, but it's worth the effort.
Good luck, Alan

alberto December 13, 2009 00:42

Quote:

Originally Posted by rudy (Post 239814)
Hi,
I am new openfoam user and I am not good at programming :eek:. I intend to find grad of a scalar variable which is a solution of my computation :confused:. Initially I used a function "gradient of unstructured variable" from paraFoam but it is giving me some error.So I am trying to make my own utility to calculate gradient of scalar quantity.Now,I guess if I make a new utility i would have to compile it with my solver and for that I am following instructions given in Userguide.I mentioned utilityFunctionObjects lib name in solver/Make/options and then used wmake command from inside solver dir. I guess it goes on well and ultimately yields a messege that solver is uptodate,but when i use the new utility command name from inside case directory it says command is not found.Can anyone please tell me what exact steps I should take to compile my newly defined utility file with the intended solver.
Thanks and regards,
rudy.

Take a look at laplacianFoam. In write.H gradients of the temperature are computed and stored. The procedure is general.

To sum it up
  • Compute the gradient vector and store it in a volVectorField as in
Code:

volVectorField gradT = fvc::grad(T);
  • You can decompose the gradient in its components too, storing them in separate files. For example for the x component, which will be stored in a file called "gradTx", you can use:
Code:

volScalarField gradTx
        (
            IOobject
            (
                "gradTx",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),
            gradT.component(vector::X)
        );

Note that
  • the instructions are enclosed in an if whose condition is runTime.outputTime(), which means that fields will be written when a set of data will be automatically saved by the solver
  • the gradient components are stored, but the gradient vector field is not stored. To do that simply add th following line after the definition of gradT:
Code:

gradT.write();
You can edit your code adding similar lines for the variable of your interest, and then rebuild the application with
Code:

wmake
in the directory containing the source code.

I hope this help.

Best,
Alberto

P.S. Simple answers to simple questions! Sometime a "search for it" simply does not work, especially for new users. :D

rudy December 14, 2009 08:43

Thanks a lot to both of u, I did develop my own utility to find gradient using ur instructions and it's working now...
regards,
rudy

doubtsincfd October 1, 2011 22:48

gradT.write(); returns a zeroGradient field for patches. But the field is non-zero in component files like gradTx. Why?


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