CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

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

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 1 Post By ngj
  • 1 Post By ngj

Reply
 
LinkBack Thread Tools Display Modes
Old   February 16, 2013, 08:45
Default how to call 'p' as pressure into my code from OpenFOAM?
  #1
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
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
atmcfd is offline   Reply With Quote

Old   February 16, 2013, 09:05
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Deltares, Delft, The Netherlands
Posts: 1,619
Rep Power: 25
ngj will become famous soon enoughngj will become famous soon enough
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
immortality likes this.
ngj is offline   Reply With Quote

Old   February 18, 2013, 01:42
Default
  #3
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
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
atmcfd is offline   Reply With Quote

Old   February 18, 2013, 05:18
Default
  #4
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Deltares, Delft, The Netherlands
Posts: 1,619
Rep Power: 25
ngj will become famous soon enoughngj will become famous soon enough
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 likes this.
ngj is offline   Reply With Quote

Old   February 18, 2013, 05:45
Default
  #5
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
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
atmcfd is offline   Reply With Quote

Old   February 18, 2013, 05:54
Default
  #6
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Deltares, Delft, The Netherlands
Posts: 1,619
Rep Power: 25
ngj will become famous soon enoughngj will become famous soon enough
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
ngj is offline   Reply With Quote

Old   February 18, 2013, 06:20
Default
  #7
Senior Member
 
atmcfd's Avatar
 
ATM
Join Date: May 2009
Location: United States
Posts: 104
Rep Power: 8
atmcfd is on a distinguished road
Quote:
Originally Posted by ngj View Post
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. Should have noticed that

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 !!
atmcfd is offline   Reply With Quote

Old   February 18, 2013, 06:28
Default
  #8
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Deltares, Delft, The Netherlands
Posts: 1,619
Rep Power: 25
ngj will become famous soon enoughngj will become famous soon enough
OK, good luck - I will keep my eyes on the thread

/ Niels
ngj is offline   Reply With Quote

Old   January 13, 2014, 12:04
Default
  #9
ndr
New Member
 
Join Date: Aug 2009
Location: Stuttgart, Germany
Posts: 20
Rep Power: 8
ndr is on a distinguished road
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
ndr is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Pressure Inlet" Boundary Setup Wijaya FLUENT 14 August 26, 2015 06:02
Pressure Rise Error emueller CFX 0 May 5, 2009 11:08
Does star cd takes reference pressure? monica CD-adapco 1 April 19, 2007 11:26
Gas pressure question Dan Moskal Main CFD Forum 0 October 24, 2002 22:02
2D CFD code using SIMPLE algorithm bfan Main CFD Forum 3 June 22, 2002 22:01


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