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

nuEff()()[patchI] and nuEff()

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By alexeym
  • 1 Post By alexeym
  • 1 Post By thomasArk47

Reply
 
LinkBack Thread Tools Display Modes
Old   March 8, 2016, 08:16
Default nuEff()()[patchI] and nuEff()
  #1
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,834
Blog Entries: 6
Rep Power: 32
Tobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Dear all,

I have a simple question about the following. In the fixedShearStress BC we find this:
Code:
    const label patchI = patch().index();

    const surfaceScalarField& phi =
        db().lookupObject<surfaceScalarField>(phiName_);

    scalarField nuEff;
    if (phi.dimensions() == dimVelocity*dimArea)
    {
        const incompressible::turbulenceModel& turbModel =
            db().lookupObject<incompressible::turbulenceModel>
            (
                "turbulenceModel"
            );

        nuEff = turbModel.nuEff()()[patchI];
    }
As far as I understand it, turbModel.nuEff()()[patchI] should return the values of each face at the patch [patchI]. Therefore the scalarField nuEff should have a size of the nFaces.

At least nuEff is empty:

Code:
nuEff
0()
If I output the nuEff() field like that:
Code:
Info<< turbModel.nuEff() << endl;
I get the list of all boundary's. So far so good. But the access to the patchI is somehow destroyed.

If I use this one, that is exactly the same, I get some complete different values:
Code:
        scalarField nuEff2(turbModel.nuEff()()[patch().index()]);

        Info<< "nuEff2: " << nuEff2 << endl;


Result:

nuEff2
124   (boundary has 500 faces)
(
6.91743e-310
2.3774e-316
4.24399e-314
2.34004e-316
8.3003e-321
4.74303e-322
.
.
.
And if I output it directly I get:
Code:
Info<< "nueff: " << turbModel.nuEff()()[patchI] << endl;


Result:

nueff: 124.601
In a programming point of view this makes not real sense to me (especially the first two):

Code:
        scalarField nuEff2(turbModel.nuEff()()[patch().index()]);
        nuEff = turbModel.nuEff()()[patchI];
Okay there are differences but the field "turbModel.nuEff()()[patchI]" has to be the same as "turbModel.nuEff()()[patch().index()]".

At least the BC will fail because we use nuEff to divide:
Code:
    operator==(tauHat*(tauHat & (tau0_*(1.0/(ry*nuEff)) + Uc)));
Any advice?


Finally, if we output the turbModel.nuEff() we get the correct values:
Code:
.
.
.

    movingWall
    {
        type            calculated;
        value           nonuniform List<scalar> 
500
(
0.285685
0.285685
0.285685
0.285685
0.285685
0.285685
0.285685
0.285685
.
.
.

I also made a bug report now because it seems really strange. http://openfoam.org/mantisbt/view.php?id=2020
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   March 8, 2016, 09:22
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,669
Rep Power: 27
alexeym will become famous soon enoughalexeym will become famous soon enough
Send a message via Skype™ to alexeym
Hi,

Maybe I am missing something but, turbulenceModel::nuEff() returns tmp<volScalarField>, so nuEff()() (http://foam.sourceforge.net/docs/cpp...2d975c8876d3d6) is volScalarField and nuEff()()[index] should be scalar.

Yet there is turbulenceModel::nuEff(label patchI), which returns viscosity on a patch.

Could you post whole code snippet (so it could be compiled and tested)?
alexeym is offline   Reply With Quote

Old   March 8, 2016, 09:41
Default
  #3
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,834
Blog Entries: 6
Rep Power: 32
Tobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hey Bruno,

thanks for the reference about ()() ... here is the link to the file.
If you are correct and ()()[patchI] returns a scalar, why we use a scalarField nuEff than and can you tell me what scalar is returned? Mean value of the patch or sth. like that?

http://www.openfoam.com/documentatio...36_source.html
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   March 8, 2016, 10:04
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,669
Rep Power: 27
alexeym will become famous soon enoughalexeym will become famous soon enough
Send a message via Skype™ to alexeym
Hi,

Not quite Bruno, but OK

Do you talk about line 112 of fixedShearStressFvPatchVectorField.C? It uses turbulenceModel::nuEff(label patchI), which returns tmp<scalarField> (http://www.openfoam.com/documentatio...4f85f6644d2d6a).
alexeym is offline   Reply With Quote

Old   March 8, 2016, 10:14
Default
  #5
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,834
Blog Entries: 6
Rep Power: 32
Tobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Aaa its version 3.0 Here it the file I was talking about...
Attached Files
File Type: gz fixedShearStress.tar.gz (5.7 KB, 5 views)
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   March 8, 2016, 10:17
Default
  #6
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,834
Blog Entries: 6
Rep Power: 32
Tobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Quote:
Originally Posted by alexeym View Post
Hi,

Not quite Bruno, but OK

Do you talk about line 112 of fixedShearStressFvPatchVectorField.C? It uses turbulenceModel::nuEff(label patchI), which returns tmp<scalarField> (http://www.openfoam.com/documentatio...4f85f6644d2d6a).
As I read
Code:
Return the effective viscosity on patch.
it is that i have a scalarField with the size of faces and each field stores one face value, am I right?
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   March 8, 2016, 10:31
Default
  #7
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,669
Rep Power: 27
alexeym will become famous soon enoughalexeym will become famous soon enough
Send a message via Skype™ to alexeym
You have scalarField with the size of the patch and it is has scalar for each face value.

Though BC uses this - turbModel.nuEff()()[patchI] - strange construction, turbulenceModel class has nuEff(label patchI) method even in 2.3.1.
Tobi likes this.

Last edited by alexeym; March 8, 2016 at 10:37. Reason: rephrasing
alexeym is offline   Reply With Quote

Old   March 8, 2016, 10:56
Default
  #8
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,834
Blog Entries: 6
Rep Power: 32
Tobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi,

Henry changed it: https://github.com/OpenFOAM/OpenFOAM...1fe57e8a140c7c

For 3.0.x it is working now but for 2.3.1 I get an error if I use the code you (or henry) mentioned:
Code:
fixedShearStress/fixedShearStressFvPatchVectorField.C: In member function 'virtual void Foam::fixedShearStressFvPatchVectorField::updateCoeffs()':
fixedShearStress/fixedShearStressFvPatchVectorField.C:136:55: error: no matching function for call to 'Foam::incompressible::turbulenceModel::nuEff(const label&) const'
       const scalarField& nuEff2(turbModel.nuEff(patchI));
                                                       ^
fixedShearStress/fixedShearStressFvPatchVectorField.C:136:55: note: candidate is:
In file included from fixedShearStress/fixedShearStressFvPatchVectorField.C:31:0:
/home/shorty/OpenFOAM/OpenFOAM-2.3.1/src/turbulenceModels/incompressible/turbulenceModel/turbulenceModel.H:199:37: note: virtual Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::incompressible::turbulenceModel::nuEff() const
         virtual tmp<volScalarField> nuEff() const = 0;
                                     ^
/home/shorty/OpenFOAM/OpenFOAM-2.3.1/src/turbulenceModels/incompressible/turbulenceModel/turbulenceModel.H:199:37: note:   candidate expects 0 arguments, 1 provided
fixedShearStress/fixedShearStressFvPatchVectorField.C:136:26: warning: unused variable 'nuEff2' [-Wunused-variable]
       const scalarField& nuEff2(turbModel.nuEff(patchI));
                          ^
So at last, there is no method for nuEff(label)
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   March 8, 2016, 11:47
Default
  #9
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,669
Rep Power: 27
alexeym will become famous soon enoughalexeym will become famous soon enough
Send a message via Skype™ to alexeym
Hi,

Even in 2.3.1 there are two types of turbulence models ones in src/turbulenceModels and another in src/TurbulenceModels (surprise, surprise). First type does not have nuEff(const label), second type has it and for RASModel it is implemented as:

Code:
        //- Return the effective viscosity on patch
        virtual tmp<scalarField> nuEff(const label patchi) const
        {
            return this->nut(patchi) + this->nu(patchi);
        }
nu(patchi) is implemented as (example from Newtonian.H):

Code:
        //- Return the laminar viscosity for patch
        tmp<scalarField> nu(const label patchi) const
        {
            return nu_.boundaryField()[patchi];
        }
nut(patchi) is implemented as (example from eddyViscosity.H):

Code:
        //- Return the turbulence viscosity on patch
        virtual tmp<scalarField> nut(const label patchi) const
        {
            return nut_.boundaryField()[patchi];
        }
so your (well, OpenFOAM's) quite frightening

Code:
nuEff = turbModel.nuEff()()[patchI]
could be in fact

Code:
scalarField nuEff(turbModel.nuEff().boundaryField()[patchI]);
Or you can use transportModel's ability to return nu for a given patch using

Code:
transport().nu(patchI)
so it would be

Code:
scalarField nuEff(transport().nu(patchI) + nut().boundaryField()[patchI]);
Tobi likes this.
alexeym is offline   Reply With Quote

Old   March 8, 2016, 12:58
Default
  #10
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,834
Blog Entries: 6
Rep Power: 32
Tobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi,

I will try it tomorrow but today I tried it with boundaryField() without success. Maybe I made a simple mistake. Thanks in advance.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   March 11, 2016, 08:08
Default
  #11
Senior Member
 
Join Date: Oct 2013
Posts: 380
Rep Power: 7
chriss85 is on a distinguished road
I think there might also be problems with memory management. You receive a tmp<volScalarField> without storing it, and only access the boundary. I had a similar issue before and for me it helped to initialize a copy of the volScalarField before accessing the patch values like this:

volScalarField copy(turb->nuEff());

Afterwards you can use the boundaries of the copied field without worrying about the scope of the classes contained in the temporary object. In my case I even regarded it as a bug or atleast a design error.
chriss85 is offline   Reply With Quote

Old   March 11, 2016, 08:29
Default
  #12
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,834
Blog Entries: 6
Rep Power: 32
Tobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hey,

thanks for the hint. At last the code has to be:
Code:
nuEff = turbModel.nuEff()().boundaryField()[patchI];
I think I will also make a copy (:
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   March 11, 2016, 19:16
Default strange things explained
  #13
Member
 
Thomas Boucheres
Join Date: May 2013
Posts: 41
Rep Power: 6
thomasArk47 is on a distinguished road
Hello Tobi.
First thanks for your tuto and videos. Good job which could help some people and help OF to be more widely used than it is

For your problem described here, Alexeym gave you good answer (using turbModel.nuEf()().boundaryField()[patchI]).

To complete the post, I can give you some answers to the "strange" things you have mentioned in your first post. All things are related to the fact that turbModel.nuEff()()[patchI] (which is clearly a bug) is a scalar as mentioned by alexeym.

A) What happens is the following:
scalarField nuEff
--> create a scalarField of size 0
nuEff = turbModel.nuEff()()[patchI]
--> it is the UList<Type>:perator =(Type& v) (with Type=scalar) which assign all values of the List to v. But do nothing here since nuEff is of size 0! So nuEff is still empty list and Info << nuEff gives 0().

B) Other thing: your "scalarField nuEff2(turbmodel.nuEff()()[patchI])"...
In fact, you try to construct a scalarField with a constructor scalarField (scalar& v)
But this constructor doesn't exist...
You have scalarField(label i, scalar v) (build a scalarField of size i and all values equal v) but clearly it is not this one you use. In fact, you use the base constructor scalarField(label i) which construct a scalarField of size i and no prescribed values (so compiler dependant / something like VSMALL for most compilers). And what is your i? The integer part of the scalar turbModel.nuEff()()[patchI] (124 for your example).

These things explain what you have seen.
Tobi likes this.
thomasArk47 is offline   Reply With Quote

Old   March 11, 2016, 20:32
Default
  #14
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,834
Blog Entries: 6
Rep Power: 32
Tobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Dear Thomas,

thanks for completing the topic and the feedback to my webpage. I am familiar with c++ but the error reported here was from a collegue in the german openfoam forum, that I just investigated during other investigations (: So at last I wanted to report you the bug, learn new things (thanks to you and Alexeym) but I did not investigate into the code deeply and of course I am not a FOAM - code expert (what function will return what or what is doing that). Its good that there are people like you that will clear the questions.

So just one question. If I will create my scalarField nuEff with the size of the real field (lets say 200), and use
Code:
nuEff = turbModel.nuEff()()[patchI]
will it work? I could test it but its 01:32 a.m. and I am too tierd (:

Nice dreams,
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   March 12, 2016, 16:30
Default
  #15
Member
 
Thomas Boucheres
Join Date: May 2013
Posts: 41
Rep Power: 6
thomasArk47 is on a distinguished road
Well if you write:

"
scalarField nuEff(200) // create a scalarField with size 200 (not yet inialized here)
....
nuEff = turbModel.nuEff()()[patchI] // assign all values of the scalarField as equal to the scalar on the right; comes from UList:perator =(scalar &v); doesn't change the size of the container as said in th previous post
"

at end, all the 200 values of the nuEff list will be equal to the same scalar value turbModel.nuEff()()[patchI]. It takes sense from informatic point of view but it is clearly not what you want I think. You should prefer the scalarField nuEff being equal to the scalarField turbModel.nuEff()().boundaryField()[patchI]. For this, you must use alexeym correct expression:

"
scalarField nuEff // create zero sized List (size doesn't matter here -- see later)
nuEff = turbModel.nuEff()().boundaryField()[patchI] // it is the UList:perator =(UList& f) function. This function resizes the calling list (nuEff here) to the size of the called one (f in the prototype / turbModel..... in the example -- this is why the instanciation of nuEff as a zero sized list doesn't matter) and equals the values.
"
thomasArk47 is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating divDevReff jposunz OpenFOAM Running, Solving & CFD 65 May 29, 2017 04:45
Add new nuEff() law to simpleFoam T.D. OpenFOAM Running, Solving & CFD 2 July 16, 2015 07:27
Calculate and display eddy viscosity ceyrows OpenFOAM Running, Solving & CFD 4 February 16, 2009 13:57


All times are GMT -4. The time now is 21:05.