CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   how to call 'p' as pressure into my code from OpenFOAM? (https://www.cfd-online.com/Forums/openfoam-programming-development/113272-how-call-p-pressure-into-my-code-openfoam.html)

atmcfd February 16, 2013 07:45

how to call 'p' as pressure into my code from OpenFOAM?
 
Hello all,

I am written a new wall function in OpenFOAM and I am trying to compile it. I am getting the error saying

Code:

error: ‘p’ was not declared in this scope
where 'p' is supposed to be the pressure. I want to call the variable for "pressure" into my code, but I do not know how I do it.

I saw the channelFoam and pisoFoam codes where the variable 'p' was used as pressure in the code. I want to do just the same in my code.

Any help will be appreciated. Thank you!

A.T.M

ngj February 16, 2013 08:05

Hi ATM,

Inside the wall functions you do not have direct access to the pressure, since it is not part of the construction. You do, however, have access to the database structure, so you can obtain a constant reference to the pressure in the following way:

Code:

const volScalarField & p = this->db().lookupObject<volScalarField>("p");
Kind regards,

Niels

atmcfd February 18, 2013 00:42

Niels,

Thank you very much for your reply - It works now. I have just one more question. Forgive me if it is very basic; its just that OpenFOAM's level of C++ takes some time to get used to, and I am fairly new to this game;)

I have included 'p' into my code as you said, but I tried taking a gradient of 'p' and it gave me compile errors. I tried
grad(p) and also Foam::fvc::grad(p)
Neither of which work. All I want to do is \frac{\partial p}{\partial x}
Is there an elegant way to do this? I want only the streamwise (x) pressure gradient, instead of the gradient in all directions.

Finally, omitting the gradient term, my code compiles saying

'libNULL.so' is up to date.

But when I run a test case with my new wall function included in the 0/nuSgs file, it aborts

Code:

Unknown patchField type NewWallFunction for patch type wall

Valid patchField types are :

69
(
advective
atmBoundaryLayerInletEpsilon
buoyantPressure
....
....
nuSgsUSpaldingWallFunction
nutLowReWallFunction
nutTabulatedWallFunction
nutURoughWallFunction
nutUSpaldingWallFunction
...
...

I have followed the nuSgsUSpaldingWallFunction file and made sure my file naming conventions are consistent, just like this one.

Can you please give me some ideas as to what I am doing wrong here? How do I integrate my New wall function into OpenFOAM like the existing ones??

Thanks for your time and help.

Regards,

A.T.M

ngj February 18, 2013 04:18

Hi ATM,

Good. I will try to answer your questions below:

1. Please provide me/us with some compilation errors, as the error could be due to a multiple number of things.

2. It does not seem as you have written the correct lines in your Make/files script, since it tells you that it outputs the library to a default name, namely libNULL.so. Please post the Make/files file here.

3. Your simulation does not recognise the new library, because the solver has not been linked to it during compilation. You can do a runTime-linking adding the following line to the controlDict:

Code:

libs ( "<myLibraryName>" );
where you in this specific case should write libNULL.so inside the "".

Kind regards,

Niels

atmcfd February 18, 2013 04:45

Hi Niels,

This is the code I inserted (NewWallFunctionFvPatchScalarField.C:138:48 in the error message)

Code:

    const scalarField GradP(Foam::fvc::grad(pr));
where 'pr' is the pressure, and I want to store an array GradP having the
\frac{\partial p}{\partial x} of the pressure in the whole field.

Here is the error msg I get - Its a dropbox link to a text file.

http://db.tt/TSnCRvcS

And this is my Make/file

Code:


NewWallFunctionFvPatchScalarField.C

EXE = $(FOAM_USER_LIBBIN)/NewWallFunction

Please let me know if this information is sufficient for you. Else I can show you the actual code and the Make/options if you need it to find the cause.
Basically, I just used the nuSgsUSpaldingWallFunction code as a template, and edited it to the new function, so as to be consistent.

Thank you very much for your help again.

Regards,
A.T.M

ngj February 18, 2013 04:54

Hi ATM,

With respect to the pressure, then the gradient of a volScalarField is a vectorField, so the following should compile:

Code:

volVectorField gradP = Foam::fvc::grad( pr )();
Then you will need to extract the x-component of the gradient field subsequently.

Secondly, as you are compiling a library and not a solver/utility, the line in your Make/files should read the following:

Code:

LIB = $(FOAM_USER_LIBBIN)/libNewWallFunction

atmcfd February 18, 2013 05:20

Quote:

Originally Posted by ngj (Post 408410)
Hi ATM,

Secondly, as you are compiling a library and not a solver/utility, the line in your Make/files should read the following:

Code:

LIB = $(FOAM_USER_LIBBIN)/libNewWallFunction

Oh! That was a really silly mistake.:eek: Should have noticed that :mad:

Meanwhile, I have been trying my code with the fix you suggested for grad(p). I am having some additional problems, but I will try my best and figure it out before I post it here for you.

Thank you very much for your help so far !!

ngj February 18, 2013 05:28

OK, good luck - I will keep my eyes on the thread :)

/ Niels

ndr January 13, 2014 11:04

Hi ATM,

did you manage to get the streamwise pressure gradient to work properly?
I'm dealing with a similar problem at the moment, and I tried the solution as destribed above with

Code:

volVectorField gradient = Foam::fvc::grad(pressure)();
This compiles without any errors and also runs fine when using only one CPU for the simulation.
However, in parallel the simulation crashes as soon as the volVectorField for the gradient definition is included in the code. It even does not matter if I really use the gradient later on, just the definition itself seems to be critical. It seems to me this is some kind of MPI and/or memory allocation problem...

Did you experience the same issue when testing your wall function and do you have an idea how to solve this?

Thanks!

Nils

canopus March 25, 2016 17:13

Where to add this in case one wants to write out the pressure gradient during runtime?

Is something like probe for p/U possible for the pressure gradient by adding locations in controldict?

Thanks


All times are GMT -4. The time now is 07:50.