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

How to access nu and nut values for a Turbulent Solver

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By suman91

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 20, 2016, 06:33
Default How to access nu and nut values for a Turbulent Solver
  #1
Member
 
Suman Chakraborty
Join Date: Sep 2014
Location: Mumbai, India
Posts: 42
Rep Power: 11
suman91 is on a distinguished road
Hi there,

I am currently running a flow over backward facing step (using LES) in OpenFAOM 2.4.0. I want access to the kinematic viscosity. So in a ".H" file which I include in pisoFoam.C, I write the following just to see if I have access to nu (kinematic viscosity) value:

Code:
double k_viscosity;
const scalarField& nuCells = nu().internalField();
forAll(mesh.cells(), celli)
{
    k_viscosity = nuCells[celli];;
    Info<< "nu = " << k_viscosity << endl;
}
But during compiling i get error: "error: ‘nu’ was not declared in this scope"

I also want to access the nut values calculated by the solver. Is there a function to access it ?

Thanks in advance.
suman91 is offline   Reply With Quote

Old   September 21, 2016, 06:59
Default
  #2
Senior Member
 
Join Date: Sep 2013
Posts: 353
Rep Power: 20
Bloerb will become famous soon enough
There is no volScalarField called nu. nu is part of the turbulence model because most of those use calculate an effective viscosity by adding a turbulent one. This is the nut file. Check those on how to access it. The correct way should be
turbulence->nu() and turbulence->nut() for the turbulent viscosity
Bloerb is offline   Reply With Quote

Old   September 21, 2016, 07:19
Default
  #3
Member
 
Suman Chakraborty
Join Date: Sep 2014
Location: Mumbai, India
Posts: 42
Rep Power: 11
suman91 is on a distinguished road
Hi,

Thank you for the reply. Will turbulence->nu() return a double value? I was trying out this command only and got an error like :

"Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ to ‘double’ in initialization"

Just by printing using:
Info<<"\n nu value is"<<turbulence->nu();


I get output:

nu value is dimensions [0 2 -1 0 0 0 0];

internalField uniform 0.00035714;

How to access only the scalar value ?

Last edited by suman91; September 21, 2016 at 07:28. Reason: Update:
suman91 is offline   Reply With Quote

Old   September 21, 2016, 08:19
Default
  #4
Member
 
Suman Chakraborty
Join Date: Sep 2014
Location: Mumbai, India
Posts: 42
Rep Power: 11
suman91 is on a distinguished road
Hi again,

Able to access nu().

The "createFields.H" file had a line:

singlePhaseTransportModel laminarTransport(U, phi);

So it is creating an object named laminartransport of type singlePhaseTransportModel

Inside singlePhaseTransportModel.H, there sits a member function

virtual tmp<volScalarField> nu() const;

So if I write:
Code:
const volScalarField k_viscosity = laminarTransport.nu();
double viscosity;
forAll(mesh.cells(), celli)
{
    viscosity = k_viscosity[celli];
    Info<< "\ncell number in list = " << celli << endl;
    Info<< "nu = " << viscosity << endl;
}
Then am getting the nu value for each cell.
elham usefi likes this.
suman91 is offline   Reply With Quote

Old   September 21, 2016, 08:53
Default
  #5
Member
 
Suman Chakraborty
Join Date: Sep 2014
Location: Mumbai, India
Posts: 42
Rep Power: 11
suman91 is on a distinguished road
Better approach:
Using the turbulenceModel object to access the viscosity rather than singlePhaseTransportModel.
Code:
const volScalarField k_viscosity = turbulence->nu(); double viscosity; forAll(mesh.cells(), celli) {     viscosity = k_viscosity[celli];     Info<< "\ncell number in list = " << celli << endl;     Info<< "nu = " << viscosity << endl; }
Similar process can be used to access nut():
Code:
const volScalarField nu_t = turbulence->nut();
forAll(mesh.cells(), celli)
{
    Info<< "nut = " << nu_t[celli] << endl;
}
suman91 is offline   Reply With Quote

Old   December 18, 2018, 09:20
Default
  #6
Member
 
Amir
Join Date: Jan 2017
Posts: 32
Rep Power: 9
albet is on a distinguished road
Hello,
I am calculating nut from two different ways, but the values are different. Could anybody explain why they give me different values please?

1.
volScalarField nu_t (turbulence -> nut());

2.
volScalarField& nut = const_cast<volScalarField&>
(mesh.lookupOblect<volScalarField>("nut"));


Regards,
Amir
albet is offline   Reply With Quote

Old   December 18, 2018, 20:50
Default
  #7
New Member
 
Weiliang Zhu
Join Date: Apr 2016
Posts: 11
Rep Power: 11
zwlwf is on a distinguished road
Quote:
Originally Posted by albet View Post
Hello,
I am calculating nut from two different ways, but the values are different. Could anybody explain why they give me different values please?

1.
volScalarField nu_t (turbulence -> nut());

2.
volScalarField& nut = const_cast<volScalarField&>
(mesh.lookupOblect<volScalarField>("nut"));


Regards,
Amir
Hello albet,

In my opinion, the first one calls a copy constructor, which just copy the value of nut. This means the nu_t is an different object with nu, the second is a referrence to nut itself. During the simulation, the nu with be updated with time, so they may have different value.
zwlwf is offline   Reply With Quote

Old   December 19, 2018, 05:30
Default
  #8
Member
 
Amir
Join Date: Jan 2017
Posts: 32
Rep Power: 9
albet is on a distinguished road
Quote:
Originally Posted by zwlwf View Post
Hello albet,

In my opinion, the first one calls a copy constructor, which just copy the value of nut. This means the nu_t is an different object with nu, the second is a referrence to nut itself. During the simulation, the nu with be updated with time, so they may have different value.

Many thanks for your reply.
I used these methods in every iteration of my simulation to have access to nut. Could you please let me know which one gives me the correct nut in every iteration?
Kind regards,
Amir
albet is offline   Reply With Quote

Old   December 19, 2018, 05:36
Default
  #9
New Member
 
Weiliang Zhu
Join Date: Apr 2016
Posts: 11
Rep Power: 11
zwlwf is on a distinguished road
I think the second one is what you want.

and I think if you write the first one as :
Code:
volScalarField& nu_t  = turbulence -> nut();
these two way should have same result.
zwlwf is offline   Reply With Quote

Old   December 19, 2018, 06:17
Default
  #10
Member
 
Amir
Join Date: Jan 2017
Posts: 32
Rep Power: 9
albet is on a distinguished road
Quote:
Originally Posted by zwlwf View Post
I think the second one is what you want.

and I think if you write the first one as :
Code:
volScalarField& nu_t  = turbulence -> nut();
these two way should have same result.
Many thanks. You are right!
based on the error I received, I think this form is correct:

Code:
const volScalarField& nu_t  = turbulence -> nut();
Kind regards,
Amir
albet 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



All times are GMT -4. The time now is 04:09.