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

difference between thermo.T() and T

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 3 Post By Mowgli

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 4, 2013, 07:39
Default difference between thermo.T() and T
  #1
New Member
 
Join Date: Feb 2012
Posts: 25
Rep Power: 14
Marshak is on a distinguished road
Can someone tell me what is the difference between defining

volScalarField myTemperature = thermo.T()
volScalarField mypressure = thermo.p()

and

const volScalarField& myTemperature = mesh_.lookupObject<volScalarField>("T");
const volScalarField& mypressure= mesh_.lookupObject<volScalarField>("p");
Marshak is offline   Reply With Quote

Old   December 4, 2013, 08:45
Default
  #2
Senior Member
 
dkxls's Avatar
 
Armin
Join Date: Feb 2011
Location: Helsinki, Finland
Posts: 156
Rep Power: 19
dkxls will become famous soon enough
Typically, in a solver that solves an energy equation (e.g. rhoPimpleFoam), the temperature is defined in the thermo class (see basicThermo.H).
You can access the field like this
Code:
const volScalarField& T = thermo.T();
(see e.g. createFields.H in the reactingFoam)

So, if you didn't implement some extra volScalarField named "T" (not quite sure if it is even possible to define two fields with the same same in the object registry), you should also be able to get access to the same field by looking it up from the object registry like this
Code:
const volScalarField& T = mesh.lookupObject<volScalarField>("T");
Note that you only get a const access to "T" from "thermo.T()".
dkxls is offline   Reply With Quote

Old   February 12, 2019, 08:35
Default
  #3
Senior Member
 
Deep
Join Date: Oct 2017
Posts: 180
Rep Power: 8
deepbandivadekar is on a distinguished road
Quote:
Originally Posted by dkxls View Post
Note that you only get a const access to "T" from "thermo.T()".
Errr, what do you exactly mean by this? Can you please elaborate a little?
deepbandivadekar is offline   Reply With Quote

Old   February 12, 2019, 11:10
Default
  #4
New Member
 
gnompher
Join Date: Jun 2016
Posts: 6
Rep Power: 9
Mowgli is on a distinguished road
const is a data-type qualifier, which gives only read access within the current scope.

So, here T calculated from thermo object (returned using thermo.T() and depending on the thermophysical model chosen for the simulation) is passed by reference(&). One thus cannot change the value of T after that and is used for further computation. (Just in case you are wondering, return value of thermo.T() can be / is updated usually at the next step of computation) .

You can look up 'passing reference by const', this technique is used to save space by not creating a new object and also, not allowing code to modify it in that scope.
Mowgli is offline   Reply With Quote

Old   December 5, 2020, 03:39
Default
  #5
New Member
 
Gerhard
Join Date: Mar 2017
Posts: 26
Rep Power: 9
Gerhard is on a distinguished road
Hi,


I am using rhoPorousSimpleFoam and in a specified cell zone I want to modify the temperature. Looping through the cells in the cell zone, I basically want to do this:
Code:
if (alignedFlow)
{
    T[i] = T_upstream[i];
}
where alignedFlow is a check if the flow is in a certain direction an T_upstream is a temperature field which I defined (it is upstream of this cell zone I am talking about).


This code, upon compilation, gives an error (as expected) that I am trying to modify a const variable.
How can I gain access to the temperature field? In other words, I want to be able to modify the temperature in this cell zone.


Any advice will be much appreciated.
Gerhard is offline   Reply With Quote

Old   December 7, 2020, 02:11
Default
  #6
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
you can get rid of the const by using const_cast<volScalarField&>. you can convert a constant type to a non-constant type which can be modified.


However by doing this you get rid of a type safety. This is not done by be developer to annoy you but has a purpose.



In case of the temperature it as a dependent variable, i.e. you do not solve explicitly for the temperature. In most solvers you solve the energy equation (either enthalpy h or internal energy e depending on the choice of the user) and the temperature is calculated a thermodynamic relation.



For details see https://caefn.com/openfoam/temperature-calculation.


So before modifying the temperature be sure you are not messing around too much.
mAlletto is offline   Reply With Quote

Old   December 7, 2020, 08:31
Default
  #7
New Member
 
Gerhard
Join Date: Mar 2017
Posts: 26
Rep Power: 9
Gerhard is on a distinguished road
Thank you for that advice, Michael.
Perhaps a better approach would be to modify the temperature by introducing an energy source term into the specified cell zone to achieve T[i] = T_upstream[i].
I will give it some thought.
Gerhard 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
high-order difference in OpenFOAM rxgrch OpenFOAM Programming & Development 6 August 28, 2017 14:11
Periodic Boundary Condition for upwind difference yohey44 Main CFD Forum 0 October 27, 2010 13:10
[General] paraview - plotting difference to reference data joewe ParaView 0 August 30, 2010 18:01
Difference between scaled residuals and... Dieter FLUENT 0 April 28, 2006 17:52
Fininte difference and Finite element Technique Mahendra Singh Mehra FLUENT 3 December 22, 2005 23:49


All times are GMT -4. The time now is 11:20.