|
[Sponsors] |
December 4, 2013, 07:39 |
difference between thermo.T() and T
|
#1 |
New Member
Join Date: Feb 2012
Posts: 25
Rep Power: 14 |
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"); |
|
December 4, 2013, 08:45 |
|
#2 |
Senior Member
Armin
Join Date: Feb 2011
Location: Helsinki, Finland
Posts: 156
Rep Power: 19 |
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(); 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"); |
|
February 12, 2019, 08:35 |
|
#3 |
Senior Member
Deep
Join Date: Oct 2017
Posts: 180
Rep Power: 8 |
||
February 12, 2019, 11:10 |
|
#4 |
New Member
gnompher
Join Date: Jun 2016
Posts: 6
Rep Power: 9 |
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. |
|
December 5, 2020, 03:39 |
|
#5 |
New Member
Gerhard
Join Date: Mar 2017
Posts: 26
Rep Power: 9 |
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]; } 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. |
|
December 7, 2020, 02:11 |
|
#6 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15 |
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. |
|
December 7, 2020, 08:31 |
|
#7 |
New Member
Gerhard
Join Date: Mar 2017
Posts: 26
Rep Power: 9 |
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. |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
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 |