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

tmp<volScalarField>

Register Blogs Community New Posts Updated Threads Search

Like Tree17Likes
  • 6 Post By JBUNSW
  • 6 Post By olesen
  • 3 Post By ngj
  • 2 Post By JBUNSW

 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old   November 21, 2012, 00:08
Default tmp<volScalarField>
  #1
New Member
 
James Behzadi
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 27
Rep Power: 14
JBUNSW is on a distinguished road
Hi there,

I have a general question regarding the concept of tmp<volScalarField>. To explain my question I use rho, as an example, from a combustion class in OF.

How can one calculate density?
The density can be accessed by invoking the rho() function which is a virtual function in basicPsiThermo class. So for example if thermo object has been setup correctly in a given class (such as ODEChemistryModel), then you can easily calculate density by equation of state of an ideal gas (there are other models available as well) by
Code:
this->thermo().rho()
which returns a tmp<volScalarField> accordingly:
Code:
virtual tmp<volScalarField> rho() const
{
	return p_*psi();
}
I was wondering what is the difference between the following four methods to access a tmp<volScalarField> quantity such as density (or any other tmp<volScalarField>).

Method 1:
Code:
const volScalarField& rho = this->db().objectRegistry::lookupObject<volScalarField>("rho");
Method 2:
Code:
tmp<volScalarField> trho = this->thermo().rho();
const volScalarField& rho = trho();

Method 3:
Code:
const volScalarField rho
(
	IOobject
	(
		"rho",
		this->time().timeName(),
		this->mesh(),
		IOobject::NO_READ,
		IOobject::NO_WRITE,
		false
	),
	this->thermo().rho()
);

Method 4:
Code:
const volScalarField rho = this->thermo().rho();

My question:
My understanding of the above is that method 1 is accessing the rho variable already stored in the objectRegistry and doesn't use the result of the virtual function rho(). The other methods all use the thermo().rho() function to calculate rho. In method 1 we do not create a "local" volScalarField variable and just use "referencing" to reference to some memory location. But in other 3 methods we are creating a "local" volScalarField variable and store the results in it.

1. Am I right?!
2. Why we use tmp<volScalarField> at all?!
3. Are all the above four methods correct?!
4. What is the difference between them?!

Thanks for your time,
Jalal
JBUNSW is offline   Reply With Quote

 

Tags
objectregistry, referencing, tmp<volscalarfield>


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



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