CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Accessing Pressure in my OpenFOAM code

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By Jerryfan
  • 2 Post By Jerryfan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 25, 2016, 13:59
Default Accessing Pressure in my OpenFOAM code
  #1
New Member
 
Dominic
Join Date: May 2016
Posts: 27
Rep Power: 10
Verse is on a distinguished road
Hello, I'd like a way to access the pressure parameter in my test case through OpenFOAM syntax. So far, the answers I've seen only refer me to this method:

Quote:
const volScalarField & p = Foam::fvPatchField<Type>::db().lookupObject<volSca larField>("P");
But I received the following error:

Quote:
error: invalid use of ‘this’ in non-member function
const volScalarField& p = this->db().lookupObject<volScalarField>("P");
Any idea what's going on? Thank you!
Verse is offline   Reply With Quote

Old   July 25, 2016, 15:53
Default
  #2
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 13
Jerryfan is on a distinguished road
Hi Verse,


where do you use this line of code? Is it in the main function? If it is, you can do it this way

Quote:
const volScalarField & p = mesh.lookupObject<volSca larField>("P");
since pressure field is registered to mesh at the time of construction. Hope this can work for you.
LogiDF likes this.
Jerryfan is offline   Reply With Quote

Old   July 25, 2016, 16:51
Default
  #3
New Member
 
Dominic
Join Date: May 2016
Posts: 27
Rep Power: 10
Verse is on a distinguished road
Hi Jerry, thank you for the answer, it works terrifically.

I was wondering if I could do the same with a different file of a different type, namely pointMotionU?

I tried the following and I seem to have run into a different error...

Code:
const pointVectorField& MotionU = mesh.lookupObject<pointVectorField>("pointMotionU");
Code:
error: forward declaration of ‘class Foam::pointMesh’
 class pointMesh;
Verse is offline   Reply With Quote

Old   July 25, 2016, 18:24
Default
  #4
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 13
Jerryfan is on a distinguished road
Hi Verse,



I think the problem is because of pointVectorField. Try to replace it with vectorField. It might work.
Verse and LogiDF like this.
Jerryfan is offline   Reply With Quote

Old   July 26, 2016, 10:18
Default
  #5
New Member
 
Dominic
Join Date: May 2016
Posts: 27
Rep Power: 10
Verse is on a distinguished road
Hi Jerry, the solution turned out to be a bit more complicated, but doing this helped solve the problem:

Code:
	pointVectorField& MotionU = const_cast<pointVectorField&>
	(
		mesh.objectRegistry::lookupObject<pointVectorField>
		(
			"pointMotionU"
		)
	);
Hopefully future users can see this post to avoid my mistake.

Thank you for the help!
Verse is offline   Reply With Quote

Old   July 26, 2016, 11:25
Default
  #6
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 13
Jerryfan is on a distinguished road
Hi Verse,

You are right. The const_cast has to be added in front to cast away the constness as lookupObject returns const type variable.

Quote:
const Type& Foam:bjectRegistry::lookupObject(const word& name) const
Jerryfan 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
how to call 'p' as pressure into my code from OpenFOAM? atmcfd OpenFOAM Programming & Development 9 March 25, 2016 18:13
Parallelizing a code that involves OpenFOAM Nicolas Périnet OpenFOAM 3 November 24, 2011 01:27
Neumann pressure BC and velocity field Antech Main CFD Forum 0 April 25, 2006 03:15
Gas pressure question Dan Moskal Main CFD Forum 0 October 24, 2002 23:02
Hydrostatic pressure in 2-phase flow modeling (CFX4.2) HB &DS CFX 0 January 9, 2000 14:19


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